Skip to content

Commit

Permalink
CLN: Align a few bits and pieces to trapping-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-Stevens-Haas committed May 30, 2024
1 parent 2d141d9 commit 8d415cc
Showing 1 changed file with 22 additions and 62 deletions.
84 changes: 22 additions & 62 deletions pysindy/optimizers/trapping_sr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,15 @@ class TrappingSR3(ConstrainedSR3):
Parameters
----------
threshold : float, optional (default 0.1)
Determines the strength of the regularization. When the
regularization function R is the L0 norm, the regularization
is equivalent to performing hard thresholding, and lambda
is chosen to threshold at the value given by this parameter.
This is equivalent to choosing lambda = threshold^2 / (2 * nu).
eta : float, optional (default 1.0e20)
Determines the strength of the stability term ||Pw-A||^2 in the
Determines the strength of the stability term :math:`||Pw-A||^2` in the
optimization. The default value is very large so that the
algorithm default is to ignore the stability term. In this limit,
this should be approximately equivalent to the ConstrainedSR3 method.
alpha_m : float, optional (default eta * 0.1)
Determines the step size in the prox-gradient descent over m.
For convergence, need alpha_m <= eta / ||w^T * PQ^T * PQ * w||.
Typically 0.01 * eta <= alpha_m <= 0.1 * eta.
alpha_A : float, optional (default eta)
Determines the step size in the prox-gradient descent over A.
For convergence, need alpha_A <= eta, so typically
alpha_A = eta is used.
eps_solver : float, optional (default 1.0e-7)
If threshold != 0, this specifies the error tolerance in the
CVXPY (OSQP) solve. Default is 1.0e-3 in OSQP.
alpha : float, optional (default 1.0e20)
Determines the strength of the local stability term ||Qijk||^2 in the
Expand All @@ -105,6 +92,22 @@ class TrappingSR3(ConstrainedSR3):
optimization. The default value is very large so that the
algorithm default is to ignore this term.
mod_matrix:
Lyapunov matrix. Trapping theorems apply to energy
:math:`\\propto \\dot y \\cdot y`, but also to any
:math:`\\propto \\dot y P \\cdot y` for Lyapunov matrix :math:`P`.
Defaults to the identity matrix.
alpha_A : float, optional (default eta)
Determines the step size in the prox-gradient descent over A.
For convergence, need alpha_A <= eta, so typically
alpha_A = eta is used.
alpha_m : float, optional (default eta * 0.1)
Determines the step size in the prox-gradient descent over m.
For convergence, need alpha_m <= eta / ||w^T * PQ^T * PQ * w||.
Typically 0.01 * eta <= alpha_m <= 0.1 * eta.
gamma : float, optional (default 0.1)
Determines the negative interval that matrix A is projected onto.
For most applications gamma = 0.1 - 1.0 works pretty well.
Expand All @@ -123,28 +126,6 @@ class TrappingSR3(ConstrainedSR3):
could be straightforwardly implemented, but L0 requires
reformulation because of nonconvexity.
thresholds : np.ndarray, shape (n_targets, n_features), optional \
(default None)
Array of thresholds 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 :math:`\\Xi` such that
:math:`\\dot{X} \\approx \\Theta(X)\\Xi`.
``thresholds[i, j]`` should specify the threshold to be used for the
(j + 1, i + 1) entry of :math:`\\Xi`. That is to say it should give the
threshold to be used for the (j + 1)st library function in the equation
for the (i + 1)st measurement variable.
eps_solver : float, optional (default 1.0e-7)
If threshold != 0, this specifies the error tolerance in the
CVXPY (OSQP) solve. Default is 1.0e-3 in OSQP.
inequality_constraints : bool, optional (default False)
If True, CVXPY methods are used.
max_iter : int, optional (default 30)
Maximum iterations of the optimization algorithm.
accel : bool, optional (default False)
Whether or not to use accelerated prox-gradient descent for (m, A).
Expand All @@ -156,26 +137,6 @@ class TrappingSR3(ConstrainedSR3):
Initial guess for vector A in the optimization. Otherwise
A is initialized as A = diag(gamma).
fit_intercept : boolean, optional (default False)
Whether to calculate the intercept for this model. If set to false, no
intercept will be used in calculations.
copy_X : boolean, optional (default True)
If True, X will be copied; else, it may be overwritten.
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.
verbose : bool, optional (default False)
If True, prints out the different error terms every iteration.
verbose_cvxpy : bool, optional (default False)
Boolean flag which is passed to CVXPY solve function to indicate if
output should be verbose or not. Only relevant for optimizers that
use the CVXPY package in some capabity.
Attributes
----------
coef_ : array, shape (n_features,) or (n_targets, n_features)
Expand Down Expand Up @@ -386,6 +347,8 @@ def __post_init_guard(self):
raise ValueError(
"Ineq. constr. -> threshold!=0 + relax_optim=True or relax_optim=False."
)
if self.mod_matrix is None:
self.mod_matrix = np.eye(self._n_tgts)

def set_params(self, **kwargs):
super().set_params(**kwargs)
Expand Down Expand Up @@ -702,9 +665,6 @@ def _reduce(self, x, y):
)
var_len = n_features * n_tgts

if self.mod_matrix is None:
self.mod_matrix = np.eye(n_tgts)

# Define PL, PQ, PT and PM tensors, only relevant if the stability term in
# trapping SINDy is turned on.
(
Expand Down

0 comments on commit 8d415cc

Please sign in to comment.