Derrom Estimator

class derrom.estimator.derrom_estimator(rdim=1, DE_l=1, full_hist=False, intercept=False, training_slices=None, dim_reducer=None, scaler=None, NL_transformer=None, optimizer=None)[source]

Bases: BaseEstimator

Delay Embedded Regressive Reduced Order Model (derrom)

This is the estimator class with facilitates the training of the model, and the prediction and scoring of trajectories. It is designed to be modular, such that different approaches for the dimensionality reduction, feature scaling, nonlinear transformation and regression weight optimization can be passed via objects that implement the appropriate methods.

Parameters:
  • rdim (int) – number of reduced latent space dimensions. The default rdim = 1 is most likely an inappropriate choice…

  • DE_l (int) – delay embedding length. The default DE_l = 1 corresponds to no embedding, i.e., only the most recent system state is used.

  • full_hist (bool) – If set to False (default), the delay embedding is padded with the least recent state if no sufficient system history is available

  • intercept (bool) – If set to True, a bias/intercept term is added to the regression step.

  • dim_reducer (dim_reducer object) – Object that implements the train, reduce, and reconstruct methods. If set to None, no dimensionality reduction is performed. More details on the dimensionality reduction implementation in Dimensionality Reducers.

  • scaler (scaler object) – Object that implements the train, transform, and inverse transform methods. If set to None, no feature scaling is performed. More details on the feature scaler implementation in Feature Scalers.

  • NL_transformer (transformer object) – Object that implements the setup and transform methods. If set to None, no nonlinear transform of the delay-embedded system state is performed. More details on the nonlinear transformer implementation in Transformers.

  • optimizer (optimizer object) – Object that implements the solve method. In set to None, a least-squares method is applied. More details on the optimizer implementation in Optimizers.

Class attributes: (attributes, which are generated during the initialization are omitted.)

w

Regression weights obtained from the fit method contained in a matrix (2D numpy.ndarray)

Type:

numpy.ndarray

reg_mode

Regression mode. Can be set to ‘AR’ (autoregression) by the fit method. Toggles the predict method to forecast in autonomous mode, i.e., to feed its own output back as an input.

Type:

str

fit(trajectories, targets='AR', rdim=None, DE_l=None, intercept=None, full_hist=None, dim_reducer=None, scaler=None, NL_transformer=None, optimizer=None)[source]

fit a derrom model

The fit method takes care of the proper delay embedding.

Parameters:
  • trajectories (list) – A list of the training trajectories, where each element of the list is expected to be a 2D numpy.ndarray that represents an individual trajectories. Time slices must be stored in the rows (first index) and the system state variables in the columns (second index). All trajectories must have the same number of variables (columns), the number of time slices, however, may vary.

  • targets ('AR', list) – A list of the training targets, where each element is an numpy.ndarray that corresponds to training trajectory with the identical list index. Each element must have the same number of rows as the corresponding trajectory. If set to ‘AR’, i.e., autoregression, the targets are automatically generated from the time-shifted trajectories and the last and first time slices are dropped from the training and target data, respectively.

The remaining parameters are identical to the init method

forecast(init, n_steps)[source]

Forecast n steps into the future in autoregression mode

Parameters:
  • init (2D numpy.ndarray) – Initial condition. For full_hist = False, only the first snapshot (first row) of is used. Otherwise the first DE_l snapshots are used.

  • n_steps (int) – Length of the forecasted trajectory. The initial condition is thus included in n_steps

Returns:

matrix – Forecasted trajectory

Return type:

2D numpy.ndarray

get_error(trajectory=None, truth=None, pred=None, norm='rms')[source]

Computes the regression error

If no prediction is supplied, but the the trajectory, the corresponding prediction is computed first.

Parameters:
  • trajectory (2D numpy.ndarray) – If no prediction is supplied, it can be computed from the trajectory. Interchangeable with truth in autoregression (AR) mode

  • truth (2D numpy.ndarray) – Ground truth, against which the prediction is compared. Interchangeable with trajectory in autoregression (AR) mode

  • pred (2D numpy.ndarray) – Prediction corresponding to the truth.

  • norm (str, "rms", "fro", "ma") – Error norm chosen by the corresponding string. “rms” refers to the root-mean-squared error regarding all matrix elements, “fro” refers to the frobenius norm (proportional to the rms error, but not normalized to the number of matrix elements), and “max” refers to the maximum absolute error regarding all matrix elements.

Returns:

regression error – the regression error for a valid norm and -1 for an invalid norm.

Return type:

float

predict(trajectory)[source]

Predicts targets for each snapshot of the input trajectory. In autoregression mode, the first time slice is used (the first DE_l in the case of full_hist = True) as initial conditions to generate a prediction with the same length (rows) as the input trajectory.

Parameters:

trajectory (2D numpy.ndarray) – Trajectory where the time slices are stored in the rows (first index) and the state variables in the columns (second indx)

Returns:

matrix – Calculated prediction

Return type:

2D numpy.ndarray

print_status()[source]

print values of the relevant class attributes

score_multiple_trajectories(trajectories, targets=None, predictions=None, **kwargs)[source]

helper function to obtain error scores for multiple trajectories. Used by the derrom.utils.get.get_KFold_CV_scores function.

Parameters:
  • trajectories (list) – A list of the trajectories to be scored, where each element of the list is expected to be a 2D numpy.ndarray that represents an individual trajectories. Time slices must be stored in the rows (first index) and the system state variables in the columns (second index). All trajectories must have the same number of variables (columns), the number of time slices, however, may vary.

  • targets (list) – A list of the targets, where each element is an numpy.ndarray that corresponds to the trajectory with the identical list index. Each element must have the same number of rows as the corresponding trajectory. If set to ‘AR’, i.e., autoregression, no targets are required.

  • predictions (list) – A list of the predictions, where each element is an numpy.ndarray that corresponds to the trajectory with the identical list index. Supplying predictions reduces computaion time if derrom.utils.get.get_KFold_CV_scores is to be evaluated for multiple error norms.

Returns:

  • mean (float) – mean regression error from all supplied trajectories

  • scores (list) – list of all individual regression errors