Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Milstein function #615

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Milstein function #615

wants to merge 4 commits into from

Conversation

psotom
Copy link
Contributor

@psotom psotom commented Jun 12, 2024

References to issues or other PRs

Describe the proposed changes

Added milstein function which computes the Milstein scheme for Stochastic Differential Equations (SDEs). Additionally, examples which show the functionality of the SDE solvers are added.

Additional information

Checklist before requesting a review

  • [x ] I have performed a self-review of my code
  • [] The code conforms to the style used in this package
  • [x ] The code is fully documented and typed (type-checked with Mypy)
  • [x ] I have added thorough tests for the new/changed functionality

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.90%. Comparing base (73161f7) to head (9ba66a5).
Report is 30 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #615      +/-   ##
===========================================
+ Coverage    86.65%   86.90%   +0.24%     
===========================================
  Files          156      158       +2     
  Lines        13322    13568     +246     
===========================================
+ Hits         11544    11791     +247     
+ Misses        1778     1777       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@vnmabus vnmabus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to do a quick review, so that you can incorporate the feedback before your presentation, but I did not review the math nor the code/tests correctness.

# %%
# Langevin dynamics is a mathematical model used to describe the behaviour of
# particles in a fluid, particularly in the context of statistical mechanic
# and molecular dynamics. It’s named after Paul Langevin a French physicist.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# and molecular dynamics. It’s named after Paul Langevin a French physicist.
# and molecular dynamics. It’s named after Paul Langevin, a French physicist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it named after him? I think the sentence is incomplete without that information.

# a probability distribution: a 2-d Gaussian mixture.
#
# Langevin dynamics enable us to sample from probability distributions from
# which a non-normalised pdf is known. This is possible thanks to the use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# which a non-normalised pdf is known. This is possible thanks to the use
# which a non-normalised pdf is known. This is possible thanks to the use

Comment on lines +71 to +72
# of :math:`N` Gaussians of mean :math:`\mu_n` and covarianze matrix
# :math:`\Sigma_n`. For the sake of simplicity, we will suppose the covarianze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# of :math:`N` Gaussians of mean :math:`\mu_n` and covarianze matrix
# :math:`\Sigma_n`. For the sake of simplicity, we will suppose the covarianze
# of :math:`N` Gaussians of mean :math:`\mu_n` and covariance matrix
# :math:`\Sigma_n`. For the sake of simplicity, we will suppose the covariance

#
# .. math::
#
# \nabla_x \log p(\mathbf{x}).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it does suddenly take a vector as input?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be always a vector. I will change it.

# \nabla_\mathbf{x} \log p(\mathbf{x}) = \nabla_\mathbf{x} \log q(\mathbf{x})
# - \nabla_\mathbf{x} \log Z = \nabla_\mathbf{x} \log q(\mathbf{x}),
#
# which is known. Once we know the score function, we can sample from the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to split the paragraph here.

Suggested change
# which is known. Once we know the score function, we can sample from the
# which is known.
#
# Once we know the score function, we can sample from the

... )

References:
Paromita Banerjee, Brynjarsdottir Jenny, Gurarie David, and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For references we are using the sphinxcontrib-bibtex functionality, in particular its footbibliography functionality.


References:
Paromita Banerjee, Brynjarsdottir Jenny, Gurarie David, and
Albert Jeffrey. Numerical Methods for Stochastic Differential Equations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to reference an article (if there is any) than a thesis, both in term of correctness (an article has been peer-reviewed, while in a thesis there can be less scrutiny) and easiness of finding the relevant information (an article is much shorter and to-the-point).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't found any article about the Milstein L=0 method apart from this thesis. Alberto has checked the thesis and he has told me that it is probably correct as the institution has high quality standards. However, there is almost no literature about the Milstein method for multidimensional data. Most people use it for one-dimensional SDEs.

with lower order of convergence.

Examples:
Example of the use of milstein for a 1-d Geometric Brownian motion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Example of the use of milstein for a 1-d Geometric Brownian motion
Example of the use of Milstein's method for a 1-d Geometric Brownian motion

and Postintervention in Structural Equation Models. PhD thesis, USA,
2020. AAI29605510
"""
random_state = validate_random_state(random_state)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have the bandwidth now to check for code correctness in depth. I will assume that Alberto has reviewed the code and tests with you thoroughly. If that is not true, please let me now to recheck it later before merging.

@@ -0,0 +1,337 @@
"""Tests of milstein."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Tests of milstein."""
"""Tests of Milstein's method."""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants