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 12 commits into
base: develop
Choose a base branch
from
Open

Milstein function #615

wants to merge 12 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

  • I have performed a self-review of my code
  • The code conforms to the style used in this package
  • The code is fully documented and typed (type-checked with Mypy)
  • 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.

examples/plot_langevin_dynamics.py Outdated Show resolved Hide resolved
examples/plot_langevin_dynamics.py Outdated Show resolved Hide resolved
examples/plot_langevin_dynamics.py Outdated Show resolved Hide resolved
examples/plot_langevin_dynamics.py Outdated Show resolved Hide resolved
examples/plot_langevin_dynamics.py Outdated Show resolved Hide resolved
skfda/datasets/_samples_generators.py Outdated Show resolved Hide resolved
skfda/datasets/_samples_generators.py Outdated Show resolved Hide resolved
skfda/datasets/_samples_generators.py Outdated Show resolved Hide resolved
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.

skfda/tests/test_milstein.py Outdated Show resolved Hide resolved
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.

First, I apologize for taking so long on reviewing this PR. I had a lot of work to do and very few time to dedicate to this.

I hope I will have more time now, so if you are busy and/or do not want to make the changes to merge this PR, just tell me and I will try to make them on my own and merge it.

# Using Milstein's method to compute SDE solutions
# ---------------------------------------------------
#
# Apart from func:`~skfda.datasets.make_sde_trajectories`, scikit-fda also
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
# Apart from func:`~skfda.datasets.make_sde_trajectories`, scikit-fda also
# Apart from :func:`~skfda.datasets.make_sde_trajectories`, scikit-fda also

Also, now they are in the same function.

# does not depend on the value of :math:`\mathbf{X}`, then both methods
# Euler Maruyama and Milstein are equivalent. In this section we show how
# to use the former function for SDEs where the diffusion term does depend
# :math:`X`.
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
# :math:`X`.
# on :math:`X`.

stop: float = 1.0,
diffusion_matricial_term: bool = True,
random_state: RandomStateLike = None,
) -> FDataGrid:
r"""Numerical integration of an Itô SDE using the Euler-Maruyana scheme.
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
r"""Numerical integration of an Itô SDE using the Euler-Maruyana scheme.
r"""Numerical integration of an Itô SDE.

(Not true anymore)

density=True,
label="Empirical pdf",
)
ax[1].plot(
Copy link
Member

Choose a reason for hiding this comment

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

It would be cool to paint this vertically on the right, to match what happens in the other plot. Not mandatory, though.

np.exp(grid_points * mu),
linewidth=2,
label="theoretical mean",
color='b',
Copy link
Member

Choose a reason for hiding this comment

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

Why do you use single quotes sometimes? I think it is better to stick with double quotes.

raise ValueError(
"Invalid initial conditions. Each of the starting points "
"must be a flat array.",
raise ValueError("Method for computing SDEs not implemented")
Copy link
Member

Choose a reason for hiding this comment

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

Include the method name for a better debugging experience.

times: NDArrayFloat,
random_state: np.random.RandomState,
) -> FDataGrid:
r"""Numerical integration of an Itô SDE using the Euler-Maruyana scheme.
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
r"""Numerical integration of an Itô SDE using the Euler-Maruyana scheme.
r"""Numerical integration of an Itô SDE using the Milstein scheme.

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.

2 participants