Note
Go to the end to download the full example code.
Velocity-dependent noise — underdamped multiplicative diffusion¶
Recover a velocity-dependent diffusion field \(D(v)\) for an inertial particle, from positions only. Many active and driven systems fluctuate harder the faster they move — motility noise, flight-force fluctuations, turbulent drag. Underdamped SFI reconstructs the unobserved velocity and infers \(F(x,v)\) and \(D(x,v)\) jointly; here the noise amplitude grows several-fold across the explored speeds. We fit \(D\) on a generic polynomial basis, let PASTIS pick the noise model, cross-check with the likelihood-based estimator, and close on the regime where velocity-dependent noise becomes genuinely hard.
Tags
synthetic · underdamped · multiplicative-noise · sparsity · 1D
stamp_output()
[Generated: 2026-10-18 18:42]
Model and simulation¶
A damped harmonic oscillator whose bath kicks grow with speed:
in the Itô convention: the force SFI infers is the Itô drift of
the velocity equation. Both fields are composed from coordinate
primitives — note the velocity primitive v entering the diffusion.
import SFI
from SFI.bases import identity_matrix_basis, unit_axes, v_components, x_components
from SFI.langevin import UnderdampedProcess
k = 1.0 # stiffness
gamma = 1.0 # friction
D0 = 0.3 # diffusion at rest
vc = 1.0 # velocity scale of the noise growth
dt = 0.01
Nsteps = 80_000
(x,) = x_components(1)
(v,) = v_components(1)
(ex,) = unit_axes(1)
I = identity_matrix_basis(1)
F_model = (-k * x - gamma * v) * ex # Itô drift of dv
D_model = D0 * (1.0 + (v / vc) ** 2) * I # D(v) — multiplicative in v
proc = UnderdampedProcess(F=F_model, D=D_model,
theta_F=jnp.ones(F_model.n_features),
theta_D=jnp.ones(D_model.n_features))
proc.initialize(jnp.array([0.0]), v0=jnp.array([0.0]))
coll = proc.simulate(dt=dt, Nsteps=Nsteps, key=random.PRNGKey(5),
prerun=500, oversampling=20)
print(f"Trajectory: {coll.T} frames, dt={dt} (positions only)")
Trajectory: 80000 frames, dt=0.01 (positions only)
Phase portrait¶
Velocity is not observed. For this plot only we estimate it by central finite differences; the inference engine does its own reconstruction and never needs it. Fast excursions (top and bottom) are noticeably noisier than slow ones.
Inference¶
The data are clean positions, so the linear underdamped sequence
applies, with the clean-data estimators chosen explicitly (the
WeakNoise diffusion constant and the clean force preset; the
automatic choice would also guard against measurement noise, which
these synthetic data do not have).
infer_force_linear()
fits the Itô drift \(F(x,v)\), then
infer_diffusion_linear()
fits \(D(x,v)\) on a polynomial basis in both variables
(include_v=True) spanning \(\{1, x, v, x^2, xv, v^2\}\). Only
\(1\) and \(v^2\) should carry weight. Both fields come with
predicted standard errors.
from SFI.bases import monomials_up_to
B_force = monomials_up_to(order=1, dim=1, include_v=True, rank="vector")
B_diff = monomials_up_to(order=2, dim=1, include_v=True, rank="symmetric_matrix")
D_labels = list(B_diff.labels)
inf = SFI.UnderdampedLangevinInference(coll)
inf.compute_diffusion_constant(method="WeakNoise")
inf.infer_force_linear(B_force, preset="clean")
inf.compute_force_error()
inf.infer_diffusion_linear(B_diff)
inf.compute_diffusion_error()
inf.compare_to_exact(model_exact=proc)
F_true = {"x0·e0": -k, "v0·e0": -gamma}
D_true = {"1·S00": D0, "v0^2·S00": D0 / vc**2}
print(f"NMSE vs truth: force {float(inf.NMSE_force):.4f}, diffusion {float(inf.NMSE_diffusion):.4f}")
print("Force F(x, v):")
for lbl, c, e in zip(B_force.labels, np.asarray(inf.force_coefficients_full),
np.asarray(inf.force_coefficients_stderr)):
print(f" {lbl:>8} = {c:+.4f} ± {e:.4f} (true {F_true.get(lbl, 0.0):+.2f})")
print("Diffusion D(x, v):")
for lbl, c, e in zip(D_labels, np.asarray(inf.diffusion_coefficients),
np.asarray(inf.diffusion_coefficients_stderr)):
print(f" {lbl:>8} = {c:+.4f} ± {e:.4f} (true {D_true.get(lbl, 0.0):+.2f})")
NMSE vs truth: force 0.0058, diffusion 0.0004
Force F(x, v):
1·e0 = +0.0188 ± 0.0326 (true +0.00)
x0·e0 = -0.9251 ± 0.0494 (true -1.00)
v0·e0 = -1.0702 ± 0.0517 (true -1.00)
Diffusion D(x, v):
1·S00 = +0.2975 ± 0.0053 (true +0.30)
x0·S00 = -0.0070 ± 0.0062 (true +0.00)
v0·S00 = +0.0040 ± 0.0133 (true +0.00)
x0^2·S00 = +0.0104 ± 0.0060 (true +0.00)
(x0·v0)·S00 = +0.0057 ± 0.0156 (true +0.00)
v0^2·S00 = +0.3011 ± 0.0172 (true +0.30)
The two true terms dominate and the four others are small.
Selecting the noise model¶
sparsify_diffusion()
turns “small” into a decision: a PASTIS search over subsets of the six
candidate terms, scored by the likelihood of the diffusion fit in the
metric of its own sandwich covariance;
compute_diffusion_error()
then gives the covariance of the selected model.
inf.sparsify_diffusion(criterion="PASTIS")
inf.compute_diffusion_error() # covariance of the selected model
print("selected diffusion terms:")
for i, c, e in zip(np.asarray(inf.diffusion_support), np.asarray(inf.diffusion_coefficients),
np.asarray(inf.diffusion_coefficients_stderr)):
lbl = D_labels[i]
tv = D_true.get(lbl, 0.0)
# format option "z": a deviation rounding to zero prints as +0.0, not -0.0
print(f" {lbl:>8} = {c:+.4f} ± {e:.4f} (true {tv:+.2f}, off by {(c - tv) / e:+z.1f}σ)")
selected diffusion terms:
1·S00 = +0.3000 ± 0.0051 (true +0.30, off by +0.0σ)
v0^2·S00 = +0.3058 ± 0.0153 (true +0.30, off by +0.4σ)
Left: the Pareto front of the diffusion fit — the information gain jumps when \(1\) and \(v^2\) enter and is flat afterwards, so PASTIS stops at two terms. Right: the selected coefficients divided by their true values, with ±2σ error bars.
Recovered diffusion profile¶
Evaluating the inferred tensor along the velocity axis recovers the parabolic noise profile (band: ±2σ predicted, from the covariance of the selected coefficients); a constant-\(D\) analysis would report only the mean.
# The inferred tensor as a callable on phase-space points [x, v]; sweeping the
# v axis (x held at 0) recovers the parabolic noise profile.
def D_inferred(pts):
pts = jnp.asarray(pts)
return inf.diffusion_inferred(pts[:, :1], v=pts[:, 1:2]) # (N, 1, 1)
def D_exact(pts):
v = np.asarray(pts)[:, 1]
return D0 * (1 + (v / vc) ** 2)
# Band on the v axis at x = 0, from the covariance of the selected
# coefficients (coeff_block embeds it in the full basis order).
v_grid = np.linspace(float(v_rec.min()), float(v_rec.max()), 200)
feats = np.asarray(B_diff(jnp.zeros((200, 1)), v=jnp.asarray(v_grid[:, None])))[:, 0, 0, :]
C_D, Cov_D = inf.coeff_block(slice(None), field="diffusion")
D_mid = feats @ C_D
D_band = np.sqrt(np.einsum("ti,ij,tj->t", feats, Cov_D, feats))
The parametric route¶
The parametric estimators fit the same fields by maximising the
likelihood of the observed positions (and would also absorb
localisation noise or coarse sampling).
infer_diffusion()
returns its coefficients with error bars from the inverse Fisher
information of that likelihood, and the same
sparsify_diffusion()
call selects the terms, then re-fits the selected model exactly.
inf_par = SFI.UnderdampedLangevinInference(coll)
inf_par.infer_force(B_force)
inf_par.infer_diffusion(B_diff)
inf_par.sparsify_diffusion(criterion="PASTIS")
inf_par.compute_diffusion_error()
print("parametric, selected diffusion terms:")
for i, c, e in zip(np.asarray(inf_par.diffusion_support), np.asarray(inf_par.diffusion_coefficients),
np.asarray(inf_par.diffusion_coefficients_stderr)):
lbl = D_labels[i]
tv = D_true.get(lbl, 0.0)
print(f" {lbl:>8} = {c:+.4f} ± {e:.4f} (true {tv:+.2f}, off by {(c - tv) / e:+z.1f}σ)")
parametric, selected diffusion terms:
1·S00 = +0.2995 ± 0.0021 (true +0.30, off by -0.3σ)
v0^2·S00 = +0.3133 ± 0.0063 (true +0.30, off by +2.1σ)
Both routes select the same two terms, and their coefficients agree with each other within the error bars; the parametric \(v^2\) coefficient lands about two of its own standard errors above the truth (printed above), at the edge of its ±2σ bar. Agreement between two estimators built on different principles is itself a useful check on real data, where the truth is unknown.
When is this hard?¶
Velocity-dependent noise has a genuinely hard regime. With \(D(v) \propto v^2\) at large speed, the velocity distribution develops power-law tails — for a free particle the stationary density decays as \(|v|^{-(2 + \gamma/D_0)}\). If friction is weak relative to the noise gradient, rare high-speed bursts dominate the statistics, and no finite sampling rate resolves them — estimates of the noise floor \(D_0\) then degrade no matter how small \(\Delta t\) is. Here \(\gamma/D_0 \approx 3.3\) keeps the tails integrable and the inference quantitative, yet the reconstructed speeds are already visibly heavier-tailed than a Gaussian of the same variance (below). For strongly driven systems, prefer saturating noise models (e.g. \(D_0 + \Delta D\, v^2/(v^2 + v_s^2)\)).
Thumbnail¶
Dedicated single-panel figure for the gallery thumbnail.
Total running time of the script: (2 minutes 35.438 seconds)