pysindy.optimizers.SR3
- class pysindy.optimizers.SR3(reg_weight_lam=0.005, regularizer='L0', relax_coeff_nu=1.0, tol=1e-05, trimming_fraction=0.0, trimming_step_size=1.0, max_iter=30, copy_X=True, initial_guess=None, normalize_columns=False, verbose=False, unbias=False)[source]
Sparse relaxed regularized regression.
Attempts to minimize the objective function
\[0.5\|y-Xw\|^2_2 + \lambda R(u) + (0.5 / \nu)\|w-u\|^2_2\]where \(R(u)\) is a regularization function. See the following references for more details:
Zheng, Peng, et al. “A unified framework for sparse relaxed regularized regression: SR3.” IEEE Access 7 (2018): 1404-1423.
Champion, K., Zheng, P., Aravkin, A. Y., Brunton, S. L., & Kutz, J. N. (2020). A unified sparse optimization framework to learn parsimonious physics-informed models from data. IEEE Access, 8, 169259-169271.
- Parameters:
reg_weight_lam (float or np.ndarray[float], shape (n_targets, n_features) optional (default 0.005)) –
Determines the strength of the regularization. When the regularization function R is the l0 norm, the regularization is equivalent to performing hard thresholding. Use the method calculate_l0_weight to calculate the weight from the threshold.
When using weighted regularization, this is the array of weights for each library function coefficient. Each row corresponds to a measurement variable and each column to a function from the feature library. Recall that SINDy seeks a matrix \(\Xi\) such that \(\dot{X} \approx \Theta(X)\Xi\).
reg_weight_lam[i, j]should specify the weight to be used for the (j + 1, i + 1) entry of \(\Xi\). That is to say it should give the weight to be used for the (j + 1)st library function in the equation for the (i + 1)st measurement variable.regularizer (string, optional (default 'L0')) – Regularization function to use. Currently implemented options are ‘L0’ (L0 norm), ‘L1’ (L1 norm) and ‘L2’ (L2 norm). Note by ‘L2 norm’ we really mean the squared L2 norm, i.e. ridge regression
relax_coeff_nu (float, optional (default 1)) – Determines the level of relaxation. Decreasing nu encourages w and v to be close, whereas increasing nu allows the regularized coefficients v to be farther from w.
tol (float, optional (default 1e-5)) – Tolerance used for determining convergence of the optimization algorithm.
trimming_fraction (float, optional (default 0.0)) – Fraction of the data samples to trim during fitting. Should be a float between 0.0 and 1.0. If 0.0, trimming is not performed.
trimming_step_size (float, optional (default 1.0)) – Step size to use in the trimming optimization procedure.
max_iter (int, optional (default 30)) – Maximum iterations of the optimization algorithm.
initial_guess (np.ndarray, shape (n_features) or (n_targets, n_features), optional (default None)) – Initial guess for coefficients
coef_. If None, least-squares is used to obtain an initial guess.normalize_columns (boolean, optional (default False)) – Normalize the columns of x (the SINDy library terms) before regression by dividing by the L2-norm. Note that the ‘normalize’ option in sklearn is deprecated in sklearn versions >= 1.0 and will be removed.
copy_X (boolean, optional (default True)) – If True, X will be copied; else, it may be overwritten.
verbose (bool, optional (default False)) – If True, prints out the different error terms every max_iter / 10 iterations.
unbias (bool (default False)) – See base class for definition. Most options are incompatible with unbiasing.
- Attributes:
coef_ (array, shape (n_features,) or (n_targets, n_features)) – Regularized weight vector(s). This is the v in the objective function.
coef_full_ (array, shape (n_features,) or (n_targets, n_features)) – Weight vector(s) that are not subjected to the regularization. This is the w in the objective function.
history_ (list) – History of sparse coefficients.
history_[k]contains the sparse coefficients (v in the optimization objective function) at iteration k.
Examples
>>> import numpy as np >>> from scipy.integrate import odeint >>> from pysindy import SINDy >>> from pysindy.optimizers import SR3 >>> lorenz = lambda z,t : [10 * (z[1] - z[0]), >>> z[0] * (28 - z[2]) - z[1], >>> z[0] * z[1] - 8 / 3 * z[2]] >>> t = np.arange(0, 2, .002) >>> x = odeint(lorenz, [-8, 8, 27], t) >>> opt = SR3(reg_weight_lam=0.1, relax_coeff_nu=1) >>> model = SINDy(optimizer=opt) >>> model.fit(x, t=t[1] - t[0]) >>> model.print() x0' = -10.004 1 + 10.004 x0 x1' = 27.994 1 + -0.993 x0 + -1.000 1 x1 x2' = -2.662 x1 + 1.000 1 x0
Methods
Calculate the L0 regularizer weight that is equivalent to a known L0 threshold
Disable trimming of potential outliers.
Enable the trimming of potential outliers.
Configure whether metadata should be requested to be passed to the
fitmethod.Configure whether metadata should be requested to be passed to the
scoremethod.Attributes
max_iternormalize_columnsinitial_guesscopy_Xunbiascoef_intercept_- static calculate_l0_weight(threshold: float | ndarray[float64], relax_coeff_nu: float)[source]
Calculate the L0 regularizer weight that is equivalent to a known L0 threshold
- See Appendix S1 of the following paper for more details.
Champion, K., Zheng, P., Aravkin, A. Y., Brunton, S. L., & Kutz, J. N. (2020). A unified sparse optimization framework to learn parsimonious physics-informed models from data. IEEE Access, 8, 169259-169271.
- enable_trimming(trimming_fraction)[source]
Enable the trimming of potential outliers.
- Parameters:
trimming_fraction (float) – The fraction of samples to be trimmed. Must be between 0 and 1.
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$', x_: bool | None | str = '$UNCHANGED$') SR3
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:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x_parameter infit.
- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SR3
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:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.- Returns:
self – The updated object.
- Return type:
object