#include <esn.h>
The "echo state" approach looks at RNNs from a new angle. Large RNNs are interpreted as "reservoirs" of complex, excitable dynamics. Output units "tap" from this reservoir by linearly combining the desired output signal from the rich variety of excited reservoir signals. This idea leads to training algorithms where only the network-to-output connection weights have to be trained. This can be done with known, highly efficient linear regression algorithms. from
Public Types | |||||||
typedef std::map < InitParameter, T > | ParameterMap | ||||||
typedef SPMatrix< T > ::Type | SPMatrix | ||||||
typedef DEMatrix< T > ::Type | DEMatrix | ||||||
typedef DEVector< T > ::Type | DEVector | ||||||
Public Member Functions | |||||||
ESN () | |||||||
ESN (const ESN< T > &src) | |||||||
const ESN & | operator= (const ESN< T > &src) | ||||||
~ESN () | |||||||
Algorithm interface | |||||||
void | init () throw (AUExcept) | ||||||
double | adapt (const DEMatrix &in) throw (AUExcept) | ||||||
void | train (const DEMatrix &in, const DEMatrix &out, int washout) throw (AUExcept) | ||||||
void | simulate (const DEMatrix &in, DEMatrix &out) | ||||||
void | resetState () | ||||||
C-style Algorithm interface | |||||||
double | adapt (T *inmtx, int inrows, int incols) throw (AUExcept) | ||||||
void | train (T *inmtx, int inrows, int incols, T *outmtx, int outrows, int outcols, int washout) throw (AUExcept) | ||||||
void | simulate (T *inmtx, int inrows, int incols, T *outmtx, int outrows, int outcols) throw (AUExcept) | ||||||
void | simulateStep (T *invec, int insize, T *outvec, int outsize) throw (AUExcept) | ||||||
Additional Interface for Bandpass and IIR-Filter Neurons | |||||||
void | setBPCutoff (const DEVector &f1, const DEVector &f2) throw (AUExcept) | ||||||
void | setBPCutoff (T *f1vec, int f1size, T *f2vec, int f2size) throw (AUExcept) | ||||||
void | setIIRCoeff (const DEMatrix &B, const DEMatrix &A, int series=1) throw (AUExcept) | ||||||
void | setIIRCoeff (T *bmtx, int brows, int bcols, T *amtx, int arows, int acols, int series=1) throw (AUExcept) | ||||||
GET parameters | |||||||
void | post () | ||||||
int | getSize () const | ||||||
int | getInputs () const | ||||||
int | getOutputs () const | ||||||
double | getNoise () const | ||||||
T | getInitParam (InitParameter key) | ||||||
InitAlgorithm | getInitAlgorithm () const | ||||||
TrainAlgorithm | getTrainAlgorithm () const | ||||||
SimAlgorithm | getSimAlgorithm () const | ||||||
ActivationFunction | getReservoirAct () const | ||||||
ActivationFunction | getOutputAct () const | ||||||
GET internal data | |||||||
const DEMatrix & | getWin () | ||||||
const SPMatrix & | getW () | ||||||
const DEMatrix & | getWback () | ||||||
const DEMatrix & | getWout () | ||||||
const DEVector & | getX () | ||||||
DEMatrix | getDelays () throw (AUExcept) | ||||||
GET internal data C-style interface | |||||||
void | getWin (T **mtx, int *rows, int *cols) | ||||||
void | getWback (T **mtx, int *rows, int *cols) | ||||||
void | getWout (T **mtx, int *rows, int *cols) | ||||||
void | getX (T **vec, int *length) | ||||||
void | getW (T *wmtx, int wrows, int wcols) throw (AUExcept) | ||||||
void | getDelays (T *wmtx, int wrows, int wcols) throw (AUExcept) | ||||||
SET methods | |||||||
void | setInitAlgorithm (InitAlgorithm alg=INIT_STD) throw (AUExcept) | ||||||
void | setTrainAlgorithm (TrainAlgorithm alg=TRAIN_PI) throw (AUExcept) | ||||||
void | setSimAlgorithm (SimAlgorithm alg=SIM_STD) throw (AUExcept) | ||||||
void | setSize (int neurons=10) throw (AUExcept) | ||||||
void | setInputs (int inputs=1) throw (AUExcept) | ||||||
void | setOutputs (int outputs=1) throw (AUExcept) | ||||||
void | setNoise (double noise) throw (AUExcept) | ||||||
void | setInitParam (InitParameter key, T value=0.) | ||||||
void | setReservoirAct (ActivationFunction f=ACT_TANH) throw (AUExcept) | ||||||
void | setOutputAct (ActivationFunction f=ACT_LINEAR) throw (AUExcept) | ||||||
SET internal data | |||||||
Additional method to set all parameters with string key-value pairs, which can be used for bindings from other languages
| |||||||
void | setWin (const DEMatrix &Win) throw (AUExcept) | ||||||
void | setW (const DEMatrix &W) throw (AUExcept) | ||||||
void | setWback (const DEMatrix &Wback) throw (AUExcept) | ||||||
void | setWout (const DEMatrix &Wout) throw (AUExcept) | ||||||
void | setX (const DEVector &x) throw (AUExcept) | ||||||
void | setLastOutput (const DEVector &last) throw (AUExcept) | ||||||
SET internal data C-style interface | |||||||
void | setWin (T *inmtx, int inrows, int incols) throw (AUExcept) | ||||||
void | setW (T *inmtx, int inrows, int incols) throw (AUExcept) | ||||||
void | setWback (T *inmtx, int inrows, int incols) throw (AUExcept) | ||||||
void | setWout (T *inmtx, int inrows, int incols) throw (AUExcept) | ||||||
void | setX (T *invec, int insize) throw (AUExcept) | ||||||
void | setLastOutput (T *last, int size) throw (AUExcept) | ||||||
Protected Types | |||||||
enum | NetInfo { RESERVOIR_ACT, OUTPUT_ACT, INIT_ALG, TRAIN_ALG, SIMULATE_ALG } | ||||||
typedef std::map < NetInfo, int > | InfoMap | ||||||
Protected Member Functions | |||||||
string | getActString (int act) | ||||||
string | getInitString (int alg) | ||||||
string | getSimString (int alg) | ||||||
string | getTrainString (int alg) | ||||||
Protected Attributes | |||||||
InitBase< T > * | init_ | ||||||
TrainBase< T > * | train_ | ||||||
SimBase< T > * | sim_ | ||||||
DEMatrix | Win_ | ||||||
SPMatrix | W_ | ||||||
DEMatrix | Wback_ | ||||||
DEMatrix | Wout_ | ||||||
DEVector | x_ | ||||||
void(* | reservoirAct_ )(T *data, int size) | ||||||
void(* | outputAct_ )(T *data, int size) | ||||||
void(* | outputInvAct_ )(T *data, int size) | ||||||
int | neurons_ | ||||||
int | inputs_ | ||||||
int | outputs_ | ||||||
double | noise_ | ||||||
ParameterMap | init_params_ | ||||||
InfoMap | net_info_ | ||||||
Friends | |||||||
algorithms are friends | |||||||
class | InitBase< T > | ||||||
class | InitStd< T > | ||||||
class | TrainBase< T > | ||||||
class | TrainPI< T > | ||||||
class | TrainLS< T > | ||||||
class | TrainRidgeReg< T > | ||||||
class | TrainDSPI< T > | ||||||
class | SimBase< T > | ||||||
class | SimStd< T > | ||||||
class | SimSquare< T > | ||||||
class | SimLI< T > | ||||||
class | SimBP< T > | ||||||
class | SimFilter< T > | ||||||
class | SimFilter2< T > | ||||||
class | SimFilterDS< T > |
typedef std::map<InitParameter,T> aureservoir::ESN< T >::ParameterMap |
typedef of a Parameter Map
typedef SPMatrix<T>::Type aureservoir::ESN< T >::SPMatrix |
typedef DEMatrix<T>::Type aureservoir::ESN< T >::DEMatrix |
typedef DEVector<T>::Type aureservoir::ESN< T >::DEVector |
typedef std::map<NetInfo, int> aureservoir::ESN< T >::InfoMap [protected] |
enum aureservoir::ESN::NetInfo [protected] |
aureservoir::ESN< T >::ESN | ( | ) | [inline] |
Constructor.
aureservoir::ESN< T >::ESN | ( | const ESN< T > & | src | ) | [inline] |
Copy Constructor.
aureservoir::ESN< T >::~ESN | ( | ) | [inline] |
Destructor.
const ESN< T > & aureservoir::ESN< T >::operator= | ( | const ESN< T > & | src | ) | [inline] |
assignement operator
void aureservoir::ESN< T >::init | ( | ) | throw (AUExcept) [inline] |
Initialization Algorithm for an Echo State Network
double aureservoir::ESN< T >::adapt | ( | const DEMatrix & | in | ) | throw (AUExcept) [inline] |
Reservoir Adaptation Algorithm Interface At the moment this is only the Gaussian-IP reservoir adaptation method for tanh neurons.
in | matrix of input values (inputs x timesteps), the reservoir will be adapted by this number of timesteps. |
void aureservoir::ESN< T >::train | ( | const DEMatrix & | in, | |
const DEMatrix & | out, | |||
int | washout | |||
) | throw (AUExcept) [inline] |
Training Algorithm Interface
in | matrix of input values (inputs x timesteps) | |
out | matrix of desired output values (outputs x timesteps) for teacher forcing | |
washout | washout time in samples, used to get rid of the transient dynamics of the network starting state |
void aureservoir::ESN< T >::simulate | ( | const DEMatrix & | in, | |
DEMatrix & | out | |||
) | [inline] |
Simulation Algorithm Interface
in | matrix of input values (inputs x timesteps) | |
out | matrix for output values (outputs x timesteps) |
void aureservoir::ESN< T >::resetState | ( | ) | [inline] |
resets the internal state vector x of the reservoir to zero
double aureservoir::ESN< T >::adapt | ( | T * | inmtx, | |
int | inrows, | |||
int | incols | |||
) | throw (AUExcept) [inline] |
C-style Reservoir Adaptation Algorithm Interface (data will be copied into a FLENS matrix) At the moment this is only the Gaussian-IP reservoir adaptation method for tanh neurons.
inmtx | matrix of input values (inputs x timesteps), the reservoir will be adapted by this number of timesteps. |
void aureservoir::ESN< T >::train | ( | T * | inmtx, | |
int | inrows, | |||
int | incols, | |||
T * | outmtx, | |||
int | outrows, | |||
int | outcols, | |||
int | washout | |||
) | throw (AUExcept) [inline] |
C-style Training Algorithm Interface (data will be copied into a FLENS matrix)
inmtx | input matrix in row major storage (usual C array) (inputs x timesteps) | |
outmtx | output matrix in row major storage (outputs x timesteps) for teacher forcing | |
washout | washout time in samples, used to get rid of the transient dynamics of the network starting state |
void aureservoir::ESN< T >::simulate | ( | T * | inmtx, | |
int | inrows, | |||
int | incols, | |||
T * | outmtx, | |||
int | outrows, | |||
int | outcols | |||
) | throw (AUExcept) [inline] |
C-style Simulation Algorithm Interface with some additional error checking. (data will be copied into a FLENS matrix)
inmtx | input matrix in row major storage (usual C array) (inputs x timesteps) | |
outmtx | output matrix in row major storage (outputs x timesteps), |
void aureservoir::ESN< T >::simulateStep | ( | T * | invec, | |
int | insize, | |||
T * | outvec, | |||
int | outsize | |||
) | throw (AUExcept) [inline] |
C-style Simulation Algorithm Interface, for single step simulation
void aureservoir::ESN< T >::setBPCutoff | ( | const DEVector & | f1, | |
const DEVector & | f2 | |||
) | throw (AUExcept) [inline] |
Set lowpass/highpass cutoff frequencies for bandpass style neurons. "
f1 | vector with lowpass cutoff for all neurons (size = neurons) | |
f2 | vector with highpass cutoffs (size = neurons) |
void aureservoir::ESN< T >::setBPCutoff | ( | T * | f1vec, | |
int | f1size, | |||
T * | f2vec, | |||
int | f2size | |||
) | throw (AUExcept) [inline] |
Set lowpass/highpass cutoff frequencies for bandpass style neurons " (C-style Interface).
f1 | vector with lowpass cutoff for all neurons (size = neurons) | |
f2 | vector with highpass cutoffs (size = neurons) |
void aureservoir::ESN< T >::setIIRCoeff | ( | const DEMatrix & | B, | |
const DEMatrix & | A, | |||
int | series = 1 | |||
) | throw (AUExcept) [inline] |
sets the IIR-Filter coefficients, like Matlabs filter object.
B | matrix with numerator coefficient vectors (m x nb) m ... nr of parallel filters (neurons) nb ... nr of filter coefficients | |
A | matrix with denominator coefficient vectors (m x na) m ... nr of parallel filters (neurons) na ... nr of filter coefficients | |
seris | nr of serial IIR filters, e.g. if series=2 the coefficients B and A will be divided in its half and calculated with 2 serial IIR filters |
void aureservoir::ESN< T >::setIIRCoeff | ( | T * | bmtx, | |
int | brows, | |||
int | bcols, | |||
T * | amtx, | |||
int | arows, | |||
int | acols, | |||
int | series = 1 | |||
) | throw (AUExcept) [inline] |
sets the IIR-Filter coefficients, like Matlabs filter object.
B | matrix with numerator coefficient vectors (m x nb) m ... nr of parallel filters (neurons) nb ... nr of filter coefficients | |
A | matrix with denominator coefficient vectors (m x na) m ... nr of parallel filters (neurons) na ... nr of filter coefficients | |
seris | nr of serial IIR filters, e.g. if series=2 the coefficients B and A will be divided in its half and calculated with 2 serial IIR filters |
void aureservoir::ESN< T >::post | ( | ) | [inline] |
posts current parameters to stdout
int aureservoir::ESN< T >::getSize | ( | ) | const [inline] |
int aureservoir::ESN< T >::getInputs | ( | ) | const [inline] |
int aureservoir::ESN< T >::getOutputs | ( | ) | const [inline] |
double aureservoir::ESN< T >::getNoise | ( | ) | const [inline] |
T aureservoir::ESN< T >::getInitParam | ( | InitParameter | key | ) | [inline] |
returns an initialization parametern from the parameter map
key | the requested parameter |
InitAlgorithm aureservoir::ESN< T >::getInitAlgorithm | ( | ) | const [inline] |
TrainAlgorithm aureservoir::ESN< T >::getTrainAlgorithm | ( | ) | const [inline] |
SimAlgorithm aureservoir::ESN< T >::getSimAlgorithm | ( | ) | const [inline] |
ActivationFunction aureservoir::ESN< T >::getReservoirAct | ( | ) | const [inline] |
ActivationFunction aureservoir::ESN< T >::getOutputAct | ( | ) | const [inline] |
const DEMatrix& aureservoir::ESN< T >::getWin | ( | ) | [inline] |
const SPMatrix& aureservoir::ESN< T >::getW | ( | ) | [inline] |
const DEMatrix& aureservoir::ESN< T >::getWback | ( | ) | [inline] |
const DEMatrix& aureservoir::ESN< T >::getWout | ( | ) | [inline] |
const DEVector& aureservoir::ESN< T >::getX | ( | ) | [inline] |
DEMatrix aureservoir::ESN< T >::getDelays | ( | ) | throw (AUExcept) [inline] |
query the trained delays in delay&sum readout
void aureservoir::ESN< T >::getWin | ( | T ** | mtx, | |
int * | rows, | |||
int * | cols | |||
) | [inline] |
get pointer to input weight matrix data and dimensions (neurons x inputs)
void aureservoir::ESN< T >::getWback | ( | T ** | mtx, | |
int * | rows, | |||
int * | cols | |||
) | [inline] |
get pointer to feedback weight matrix data and dimensions (neurons x outputs)
void aureservoir::ESN< T >::getWout | ( | T ** | mtx, | |
int * | rows, | |||
int * | cols | |||
) | [inline] |
get pointer to output weight matrix data and dimensions (outputs x neurons+inputs)
void aureservoir::ESN< T >::getX | ( | T ** | vec, | |
int * | length | |||
) | [inline] |
get pointer to internal state vector x data and length
void aureservoir::ESN< T >::getW | ( | T * | wmtx, | |
int | wrows, | |||
int | wcols | |||
) | throw (AUExcept) [inline] |
Copies data of the sparse reservoir weight matrix into a dense C-style matrix.
wmtx | pointer to matrix of size (neurons_ x neurons_) |
void aureservoir::ESN< T >::getDelays | ( | T * | wmtx, | |
int | wrows, | |||
int | wcols | |||
) | throw (AUExcept) [inline] |
query the trained delays in delay&sum readout
wmtx | matrix with delay form neurons+inputs to all outputs size = (output x neurons+inputs) |
void aureservoir::ESN< T >::setInitAlgorithm | ( | InitAlgorithm | alg = INIT_STD |
) | throw (AUExcept) [inline] |
set initialization algorithm
void aureservoir::ESN< T >::setTrainAlgorithm | ( | TrainAlgorithm | alg = TRAIN_PI |
) | throw (AUExcept) [inline] |
set training algorithm
void aureservoir::ESN< T >::setSimAlgorithm | ( | SimAlgorithm | alg = SIM_STD |
) | throw (AUExcept) [inline] |
set simulation algorithm
void aureservoir::ESN< T >::setSize | ( | int | neurons = 10 |
) | throw (AUExcept) [inline] |
set reservoir size (nr of neurons)
void aureservoir::ESN< T >::setInputs | ( | int | inputs = 1 |
) | throw (AUExcept) [inline] |
set nr of inputs to the reservoir
void aureservoir::ESN< T >::setOutputs | ( | int | outputs = 1 |
) | throw (AUExcept) [inline] |
set nr of outputs from the reservoir
void aureservoir::ESN< T >::setNoise | ( | double | noise | ) | throw (AUExcept) [inline] |
set noise level for training/simulation algorithm
noise | with uniform distribution within [-noise|+noise] |
void aureservoir::ESN< T >::setInitParam | ( | InitParameter | key, | |
T | value = 0. | |||
) | [inline] |
set initialization parameter
void aureservoir::ESN< T >::setReservoirAct | ( | ActivationFunction | f = ACT_TANH |
) | throw (AUExcept) [inline] |
set reservoir activation function
void aureservoir::ESN< T >::setOutputAct | ( | ActivationFunction | f = ACT_LINEAR |
) | throw (AUExcept) [inline] |
set output activation function
void aureservoir::ESN< T >::setWin | ( | const DEMatrix & | Win | ) | throw (AUExcept) [inline] |
set input weight matrix (neurons x inputs)
void aureservoir::ESN< T >::setW | ( | const DEMatrix & | W | ) | throw (AUExcept) [inline] |
set reservoir weight matrix (neurons x neurons)
void aureservoir::ESN< T >::setWback | ( | const DEMatrix & | Wback | ) | throw (AUExcept) [inline] |
set feedback weight matrix (neurons x outputs)
void aureservoir::ESN< T >::setWout | ( | const DEMatrix & | Wout | ) | throw (AUExcept) [inline] |
set output weight matrix (outputs x neurons+inputs)
void aureservoir::ESN< T >::setX | ( | const DEVector & | x | ) | throw (AUExcept) [inline] |
set internal state vector (size = neurons)
void aureservoir::ESN< T >::setLastOutput | ( | const DEVector & | last | ) | throw (AUExcept) [inline] |
set last output, stored by the simulation algorithm needed in singleStep simulation with feedback
last | vector with length = outputs |
void aureservoir::ESN< T >::setWin | ( | T * | inmtx, | |
int | inrows, | |||
int | incols | |||
) | throw (AUExcept) [inline] |
set input weight matrix C-style interface (neurons x inputs) (data will be copied into a FLENS matrix)
inmtx | pointer to win matrix in row major storage |
void aureservoir::ESN< T >::setW | ( | T * | inmtx, | |
int | inrows, | |||
int | incols | |||
) | throw (AUExcept) [inline] |
set reservoir weight matrix C-style interface (neurons x neurons) (data will be copied into a FLENS matrix)
inmtx | pointer to a dense reservoir matrix in row major storage |
void aureservoir::ESN< T >::setWback | ( | T * | inmtx, | |
int | inrows, | |||
int | incols | |||
) | throw (AUExcept) [inline] |
set feedback weight matrix C-style interface (neurons x outputs) (data will be copied into a FLENS matrix)
inmtx | pointer to wback matrix in row major storage |
void aureservoir::ESN< T >::setWout | ( | T * | inmtx, | |
int | inrows, | |||
int | incols | |||
) | throw (AUExcept) [inline] |
set output weight matrix C-style interface (outputs x neurons+inputs) (data will be copied into a FLENS matrix)
inmtx | pointer to wout matrix in row major storage |
void aureservoir::ESN< T >::setX | ( | T * | invec, | |
int | insize | |||
) | throw (AUExcept) [inline] |
set internal state vector C-style interface (size = neurons) (data will be copied into a FLENS matrix)
invec | pointer to state vector |
void aureservoir::ESN< T >::setLastOutput | ( | T * | last, | |
int | size | |||
) | throw (AUExcept) [inline] |
set last output, stored by the simulation algorithm needed in singleStep simulation with feedback
last | vector with size = outputs |
string aureservoir::ESN< T >::getActString | ( | int | act | ) | [inline, protected] |
string aureservoir::ESN< T >::getInitString | ( | int | alg | ) | [inline, protected] |
string aureservoir::ESN< T >::getSimString | ( | int | alg | ) | [inline, protected] |
string aureservoir::ESN< T >::getTrainString | ( | int | alg | ) | [inline, protected] |
friend class InitBase< T > [friend] |
friend class InitStd< T > [friend] |
friend class TrainBase< T > [friend] |
friend class TrainPI< T > [friend] |
friend class TrainLS< T > [friend] |
friend class TrainRidgeReg< T > [friend] |
friend class TrainDSPI< T > [friend] |
friend class SimBase< T > [friend] |
friend class SimStd< T > [friend] |
friend class SimSquare< T > [friend] |
friend class SimLI< T > [friend] |
friend class SimBP< T > [friend] |
friend class SimFilter< T > [friend] |
friend class SimFilter2< T > [friend] |
friend class SimFilterDS< T > [friend] |
InitBase<T>* aureservoir::ESN< T >::init_ [protected] |
function object for initialization algorithm
TrainBase<T>* aureservoir::ESN< T >::train_ [protected] |
function object for training algorithm
SimBase<T>* aureservoir::ESN< T >::sim_ [protected] |
function object for simulation algorithm
DEMatrix aureservoir::ESN< T >::Win_ [protected] |
input weight matrix
SPMatrix aureservoir::ESN< T >::W_ [protected] |
reservoir weight matrix
DEMatrix aureservoir::ESN< T >::Wback_ [protected] |
feedback (output to reservoir) weight matrix
DEMatrix aureservoir::ESN< T >::Wout_ [protected] |
output weight matrix (this will be trained)
DEVector aureservoir::ESN< T >::x_ [protected] |
internal state vector holding the current value of each neuron in the reservoir
void(* aureservoir::ESN< T >::reservoirAct_)(T *data, int size) [protected] |
activation function for the reservoir
void(* aureservoir::ESN< T >::outputAct_)(T *data, int size) [protected] |
activation function for the outputs
void(* aureservoir::ESN< T >::outputInvAct_)(T *data, int size) [protected] |
inverse activation function for the outputs
int aureservoir::ESN< T >::neurons_ [protected] |
nr of neurons in the reservoir (= reservoir size)
int aureservoir::ESN< T >::inputs_ [protected] |
nr of inputs to the reservoir
int aureservoir::ESN< T >::outputs_ [protected] |
nr of outputs from the reservoir
double aureservoir::ESN< T >::noise_ [protected] |
noise level
ParameterMap aureservoir::ESN< T >::init_params_ [protected] |
parameter map for initialization arguments
InfoMap aureservoir::ESN< T >::net_info_ [protected] |
holds strings of various ESN settings