Skip to content

Commit

Permalink
enh(feature-library): simplify identity library
Browse files Browse the repository at this point in the history
  • Loading branch information
himkwtn committed Jul 16, 2024
1 parent 3503c15 commit c54445d
Showing 1 changed file with 4 additions and 72 deletions.
76 changes: 4 additions & 72 deletions pysindy/feature_library/identity_library.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from sklearn.utils.validation import check_is_fitted
from .polynomial_library import PolynomialLibrary

from .base import BaseFeatureLibrary
from .base import x_sequence_or_item


class IdentityLibrary(BaseFeatureLibrary):
class IdentityLibrary(PolynomialLibrary):
"""
Generate an identity library which maps all input features to
themselves.
Expand Down Expand Up @@ -32,70 +29,5 @@ class IdentityLibrary(BaseFeatureLibrary):
['x0', 'x1']
"""

def get_feature_names(self, input_features=None):
"""
Return feature names for output features
Parameters
----------
input_features : list of string, length n_features, optional
String names for input features if available. By default,
"x0", "x1", ... "xn_features" is used.
Returns
-------
output_feature_names : list of string, length n_output_features
"""
check_is_fitted(self)
n_input_features = self.n_features_in_
if input_features:
if len(input_features) == n_input_features:
return input_features
else:
raise ValueError("input features list is not the right length")
return ["x%d" % i for i in range(n_input_features)]

@x_sequence_or_item
def fit(self, x_full, y=None):
"""
Compute number of output features.
Parameters
----------
x : array-like, shape (n_samples, n_features)
The data.
Returns
-------
self : instance
"""
n_features = x_full[0].shape[x_full[0].ax_coord]
self.n_features_in_ = n_features
self.n_output_features_ = n_features
return self

@x_sequence_or_item
def transform(self, x_full):
"""Perform identity transformation (return a copy of the input).
Parameters
----------
x : array-like, shape (n_samples, n_features)
The data to transform, row by row.
Returns
-------
x : np.ndarray, shape (n_samples, n_features)
The matrix of features, which is just a copy of the input data.
"""
check_is_fitted(self)

xp_full = []
for x in x_full:
n_features = x.shape[x.ax_coord]
n_input_features = self.n_features_in_
if n_features != n_input_features:
raise ValueError("x shape does not match training shape")

xp_full = xp_full + [x.copy()]
return xp_full
def __init__(self):
super().__init__(degree=1, include_bias=False)

0 comments on commit c54445d

Please sign in to comment.