class SINDyModel

class deeptime.sindy.SINDyModel(library, coefficients, input_features, intercept=0)

The SINDy model. Stores the parameters learned by a SINDy estimator to encode a first order differential equation model for the measurement data. It can be used to make derivative predictions, simulate forward in time from initial conditions, and for self-scoring.

The model encodes a dynamical system

\[\dot{X} = \Theta(X)\Xi \]

via the following correpondences library = \(\Theta\) and (intercept, coefficients) = \(\Xi^\top\).

Parameters:
  • library (library object) – The feature library, \(\Theta\). It is assumed that this object has already been fit to the input data. The object should implement transform() and get_feature_names_out() methods.

  • coefficients (np.ndarray, shape (n_input_features, n_output_features)) – Coefficients giving the linear combination of basis functions to approximate derivative data, i.e. \(\Xi^\top\). Note that coefficients may or may not contain information about the intercepts depending on the library used (e.g. a polynomial library can contain the constant function).

  • input_features (iterable of str) – List of input feature names.

  • intercept (float, optional, default=0) – The intercept/bias for the learned model. If the library already contains a constant function, there is no need for an intercept term.

Attributes

coefficients

Returns the learned model coefficients, i.e. \(\Xi^\top\).

intercept

Returns the intercept (bias) for the learned model.

Methods

copy()

Makes a deep copy of this model.

equations([precision])

Get the right-hand sides of the learned equations.

get_params([deep])

Get the parameters.

predict(x)

Predict the derivative of x using the learned model, i.e. predict \(\dot{X}\) via \(\dot{X} \approx \Theta(X)\Xi\).

print([lhs, precision])

Print the learned equations in a human-readable way.

score(x[, y, t, scoring])

Compute a score for the time derivative prediction produced by the model.

set_params(**params)

Set the parameters of this estimator.

simulate(x0, t[, integrator, integrator_kws])

Simulate the SINDy model forward in time.

transform(x)

Apply the functions of the feature library.

copy() Model

Makes a deep copy of this model.

Returns:

A new copy of this model.

Return type:

copy

equations(precision=3)

Get the right-hand sides of the learned equations.

Parameters:

precision (int, optional, default=3) – Precision to which coefficients are rounded.

Returns:

equations – List of model equations, with one for each input variable.

Return type:

list of strings, length (n_input_features)

get_params(deep=False)

Get the parameters.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

predict(x)

Predict the derivative of x using the learned model, i.e. predict \(\dot{X}\) via \(\dot{X} \approx \Theta(X)\Xi\).

Parameters:

x (np.ndarray, shape (n_samples, n_input_features)) – Measurement data.

Returns:

y – Model prediction of the derivative \(\dot{X}\).

Return type:

np.ndarray, shape (n_samples, n_input_features)

print(lhs=None, precision=3)

Print the learned equations in a human-readable way.

Parameters:
  • lhs (list of strings, optional, default=None) – List of variables to print on the left-hand side of the equations. By default self.input_features are used.

  • precision (int, optional, default=3) – Precision to be used when printing out model coefficients.

score(x, y=None, t=None, scoring=<function r2_score>, **scoring_kws)

Compute a score for the time derivative prediction produced by the model.

Parameters:
  • x (np.ndarray, shape (n_samples, n_input_features)) – Measurement data.

  • y (np.ndarray, shape (n_samples, n_input_features), optional, default=None) – Array of derivatives of x. By default, np.gradient is used to compute the derivatives.

  • t (np.ndarray, shape (n_samples,) or a scalar, optional, default=None) – The times when the measurements in x were taken or the (uniform) time spacing between measurements in x. By default a timestep of 1 is assumed. This argument is ignored if y is passed.

  • scoring (callable, optional, default=r2_score) – Function by which to score the prediction. By default, the R^22 coefficient of determination is computed. See Scikit-learn for more options.

Returns:

s – Score for the time derivative prediction.

Return type:

float

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

object

simulate(x0, t, integrator=<function odeint>, integrator_kws=None)

Simulate the SINDy model forward in time.

Parameters:
  • x0 (numpy array, size [n_features]) – Initial condition from which to simulate.

  • t (int or numpy array of size [n_samples]) – If the model is in continuous time, t must be an array of time points at which to simulate. If the model is in discrete time, t must be an integer indicating how many steps to predict.

  • integrator (callable, optional (default odeint)) – Function to use to integrate the system. Default is scipy.integrate.odeint.

  • integrator_kws (dict, optional (default None)) – Optional keyword arguments to pass to the integrator

Returns:

x – Simulation results.

Return type:

numpy array, shape (n_samples, n_features)

transform(x)

Apply the functions of the feature library.

This method computes \(\Theta(X)\).

Parameters:

x (np.ndarray, shape (n_samples, n_input_features)) – Measurement data.

Returns:

y – The feature library evaluated on x, i.e. \(\Theta(X)\).

Return type:

np.ndarray, shape (n_samples, n_output_features)

property coefficients

Returns the learned model coefficients, i.e. \(\Xi^\top\)

Returns:

coefficients – Learned model coefficients \(\Xi^\top\).

Return type:

np.ndarray, shape (n_input_features, n_output_features)

property intercept

Returns the intercept (bias) for the learned model.

Returns:

intercept – The intercept or intercepts for each input feature.

Return type:

np.ndarray, shape (n_input_features,) or float