diff --git a/pysindy/optimizers/stlsq.py b/pysindy/optimizers/stlsq.py index fffdb381a..ac3ff79d7 100644 --- a/pysindy/optimizers/stlsq.py +++ b/pysindy/optimizers/stlsq.py @@ -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` @@ -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_ @@ -140,10 +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( - self.threshold - ) + "Sparsity parameter is too big ({}) and eliminated all " + "coefficients".format(self.threshold) ) coef = np.zeros((n_targets, n_features)) break @@ -152,10 +148,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( - self.threshold - ) + "Sparsity parameter is too big ({}) and eliminated all " + "coefficients".format(self.threshold) ) continue coef_i = self._regress(x[:, ind[i]], y[:, i]) diff --git a/pysindy/pysindy.py b/pysindy/pysindy.py index 4e317781f..27aca208c 100644 --- a/pysindy/pysindy.py +++ b/pysindy/pysindy.py @@ -93,15 +93,21 @@ class SINDy(BaseEstimator): def __init__( self, - optimizer=STLSQ(), - feature_library=PolynomialFeatures(), - differentiation_method=FiniteDifference(), + optimizer=None, + feature_library=None, + differentiation_method=None, feature_names=None, discrete_time=False, n_jobs=1, ): + if optimizer is None: + optimizer = STLSQ() self.optimizer = optimizer + if feature_library is None: + feature_library = PolynomialFeatures() self.feature_library = feature_library + if differentiation_method is None: + differentiation_method = FiniteDifference() self.differentiation_method = differentiation_method self.feature_names = feature_names self.discrete_time = discrete_time