Python implementation of SINDy-PI (Sparse Identification of Nonlinear Dynamics with Parallel Implicit models) applied to a compound double pendulum with viscous friction.
SINDy-PI discovers governing equations directly from time-series data — including systems with rational structure that standard SINDy cannot handle. The double pendulum is a natural test case because its mass matrix coupling produces equations with angle-dependent denominators.
From 10 seconds of simulation data, SINDy-PI recovers the dominant dynamics with 5 sparse terms per equation and <1% one-step prediction error:
The shared
- Simulate the double pendulum to generate training, test, and validation datasets
- Build a candidate library of 39 terms: trig functions, velocity products, and acceleration-coupled terms
- Parallel implicit regression: each library term is tested as a candidate left-hand side, with STLS (Sequential Thresholded Least Squares) finding sparse coefficients
- Model selection: sweep sparsification thresholds, score on held-out test data
- Refinement: prune noise-level coefficients and re-fit
- Validation: simulate the discovered ODE from an unseen initial condition
| Metric | phi1_ddot | phi2_ddot |
|---|---|---|
| Active terms (of 39) | 5 | 5 |
| One-step prediction error | 0.53% | 0.78% |
| Trajectory error @ 1s | 0.46% | 1.47% |
| Trajectory error @ 3s | 14.9% | 11.5% |
Short-term trajectory agreement is excellent; divergence beyond ~3s is expected for chaotic systems (Lyapunov instability). The notebook includes energy conservation checks, phase portraits, and lambda sweep diagnostics.
conda create -n sindy python numpy scipy matplotlib sympy pandas -y
conda activate sindy
jupyter notebook SINDy_PI_Double_Pendulum.ipynb- Kaheman, K., Kutz, J.N., & Brunton, S.L. (2020). SINDy-PI: a robust algorithm for parallel implicit sparse identification of nonlinear dynamics. Proceedings of the Royal Society A.
- Original MATLAB implementation: github.com/dynamicslab/SINDy-PI