Note
Go to the end to download the full example code.
2D limit cycle — nonlinear overdamped inference¶
A noisy oscillator: a radial force pulls the system onto the unit circle while a constant angular drift turns it around — a non-equilibrium steady state with a circulating probability current. From one trajectory, we recover the full nonlinear force field with a generic cubic dictionary, check it with residual diagnostics and simulations of the inferred model, and then repeat the inference on positions blurred by localisation noise.
Tags
synthetic · overdamped · nonlinear · non-equilibrium · 2D
stamp_output()
[Generated: 2026-10-18 18:23]
The system¶
In polar coordinates the drift is \(\dot r = r(1 - r^2)\), \(\dot\theta = \omega\); in Cartesian coordinates the force reads
with \(\omega = 2\) (period \(\pi\)) and isotropic noise \(D = 0.1\). We record 200 time units — about 64 turns — at \(\Delta t = 0.05\).
from SFI.bases import named_scalars, ones_basis, unit_axes, x_components
from SFI.langevin import OverdampedProcess
# The true force, written symbolically:
# F = (1 - r^2) (x e_x + y e_y) + omega (x e_y - y e_x), r^2 = x^2 + y^2
x, y = x_components(2)
ex, ey = unit_axes(2)
one = ones_basis(2)
(omega_p,) = named_scalars(omega=2.0)
F_true = (one - (x * x + y * y)) * (x * ex + y * ey) + omega_p * (x * ey - y * ex)
D0, dt, Nsteps = 0.1, 0.05, 4_000
proc = OverdampedProcess(F_true, D=jnp.eye(2) * D0)
proc.initialize(jnp.array([0.5, 0.0]))
coll = proc.simulate(dt=dt, Nsteps=Nsteps, key=random.PRNGKey(0), prerun=5000, oversampling=20)
Inference and sparse selection¶
A cubic polynomial dictionary in \((x, y)\) offers 20 candidate
terms; the true force uses 8. The data are noise-free and the drift per
step is large compared with the noise, so we estimate the diffusion with
"WeakNoise" and use the "clean" preset of the linear force
estimator; PASTIS then selects the terms.
from SFI import OverdampedLangevinInference
from SFI.bases import monomials_up_to
B = monomials_up_to(order=3, dim=2, include_constant=True, rank="vector")
inf = OverdampedLangevinInference(coll)
inf.compute_diffusion_constant(method="WeakNoise")
inf.infer_force_linear(B, preset="clean")
inf.sparsify_force(criterion="PASTIS")
inf.compute_force_error()
inf.compare_to_exact(model_exact=proc, maxpoints=2000)
inf.print_report()
--- StochasticForceInference Report ---
Average diffusion tensor:
[[ 0.1006882 -0.0014048 ]
[-0.0014048 0.10216548]]
Measurement noise tensor:
[[-0.00485671 -0.00024895]
[-0.00024895 -0.00476173]]
Force estimated information: 2095.8720703125
Force: estimated normalized mean squared error (sampling only): 0.0019085138880055336
Force Gram condition number: 80.8
Normalized MSE (force): 0.0017
Normalized MSE (diffusion): 0.0004
Force Coefficient Table
─────────────────────────────────────────────────────────────────────
# Label Coefficient Std.Err SNR Sig
─────────────────────────────────────────────────────────────────────
2 x0·e0 1.13881e+00 1.45093e-01 7.8 *
3 x0·e1 2.03314e+00 4.49433e-02 45.2 **
4 x1·e0 -1.94517e+00 4.42806e-02 43.9 **
5 x1·e1 9.05424e-01 1.38879e-01 6.5 *
12 x0^3·e0 -1.02404e+00 1.18844e-01 8.6 *
15 (x0^2·x1)·e1 -1.03951e+00 1.52218e-01 6.8 *
16 (x0·x1^2)·e0 -1.14151e+00 1.54966e-01 7.4 *
19 x1^3·e1 -9.12634e-01 1.12611e-01 8.1 *
─────────────────────────────────────────────────────────────────────
8/20 basis functions in support, sig: 8* / 2** / 0*** (|SNR| ≥ 2 / 10 / 100)
(Std.err. reflects sampling error only; discretization bias is not included.)
Zeroed (12): 1·e0, 1·e1, x0^2·e0, x0^2·e1, (x0·x1)·e0, (x0·x1)·e1, x1^2·e0, x1^2·e1, x0^3·e1, (x0^2·x1)·e0, (x0·x1^2)·e1, x1^3·e0
The Pareto front (left) jumps with the two rotation terms, climbs more gently as the six radial terms enter, and is flat beyond: PASTIS keeps exactly the eight true terms, each within about one error bar of its true value (right). In space, the inferred field (gold arrows) matches the exact one where the data are; the error map (right) shows the reconstruction error growing only towards the corners, outside the explored region.
Diagnostics¶
diagnose() tests the
standardised residuals of the fit: they should be i.i.d.
\(\mathcal{N}(0, 1)\), with a realised error consistent with the
predicted one.
report = inf.diagnose()
report.print_summary()
=== SFI diagnostics report ===
backend : linear
regime : OD
n_obs : 3999 n_particles: 1 d: 2
level : standard
-- Residuals --
mean = +0.0133 std = 0.9777 skew = +0.007 kurt-3 = +0.010 (n=7998)
✓ normality ks stat=0.0136 p=0.103
✓ autocorr ljung_box stat=20 p=0.456
✓ autocorr ljung_box_squared stat=22.7 p=0.303
predicted NMSE = 0.00191 χ²-excess NMSE = 0.0146 (≤ 0.049 at 95%) χ² z = +0.71 (|z|>5 ⇒ bias)
-- Finite sampling interval --
dt*|grad F| rms = 0.189 p99 = 0.303 (w.r.t. x, 4000 points) verdict: coarse
-- Flags --
! [finite_dt] dt*|grad F| = 0.189 (p99 0.303): coarse sampling — O(Δt) biases of a few to tens of per cent — confirm with the parametric estimator (infer_force) or a stride-2 subsample
All residual tests pass. The finite_dt flag notes that
\(\Delta t\,|\nabla F|\) is not small, so the linear estimates carry
an \(O(\Delta t)\) bias; here it stays below the sampling error,
since the realised error is consistent with its prediction.
Simulating the inferred model¶
simulate_bootstrapped_trajectory()
runs the inferred force and diffusion from the first recorded point.
The movie plays the data and the simulation side by side over the
inferred flow lines (first 25 time units): same radius, same rotation
speed, same jitter.
coll_boot, _ = inf.simulate_bootstrapped_trajectory(random.PRNGKey(123), oversampling=20)
Robustness: localisation noise¶
Tracked positions carry a localisation error. We add Gaussian noise of
standard deviation \(\sigma = 0.08\) to every position — almost the
size of the diffusive step \(\sqrt{2D\Delta t} = 0.1\). The linear
estimator with its default settings is compared with the parametric
estimator infer_force(),
which models the noise explicitly (profiling its amplitude
\(\Lambda = \sigma^2\) jointly with \(D\)) and integrates the
flow over each interval. PASTIS runs on both.
coll_noisy = coll.degrade(noise=0.08, seed=1)
inf_lin = OverdampedLangevinInference(coll_noisy)
inf_lin.compute_diffusion_constant()
inf_lin.infer_force_linear(B)
inf_lin.sparsify_force(criterion="PASTIS")
inf_lin.compute_force_error()
inf_lin.compare_to_exact(force_exact=proc.force_sf, data_exact=coll, maxpoints=2000)
inf_par = OverdampedLangevinInference(coll_noisy)
inf_par.infer_force(B)
inf_par.sparsify_force(criterion="PASTIS")
inf_par.compute_force_error()
inf_par.compare_to_exact(force_exact=proc.force_sf, data_exact=coll, maxpoints=2000)
for name, fit in [("linear (default)", inf_lin), ("parametric", inf_par)]:
D_hat = np.diag(np.asarray(fit.diffusion_average))
sigma_hat = np.sqrt(np.maximum(np.diag(np.asarray(fit.Lambda)), 0.0))
print(f"{name:17s} terms kept = {len(fit.force_support):2d} "
f"D = {D_hat.round(3)} σ = {sigma_hat.round(3)} "
f"force NMSE vs truth = {fit.NMSE_force:.4f} (predicted {fit.force_predicted_MSE:.4f})")
print("truth terms = 8 D = [0.1 0.1] σ = [0.08 0.08]")
linear (default) terms kept = 4 D = [0.243 0.242] σ = [0.045 0.041] force NMSE vs truth = 0.0298 (predicted 0.0024)
parametric terms kept = 8 D = [0.107 0.097] σ = [0.08 0.081] force NMSE vs truth = 0.0015 (predicted 0.0022)
truth terms = 8 D = [0.1 0.1] σ = [0.08 0.08]
The default linear estimator is overwhelmed: localisation noise inflates its diffusion estimate and hides the weak radial terms, so PASTIS keeps only the strongest ones and the realised error far exceeds the predicted one — the signature of a bias. The parametric estimator recovers the eight true terms, both \(D\) and \(\sigma\), and a force error at its predicted, sampling-limited level, as on clean data.
Takeaways¶
A generic cubic dictionary plus PASTIS finds the eight terms of the limit cycle, with error bars and a predicted error that the comparison with the truth confirms.
Residual diagnostics and simulations of the inferred model validate the fit without reference to the truth.
When positions are noisy, switch to the parametric estimator: it separates localisation noise from diffusion and keeps the force unbiased.
Thumbnail¶
Dedicated single-panel figure for the gallery thumbnail.
Total running time of the script: (3 minutes 14.527 seconds)