pysindy.feature_library.FourierLibrary
- class pysindy.feature_library.FourierLibrary(n_frequencies=1, include_sin=True, include_cos=True)[source]
Generate a library with trigonometric functions.
- Parameters:
n_frequencies (int, optional (default 1)) – Number of frequencies to include in the library. The library will include functions \(\sin(x), \sin(2x), \dots \sin(n_{frequencies}x)\) for each input feature \(x\) (depending on which of sine and/or cosine features are included).
include_sin (boolean, optional (default True)) – If True, include sine terms in the library.
include_cos (boolean, optional (default True)) – If True, include cosine terms in the library.
- 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
2 * n_input_features_ * n_frequenciesif both sines and cosines are included. Otherwise it isn_input_features * n_frequencies.
Examples
>>> import numpy as np >>> from pysindy.feature_library import FourierLibrary >>> x = np.array([[0.],[1.],[2.]]) >>> lib = FourierLibrary(n_frequencies=2).fit(x) >>> lib.transform(x) array([[ 0. , 1. , 0. , 1. ], [ 0.84147098, 0.54030231, 0.90929743, -0.41614684], [ 0.90929743, -0.41614684, -0.7568025 , -0.65364362]]) >>> lib.get_feature_names() ['sin(1 x0)', 'cos(1 x0)', 'sin(2 x0)', 'cos(2 x0)']
Methods
Compute number of output features.
Return feature names for output features
Configure whether metadata should be requested to be passed to the
fitmethod.Configure whether metadata should be requested to be passed to the
transformmethod.Transform data to Fourier features
Attributes
n_features_in_n_output_features_- fit(x_full, y=None)[source]
Compute number of output features.
- Parameters:
x (array-like, shape (n_samples, n_features)) – The data.
- Returns:
self
- Return type:
instance
- get_feature_names(input_features=None)[source]
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
- Return type:
list of string, length n_output_features
- set_fit_request(*, x_full: bool | None | str = '$UNCHANGED$') FourierLibrary
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
x_full (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x_fullparameter infit.- Returns:
self – The updated object.
- Return type:
object
- set_transform_request(*, x_full: bool | None | str = '$UNCHANGED$') FourierLibrary
Configure whether metadata should be requested to be passed to the
transformmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
x_full (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x_fullparameter intransform.- Returns:
self – The updated object.
- Return type:
object
- transform(x_full)[source]
Transform data to Fourier features
- Parameters:
x (array-like, shape (n_samples, n_features)) – The data to transform, row by row.
- Returns:
xp – The matrix of features, where n_output_features is the number of Fourier features generated from the inputs.
- Return type:
np.ndarray, shape (n_samples, n_output_features)