pykoop.DelayLiftingFn

class DelayLiftingFn(n_delays_state=0, n_delays_input=0)

Bases: EpisodeDependentLiftingFn

Lifting function to generate delay coordinates for state and input.

See [PD20] for an in-depth treatment of time-delay embeddings.

Parameters:
  • n_delays_state (int) –

  • n_delays_input (int) –

n_features_in_

Number of features before transformation, including episode feature if present.

Type:

int

n_states_in_

Number of states before transformation.

Type:

int

n_inputs_in_

Number of inputs before transformation.

Type:

int

n_features_out_

Number of features after transformation, including episode feature if present.

Type:

int

n_states_out_

Number of states after transformation.

Type:

int

n_inputs_out_

Number of inputs after transformation.

Type:

int

min_samples_

Minimum number of samples needed to use the transformer.

Type:

int

episode_feature_

Indicates if episode feature was present during fit().

Type:

bool

feature_names_in_

Array of input feature name strings.

Type:

np.ndarray

Warning

transform() and inverse_transform() are not exact inverses unless n_delays_x and n_delays_u are the same. Only the last samples will be the same, since the abs(n_delays_x - n_delays_u) earliest samples will need to be dropped to ensure the output array is rectangular.

Examples

Apply delay lifting function to mass-spring-damper data

>>> delay = pykoop.DelayLiftingFn(n_delays_state=1, n_delays_input=1)
>>> delay.fit(X_msd, n_inputs=1, episode_feature=True)
DelayLiftingFn(n_delays_input=1, n_delays_state=1)
>>> delay.get_feature_names_in().tolist()
['ep', 'x0', 'x1', 'u0']
>>> delay.get_feature_names_out().tolist()
['ep', 'x0', 'x1', 'D1(x0)', 'D1(x1)', 'u0', 'D1(u0)']
>>> Xt_msd = delay.transform(X_msd[:3, :])
__init__(n_delays_state=0, n_delays_input=0)

Instantiate DelayLiftingFn.

Parameters:
  • n_delays_state (int) – Number of delays to apply to the state.

  • n_delays_input (int) – Number of delays to apply to the input.

Return type:

None

Methods

__init__([n_delays_state, n_delays_input])

Instantiate DelayLiftingFn.

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()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

inverse_transform(X)

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:
  • X (np.ndarray) – Data matrix.

  • y (Optional[np.ndarray]) – Ignored.

  • n_inputs (int) – Number of input features at the end of X.

  • episode_feature (bool) – True if first feature indicates which episode a timestep is from.

Returns:

Instance of itself.

Return type:

KoopmanLiftingFn

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:
  • format (Optional[str]) – Feature name formatting method. Possible values are 'plaintext' (default if None) 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:

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_. If None, 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 if None) 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.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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.

Parameters:

n_samples_out (int) – Number of samples needed at the output.

Returns:

Number of samples needed at the input.

Return type:

int

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 of plt.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 (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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.

New 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 in fit.

  • n_inputs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for n_inputs parameter in fit.

  • self (DelayLiftingFn) –

Returns:

self – The updated object.

Return type:

object

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

  • None: Transform configuration is unchanged

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