pysnape¶
pysnape estimates the unknown coefficients of a differential equation from measured data. You give it the equation as you would write it on paper, with the coefficients you do not know left as names, and the measurements; it returns the coefficients, the smooth signal behind the measurements, and how sure the estimates are.
It never differentiates the noisy data, and it needs no initial or boundary conditions. It represents each measured field as a B-spline and fits the spline and the equation's coefficients together, which is the SNAPE method (SimultaNeous basis function Approximation and Parameter Estimation).
It works for ordinary and partial differential equations, linear or nonlinear, one equation or several sharing coefficients: an oscillator, a chain of masses and springs, Burgers' or the Korteweg–de Vries equation, a 2-D wave.
Install¶
pip install pysnape
Optional extras:
pip install "pysnape[plot]"forFit.plot()and the example notebooks;pip install "pysnape[sparse]"for CHOLMOD, a sparse solver many times faster on large problems. It needs the SuiteSparse library first:brew install suite-sparseon macOS,sudo apt install libsuitesparse-devon Debian or Ubuntu. pysnape works without it.
The latest development version: pip install git+https://github.com/sutanubhowmick/pysnape.
In thirty seconds¶
import pysnape as ps
from pysnape.data.generators import ode
# a Van der Pol oscillator, measured with 20 % noise
data = ode.vanderpol(t_end=20.0, n=1001, mu=2.0).add_noise(percent=20, seed=2)
result = ps.fit(
"x_tt + th1*x_t + th2*x**2*x_t + th3*x = 0",
data,
unknowns={"th1": 5.0, "th2": 5.0, "th3": 5.0},
multistart=False,
)
print(result.theta) # th1 = -2.06, th2 = 2.06, th3 = 1.02; the truth is (-2, 2, 1)
Where next¶
- Getting started: your own data, reading the result, how sure it is.
- Writing equations: what an equation may contain.
- Data: grids, noise, files, published datasets.
- Ready-made models: the systems of the SNAPE papers and more.
- How the solver works: the basis, the equation weight, speed and accuracy.
- Uncertainty: ensembles and the bootstrap.
- Examples: five notebooks, from an oscillator to published data.
- API reference.
Citing¶
The SNAPE method is described in two papers:
- S. Bhowmick, S. Nagarajaiah and A. Kyrillidis, "Data- and theory-guided learning of partial differential equations using SimultaNeous basis function Approximation and Parameter Estimation (SNAPE)", Mechanical Systems and Signal Processing 189 (2023). doi:10.1016/j.ymssp.2022.110059
- S. Bhowmick and S. Nagarajaiah, "Physics-guided identification of Euler–Bernoulli beam PDE model from full-field displacement response with SimultaNeous basis function Approximation and Parameter Estimation (SNAPE)", Engineering Structures 289 (2023). doi:10.1016/j.engstruct.2023.116231
pysnape's solver, Nested, is known in statistics as profiled estimation: J. O. Ramsay,
G. Hooker, D. Campbell and J. Cao, "Parameter estimation for differential equations: a
generalized smoothing approach", Journal of the Royal Statistical Society B 69(5) (2007).