pysindy.feature_library.GeneralizedLibrary
- class pysindy.feature_library.GeneralizedLibrary(libraries: list, tensor_array=None, inputs_per_library: Sequence[Sequence[int]] | None = None, exclude_libraries=[])[source]
Put multiple libraries into one library. All settings provided to individual libraries will be applied. Note that this class allows one to specifically choose which input variables are used for each library, and take tensor products of any pair of libraries. Tensored libraries inherit the same input variables specified for the individual libraries.
- Parameters:
libraries (list of libraries) – Library instances to be applied to the input matrix.
tensor_array (2D list of booleans, optional, (default None)) – Default is to not tensor any of the libraries together. Shape equal to the # of tensor libraries and the # feature libraries. Indicates which pairs of libraries to tensor product together and add to the overall library. For instance if you have 5 libraries, and want to do two tensor products, you could use the list [[1, 0, 0, 1, 0], [0, 1, 0, 1, 1]] to indicate that you want two tensored libraries from tensoring libraries 0 and 3 and libraries 1, 3, and 4.
inputs_per_library (Sequence of Seqeunces of ints (default None)) – list that specifies which input indexes should be passed as inputs for each of the individual feature libraries. length must equal the number of feature libraries. Default is that all inputs are used for every library.
- Attributes:
self.libraries_full_ (list[BaseFeatureLibrary]) – The fitted libraries
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 the sum of the numbers of output features for each of the concatenated libraries.
Examples
>>> import numpy as np >>> from pysindy.feature_library import FourierLibrary, CustomLibrary >>> from pysindy.feature_library import GeneralizedLibrary >>> x = np.array([[0.,-1],[1.,0.],[2.,-1.]]) >>> functions = [lambda x : np.exp(x), lambda x,y : np.sin(x+y)] >>> lib_custom = CustomLibrary(library_functions=functions) >>> lib_fourier = FourierLibrary() >>> lib_generalized = GeneralizedLibrary([lib_custom, lib_fourier]) >>> lib_generalized.fit(x) >>> lib_generalized.transform(x)
Methods
calc_trajectoryCompute number of output features.
Return feature names for output features.
get_spatial_gridConfigure 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 with libs provided below.
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$') GeneralizedLibrary
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$') GeneralizedLibrary
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 with libs provided below.
- Parameters:
x (array-like, shape [n_samples, n_features]) – The data to transform, row by row.
- Returns:
xp – The matrix of features, where NP is the number of features generated from applying the custom functions to the inputs.
- Return type:
np.ndarray, shape [n_samples, NP]