Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.When the rule of motion includes chance
Some systems never follow the same path twice. A speck of pollen in water is kicked around by molecules; a protein flips between shapes now and then; a satellite’s drag changes with unpredictable bursts of solar activity. Their rules of motion contain a steady part, the drift, and a random part whose strength we call the diffusion. A neural stochastic differential equation learns both from data. A model with only the steady part would settle down and miss the random jumps. The demo simulates noisy paths and recovers the drift and noise strength from them.
Molecular dynamics, financial risk models and stochastic weather parameterisations all simulate stochastic differential equations; learned versions are used to model cloud processes and turbulence in climate models.
- 1. The random part of an SDE is described by its…
- 2. A model with only a drift will…
- 3. A neural SDE learns…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- SDE: dX = μ(X, t)dt + g(X, t)dW, with W a Brownian motion (A4-4-4): independent Gaussian increments ΔW ~ N(0, Δt). Itô calculus (A4-4-5) adds the term ½g²f″ to the chain rule.
- Simulation:
- Euler–Maruyama: X_(k+1) = X_k + μΔt + g√Δt Z, strong order ½, weak order 1.
- Milstein: adds ½gg′(ΔW² − Δt), strong order 1; identical to Euler–Maruyama for additive noise.
- Strong error measures pathwise accuracy against the same Brownian path; weak error measures accuracy of expectations.
- Learning: for short intervals, ΔX | X ~ N(μ(X)Δt, g(X)²Δt). Maximising this likelihood gives drift by regression of ΔX/Δt and squared diffusion by regression of the squared residuals divided by Δt. With sparse observations, latent SDEs (Li et al., 2020) use variational inference; neural SDEs as GANs (Kidger et al., 2021) match distributions of paths.
- Gradients: the stochastic adjoint (Li et al., 2020) reuses the noise path backward; torchsde and diffrax implement it.
- Related: score-based diffusion models (H7-3) run a learned reverse-time SDE; Fokker–Planck equations describe how the density of X evolves.
- 1. Euler–Maruyama's strong order is…
- 2. For additive noise, Milstein…
- 3. For short intervals, ΔX given X is approximately…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Simulating SDEs and measuring convergence
Exercise 1.
- Euler–Maruyama and Milstein for geometric Brownian motion, driven by shared Brownian increments, against the exact solution.
- Strong errors at five step sizes and the observed order from a log–log fit.
- Ornstein–Uhlenbeck mean and variance checked against the exact formulas.
Practice.
- Check the scheme on a solvable SDE (Ornstein–Uhlenbeck, geometric Brownian motion) before using it on a learned one.
- Match the likelihood to the sampling interval: Euler–Maruyama likelihoods are biased when Δt is not small compared with the system’s time scales; use finer simulation between observations, latent SDEs or simulation-based inference (J7-2).
- Keep the diffusion positive by learning log g or softplus(g), and floor it.
- Validate distributions, not single paths: compare histograms, autocorrelations and transition rates against data, and against the variation between two runs of the true process.
- Tools: torchsde (sdeint, sdeint_adjoint), diffrax (JAX), StochasticDiffEq.jl.
import torch, torchsde
class SDE(torch.nn.Module):
noise_type, sde_type = "diagonal", "ito"
def __init__(self):
super().__init__()
self.mu = torch.nn.Sequential(torch.nn.Linear(1, 32), torch.nn.Tanh(), torch.nn.Linear(32, 1))
self.logg = torch.nn.Sequential(torch.nn.Linear(1, 32), torch.nn.Tanh(), torch.nn.Linear(32, 1))
def f(self, t, x): return self.mu(x) # drift
def g(self, t, x): return torch.exp(self.logg(x)) # diffusion, kept positive
sde = SDE()
paths = torchsde.sdeint(sde, x0, ts, method="euler", dt=0.01) # shape (len(ts), batch, 1)- 1. A Python library for neural SDEs in PyTorch:
- 2. To keep the diffusion positive, learn…
- 3. Learned SDEs should be validated by comparing…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Strong orders. For Euler–Maruyama the local error contains the term ½gg′(ΔW² − Δt), which has mean zero but standard deviation of order Δt per step; over 1/Δt steps these add like a random walk to O(√Δt), so the strong order is ½. Milstein includes this term, leaving errors of order Δt. In Exercise 1 the observed orders were 0.49 and 0.96.
Why coarse sampling biases the estimates. The Euler–Maruyama likelihood treats E[ΔX | x] as μ(x)Δt and Var[ΔX | x] as g²Δt. Near a stable state the process relaxes at a rate κ (here κ = 2 at x = ±1), so over an interval Δt the true conditional mean change is (1 − e^(−κΔt))/κ · μ(x) and the variance is g²(1 − e^(−2κΔt))/(2κ). Both grow more slowly than Δt; dividing by Δt underestimates drift and diffusion when κΔt is not small. With Δt = 0.5 and g = 0.5 the variance formula gives σ̂ ≈ 0.33, matching the 0.34 found near the well in Exercise 2.
Noise is part of the physics. In the double well, transitions between ±1 happen only because noise pushes paths over the barrier; their rate scales like exp(−2ΔV/σ²) with barrier height ΔV = ¼ (Kramers’ law). A drift-only model has no transitions, and its histogram collapses to two spikes. A learned SDE reproduces the bimodal distribution, though transition rates estimated from 20 paths are themselves noisy.
- 1. Euler–Maruyama's strong order is ½ because…
- 2. With coarse sampling, Euler–Maruyama estimates of drift are…
- 3. Kramers' law says the transition rate scales like…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Can drift and diffusion be learned from observed paths, and what goes wrong when observations are sparse?
History.
- K. Itô (1944) built stochastic integrals; G. Maruyama (1955) analysed the Euler scheme for SDEs; G. Milstein (1974) added the correction term for strong order 1.
- H. Kramers (1940) derived escape rates over barriers in noisy systems.
- X. Li, T.-K. L. Wong, R. T. Q. Chen and D. Duvenaud (2020) introduced the stochastic adjoint and latent SDEs; P. Kidger et al. (2021) trained neural SDEs as GANs.
- Y. Song et al. (2021) formulated score-based generative models as SDEs (H7-3).
Exercise 2. Double well dX = (X − X³)dt + 0.5dW. Data: 20 paths of length 50 (Euler–Maruyama with Δt = 0.005), observed every Δt = 0.01, 0.1 or 0.5. Model: drift and squared diffusion as combinations of nine Gaussian bumps, fitted by the Euler–Maruyama moment equations. The learned SDE and a drift-only ODE are simulated like the data. Histogram distance is the L1 distance between normalised histograms; two runs of the true SDE differ by 0.17.
| drift at 1.5 | σ at 0 | σ at 1 | switches per unit time | histogram distance | |
|---|---|---|---|---|---|
| truth | −1.875 | 0.5 | 0.5 | 0.038 | — |
| learned, Δt = 0.01 | −1.87 | 0.51 | 0.5 | 0.03 | 0.08 |
| learned, Δt = 0.1 | −1.35 | 0.51 | 0.46 | 0.022 | 0.14 |
| learned, Δt = 0.5 | −0.75 | 0.57 | 0.34 | 0.023 | 0.2 |
| drift-only ODE | — | 0 | 0 | 0 | 1.45 |
- Fine sampling recovered both functions. The drift and noise level matched to within 2%.
- Coarse sampling biased them as the theory predicts: drift and near-well diffusion shrank. The bimodal histogram was still reproduced (distance 0.2, near the 0.17 between two runs of the true process).
- Without noise the model was qualitatively wrong: no transitions and a distribution of two spikes.
- Distribution statistics are noisy: all learned-SDE histogram distances were close to the 0.17 between two runs of the true process, and switch counts came from only a few dozen transitions.
- Seeds 1 and 2: with Δt = 0.01, drift at 1.5 was −1.8 and −2.01, σ at 0 was 0.5 and 0.5; with Δt = 0.5, −0.81 and −0.75, σ at 1 0.34 and 0.36; the drift-only ODE’s histogram distances were 1.48 and 1.44.
Stochastic dynamics in science and engineering
- Molecular dynamics: coarse-grained models learn effective drift and noise for slow variables such as protein folding coordinates.
- Climate: stochastic parameterisations of clouds and convection add learned noise to deterministic models, improving ensemble spread.
- Space weather and orbits: stochastic models of atmospheric density give realistic uncertainty in satellite drag and conjunction risk (J9).
- Generative AI: diffusion models generate images, molecules and weather fields by integrating a learned reverse SDE.
References
- X. Li, T.-K. L. Wong, R. T. Q. Chen and D. Duvenaud (2020). “Scalable gradients for stochastic differential equations.” AISTATS.
- P. Kidger, J. Foster, X. Li and T. Lyons (2021). “Neural SDEs as infinite-dimensional GANs.” ICML.
- P. E. Kloeden and E. Platen (1992). Numerical Solution of Stochastic Differential Equations. Springer.
- H. A. Kramers (1940). “Brownian motion in a field of force and the diffusion model of chemical reactions.” Physica.
- Y. Song et al. (2021). “Score-based generative modeling through stochastic differential equations.” ICLR.