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: #455 Make IdentityLibrary a subclass of Polynomial Library #533

Merged
merged 4 commits into from
Jul 30, 2024
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
2 changes: 1 addition & 1 deletion pysindy/feature_library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .custom_library import CustomLibrary
from .fourier_library import FourierLibrary
from .generalized_library import GeneralizedLibrary
from .identity_library import IdentityLibrary
from .parameterized_library import ParameterizedLibrary
from .pde_library import PDELibrary
from .polynomial_library import IdentityLibrary
from .polynomial_library import PolynomialLibrary
from .sindy_pi_library import SINDyPILibrary
from .weak_pde_library import WeakPDELibrary
Expand Down
33 changes: 0 additions & 33 deletions pysindy/feature_library/identity_library.py

This file was deleted.

30 changes: 30 additions & 0 deletions pysindy/feature_library/polynomial_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,33 @@ def n_poly_features(
else:
n_feat += comb(n_in_feat + deg - 1, deg)
return n_feat


def IdentityLibrary():
"""
Generate an identity library which maps all input features to
themselves.

Attributes
----------
n_features_in_ : int
The total number of input features.

n_output_features_ : int
The total number of output features. The number of output features
is equal to the number of input features.

Examples
--------
>>> import numpy as np
>>> from pysindy.feature_library import IdentityLibrary
>>> x = np.array([[0,-1],[0.5,-1.5],[1.,-2.]])
>>> lib = IdentityLibrary().fit(x)
>>> lib.transform(x)
array([[ 0. , -1. ],
[ 0.5, -1.5],
[ 1. , -2. ]])
>>> lib.get_feature_names()
['x0', 'x1']
"""
himkwtn marked this conversation as resolved.
Show resolved Hide resolved
return PolynomialLibrary(degree=1, include_bias=False)
8 changes: 0 additions & 8 deletions test/test_feature_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,9 @@ def test_sindypi_library_bad_params(params):
@pytest.mark.parametrize(
"library",
[
IdentityLibrary(),
PolynomialLibrary(),
PolynomialLibrary(include_bias=False),
FourierLibrary(),
IdentityLibrary() + PolynomialLibrary(),
himkwtn marked this conversation as resolved.
Show resolved Hide resolved
pytest.lazy_fixture("custom_library"),
pytest.lazy_fixture("custom_library_bias"),
pytest.lazy_fixture("generalized_library"),
Expand All @@ -246,11 +244,9 @@ def test_fit_transform(data_lorenz, library):
@pytest.mark.parametrize(
"library",
[
IdentityLibrary(),
PolynomialLibrary(),
PolynomialLibrary(include_bias=False),
FourierLibrary(),
IdentityLibrary() + PolynomialLibrary(),
himkwtn marked this conversation as resolved.
Show resolved Hide resolved
pytest.lazy_fixture("custom_library"),
pytest.lazy_fixture("custom_library_bias"),
pytest.lazy_fixture("generalized_library"),
Expand All @@ -269,10 +265,8 @@ def test_change_in_data_shape(data_lorenz, library):
@pytest.mark.parametrize(
"library, shape",
[
(IdentityLibrary(), 3),
(PolynomialLibrary(include_bias=False), 9),
(PolynomialLibrary(), 10),
(IdentityLibrary() + PolynomialLibrary(), 13),
himkwtn marked this conversation as resolved.
Show resolved Hide resolved
(FourierLibrary(), 6),
(pytest.lazy_fixture("custom_library_bias"), 13),
(pytest.lazy_fixture("custom_library"), 12),
Expand All @@ -292,7 +286,6 @@ def test_output_shape(data_lorenz, library, shape):
@pytest.mark.parametrize(
"library",
[
IdentityLibrary(),
PolynomialLibrary(),
PolynomialLibrary(include_bias=False),
FourierLibrary(),
Expand Down Expand Up @@ -410,7 +403,6 @@ def test_tensored(data_lorenz):
@pytest.mark.parametrize(
"library",
[
IdentityLibrary(),
PolynomialLibrary(),
FourierLibrary(),
PolynomialLibrary() + FourierLibrary(),
Expand Down
Loading