Simulating SINDy-PI generated model of a higher dimensional ODE #234
-
Hello I am trying to model a 2D ODE system using SINDy-PI with a PDE library to get models in the form of Calling The system I am working on: And some of my beginning code: import numpy as np
from scipy.integrate import solve_ivp
import pysindy as ps
import sympy as sp
# system definition
a, b = 2, 1
beta, gamma = 2, 2
dudt = lambda u, v: -u + (a / (1+v**beta))
dvdt = lambda u, v: -v + (b / (1+u**gamma))
netswitch = lambda t, x: np.array([dudt(x[0], x[1]), dvdt(x[0], x[1])])
var = ['u', 'v']
integrator_keywords = {}
integrator_keywords['rtol'] = 1e-12
integrator_keywords['method'] = 'LSODA'
integrator_keywords['atol'] = 1e-12
# training data creation
r = len(var) # appears to be # of var in example (x0, x1, x2,...)
dt = 0.01
T = 20
t = np.arange(0, T + dt, dt)
t_span = (t[0], t[-1])
netswitch0_train = np.random.random(r) * 5
netswitch_train = solve_ivp(netswitch, t_span, netswitch0_train, t_eval=t, **integrator_keywords).y.T
library_functions = [
lambda x: x,
lambda x, y: x * y,
lambda x: x ** 2,
lambda x, y: x * y ** 2,
lambda x: x ** 3,
lambda x, y: x * y ** 3,
lambda x: x ** 4
]
x_dot_library_functions = [lambda x: x]
library_function_names = [
lambda x: x,
lambda x, y: x + y,
lambda x: x + x,
lambda x, y: x + y + y,
lambda x: x + x + x,
lambda x, y: x + y + y + y,
lambda x: x + x + x + x
]
pde_library = ps.PDELibrary(
library_functions=library_functions,
temporal_grid=t,
function_names=library_function_names,
include_bias=True,
implicit_terms=True,
derivative_order=1,
include_interaction=False#,
#interaction_only=False
)
sindy_opt = ps.SINDyPI(
threshold=1e-6,
tol=1e-8,
thresholder="l1",
max_iter=20000,
)
model = ps.SINDy(
optimizer=sindy_opt,
feature_library=pde_library,
differentiation_method=ps.FiniteDifference(drop_endpoints=True)
)
model.fit(netswitch_train, t=dt)
model.print() |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
What equations do you find with your model? The analytic equations look like they can be written x0_dot = f0(x0, x1). You can also choose library terms such that x1_dot is not in the library for the x0_dot equation. Since you are doing SINDy-PI with PDEs, the newest main branch of PySINDy actually uses the PDELibrary for this (https://github.com/dynamicslab/pysindy/blob/master/examples/9_sindypi_with_sympy.ipynb) and this probably a better way to go. |
Beta Was this translation helpful? Give feedback.
-
Also for clarification, |
Beta Was this translation helpful? Give feedback.
What equations do you find with your model? The analytic equations look like they can be written x0_dot = f0(x0, x1). You can also choose library terms such that x1_dot is not in the library for the x0_dot equation. Since you are doing SINDy-PI with PDEs, the newest main branch of PySINDy actually uses the PDELibrary for this (https://github.com/dynamicslab/pysindy/blob/master/examples/9_sindypi_with_sympy.ipynb) and this probably a better way to go.