pykoop.lmi_regressors.LmiDmdc

class LmiDmdc(alpha=0, ratio=1, tsvd_unshifted=None, tsvd_shifted=None, reg_method='tikhonov', square_norm=False, picos_eps=0, solver_params=None)

Bases: LmiRegressor

LMI-based DMDc with regularization.

Supports Tikhonov regularization, optionally mixed with matrix two-norm regularization or nuclear norm regularization.

Parameters:
  • alpha (float) –

  • ratio (float) –

  • tsvd_unshifted (Tsvd | None) –

  • tsvd_shifted (Tsvd | None) –

  • reg_method (str) –

  • square_norm (bool) –

  • picos_eps (float) –

  • solver_params (Dict[str, Any] | None) –

alpha_tikhonov_

Tikhonov regularization coefficient used.

Type:

float

alpha_other_

Matrix two norm or nuclear norm regularization coefficient used.

Type:

float

tsvd_unshifted_

Fit truncated SVD object for unshifted data matrix.

Type:

pykoop.Tsvd

tsvd_shifted_

Fit truncated SVD object for shifted data matrix.

Type:

pykoop.Tsvd

U_hat_

Reduced Koopman matrix for debugging.

Type:

np.ndarray

solver_params_

Solver parameters used (defaults merged with constructor input).

Type:

Optional[Dict[str, Any]]

n_features_in_

Number of features input, including episode feature.

Type:

int

n_states_in_

Number of states input.

Type:

int

n_inputs_in_

Number of inputs input.

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

coef_

Fit coefficient matrix.

Type:

np.ndarray

Examples

LMI DMDc without regularization

>>> kp = pykoop.KoopmanPipeline(regressor=pykoop.lmi_regressors.LmiDmdc())
>>> kp.fit(X_msd, n_inputs=1, episode_feature=True)  
KoopmanPipeline(regressor=LmiDmdc())

LMI DMDc with Tikhonov regularization

>>> kp = pykoop.KoopmanPipeline(
...     regressor=pykoop.lmi_regressors.LmiDmdc(
...         alpha=1,
...         reg_method='tikhonov',
...     )
... )
>>> kp.fit(X_msd, n_inputs=1, episode_feature=True)  
KoopmanPipeline(regressor=LmiDmdc(alpha=1))

LMI DMDc with matrix two-norm regularization

>>> kp = pykoop.KoopmanPipeline(
...     regressor=pykoop.lmi_regressors.LmiDmdc(
...         alpha=1,
...         reg_method='twonorm',
...     )
... )
>>> kp.fit(X_msd, n_inputs=1, episode_feature=True)  
KoopmanPipeline(regressor=LmiDmdc(alpha=1, reg_method='twonorm'))

LMI DMDc with nuclear norm regularization and SVD truncation

>>> kp = pykoop.KoopmanPipeline(
...     regressor=pykoop.lmi_regressors.LmiDmdc(
...         alpha=1,
...         reg_method='nuclear',
...         tsvd_unshifted=pykoop.Tsvd('known_noise', 0.1),
...         tsvd_shifted=pykoop.Tsvd('known_noise', 0.1),
...     )
... )
>>> kp.fit(X_msd, n_inputs=1, episode_feature=True)  
KoopmanPipeline(regressor=LmiDmdc(alpha=1, reg_method='nuclear',
tsvd_shifted=Tsvd(truncation='known_noise', truncation_param=0.1),
tsvd_unshifted=Tsvd(truncation='known_noise', truncation_param=0.1)))
__init__(alpha=0, ratio=1, tsvd_unshifted=None, tsvd_shifted=None, reg_method='tikhonov', square_norm=False, picos_eps=0, solver_params=None)

Instantiate LmiDmdc.

Parameters:
  • alpha (float) – Regularization coefficient. Can only be zero if reg_method='tikhonov'.

  • ratio (float) – Ratio of matrix two-norm or nuclear norm to use in mixed regularization. If ratio=1, no Tikhonov regularization is used. Cannot be zero. Ignored if reg_method='tikhonov'.

  • tsvd_unshifted (Optional[pykoop.Tsvd]) – Singular value truncation method used to change basis of unshifted data matrix. If None, economy SVD is used.

  • tsvd_shifted (Optional[pykoop.Tsvd]) – Singular value truncation method used to change basis of shifted data matrix. If None, economy SVD is used.

  • reg_method (str) –

    Regularization method to use. Possible values are

    • 'tikhonov' – pure Tikhonov regularization (ratio is ignored),

    • 'twonorm' – matrix two-norm regularization mixed with Tikhonov regularization, or

    • 'nuclear' – nuclear norm regularization mixed with Tikhonov regularization.

  • square_norm (bool) – Square norm in matrix two-norm or nuclear norm regularizer. Enabling may increase computation time. Frobenius norm used in Tikhonov regularizer is always squared.

  • picos_eps (float) – Tolerance used for strict LMIs. If nonzero, should be larger than solver tolerance.

  • solver_params (Optional[Dict[str, Any]]) – Parameters passed to PICOS picos.Problem.solve(). By default, allows chosen solver to select its own tolerances.

Return type:

None

Methods

__init__([alpha, ratio, tsvd_unshifted, ...])

Instantiate LmiDmdc.

fit(X[, y, n_inputs, episode_feature])

Fit the regressor.

frequency_response(t_step[, f_min, f_max, ...])

Compute frequency response of Koopman system.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

plot_bode(t_step[, f_min, f_max, n_points, ...])

Plot frequency response of Koopman system.

plot_eigenvalues([unit_circle, figure_kw, ...])

Plot eigenvalues of Koopman A matrix.

plot_koopman_matrix([subplots_kw, plot_kw])

Plot heatmap of Koopman matrices.

plot_svd([subplots_kw, plot_kw])

Plot singular values of Koopman matrices.

predict(X)

Perform a single-step prediction for each state in each episode.

score(X, y[, sample_weight])

Return the coefficient of determination of the prediction.

set_fit_request(*[, episode_feature, n_inputs])

Request metadata passed to the fit method.

set_params(**params)

Set the parameters of this estimator.

set_score_request(*[, sample_weight])

Request metadata passed to the score method.

fit(X, y=None, n_inputs=0, episode_feature=False)

Fit the regressor.

If only X is specified, the regressor will compute its unshifted and shifted versions. If X and y are specified, X is treated as the unshifted data matrix, while y is treated as the shifted data matrix.

Parameters:
  • X (np.ndarray) – Full data matrix if y=None. Unshifted data matrix if y is specified.

  • y (Optional[np.ndarray]) – Optional shifted data matrix. If None, shifted data matrix is computed using X.

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

KoopmanRegressor

Raises:

ValueError – If constructor or fit parameters are incorrect.

frequency_response(t_step, f_min=0, f_max=None, n_points=1000, decibels=True)

Compute frequency response of Koopman system.

Parameters:
  • t_step (float) – Sampling timestep.

  • f_min (float) – Minimum frequency to plot.

  • f_max (Optional[float]) – Maximum frequency to plot. If None, uses Nyquist frequency.

  • n_points (int) – Number of frequecy points to plot.

  • decibels (bool) – Plot gain in dB (default is true).

Returns:

Frequency (Hz) and frequency response (gain or dB).

Return type:

Tuple[np.ndarray, np.ndarray]

Raises:

ValueError – If f_min is less than zero or f_max is greater than the Nyquist frequency.

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

plot_bode(t_step, f_min=0, f_max=None, n_points=1000, decibels=True, subplots_kw=None, plot_kw=None)

Plot frequency response of Koopman system.

Parameters:
  • t_step (float) – Sampling timestep.

  • f_min (float) – Minimum frequency to plot.

  • f_max (Optional[float]) – Maximum frequency to plot. If None, uses Nyquist frequency.

  • n_points (int) – Number of frequecy points to plot.

  • decibels (bool) – Plot gain in dB (default is true).

  • 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 and plt.Axes objects.

Return type:

Tuple[plt.Figure, plt.Axes]

Raises:

ValueError – If f_min is less than zero or f_max is greater than the Nyquist frequency.

plot_eigenvalues(unit_circle=True, figure_kw=None, subplot_kw=None, plot_kw=None)

Plot eigenvalues of Koopman A matrix.

Parameters:
  • figure_kw (Optional[Dict[str, Any]]) – Keyword arguments for plt.figure().

  • subplot_kw (Optional[Dict[str, Any]]) – Keyword arguments for plt.subplot().

  • plot_kw (Optional[Dict[str, Any]]) – Keyword arguments for Matplotlib plt.Axes.plot().

  • unit_circle (bool) –

Returns:

Matplotlib plt.Figure and plt.Axes objects.

Return type:

Tuple[plt.Figure, plt.Axes]

plot_koopman_matrix(subplots_kw=None, plot_kw=None)

Plot heatmap of Koopman matrices.

Parameters:
  • 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 and plt.Axes objects.

Return type:

Tuple[plt.Figure, plt.Axes]

plot_svd(subplots_kw=None, plot_kw=None)

Plot singular values of Koopman matrices.

Parameters:
  • 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 and plt.Axes objects.

Return type:

Tuple[plt.Figure, plt.Axes]

predict(X)

Perform a single-step prediction for each state in each episode.

Parameters:

X (np.ndarray) – Data matrix.

Returns:

Predicted data matrix.

Return type:

np.ndarray

score(X, y, sample_weight=None)

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)** 2).sum() and \(v\) is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.

  • sample_weight (array-like of shape (n_samples,), default=None) – Sample weights.

Returns:

score\(R^2\) of self.predict(X) w.r.t. y.

Return type:

float

Notes

The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score(). This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

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

Returns:

self – The updated object.

Return type:

object

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

set_score_request(*, sample_weight='$UNCHANGED$')

Request metadata passed to the score 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 score 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 score.

  • 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:
  • sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

  • self (LmiDmdc) –

Returns:

self – The updated object.

Return type:

object