pysindy icon indicating copy to clipboard operation
pysindy copied to clipboard

added SINDy library input option to WeakPDELibrary

Open znicolaou opened this issue 1 year ago • 7 comments

As a partial response to issue #351 and discussion #429 here, I'm adding an option to replace the library_functions and function_names input of WeakPDELibrary with library, which is an existing instance of BaseFeatureLibrary. I've only tested so far on the first example in the example notebook 12, which reproduces the previous result:

import numpy as np
import pysindy as ps
from scipy.integrate import solve_ivp
from pysindy.utils import lorenz

# Generate measurement data
dt = 0.002
t_train = np.arange(0, 10, dt)
t_train_span = (t_train[0], t_train[-1])
u0_train = [-8, 8, 27]
u_train = solve_ivp(
    lorenz, t_train_span, u0_train, t_eval=t_train
).y.T

# Define weak form ODE library
# defaults to derivative_order = 0 if not specified,
# and if spatial_grid is not specified, defaults to None,
# which allows weak form ODEs.
poly_lib = ps.PolynomialLibrary(
    degree=2,
    include_bias=False
)

ode_lib2 = ps.WeakPDELibrary(
    library=poly_lib,
    spatiotemporal_grid=t_train,
    is_uniform=True,
    K=100,
)


# Instantiate and fit the SINDy model with the integral of u_dot
model = ps.SINDy(feature_library=ode_lib2, optimizer)
model.fit(u_train)
model.print()

I'd also like to take some time to look through the PDE example notebooks to clean them up and make sure deprecated input has been removed, so I'm making this a draft for now. If anyone has other suggestions on modifications to the weak/pde input or functionality, this is a good chance. I may also look into #222 if it isn't a huge headache.

znicolaou avatar Nov 29 '23 00:11 znicolaou