reservoirpy.compat.ESNOnline#
- class reservoirpy.compat.ESNOnline(lr, W, Win, dim_out, alpha_coef=1e-06, use_raw_input=False, input_bias=True, Wfb=None, fbfunc=None, typefloat=<class 'numpy.float64'>)[source]#
Echo State Networks using FORCE algorithm as an online learning rule.
Warning
The v0.2 model
compat.ESNOnline
is deprecated. Consider using the new Node API introduced in v0.3 (see Node functional API).The
compat.ESNOnline
implements FORCE, an online learning method. Online Echo State Networks allow one to: - quickly build online ESNs, using thereservoirpy.mat_gen
module to initialize weights, - train and test ESNs on the task of your choice in an online fashion, i.e. continuously in time.- Parameters:
lr (float) – Leaking rate
W (np.ndarray) – Reservoir weights matrix
Win (np.ndarray) – Input weights matrix
Wout (np.ndarray) – Readout weights matrix
alpha_coef (float, optional) – Coefficient to scale the inverted state correlation matrix used for FORCE learning. By default, equal to \(1e^{-6}\).
use_raw_input (bool, optional) – If True, input is used directly when computing output. By default, is False.
input_bias (bool, optional) – If True, will add a constant bias to the input vector. By default, True.
Wfb (np.array, optional) – Feedback weights matrix.
fbfunc (Callable, optional) – Feedback activation function.
typefloat (numpy.dtype, optional) –
- Wout#
Readout matrix
- Type:
np.ndarray
- state#
Last internal state computed, used to store internal dynamics of the reservoir over time, to enable online learning.
- Type:
- output_values#
Last values predicted by the network, used to store the last response of the reservoir to enable online learning.
- Type:
- state_corr_inv#
Inverse correlation matrix used in FORCE learning algorithm.
- Type:
Methods
__init__
(lr, W, Win, dim_out[, alpha_coef, ...])compute_output
(single_input[, wash_nr_time_step])Compute output from input to the reservoir.
Compute output from current state s(t) of the reservoir.
Reset inverse correlation state matrix to the initial value :
Reset reservoir by setting internal values to zero.
Reset reservoir by setting internal values to zero.
run
(inputs[, verbose])Run the model on a sequence of inputs, and returned the states and
save
(directory)Save the ESN to disk.
train
(inputs, teachers[, wash_nr_time_step, ...])Train the ESN model on a sequence of inputs.
train_from_current_state
(targeted_output[, ...])Train Wout from current internal state.
- compute_output(single_input, wash_nr_time_step=0)[source]#
Compute output from input to the reservoir.
- Parameters:
single_input (np.ndarray) – Input vector u(t)
wash_nr_time_step (int, optional) – Time for reservoir to run without collecting output or fitting
Wout
. (default, 0)
- Returns:
New state after input u(t) is passed and output after input u(t) is passed
- Return type:
np.ndarray, np.ndarray
- compute_output_from_current_state()[source]#
Compute output from current state s(t) of the reservoir.
- Returns:
Output at time t.
- Return type:
np.ndarray
- reset_correlation_matrix()[source]#
Reset inverse correlation state matrix to the initial value :
\[Corr^{inv} = Id_{N} * \alpha\]where \(\alpha\) is the
alpha_coef
and \(N\) is the number of units in the reservoir.
- run(inputs, verbose=False)[source]#
- Run the model on a sequence of inputs, and returned the states and
readouts vectors.
- Parameters:
inputs (list of numpy.ndarray) – List of inputs. Note that it should always be a list of sequences, i.e. if only one sequence (array with rows representing time axis) of inputs is used, it should be alone in a list.
verbose (bool) –
- Returns:
All outputs computed from readout and all corresponding internal states, for all inputs.
- Return type:
list of numpy.ndarray, list of numpy.ndarray
- save(directory)[source]#
Save the ESN to disk.
- Parameters:
directory (str or Path) – Directory where to save the model..
- train(inputs, teachers, wash_nr_time_step=0, verbose=False)[source]#
Train the ESN model on a sequence of inputs.
- Parameters:
inputs (list of numpy.ndarray) – List of inputs. Note that it should always be a list of sequences, i.e. if only one sequence (array with rows representing time axis) of inputs is used, it should be alone in a list.
teachers (list of numpy.ndarray) – List of ground truths. Note that is should always be a list of sequences of the same length than the inputs, i.e. if only one sequence of inputs is used, it should be alone in a list.
wash_nr_time_step (int, optional) – Number of states to considered as transient when training. Transient states will be discarded when computing readout matrix. By default, no states are removes.
verbose (bool) –
- Returns:
All states computed, for all inputs.
- Return type:
list of np.ndarray