Skip to content

Commit

Permalink
Remove normalize parameter from sindy (#292)
Browse files Browse the repository at this point in the history
* Remove normalize parameter from sindy
  • Loading branch information
clonker authored May 14, 2024
1 parent e6419d8 commit d8596f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions deeptime/sindy/_sindy.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,18 @@ class STLSQ(LinearRegression):
.. footbibliography::
"""

def __init__(self, threshold=0.1, alpha=0.05, max_iter=20, ridge_kw=None, normalize=False, fit_intercept=False,
copy_X=True):
def __init__(self, threshold=0.1, alpha=0.05, max_iter=20, ridge_kw=None, fit_intercept=False,
copy_X=True, **kw):
super().__init__(fit_intercept=fit_intercept, copy_X=copy_X)
self.threshold = threshold
self.alpha = alpha
self.max_iter = max_iter
self.ridge_kw = ridge_kw
self.normalize = normalize
self.fit_intercept = fit_intercept
self.copy_X = copy_X
if "normalize" in kw.keys():
raise RuntimeError("`normalize` was removed in more recent versions of scikit-learn (>=1.2.2), "
"please perform normalization a priori if desired.")

def fit(self, x_, y):
r"""Fit to the data.
Expand All @@ -442,7 +444,6 @@ def fit(self, x_, y):
x_,
y,
fit_intercept=self.fit_intercept,
normalize=self.normalize,
copy=self.copy_X,
)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ requires-python = ">= 3.8"
dependencies = [
'numpy>=1.20',
'scipy>=1.9.0',
'scikit-learn<=1.2.2',
'scikit-learn>=1.2.2',
'threadpoolctl>=3.1.0'
]
dynamic = ['version']
Expand Down
7 changes: 6 additions & 1 deletion tests/sindy/test_sindy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pytest
from numpy.testing import assert_equal, assert_
from numpy.testing import assert_equal, assert_, assert_raises
from scipy.integrate import odeint
from sklearn.preprocessing import PolynomialFeatures

Expand Down Expand Up @@ -54,6 +54,11 @@ def test_learned_coefficients(data_lorenz):
np.testing.assert_almost_equal(true_coef, model_coef, decimal=3)


def test_removed_args_error():
with assert_raises(RuntimeError):
STLSQ(normalize=True)


def test_score(data_lorenz):
x, x_dot, t = data_lorenz
model = SINDy().fit(x, y=x_dot).fetch_model()
Expand Down

0 comments on commit d8596f1

Please sign in to comment.