dabench.model
Model classes
Classes
Base for Model objects |
|
A simple Reservoir Computing data-driven model |
Package Contents
- class dabench.model.Model(system_dim=None, delta_t=None, model_obj=None)
Base for Model objects
- class dabench.model.RCModel(system_dim, input_dim, reservoir_dim=512, sparsity=0.99, sparse_adj_matrix=False, sigma=0.5, sigma_bias=0, leak_rate=1.0, spectral_radius=0.9, tikhonov_parameter=0, readout_method='linear', random_seed=1, **kwargs)
A simple Reservoir Computing data-driven model
- Parameters:
system_dim (int) – Dimension of reservoir output.
input_dim (int) – Dimension of reservoir input signal.
reservoir_dim (int) – Dimension of reservoir state. Default: 512.
sparsity (float) – the percentage of zero-valued entries in the adjacency matrix (A). Default: 0.99.
sparse_adj_matrix (bool) – If True, A is computed using scipy sparse.
sigma (float) – Scaling of the input weight matrix. Default: 0.5.
sigma_bias (float) – Bias term for sigma. Default: 0.
leak_rate (float) –
(1-leak_rate)of the reservoir state at the previous time step is incorporated during timestep update. Default: 1.spectral_radius (float) – Scaling of the reservoir adjacency matrix. Default: 0.9.
tikhonov_parameter (float) – Regularization parameter in the linear solving, penalizing amplitude of weight matrix elements. Default: 0.0.
readout_method (str) – How to handle reservoir state elements during readout. One of ‘linear’, ‘biased’, or ‘quadratic’. Default: ‘linear’.
random_seed (int) – Random seed for random number generation. Default is 1.
s (ndarray) – Model states over entire time series.
s_last (ndarray) – Last
ybar (ndarray) – y.T @ st, set in _compute_Wout.
sbar (ndarray) – st.T @ st, set in _compute_Wout.
A (ndarray) – reservoir adjacency weight matrix, set in
.weights_init().Win (ndarray) – reservoir input weight matrix, set in
.weights_init().Wout (ndarray) – trained output weight matrix, set in
.train().
- generate(state_vec, A=None, Win=None, r0=None)
generate reservoir time series from input signal u
- Parameters:
u (array_like) – (time_dimension, system_dimension), input signal to reservoir
A (array_like, optional) – (reservoir_dim, reservoir_dim), reservoir adjacency matrix
Win (array_like, optional) – (reservoir_dim, system_dimension), reservoir input weight matrix
r0 (array_like, optional) – (reservoir_dim,) initial reservoir state
save_states (bool) – If True, saves reservoir states as self.states. If False, returns states. Default: False.
- Returns:
Reservoirs state, size (time_dim, reservoir_dim)
- load_weights(pkl_path)
Load RC reservoir weights from pkl file.
- Parameters:
pkl_path (str) – Filepath with save weight matrix.
- predict(state_vec, delta_t, initial_index=0, n_steps=100, spinup_steps=0, r0=None, keep_spinup=True)
Compute the prediction phase of the RC
- Parameters:
dataobj (Data) – data object containing the initial conditions
initial_index (int, optional) – time index of initial conditions in the data object ‘values’
n_steps (int, optional) – number of steps to conduct the prediction
spinup_steps (int, optional) – number of steps before the initial_index to use for spinning up the reservoir state
r0 (array_like, optional) – initial reservoir state
- Returns:
Data object covering prediction period
- readout(rt, Wout=None, utm1=None)
use Wout to map reservoir state to output
- Parameters:
rt (array_like) – 1D or 2D with dims: (Nr,) or (Ntime, Nr) reservoir state, either passed as single time snapshot, or as matrix, with reservoir dimension as last index
utm1 (array_like) – 1D or 2D with dims: (Nu,) or (Ntime, Nu) u(t-1) for r(t), only used if readout_method = ‘biased’, then Wout*[1, u(t-1), r(t)]=u(t)
- Returns:
1D or 2D array with dims(Nout,) or (Ntime, Nout) depending on shape of input array
- save_weights(pkl_path)
Save RC reservoir weights as pkl file.
- Parameters:
pkl_path (str) – Filepath for saving with .pkl extension
- train(data_obj, update_Wout=True)
Train the localized RC model
- Parameters:
- Sets Attributes:
Wout (array_like): Trained output weight matrix
- update(r, u, A=None, Win=None)
Update reservoir state with input signal and previous state
- Parameters:
r (array_like) – (reservoir_dim,) Previous reservoir state
u (array_like) – (input_dimension,) input signal
A (array_like, optional) – (reservoir_dim, reservoir_dim), reservoir adjacency matrix. If None, uses self.A. Default is None.
Win (array_like, optional) – (reservoir_dim, input_dimension), reservoir input weight matrix. If None, uses self.Win. Default is None
- Returns:
Reservoir state at next time step, of size (reservoir_dim,)
- weights_init()
Initialize the weight matrices
Notes
Generate the random adjacency (A) and input weight matrices (Win) with sparsity determined by
sparsityattribute, scaled byspectral_radiusandsigmaparameters, respectively. If sparse_adj_matrix is True, then use scipy sparse matrices for computational speed up.- Sets Attributes:
- A (array_like): (reservoir_dim, reservoir_dim),
reservoir adjacency matrix
- Win (array_like): (reservoir_dim, input_dim),
reservoir input weight matrix
- Adense (array_like): stores dense version of A if A is specified
as sparse format.