Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Raise explicit error when FROLS has linearly dependent columns. #193

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion pysindy/optimizers/frols.py
@@ -1,3 +1,5 @@
import warnings

import numpy as np
from sklearn.linear_model import ridge_regression

Expand Down Expand Up @@ -104,7 +106,14 @@ def __init__(
self.verbose = verbose

def _normed_cov(self, a, b):
return np.vdot(a, b) / np.vdot(a, a)
with warnings.catch_warnings():
warnings.filterwarnings("error", category=RuntimeWarning)
try:
return np.vdot(a, b) / np.vdot(a, a)
except RuntimeWarning:
raise ValueError(
"Trying to orthogonalize linearly dependent columns created NaNs"
)

def _select_function(self, x, y, sigma, skip=[]):
n_features = x.shape[1]
Expand Down
8 changes: 8 additions & 0 deletions test/optimizers/test_optimizers.py
Expand Up @@ -1020,3 +1020,11 @@ def test_optimizers_verbose_cvxpy(data_lorenz, optimizer):
model = optimizer(verbose_cvxpy=True)
model.fit(x, x_dot)
check_is_fitted(model)


def test_frols_error_linear_dependence():
opt = FROLS(normalize_columns=True)
x = np.array([[1.0, 1.0]])
y = np.array([[1.0, 1.0]])
with pytest.raises(ValueError):
opt.fit(x, y)