reservoir_computing.modules
Classes
Build and evaluate a RC-based model for time series classification or clustering. |
|
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:
objectBuild 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], whereNis the number of samples,Tis the number of time steps in each sample,Vis the number of variables in each sample.Training and test labels have shape
[N,C], withCbeing 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(defaultNone) Precomputed reservoir. IfNone, 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, setspectral_radius <= leak <= 1)leak – float (default
None) Amount of leakage in the reservoir state update. IfNoneor1.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 ifmts_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), orNone. IfNone, the input representations will be saved in the.input_reprattribute: 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 forreadout_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 whenreadout_type=='mlp'.num_epochs – int (default
None) Number of iterations during the optimization. Used only whenreadout_type=='mlp'.w_l2 – float (default
None) Weight of the L2 regularization. Used only whenreadout_type=='mlp'.nonlinearity – str (default
None) Type of activation function{'relu', 'tanh', 'logistic', 'identity'}. Used only whenreadout_type=='mlp'.svm_gamma – float (default
1.0) Bandwidth of the RBF kernel. Used only whenreadout_type=='svm'.svm_C – float (default
1.0) Regularization for SVM hyperplane. Used only whenreadout_type=='svm'.
- n_drop = 0
- bidir = False
- dimred_method = None
- mts_rep = 'mean'
- readout_type = 'lin'
- svm_gamma = 1.0
- 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:
objectClass to perform time series forecasting with RC.
The training and test data are multidimensional arrays of shape
[T,V], withT= 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_horizonsteps ahead:Yhat[t,:] = Xte[t+forecast_horizon,:]Reservoir parameters:
- Parameters:
reservoir – object of class
Reservoir(defaultNone) Precomputed reservoir. IfNone, 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, setspectral_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.