Skip to content

Commit

Permalink
CLN: Remove deprecated ensembling code
Browse files Browse the repository at this point in the history
Removing/fixing tests will happen in a separate commit
  • Loading branch information
Jacob-Stevens-Haas committed Jun 30, 2023
1 parent ac61b4a commit 819893f
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 290 deletions.
76 changes: 2 additions & 74 deletions pysindy/feature_library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,8 @@ class BaseFeatureLibrary(TransformerMixin):
Forces subclasses to implement ``fit``, ``transform``,
and ``get_feature_names`` methods.
Parameters
----------
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library)
ensemble_indices : integer array, optional (default [0])
The indices to use for ensembling the library.
"""

def __init__(self, library_ensemble=None, ensemble_indices=[0]):
if library_ensemble is not None:
warnings.warn(
"Library ensembling is no longer performed by feature libraries. Use "
"EnsemblingOptimizer to fit an ensemble model.",
DeprecationWarning,
)
self.library_ensemble = library_ensemble
if np.any(np.asarray(ensemble_indices) < 0):
raise ValueError("Library ensemble indices must be 0 or positive integers.")
self.ensemble_indices = ensemble_indices

def validate_input(self, x, *args, **kwargs):
return validate_no_reshape(x, *args, **kwargs)

Expand Down Expand Up @@ -143,29 +122,6 @@ def get_feature_names(self, input_features=None):
"""
raise NotImplementedError

def _ensemble(self, xp):
"""
If library bagging, return xp without
the terms at ensemble_indices
"""
warnings.warn(
"Library ensembling is no longer performed by feature libraries. Use "
"EnsemblingOptimizer to fit an ensemble model.",
UserWarning,
)

if self.library_ensemble:
if self.n_output_features_ <= len(self.ensemble_indices):
raise ValueError(
"Error: you are trying to chop more library terms "
"than are available to remove!"
)
inds = range(self.n_output_features_)
inds = np.delete(inds, self.ensemble_indices)
return [x[..., inds] for x in xp]
else:
return xp

def __add__(self, other):
return ConcatLibrary([self, other])

Expand Down Expand Up @@ -220,14 +176,6 @@ class ConcatLibrary(BaseFeatureLibrary):
libraries : list of libraries
Library instances to be applied to the input matrix.
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library).
ensemble_indices : integer array, optional (default [0])
The indices to use for ensembling the library. For instance, if
ensemble_indices = [0], it chops off the first column of the library.
Attributes
----------
libraries_ : list of libraries
Expand Down Expand Up @@ -258,12 +206,8 @@ class ConcatLibrary(BaseFeatureLibrary):
def __init__(
self,
libraries: list,
library_ensemble=False,
ensemble_indices=[0],
):
super(ConcatLibrary, self).__init__(
library_ensemble=library_ensemble, ensemble_indices=ensemble_indices
)
super().__init__()
self.libraries_ = libraries

@x_sequence_or_item
Expand Down Expand Up @@ -320,8 +264,6 @@ def transform(self, x_full):

xp = AxesArray(xp, comprehend_axes(xp))
xp_full.append(xp)
if self.library_ensemble:
xp_full = self._ensemble(xp_full)
return xp_full

def get_feature_names(self, input_features=None):
Expand Down Expand Up @@ -356,14 +298,6 @@ class TensoredLibrary(BaseFeatureLibrary):
libraries : list of libraries
Library instances to be applied to the input matrix.
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library).
ensemble_indices : integer array, optional (default [0])
The indices to use for ensembling the library. For instance, if
ensemble_indices = [0], it chops off the first column of the library.
Attributes
----------
libraries_ : list of libraries
Expand Down Expand Up @@ -399,13 +333,9 @@ class TensoredLibrary(BaseFeatureLibrary):
def __init__(
self,
libraries: list,
library_ensemble=False,
inputs_per_library=None,
ensemble_indices=[0],
):
super(TensoredLibrary, self).__init__(
library_ensemble=library_ensemble, ensemble_indices=ensemble_indices
)
super().__init__()
self.libraries_ = libraries
self.inputs_per_library_ = inputs_per_library

Expand Down Expand Up @@ -534,8 +464,6 @@ def transform(self, x_full):
xp = np.concatenate(xp, axis=xp[0].ax_coord)
xp = AxesArray(xp, comprehend_axes(xp))
xp_full.append(xp)
if self.library_ensemble:
xp_full = self._ensemble(xp_full)
return xp_full

def get_feature_names(self, input_features=None):
Expand Down
15 changes: 1 addition & 14 deletions pysindy/feature_library/custom_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ class CustomLibrary(BaseFeatureLibrary):
will be included.
If False, all combinations will be included.
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library)
ensemble_indices : integer array, optional (default [0])
The indices to use for ensembling the library.
include_bias : boolean, optional (default False)
If True (default), then include a bias column, the feature in which
all polynomial powers are zero (i.e. a column of ones - acts as an
Expand Down Expand Up @@ -92,13 +85,9 @@ def __init__(
library_functions,
function_names=None,
interaction_only=True,
library_ensemble=False,
ensemble_indices=[0],
include_bias=False,
):
super(CustomLibrary, self).__init__(
library_ensemble=library_ensemble, ensemble_indices=ensemble_indices
)
super().__init__()
self.functions = library_functions
self.function_names = function_names
if function_names and (
Expand Down Expand Up @@ -219,6 +208,4 @@ def transform(self, x_full):

xp = AxesArray(xp, comprehend_axes(xp))
xp_full.append(xp)
if self.library_ensemble:
xp_full = self._ensemble(xp_full)
return xp_full
15 changes: 1 addition & 14 deletions pysindy/feature_library/fourier_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ class FourierLibrary(BaseFeatureLibrary):
include_cos : boolean, optional (default True)
If True, include cosine terms in the library.
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library)
ensemble_indices : integer array, optional (default 0)
The indices to use for ensembling the library.
Attributes
----------
n_features_in_ : int
Expand Down Expand Up @@ -61,12 +54,8 @@ def __init__(
n_frequencies=1,
include_sin=True,
include_cos=True,
library_ensemble=False,
ensemble_indices=[0],
):
super(FourierLibrary, self).__init__(
library_ensemble=library_ensemble, ensemble_indices=ensemble_indices
)
super().__init__()
if not (include_sin or include_cos):
raise ValueError("include_sin and include_cos cannot both be False")
if n_frequencies < 1 or not isinstance(n_frequencies, int):
Expand Down Expand Up @@ -164,6 +153,4 @@ def transform(self, x_full):
idx += 1
xp = AxesArray(xp, comprehend_axes(xp))
xp_full.append(xp)
if self.library_ensemble:
xp_full = self._ensemble(xp_full)
return xp_full
16 changes: 1 addition & 15 deletions pysindy/feature_library/generalized_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ class GeneralizedLibrary(BaseFeatureLibrary):
subsets of the input variables. Note that this must be specified for
all the individual feature libraries.
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library).
ensemble_indices : integer array, optional (default [0])
The indices to use for ensembling the library. For instance, if
ensemble_indices = [0], it chops off the first column of the library.
Attributes
----------
libraries_ : list of libraries
Expand Down Expand Up @@ -96,13 +88,9 @@ def __init__(
libraries: list,
tensor_array=None,
inputs_per_library=None,
library_ensemble=False,
ensemble_indices=[0],
exclude_libraries=[],
):
super(GeneralizedLibrary, self).__init__(
library_ensemble=library_ensemble, ensemble_indices=ensemble_indices
)
super().__init__()
if len(libraries) > 0:
self.libraries_ = libraries

Expand Down Expand Up @@ -262,8 +250,6 @@ def transform(self, x_full):

xp = AxesArray(np.concatenate(xps, axis=xps[0].ax_coord), xps[0].__dict__)
xp_full = xp_full + [xp]
if self.library_ensemble:
xp_full = self._ensemble(xp_full)
return xp_full

def get_feature_names(self, input_features=None):
Expand Down
18 changes: 0 additions & 18 deletions pysindy/feature_library/identity_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ class IdentityLibrary(BaseFeatureLibrary):
The total number of output features. The number of output features
is equal to the number of input features.
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library)
ensemble_indices : integer array, optional (default [0])
The indices to use for ensembling the library.
Examples
--------
>>> import numpy as np
Expand All @@ -39,15 +32,6 @@ class IdentityLibrary(BaseFeatureLibrary):
['x0', 'x1']
"""

def __init__(
self,
library_ensemble=False,
ensemble_indices=[0],
):
super(IdentityLibrary, self).__init__(
library_ensemble=library_ensemble, ensemble_indices=ensemble_indices
)

def get_feature_names(self, input_features=None):
"""
Return feature names for output features
Expand Down Expand Up @@ -114,6 +98,4 @@ def transform(self, x_full):
raise ValueError("x shape does not match training shape")

xp_full = xp_full + [x.copy()]
if self.library_ensemble:
xp_full = self._ensemble(xp_full)
return xp_full
4 changes: 0 additions & 4 deletions pysindy/feature_library/parameterized_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def __init__(
feature_library=PolynomialLibrary(),
num_parameters=3,
num_features=3,
library_ensemble=False,
ensemble_indices=[0],
):
if not isinstance(feature_library, BaseFeatureLibrary) or not isinstance(
parameter_library, BaseFeatureLibrary
Expand Down Expand Up @@ -101,8 +99,6 @@ def __init__(
tensor_array=tensor_array,
exclude_libraries=[0, 1],
inputs_per_library=inputs_per_libraries,
library_ensemble=library_ensemble,
ensemble_indices=ensemble_indices,
)

def calc_trajectory(self, diff_method, x, t):
Expand Down
15 changes: 1 addition & 14 deletions pysindy/feature_library/pde_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ class PDELibrary(BaseFeatureLibrary):
will consist of only pure no-derivative terms and pure derivative
terms, with no mixed terms.
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library)
ensemble_indices : integer array, optional (default [0])
The indices to use for ensembling the library.
implicit_terms : boolean
Flag to indicate if SINDy-PI (temporal derivatives) is being used
for the right-hand side of the SINDy fit.
Expand Down Expand Up @@ -118,18 +111,14 @@ def __init__(
function_names=None,
include_bias=False,
include_interaction=True,
library_ensemble=False,
ensemble_indices=[0],
implicit_terms=False,
multiindices=None,
differentiation_method=FiniteDifference,
diff_kwargs={},
is_uniform=None,
periodic=None,
):
super(PDELibrary, self).__init__(
library_ensemble=library_ensemble, ensemble_indices=ensemble_indices
)
super().__init__()
self.functions = library_functions
self.derivative_order = derivative_order
self.function_names = function_names
Expand Down Expand Up @@ -472,8 +461,6 @@ def transform(self, x_full):
library_idx += n_library_terms * self.num_derivatives * n_features
xp = AxesArray(xp, comprehend_axes(xp))
xp_full.append(xp)
if self.library_ensemble:
xp_full = self._ensemble(xp_full)
return xp_full

def get_spatial_grid(self):
Expand Down
14 changes: 0 additions & 14 deletions pysindy/feature_library/polynomial_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ class PolynomialLibrary(PolynomialFeatures, BaseFeatureLibrary):
Order of output array in the dense case. 'F' order is faster to
compute, but may slow down subsequent estimators.
library_ensemble : boolean, optional (default False)
Whether or not to use library bagging (regress on subset of the
candidate terms in the library)
ensemble_indices : integer array, optional (default [0])
The indices to use for ensembling the library.
Attributes
----------
powers_ : array, shape (n_output_features, n_input_features)
Expand All @@ -71,18 +64,13 @@ def __init__(
interaction_only=False,
include_bias=True,
order="C",
library_ensemble=False,
ensemble_indices=[0],
):
super(PolynomialLibrary, self).__init__(
degree=degree,
interaction_only=interaction_only,
include_bias=include_bias,
order=order,
)
BaseFeatureLibrary.__init__(
self, library_ensemble=library_ensemble, ensemble_indices=ensemble_indices
)
if degree < 0 or not isinstance(degree, int):
raise ValueError("degree must be a nonnegative integer")
if (not include_interaction) and interaction_only:
Expand Down Expand Up @@ -284,6 +272,4 @@ def transform(self, x_full):
for i, comb in enumerate(combinations):
xp[..., i] = x[..., comb].prod(-1)
xp_full = xp_full + [xp]
if self.library_ensemble:
xp_full = self._ensemble(xp_full)
return xp_full
Loading

0 comments on commit 819893f

Please sign in to comment.