📄 esn.h
字号:
/// @return simulation algorithm SimAlgorithm getSimAlgorithm() const { return static_cast<SimAlgorithm>(net_info_.at(SIMULATE_ALG)); } /// @return reservoir activation function ActivationFunction getReservoirAct() const { return static_cast<ActivationFunction>(net_info_.at(RESERVOIR_ACT)); } /// @return output activation function ActivationFunction getOutputAct() const { return static_cast<ActivationFunction>(net_info_.at(OUTPUT_ACT)); } //@} //! @name GET internal data //@{ /// @return input weight matrix (neurons x inputs) const DEMatrix &getWin() { return Win_; } /// @return reservoir weight matrix (neurons x neurons) const SPMatrix &getW() { return W_; } /// @return feedback (output to reservoir) weight matrix (neurons x outputs) const DEMatrix &getWback() { return Wback_; } /// @return output weight matrix (outputs x neurons+inputs) const DEMatrix &getWout() { return Wout_; } /// @return internal state vector x (size = neurons) const DEVector &getX() { return x_; } /** * query the trained delays in delay&sum readout \sa class SimFilterDS * @return matrix with delay form neurons+inputs to all outputs * size = (output x neurons+inputs) */ DEMatrix getDelays() throw(AUExcept) { return sim_->getDelays(); } //@} //! @name GET internal data C-style interface //@{ /// get pointer to input weight matrix data and dimensions /// (neurons x inputs) /// \warning This data is in fortran style column major storage ! void getWin(T **mtx, int *rows, int *cols); /// get pointer to feedback weight matrix data and dimensions /// (neurons x outputs) /// \warning This data is in fortran style column major storage ! void getWback(T **mtx, int *rows, int *cols); /// get pointer to output weight matrix data and dimensions /// (outputs x neurons+inputs) /// \warning This data is in fortran style column major storage ! void getWout(T **mtx, int *rows, int *cols); /// get pointer to internal state vector x data and length void getX(T **vec, int *length); /*! * Copies data of the sparse reservoir weight matrix * into a dense C-style matrix. * \attention Memory of the C array must be allocated before! * @param wmtx pointer to matrix of size (neurons_ x neurons_) */ void getW(T *wmtx, int wrows, int wcols) throw(AUExcept); /** * query the trained delays in delay&sum readout \sa class SimFilterDS * and copies the data into a C-style matrix * \attention Memory of the C array must be allocated before! * @param wmtx matrix with delay form neurons+inputs to all outputs * size = (output x neurons+inputs) */ void getDelays(T *wmtx, int wrows, int wcols) throw(AUExcept); //@} //! @name SET methods //@{ /// set initialization algorithm void setInitAlgorithm(InitAlgorithm alg=INIT_STD) throw(AUExcept); /// set training algorithm void setTrainAlgorithm(TrainAlgorithm alg=TRAIN_PI) throw(AUExcept); /// set simulation algorithm void setSimAlgorithm(SimAlgorithm alg=SIM_STD) throw(AUExcept); /// set reservoir size (nr of neurons) void setSize(int neurons=10) throw(AUExcept); /// set nr of inputs to the reservoir void setInputs(int inputs=1) throw(AUExcept); /// set nr of outputs from the reservoir void setOutputs(int outputs=1) throw(AUExcept); /// set noise level for training/simulation algorithm /// @param noise with uniform distribution within [-noise|+noise] void setNoise(double noise) throw(AUExcept); /// set initialization parameter void setInitParam(InitParameter key, T value=0.); /// set reservoir activation function void setReservoirAct(ActivationFunction f=ACT_TANH) throw(AUExcept); /// set output activation function void setOutputAct(ActivationFunction f=ACT_LINEAR) throw(AUExcept); /*! * Additional method to set all parameters with string key-value * pairs, which can be used for bindings from other languages * @param param the parameter to set * @param value the value of that parameter */// void setParameter(string param, string value) throw(AUExcept); //@} //! @name SET internal data //@{ /// set input weight matrix (neurons x inputs) void setWin(const DEMatrix &Win) throw(AUExcept); /// set reservoir weight matrix (neurons x neurons) void setW(const DEMatrix &W) throw(AUExcept); /// set feedback weight matrix (neurons x outputs) void setWback(const DEMatrix &Wback) throw(AUExcept); /// set output weight matrix (outputs x neurons+inputs) void setWout(const DEMatrix &Wout) throw(AUExcept); /// set internal state vector (size = neurons) void setX(const DEVector &x) throw(AUExcept); /*! * set last output, stored by the simulation algorithm * needed in singleStep simulation with feedback * @param last vector with length = outputs */ void setLastOutput(const DEVector &last) throw(AUExcept); //@} //! @name SET internal data C-style interface //@{ /*! * set input weight matrix C-style interface (neurons x inputs) * (data will be copied into a FLENS matrix) * @param inmtx pointer to win matrix in row major storage */ void setWin(T *inmtx, int inrows, int incols) throw(AUExcept); /*! * set reservoir weight matrix C-style interface (neurons x neurons) * (data will be copied into a FLENS matrix) * @param inmtx pointer to a dense reservoir matrix in row major storage */ void setW(T *inmtx, int inrows, int incols) throw(AUExcept); /*! * set feedback weight matrix C-style interface (neurons x outputs) * (data will be copied into a FLENS matrix) * @param inmtx pointer to wback matrix in row major storage */ void setWback(T *inmtx, int inrows, int incols) throw(AUExcept); /*! * set output weight matrix C-style interface (outputs x neurons+inputs) * (data will be copied into a FLENS matrix) * @param inmtx pointer to wout matrix in row major storage */ void setWout(T *inmtx, int inrows, int incols) throw(AUExcept); /*! * set internal state vector C-style interface (size = neurons) * (data will be copied into a FLENS matrix) * @param invec pointer to state vector */ void setX(T *invec, int insize) throw(AUExcept); /*! * set last output, stored by the simulation algorithm * needed in singleStep simulation with feedback * @param last vector with size = outputs */ void setLastOutput(T *last, int size) throw(AUExcept); //@} protected: /// function object for initialization algorithm InitBase<T> *init_; /// function object for training algorithm TrainBase<T> *train_; /// function object for simulation algorithm SimBase<T> *sim_; /// input weight matrix /// \todo also sparse version !? DEMatrix Win_; /// reservoir weight matrix SPMatrix W_; /// feedback (output to reservoir) weight matrix /// \todo also sparse version !? DEMatrix Wback_; /// output weight matrix (this will be trained) /// \todo also sparse version !? DEMatrix Wout_; /// internal state vector holding the current value of each /// neuron in the reservoir DEVector x_; /*! * activation function for the reservoir * \sa activations.h */ void (*reservoirAct_)(T *data, int size); /*! * activation function for the outputs * \sa activations.h */ void (*outputAct_)(T *data, int size); /*! * inverse activation function for the outputs * \sa activations.h */ void (*outputInvAct_)(T *data, int size); /// nr of neurons in the reservoir (= reservoir size) int neurons_; /// nr of inputs to the reservoir int inputs_; /// nr of outputs from the reservoir int outputs_; /// noise level double noise_; /// parameter map for initialization arguments ParameterMap init_params_; /// enum used in the InfoMap to query network enum NetInfo { RESERVOIR_ACT, //!< reservoir activation function OUTPUT_ACT, //!< output activation function INIT_ALG, //!< initialization algorithm TRAIN_ALG, //!< training algorithm SIMULATE_ALG //!< simulation algorithm }; typedef std::map<NetInfo, int> InfoMap; /// holds strings of various ESN settings InfoMap net_info_; /// @return string of activation function enum string getActString(int act); /// @return string of init algorithm enum string getInitString(int alg); /// @return string of simulation algorithm enum string getSimString(int alg); /// @return string of training algorithm enum string getTrainString(int alg); //! @name algorithms are friends //@{ friend class InitBase<T>; friend class InitStd<T>; friend class TrainBase<T>; friend class TrainPI<T>; friend class TrainLS<T>; friend class TrainRidgeReg<T>; friend class TrainDSPI<T>; friend class SimBase<T>; friend class SimStd<T>; friend class SimSquare<T>; friend class SimLI<T>; friend class SimBP<T>; friend class SimFilter<T>; friend class SimFilter2<T>; friend class SimFilterDS<T>; //@}};} // end of namespace aureservoir#include <aureservoir/esn.hpp>#include <aureservoir/init.hpp>#include <aureservoir/simulate.hpp>#include <aureservoir/train.hpp>#endif // AURESERVOIR_ESN_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -