pykoop.BilinearInputLiftingFn
- class BilinearInputLiftingFn
Bases:
EpisodeIndependentLiftingFn
Lifting function to generate bilinear products of the state and input.
As proposed in [BFV20]. Given a state
x
and input:u = np.array([ [u1], [u2], [u3], ])
the bilinear lifted state has the form:
psi = np.array([ [x], [u], [x * u1], [x * u2], [x * u3], ])
where the products are element-wise.
- feature_names_in_
Array of input feature name strings.
- Type:
np.ndarray
Examples
Apply bilinear input features to mass-spring-damper data
>>> bilin = pykoop.BilinearInputLiftingFn() >>> bilin.fit(X_msd, n_inputs=1, episode_feature=True) BilinearInputLiftingFn() >>> bilin.get_feature_names_in().tolist() ['ep', 'x0', 'x1', 'u0'] >>> bilin.get_feature_names_out().tolist() ['ep', 'x0', 'x1', 'u0', 'x0*u0', 'x1*u0'] >>> Xt_msd = bilin.transform(X_msd[:2, :])
- __init__()
Instantiate
BilinearInputLiftingFn
.- Return type:
None
Methods
__init__
()Instantiate
BilinearInputLiftingFn
.fit
(X[, y, n_inputs, episode_feature])Fit the lifting function.
fit_transform
(X[, y])Fit to data, then transform it.
get_feature_names_in
([format, episode_feature])Automatically generate input feature names.
get_feature_names_out
([input_features, ...])Get output feature names.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
Invert transformed data.
lift
(X[, episode_feature])Lift state and input.
lift_input
(X[, episode_feature])Lift input only.
lift_state
(X[, episode_feature])Lift state only.
n_samples_in
([n_samples_out])Calculate number of input samples required for given output length.
plot_lifted_trajectory
(X[, episode_feature, ...])Plot lifted data matrix.
retract
(X[, episode_feature])Retract lifted state and input.
retract_input
(X[, episode_feature])Retract lifted input only.
retract_state
(X[, episode_feature])Retract lifted state only.
set_fit_request
(*[, episode_feature, n_inputs])Request metadata passed to the
fit
method.set_output
(*[, transform])Set output container.
set_params
(**params)Set the parameters of this estimator.
transform
(X)Transform data.
- fit(X, y=None, n_inputs=0, episode_feature=False)
Fit the lifting function.
- Parameters:
- Returns:
Instance of itself.
- Return type:
- Raises:
ValueError – If constructor or fit parameters are incorrect.
- fit_transform(X, y=None, **fit_params)
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).
**fit_params (dict) – Additional fit parameters.
- Returns:
X_new – Transformed array.
- Return type:
ndarray array of shape (n_samples, n_features_new)
- get_feature_names_in(format=None, episode_feature=None)
Automatically generate input feature names.
- Parameters:
- Returns:
Automatically generated input feaure names.
- Return type:
np.ndarray
- get_feature_names_out(input_features=None, symbols_only=False, format=None, episode_feature=None)
Get output feature names.
- Parameters:
input_features (Optional[np.ndarray]) – Array of string input feature names. If provided, they are checked against
feature_names_in_
. IfNone
, ignored.symbols_only (bool) – If true, only return symbols (
theta_0
,upsilon_0
, etc.). Otherwise, returns the full equations (default).format (Optional[str]) – Feature name formatting method. Possible values are
'plaintext'
(default ifNone
) or'latex'
.episode_feature (Optional[bool]) – True if first feature indicates which episode a timestep is from. If
None
,self.episode_feature_
is used.
- Returns:
Output feature names.
- Return type:
np.ndarray
- get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing – A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)
Get parameters for this estimator.
- inverse_transform(X)
Invert transformed data.
- Parameters:
X (np.ndarray) – Transformed data matrix.
- Returns:
Inverted transformed data matrix.
- Return type:
np.ndarray
- lift(X, episode_feature=None)
Lift state and input.
Potentially more convenient alternative to calling
transform()
.- Parameters:
X (np.ndarray) – State and input.
episode_feature (Optional[bool]) – True if first feature indicates which episode a timestep is from. If
None
,self.episode_feature_
is used.
- Returns:
Lifted state and input.
- Return type:
np.ndarray
- lift_input(X, episode_feature=None)
Lift input only.
More convenient alternative to calling
transform()
, then stripping the unwanted lifted states.- Parameters:
X (np.ndarray) – State and input.
episode_feature (Optional[bool]) – True if first feature indicates which episode a timestep is from. If
None
,self.episode_feature_
is used.
- Returns:
Lifted input.
- Return type:
np.ndarray
- lift_state(X, episode_feature=None)
Lift state only.
More convenient alternative to padding the state with dummy inputs, calling
transform()
, then stripping the unwanted lifted inputs.- Parameters:
X (np.ndarray) – State.
episode_feature (Optional[bool]) – True if first feature indicates which episode a timestep is from. If
None
,self.episode_feature_
is used.
- Returns:
Lifted state.
- Return type:
np.ndarray
- n_samples_in(n_samples_out=1)
Calculate number of input samples required for given output length.
- plot_lifted_trajectory(X, episode_feature=None, episode_style=None, subplots_kw=None, plot_kw=None)
Plot lifted data matrix.
- Parameters:
X (np.ndarray) – Data matrix.
episode_feature (Optional[bool]) – True if first feature indicates which episode a timestep is from. If
None
,self.episode_feature_
is used.episode_style (Optional[str]) – If
'columns'
, each episode is a column (default). If'overlay'
, states from each episode are plotted overtop of each other in different colors.subplots_kw (Optional[Dict[str, Any]]) – Keyword arguments for
plt.subplots()
.plot_kw (Optional[Dict[str, Any]]) – Keyword arguments for Matplotlib
plt.Axes.plot()
.
- Returns:
Matplotlib
plt.Figure
object and two-dimensional array ofplt.Axes
objects.- Return type:
Tuple[plt.Figure, np.ndarray]
- retract(X, episode_feature=None)
Retract lifted state and input.
Potentially more convenient alternative to calling
inverse_transform()
.- Parameters:
X (np.ndarray) – Lifted state and input.
episode_feature (Optional[bool]) – True if first feature indicates which episode a timestep is from. If
None
,self.episode_feature_
is used.
- Returns:
State and input.
- Return type:
np.ndarray
- retract_input(X, episode_feature=None)
Retract lifted input only.
More convenient alternative to padding the lifted state with dummy lifted states, calling
inverse_transform()
, then stripping the unwanted states.- Parameters:
X (np.ndarray) – Lifted input.
episode_feature (Optional[bool]) – True if first feature indicates which episode a timestep is from. If
None
,self.episode_feature_
is used.
- Returns:
Input.
- Return type:
np.ndarray
- retract_state(X, episode_feature=None)
Retract lifted state only.
More convenient alternative to padding the lifted state with dummy lifted inputs, calling
inverse_transform()
.- Parameters:
X (np.ndarray) – Lifted state.
episode_feature (Optional[bool]) – True if first feature indicates which episode a timestep is from. If
None
,self.episode_feature_
is used.
- Returns:
State.
- Return type:
np.ndarray
- set_fit_request(*, episode_feature='$UNCHANGED$', n_inputs='$UNCHANGED$')
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if 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.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
episode_feature (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
episode_feature
parameter infit
.n_inputs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
n_inputs
parameter infit
.self (BilinearInputLiftingFn)
- Returns:
self – The updated object.
- Return type:
- set_output(*, transform=None)
Set output container.
See Introducing the set_output API for an example on how to use the API.
- Parameters:
transform ({"default", "pandas"}, default=None) –
Configure output of transform and fit_transform.
”default”: Default output format of a transformer
”pandas”: DataFrame output
”polars”: Polars output
None: Transform configuration is unchanged
Added in version 1.4: “polars” option was added.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- set_params(**params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- transform(X)
Transform data.
- Parameters:
X (np.ndarray) – Data matrix.
- Returns:
Transformed data matrix.
- Return type:
np.ndarray