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

Change to SINDy init defaults for optimizer, feature_library, and differentiation_method #69

Merged
merged 5 commits into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions pysindy/optimizers/stlsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@


class STLSQ(BaseOptimizer):
"""
Sequentially thresholded least squares algorithm.
"""Sequentially thresholded least squares algorithm.

Attempts to minimize the objective function
:math:`\\|y - Xw\\|^2_2 + alpha \\times \\|w\\|^2_2`
Expand Down Expand Up @@ -128,8 +127,7 @@ def _no_change(self):
return all(bool(i) == bool(j) for i, j in zip(this_coef, last_coef))

def _reduce(self, x, y):
"""
Iterates the thresholding. Assumes an initial guess is saved in
"""Iterates the thresholding. Assumes an initial guess is saved in
self.coef_ and self.ind_
"""
ind = self.ind_
Expand All @@ -140,8 +138,8 @@ def _reduce(self, x, y):
for _ in range(self.max_iter):
if np.count_nonzero(ind) == 0:
warnings.warn(
"""Sparsity parameter is too big ({}) and eliminated all
coefficients""".format(
"Sparsity parameter is too big ({}) and eliminated all "
"coefficients".format(
self.threshold
)
briandesilva marked this conversation as resolved.
Show resolved Hide resolved
)
Expand All @@ -152,8 +150,8 @@ def _reduce(self, x, y):
for i in range(n_targets):
if np.count_nonzero(ind[i]) == 0:
warnings.warn(
"""Sparsity parameter is too big ({}) and eliminated all
coefficients""".format(
"Sparsity parameter is too big ({}) and eliminated all "
"coefficients".format(
self.threshold
)
briandesilva marked this conversation as resolved.
Show resolved Hide resolved
)
Expand Down
27 changes: 15 additions & 12 deletions pysindy/pysindy.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,21 @@ class SINDy(BaseEstimator):
0.999999985520653
"""

def __init__(
self,
optimizer=STLSQ(),
feature_library=PolynomialFeatures(),
differentiation_method=FiniteDifference(),
feature_names=None,
discrete_time=False,
n_jobs=1,
):
self.optimizer = optimizer
self.feature_library = feature_library
self.differentiation_method = differentiation_method
def __init__(self, optimizer=None, feature_library=None,
differentiation_method=None, feature_names=None,
discrete_time=False, n_jobs=1):
briandesilva marked this conversation as resolved.
Show resolved Hide resolved
if optimizer is None:
self.optimizer = STLSQ()
else:
self.optimizer = optimizer
briandesilva marked this conversation as resolved.
Show resolved Hide resolved
if feature_library is None:
self.feature_library = PolynomialFeatures()
else:
self.feature_library = feature_library
if differentiation_method is None:
self.differentiation_method = FiniteDifference()
else:
self.differentiation_method = differentiation_method
briandesilva marked this conversation as resolved.
Show resolved Hide resolved
self.feature_names = feature_names
self.discrete_time = discrete_time
self.n_jobs = n_jobs
Expand Down