pykoopman.analytics package

Module contents

class pykoopman.analytics.BaseAnalyzer(model)[source]

Bases: object

Initialize the BaseAnalyzer object.

Parameters:

model (Koopman) – An instance of pykoopman.koopman.Koopman.

validate(t, validate_data_one_traj)[source]

Validate Koopman psi.

Given a single trajectory, compute the norm of the difference between observed psi and evolved psi for each mode.

Parameters:
  • t (numpy.ndarray) – Time stamp of this validation trajectory.

  • validate_data_one_traj (numpy.ndarray) – Data matrix of this validation trajectory.

Returns:

Difference in norm for each mode.

Return type:

list

abstract prune_model(*params, **kwargs)[source]

Prune the model.

This method should be implemented by the derived classes.

Parameters:
  • *params – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Raises:

NotImplementedError – If the method is not implemented by the derived class.

class pykoopman.analytics.ModesSelectionPAD21(model: Koopman, validate_data_traj: list, truncation_threshold=0.001, max_terms_allowed=10, plot=False)[source]

Bases: BaseAnalyzer

Initialize the ModesSelectionPAD21 object.

Parameters:
  • model (Koopman) – An instance of pykoopman.koopman.Koopman.

  • validate_data_traj (list) – A list of dictionaries that contains validation trajectories. Each dictionary should have the keys ‘t’ and ‘x’, corresponding to time stamps and data matrix, respectively.

  • truncation_threshold (float, optional) – When sweeping the alpha in the sparse linear regression solver over the data, we consider any term with an absolute coefficient smaller than the truncation threshold as zero. Defaults to 1e-3.

  • max_terms_allowed (int, optional) – The maximum number of terms used to perform sparse linear regression. It can be inferred by the Q-R plot. Defaults to 10.

  • plot (bool, optional) – Set to True to plot the figures. Defaults to False.

sweep_among_best_L_modes(L: int, ALPHA_RANGE=array([1.00000000e-03, 1.09749877e-03, 1.20450354e-03, 1.32194115e-03, 1.45082878e-03, 1.59228279e-03, 1.74752840e-03, 1.91791026e-03, 2.10490414e-03, 2.31012970e-03, 2.53536449e-03, 2.78255940e-03, 3.05385551e-03, 3.35160265e-03, 3.67837977e-03, 4.03701726e-03, 4.43062146e-03, 4.86260158e-03, 5.33669923e-03, 5.85702082e-03, 6.42807312e-03, 7.05480231e-03, 7.74263683e-03, 8.49753436e-03, 9.32603347e-03, 1.02353102e-02, 1.12332403e-02, 1.23284674e-02, 1.35304777e-02, 1.48496826e-02, 1.62975083e-02, 1.78864953e-02, 1.96304065e-02, 2.15443469e-02, 2.36448941e-02, 2.59502421e-02, 2.84803587e-02, 3.12571585e-02, 3.43046929e-02, 3.76493581e-02, 4.13201240e-02, 4.53487851e-02, 4.97702356e-02, 5.46227722e-02, 5.99484250e-02, 6.57933225e-02, 7.22080902e-02, 7.92482898e-02, 8.69749003e-02, 9.54548457e-02, 1.04761575e-01, 1.14975700e-01, 1.26185688e-01, 1.38488637e-01, 1.51991108e-01, 1.66810054e-01, 1.83073828e-01, 2.00923300e-01, 2.20513074e-01, 2.42012826e-01, 2.65608778e-01, 2.91505306e-01, 3.19926714e-01, 3.51119173e-01, 3.85352859e-01, 4.22924287e-01, 4.64158883e-01, 5.09413801e-01, 5.59081018e-01, 6.13590727e-01, 6.73415066e-01, 7.39072203e-01, 8.11130831e-01, 8.90215085e-01, 9.77009957e-01, 1.07226722e+00, 1.17681195e+00, 1.29154967e+00, 1.41747416e+00, 1.55567614e+00, 1.70735265e+00, 1.87381742e+00, 2.05651231e+00, 2.25701972e+00, 2.47707636e+00, 2.71858824e+00, 2.98364724e+00, 3.27454916e+00, 3.59381366e+00, 3.94420606e+00, 4.32876128e+00, 4.75081016e+00, 5.21400829e+00, 5.72236766e+00, 6.28029144e+00, 6.89261210e+00, 7.56463328e+00, 8.30217568e+00, 9.11162756e+00, 1.00000000e+01]), MAX_ITER=100000.0, save_figure=True, plot=True)[source]

Perform sweeping among the best L modes using multi-task elastic net.

Computes multi-task elastic net over a list of alpha values and saves the coefficients for each path.

Parameters:
  • L (int) – The number of eigenmodes considered for sparse linear regression.

  • ALPHA_RANGE (numpy.ndarray, optional) – An array of alpha values on which to perform sparse linear regression. Defaults to np.logspace(-3, 1, 100).

  • MAX_ITER (int, optional) – Maximum iterations allowed in the coordinate descent algorithm. Defaults to 1e5.

  • save_figure (bool, optional) – True if the figures should be saved. Defaults to True.

  • plot (bool, optional) – True if the figures should be plotted. Defaults to True.

prune_model(i_alpha, x_train, dt=1)[source]

Prune the pykoopman.koopman.Koopman model.

Returns a pruned model that contains most of the functionality of the original model.

Parameters:
  • i_alpha (int) – The chosen index from the result of sparse linear regression to prune the model.

  • x_train (numpy.ndarray) – The training data, but only the x. Used to refit the Koopman V since the Koopman eigenmodes are sparsified.

  • dt (float, optional) – Time step used in the original model. Defaults to 1.

Returns:

The pruned model with fewer Koopman V, but

similar accuracy.

Return type:

pruned_model (PrunedKoopman)

class pykoopman.analytics.PrunedKoopman(model: Koopman, sweep_index: ndarray, dt)[source]

Bases: object

Prune the given original Koopman model at sweep_index.

Parameters:
  • model (Koopman) – An instance of pykoopman.koopman.Koopman.

  • sweep_index (np.ndarray) – Selected indices in the original Koopman model.

  • dt (float) – Time step used in the original model.

Attributes:
  • sweep_index (np.ndarray) – Selected indices in the original Koopman model.

  • lamda_ (np.ndarray) – Diagonal matrix that contains the selected eigenvalues.

  • original_model (Koopman) – An instance of pykoopman.koopman.Koopman.

  • W_ (np.ndarray) – Matrix that maps selected Koopman eigenfunctions back to the system state.

fit(x)[source]

Fit the pruned model to the training data x.

predict(x)[source]

Predict the system state at the next time stamp given x.

psi(x_col)[source]

Evaluate the selected eigenfunctions at a given state x.

phi(x_col)[source]

Not implemented.

ur()

Not implemented.

A()

Not implemented.

B()

Not implemented.

C()

Property. Returns NotImplementedError.

W()

Property. Returns the matrix that maps the selected Koopman eigenfunctions back to the system state.

lamda()

Property. Returns the diagonal matrix of selected eigenvalues.

lamda_array()

Property. Returns the selected eigenvalues as a 1D array.

continuous_lamda_array()

Property. Returns the selected eigenvalues in continuous-time as a 1D array.

fit(x)[source]

Fit the pruned model given data matrix x

Parameters:

x (numpy.ndarray) – Training data for refitting the Koopman V

Returns:

self

Return type:

PrunedKoopman

predict(x)[source]

Predict system state at the next time stamp given x

Parameters:

x (numpy.ndarray) – System state x in row-wise

Returns:

xnext – System state at the next time stamp

Return type:

numpy.ndarray

psi(x_col)[source]

Evaluate the selected psi at given state x

Parameters:

x (numpy.ndarray) – System state x in column-wise

Returns:

eigenphi – Selected eigenfunctions’ value at given state x

Return type:

numpy.ndarray

phi(x_col)[source]
property ur
property A
property B
property C
property W
property lamda
property lamda_array
property continuous_lamda_array