pysindy.BINDy
- class pysindy.BINDy(sigma_x: float, optimizer: EvidenceGreedy | None = None, feature_library: BaseFeatureLibrary | None = None, differentiation_method: FiniteDifference | None = None)[source]
Bayesian Identification of Nonlinear Dynamical Systems (BINDy)
Learns a dynamical model with corrections for measurement noise passing through differentiation and feature library. Maximizes a Gaussian (Laplace) approximation of the posterior with a weakly informed hyper prior on the feature coefficients, then greedily eliminates model features to maximize Bayesian evidence.
For more information, see this paper: https://doi.org/10.1098/rspa.2024.0200 .
See also
SBRA Bayesian optimizer that uses a more sophisticated sparsifying prior and Monte Carlo sampling. Slower but more accurate.
EnsembleOptimizerModel sparsification by b(r)agging. Empirically approximating Bayesian method.
- Parameters:
(required) (sigma_x) –
Measurement noise standard deviation (std) for the state measurements
x. Ifx_dotis provided,sigma_xis used to set the noise varianceoptimizer._sigma2 = sigma_x**2.Otherwise,
sigma_xis propagated through thedifferentiation_methodto estimate the derivative noise variance:_sigma2 = TemporalNoisePropagation( differentiation_method, t_grid, sigma_x )
For multiple trajectories,
_sigma2is computed per trajectory and averaged.
- optimizer
Optimization method used to fit the SINDy model. This must be a class extending
pysindy.optimizers.BaseOptimizer. The default ispysindy.optimizers.EvidenceGreedy.- feature_library
Feature library object used to specify candidate right-hand side features. This must be a class extending
pysindy.feature_library.base.BaseFeatureLibrary. The default option ispysindy.feature_library.PolynomialLibrary.- differentiation_method
Method for differentiating the data. This must be a class extending
pysindy.differentiation.base.BaseDifferentiationclass. It must also be a linear method. The default option is centered finite differences.
- Attributes:
model (
sklearn.pipeline.Pipeline) – The fitted SINDy model pipeline.n_input_features_ (int) – The total number of input features.
n_output_features_ (int) – The total number of output features.
n_control_features_ (int) – The total number of control input features.
feature_names (list of str or None) – Names for the input features.
Notes
Noise propagation from measurement noise
sigma_xto the derivative noise variance used by the regression (optimizer._sigma2) is only performed when:x_dotis not provided, and derivatives are estimated internally.differentiation_methodis linear (e.g.,FiniteDifferenceorSmoothedFiniteDifference).
Spectral differentiation is currently not supported for noise propagation.
FiniteDifference is strongly recommended for EvidenceGreedy because the noise propagation algorithm assumes a linear differential operator. If you use a different differentiator, set
optimizer._sigma2manually.
Examples
>>> import numpy as np >>> from scipy.integrate import odeint >>> import pysindy as ps >>> from pysindy.differentiation import FiniteDifference >>> from pysindy.optimizers import EvidenceGreedy >>> >>> def lorenz(z, t): ... x, y, z_ = z ... return [10.0 * (y - x), x * (28.0 - z_) - y, x * y - 8.0 / 3.0 * z_] >>> >>> t = np.arange(0, 10, 0.01) >>> x0 = np.array([-8.0, 8.0, 27.0]) >>> sigma_x = 0.01 >>> x = odeint(lorenz, x0, t) >>> x = x + sigma_x * np.random.normal(size=x.shape) # add noise >>> dt = t[1] - t[0] >>> >>> model = ps.BINDy(sigma_x=sigma_x) # You MUST specify sigma_x >>> model.fit(x, t=dt) >>> model.print()
Methods
Fit an BINDy model.
Configure whether metadata should be requested to be passed to the
fitmethod.Configure whether metadata should be requested to be passed to the
predictmethod.Configure whether metadata should be requested to be passed to the
scoremethod.Attributes
feature_libraryoptimizerfeature_names- fit(x, t, x_dot=None, u=None, feature_names: list[str] | None = None)[source]
Fit an BINDy model.
See
pysindy.SINDy.fitfor full parameter documentation.
- set_fit_request(*, feature_names: bool | None | str = '$UNCHANGED$', t: bool | None | str = '$UNCHANGED$', u: bool | None | str = '$UNCHANGED$', x: bool | None | str = '$UNCHANGED$', x_dot: bool | None | str = '$UNCHANGED$') BINDy
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
feature_names (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
feature_namesparameter infit.t (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
tparameter infit.u (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
uparameter infit.x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
xparameter infit.x_dot (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x_dotparameter infit.
- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, u: bool | None | str = '$UNCHANGED$', x: bool | None | str = '$UNCHANGED$') BINDy
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
u (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
uparameter inpredict.x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
xparameter inpredict.
- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, metric: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$', t: bool | None | str = '$UNCHANGED$', u: bool | None | str = '$UNCHANGED$', x: bool | None | str = '$UNCHANGED$', x_dot: bool | None | str = '$UNCHANGED$') BINDy
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
metricparameter inscore.sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.t (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
tparameter inscore.u (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
uparameter inscore.x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
xparameter inscore.x_dot (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x_dotparameter inscore.
- Returns:
self – The updated object.
- Return type:
object