dynamicslab / pysindy

A package for the sparse identification of nonlinear dynamical systems from data
https://pysindy.readthedocs.io/en/latest/
Other
1.36k stars 304 forks source link

[BUG] sparse_ind argument in stlsq.py is not working #424

Closed anur2203 closed 8 months ago

anur2203 commented 8 months ago

TypeError Traceback (most recent call last) Cell In[4], line 13 11 differentiation_method = ps.FiniteDifference(order=2) 12 feature_library = ps.PolynomialLibrary(degree=2) ---> 13 optimizer = ps.STLSQ(threshold=stlsq_lambda, alpha=0.05, max_iter=20, ridge_kw=None, normalize_columns=False, 14 copy_X=True, initial_guess=None, verbose=False, sparse_ind=None, unbias=True,) 15 model = ps.SINDy( 16 differentiation_method=differentiation_method, 17 feature_library=feature_library, 18 optimizer=optimizer, 19 feature_names=["x", "y", "z"] 20 ) 21 model.fit(x_train_multi, t=dt, multiple_trajectories=True)

TypeError: STLSQ.init() got an unexpected keyword argument 'sparse_ind' Is this a error in code or I am doing something wrong?

Jacob-Stevens-Haas commented 8 months ago

sparse_ind is very new and only in the master branch - it hasn't been included in any release yet (hopefully by the end of the year!). It exists in order to to use a sparse optimizer when fitting the derivatives and the function library at the same time. This capability is only provided by the SSSINDy class (Single-step SINDy), which is in the sss branch and not even merged yet.

Were you installing pysindy from PyPI or directly from Github?

anur2203 commented 8 months ago

I have installed from PyPI

anur2203 commented 8 months ago

I am working with 3 state variable's and I want to discover each equation separately using different regularization constant. Because one regularization constant is not working for the whole system.

Jacob-Stevens-Haas commented 8 months ago

Try using SR3, which allows separate thresholds not just for each equation, but for each term in each equation.

    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.