reservoir_computing.modules

Classes

RC_model

Build and evaluate a RC-based model for time series classification or clustering.

RC_forecaster

Class to perform time series forecasting with RC.

Module Contents

class reservoir_computing.modules.RC_model(reservoir=None, n_internal_units=100, spectral_radius=0.99, leak=None, connectivity=0.3, input_scaling=0.2, noise_level=0.0, n_drop=0, bidir=False, circle=False, dimred_method=None, n_dim=None, mts_rep='mean', w_ridge_embedding=1.0, readout_type='lin', w_ridge=1.0, mlp_layout=None, num_epochs=None, w_l2=None, nonlinearity=None, svm_gamma=1.0, svm_C=1.0)

Bases: object

Build and evaluate a RC-based model for time series classification or clustering.

The training and test Multivariate Time Series (MTS) are multidimensional arrays of shape [N,T,V], where N is the number of samples, T is the number of time steps in each sample, V is the number of variables in each sample.

Training and test labels have shape [N,C], with C being the number of classes.

The dataset consists of training data and respective labels (X, Y) and test data and respective labels (Xte, Yte).

Reservoir parameters:

Parameters:
  • reservoir – object of class Reservoir (default None) Precomputed reservoir. If None, the following structural hyperparameters must be specified.

  • n_internal_units – int (default 100) Processing units in the reservoir.

  • spectral_radius – float (default 0.99) Largest eigenvalue of the reservoir matrix of connection weights. To ensure the Echo State Property, set spectral_radius <= leak <= 1)

  • leak – float (default None) Amount of leakage in the reservoir state update. If None or 1.0, no leakage is used.

  • connectivity – float (default 0.3) Percentage of nonzero connection weights. Unused in circle reservoir.

  • input_scaling – float (default 0.2) Scaling of the input connection weights. Note that the input weights are randomly drawn from {-1,1}.

  • noise_level – float (default 0.0) Standard deviation of the Gaussian noise injected in the state update.

  • n_drop – int (default 0) Number of transient states to drop.

  • bidir – bool (default False) Use a bidirectional reservoir (True) or a standard one (False).

  • circle – bool (default False) Generate determinisitc reservoir with circle topology where each connection has the same weight.

Dimensionality reduction parameters:

Parameters:
  • dimred_method – str (default None) Procedure for reducing the number of features in the sequence of reservoir states. Possible options are: None (no dimensionality reduction), 'pca' (standard PCA), or 'tenpca' (tensorial PCA for multivariate time series data).

  • n_dim – int (default None) Number of resulting dimensions after the dimensionality reduction procedure.

Representation parameters:

Parameters:
  • mts_rep – str (default None) Type of MTS representation. It can be 'last' (last state), 'mean' (mean of all the states), 'output' (output model space), or 'reservoir' (reservoir model space).

  • w_ridge_embedding – float (default 1.0) Regularization parameter of the ridge regression in the output model space and reservoir model space representation; ignored if mts_rep == None.

Readout parameters:

Parameters:
  • readout_type – str (default 'lin') Type of readout used for classification. It can be 'lin' (ridge regression), 'mlp' (multiplayer perceptron), 'svm' (support vector machine), or None. If None, the input representations will be saved in the .input_repr attribute: this is useful for clustering and visualization. Also, if ``None``, the other Readout hyperparameters can be left unspecified.

  • w_ridge – float (default 1.0) Regularization parameter of the ridge regression readout (only for readout_type=='lin').

  • mlp_layout – tuple (default None) Tuple with the sizes of MLP layers, e.g., (20, 10) defines a MLP with 2 layers of 20 and 10 units respectively. Used only when readout_type=='mlp'.

  • num_epochs – int (default None) Number of iterations during the optimization. Used only when readout_type=='mlp'.

  • w_l2 – float (default None) Weight of the L2 regularization. Used only when readout_type=='mlp'.

  • nonlinearity – str (default None) Type of activation function {'relu', 'tanh', 'logistic', 'identity'}. Used only when readout_type=='mlp'.

  • svm_gamma – float (default 1.0) Bandwidth of the RBF kernel. Used only when readout_type=='svm'.

  • svm_C – float (default 1.0) Regularization for SVM hyperplane. Used only when readout_type=='svm'.

n_drop = 0
bidir = False
dimred_method = None
mts_rep = 'mean'
readout_type = 'lin'
svm_gamma = 1.0
fit(X, Y=None, verbose=True)

Train the RC model.

Parameters:

Xnp.ndarray

Array of of shape [N, T, V] representin the training data.

Ynp.ndarray

Array of shape [N, C] representing the target values.

verbosebool

If True, print the training time.

Returns:

None

predict(Xte)

Computes predictions for out-of-sample (test) data.

Parameters:

Xtenp.ndarray

Array of shape [N, T, V] representing the test data.

Returns:

pred_classnp.ndarray

Array of shape [N] representing the predicted classes.

class reservoir_computing.modules.RC_forecaster(reservoir=None, n_internal_units=100, spectral_radius=0.99, leak=None, connectivity=0.3, input_scaling=0.2, noise_level=0.0, n_drop=0, circle=False, dimred_method=None, n_dim=None, w_ridge=1.0)

Bases: object

Class to perform time series forecasting with RC.

The training and test data are multidimensional arrays of shape [T,V], with

  • T = number of time steps in each sample,

  • V = number of variables in each sample.

Given a time series X, the training data are supposed to be as follows:

Xtr, Ytr = X[0:-forecast_horizon,:], X[forecast_horizon:,:]

Once trained, the model can be used to compute prediction forecast_horizon steps ahead:

Yhat[t,:] = Xte[t+forecast_horizon,:]

Reservoir parameters:

Parameters:
  • reservoir – object of class Reservoir (default None) Precomputed reservoir. If None, the following structural hyperparameters must be specified.

  • n_internal_units – int (default 100) Processing units in the reservoir.

  • spectral_radius – float (default 0.99) Largest eigenvalue of the reservoir matrix of connection weights. To ensure the Echo State Property, set spectral_radius <= leak <= 1)

  • leak – float (default None) Amount of leakage in the reservoir state update.

  • connectivity – float (default 0.3) Percentage of nonzero connection weights.

  • input_scaling – float (default 0.2) Scaling of the input connection weights. Note that the input weights are randomly drawn from {-1,1}.

  • noise_level – float (default 0.0) Standard deviation of the Gaussian noise injected in the state update.

  • n_drop – int (default 0) Number of transient states to drop.

  • circle – bool (default False) Generate determinisitc reservoir with circle topology where each connection has the same weight.

Dimensionality reduction parameters:

Parameters:
  • dimred_method – str (default None) Procedure for reducing the number of features in the sequence of reservoir states. Possible options are: None (no dimensionality reduction), 'pca' (standard PCA), or 'tenpca' (tensorial PCA for multivariate time series data).

  • n_dim – int (default None) Number of resulting dimensions after the dimensionality reduction procedure.

Readout parameters:

Parameters:

w_ridge – float (default 1.0) Regularization parameter of the ridge regression readout.

n_drop = 0
dimred_method = None
readout
fit(X, Y, verbose=True)

Train the RC model for forecasting.

Parameters:

Xnp.ndarray

Array of shape [T, V] representing the training data.

Ynp.ndarray

Array of shape [T, V] representing the target values.

verbosebool

If True, print the training time.

Returns:

red_statesnp.ndarray

Array of shape [T, n_dim] representing the reservoir states of the time steps used for training.

predict(Xte, return_states=False)

Computes predictions for out-of-sample (test) data.

Parameters:

Xtenp.ndarray

Array of shape [T, V] representing the test data.

return_statesbool

If True, return the predicted states.

Returns:

Yhatnp.ndarray

Array of shape [T, V] representing the predicted values.

red_states_tenp.ndarray

Array of shape [T, n_dim] representing the reservoir states of the new time steps.

get_fitted_states()

Return the fitted reservoir states.

Returns:

fitted_statesnp.ndarray

Array of shape [T, n_dim] representing the fitted reservoir states.

get_predicted_states()

Return the predicted reservoir states.

Returns:

predicted_statesnp.ndarray

Array of shape [T, n_dim] representing the predicted reservoir states.