Solvers#21
Merged
Merged
Conversation
Introduce heun_maruyama_method: a fixed-step predictor-corrector integrator for SDEs (Heun–Maruyama) with shared Wiener increments, offering improved strong/weak convergence for additive noise. The function builds a time grid, handles RNG defaulting to numpy's default_rng, validates noise_func output shape against the state, and returns a Solution(t, y). Also update the module docstring to list Heun-Maruyama among available integrators.
Introduce a Milstein fixed-step integrator for SDEs (paleobeasts.utils.solver.milstein_method) with element-wise finite-difference approximation of ∂g/∂y, RNG handling, and Milstein correction for diagonal diffusion. Wire the new solver into PBModel (accept 'milstein' as a method, validate dt for fixed-step methods, create RNG from random_seed, and call milstein_method with sde_noise fallback). Update docstring guidance to describe SDE solver choices and when to prefer Milstein (multiplicative noise). Add comprehensive tests (paleobeasts/tests/test_utils_solver_sde.py) covering structural behavior, reproducibility, and convergence comparisons against Euler-Maruyama and Heun-Maruyama.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds two new stochastic differential equation (SDE) solvers, Heun-Maruyama and Milstein, to the PaleoBeasts modeling framework. These solvers offer improved accuracy for SDE integration, especially for models with additive or multiplicative noise. The integration interface and documentation are updated accordingly, and comprehensive tests are included to ensure correctness, reproducibility, and convergence.
New SDE solvers and integration support:
heun_maruyama_methodandmilstein_methodtopaleobeasts/utils/solver.py, providing higher-order strong convergence for SDEs. Heun-Maruyama achieves strong order 1.0 for additive noise, and Milstein achieves strong order 1.0 for multiplicative noise using a finite-difference approximation, requiring no analytic Jacobian. Both methods include detailed docstrings and error handling.PBModel.integrateinpaleobeasts/core/pbmodel.pyto support the new methods via themethodargument, with improved documentation explaining solver selection and requirements. [1] [2] [3]Testing and validation:
test_utils_solver_sde.pycovering structural correctness, reproducibility (random seed behavior), and convergence order of the new SDE solvers. Tests verify output shapes, error handling, and that the new solvers outperform Euler-Maruyama as expected.Documentation improvements:
paleobeasts/utils/solver.pyto reflect the new solvers and their mathematical properties, including guidance for modelers on when to use each method. [1] [2]These changes significantly enhance the modeling capabilities for stochastic systems, particularly in climate and paleobiological applications.