A recurrent neural network regression model optimized for online learning. More...
#include <shark/Models/OnlineRNNet.h>
Public Member Functions | |
SHARK_EXPORT_SYMBOL | OnlineRNNet (RecurrentStructure *structure) |
creates a configured neural network More... | |
std::string | name () const |
From INameable: return the class name. More... | |
SHARK_EXPORT_SYMBOL void | eval (RealMatrix const &pattern, RealMatrix &output) |
Feeds a timestep of a time series to the model and calculates it's output. More... | |
std::size_t | inputSize () const |
obtain the input dimension More... | |
std::size_t | outputSize () const |
obtain the output dimension More... | |
SHARK_EXPORT_SYMBOL void | weightedParameterDerivative (RealMatrix const &pattern, RealMatrix const &coefficients, RealVector &gradient) |
calculates the weighted sum of gradients w.r.t the parameters More... | |
RealVector | parameterVector () const |
get internal parameters of the model More... | |
void | setParameterVector (RealVector const &newParameters) |
set internal parameters of the model More... | |
std::size_t | numberOfParameters () const |
number of parameters of the network More... | |
void | resetInternalState () |
void | setOutputActivation (RealVector const &activation) |
This Method sets the activation of the output neurons. More... | |
![]() | |
AbstractModel () | |
virtual | ~AbstractModel () |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasFirstParameterDerivative () const |
Returns true when the first parameter derivative is implemented. More... | |
bool | hasSecondParameterDerivative () const |
Returns true when the second parameter derivative is implemented. More... | |
bool | hasFirstInputDerivative () const |
Returns true when the first input derivative is implemented. More... | |
bool | hasSecondInputDerivative () const |
Returns true when the second parameter derivative is implemented. More... | |
bool | isSequential () const |
virtual boost::shared_ptr< State > | createState () const |
Creates an internal state of the model. More... | |
virtual void | read (InArchive &archive) |
From ISerializable, reads a model from an archive. More... | |
virtual void | write (OutArchive &archive) const |
writes a model to an archive More... | |
virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const=0 |
Standard interface for evaluating the response of the model to a batch of patterns. More... | |
virtual void | eval (InputType const &pattern, OutputType &output) const |
Standard interface for evaluating the response of the model to a single pattern. More... | |
Data< OutputType > | operator() (Data< InputType > const &patterns) const |
Model evaluation as an operator for a whole dataset. This is a convenience function. More... | |
OutputType | operator() (InputType const &pattern) const |
Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
BatchOutputType | operator() (BatchInputType const &patterns) const |
Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const |
calculates the weighted sum of derivatives w.r.t the parameters. More... | |
virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, Batch< RealMatrix >::type const &errorHessian, State const &state, RealVector &derivative, RealMatrix &hessian) const |
calculates the weighted sum of derivatives w.r.t the parameters More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, typename Batch< RealMatrix >::type const &errorHessian, State const &state, RealMatrix &derivative, Batch< RealMatrix >::type &hessian) const |
calculates the weighted sum of derivatives w.r.t the inputs More... | |
virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
calculates weighted input and parameter derivative at the same time More... | |
![]() | |
virtual | ~IParameterizable () |
![]() | |
virtual | ~INameable () |
![]() | |
virtual | ~ISerializable () |
Virtual d'tor. More... | |
void | load (InArchive &archive, unsigned int version) |
Versioned loading of components, calls read(...). More... | |
void | save (OutArchive &archive, unsigned int version) const |
Versioned storing of components, calls write(...). More... | |
BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Attributes | |
RecurrentStructure * | mpe_structure |
the topology of the network. More... | |
RealVector | m_activation |
the activation of the network at time t (after evaluation) More... | |
RealVector | m_lastActivation |
the activation of the network at time t-1 (before evaluation) More... | |
RealMatrix | m_unitGradient |
the gradient of the hidden units with respect to every weight More... | |
![]() | |
Features | m_features |
Additional Inherited Members | |
![]() | |
enum | Feature |
typedef RealVector | InputType |
Defines the input type of the model. More... | |
typedef RealVector | OutputType |
Defines the output type of the model. More... | |
typedef Batch< InputType >::type | BatchInputType |
defines the batch type of the input type. More... | |
typedef Batch< OutputType >::type | BatchOutputType |
defines the batch type of the output type More... | |
typedef TypedFlags< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
A recurrent neural network regression model optimized for online learning.
The OnlineRNNet can only process a single input at a time. Internally it stores the last activation as well as the derivatives which get updated over the course of the sequence. Instead of feeding in the whole sequence, the inputs must be given on after another. However if the whole sequence is available in advance, this implementation is not advisable, since it is a lot slower than RNNet which is targeted to whole sequences.
Definition at line 52 of file OnlineRNNet.h.
SHARK_EXPORT_SYMBOL shark::OnlineRNNet::OnlineRNNet | ( | RecurrentStructure * | structure | ) |
creates a configured neural network
SHARK_EXPORT_SYMBOL void shark::OnlineRNNet::eval | ( | RealMatrix const & | pattern, |
RealMatrix & | output | ||
) |
Feeds a timestep of a time series to the model and calculates it's output.
pattern | Input patterns for the network. |
output | Used to store the outputs of the network. |
Referenced by shark::GruauPole::balanceFit(), shark::GruauPole::generalFit(), shark::GruauPole::gruauFit(), and name().
|
inline |
obtain the input dimension
Definition at line 71 of file OnlineRNNet.h.
References shark::RecurrentStructure::inputs(), and mpe_structure.
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 59 of file OnlineRNNet.h.
References eval(), and SHARK_EXPORT_SYMBOL.
|
inlinevirtual |
number of parameters of the network
Reimplemented from shark::IParameterizable.
Definition at line 101 of file OnlineRNNet.h.
References mpe_structure, and shark::RecurrentStructure::parameters().
Referenced by shark::GruauPole::GruauPole(), and shark::NonMarkovPole::NonMarkovPole().
|
inline |
obtain the output dimension
Definition at line 76 of file OnlineRNNet.h.
References mpe_structure, shark::RecurrentStructure::outputs(), SHARK_EXPORT_SYMBOL, and weightedParameterDerivative().
Referenced by setOutputActivation().
|
inlinevirtual |
get internal parameters of the model
Reimplemented from shark::IParameterizable.
Definition at line 92 of file OnlineRNNet.h.
References mpe_structure, and shark::RecurrentStructure::parameterVector().
|
inline |
resets the internal state of the network. it resets the network to 0 activation and clears the derivative this method needs to be called, when a sequence ends and a new sequence is to be started
Definition at line 108 of file OnlineRNNet.h.
References m_activation, m_lastActivation, and m_unitGradient.
Referenced by shark::GruauPole::balanceFit(), shark::GruauPole::generalFit(), and shark::GruauPole::gruauFit().
|
inline |
This Method sets the activation of the output neurons.
This is usefull when teacher forcing is used. When the network is trained to predict a timeseries and diverges from the sequence at an early stage, the resulting gradient might not be very helpfull. In this case, teacher forcing can be applied to prevent diverging. However, the network might become unstable, when teacher-forcing is turned off because there is no force which prevents it from diverging anymore.
activation | Input patterns for the network. |
Definition at line 124 of file OnlineRNNet.h.
References m_activation, mpe_structure, shark::RecurrentStructure::numberOfUnits(), outputSize(), and shark::blas::subrange().
|
inlinevirtual |
set internal parameters of the model
Reimplemented from shark::IParameterizable.
Definition at line 96 of file OnlineRNNet.h.
References mpe_structure, and shark::RecurrentStructure::setParameterVector().
Referenced by shark::GruauPole::balanceFit(), shark::GruauPole::generalFit(), and shark::GruauPole::gruauFit().
SHARK_EXPORT_SYMBOL void shark::OnlineRNNet::weightedParameterDerivative | ( | RealMatrix const & | pattern, |
RealMatrix const & | coefficients, | ||
RealVector & | gradient | ||
) |
calculates the weighted sum of gradients w.r.t the parameters
Uses an iterative update scheme to calculate the gradient at timestep t from the gradient at timestep t-1 using forward propagation. This Methods requires O(n^3) Memory and O(n^4) computations, where n is the number of neurons. So if the network is very large, RNNet should be used!
pattern | the pattern to evaluate |
coefficients | the oefficients which are used to calculate the weighted sum |
gradient | the calculated gradient |
Referenced by outputSize().
|
protected |
the activation of the network at time t (after evaluation)
Definition at line 134 of file OnlineRNNet.h.
Referenced by resetInternalState(), and setOutputActivation().
|
protected |
the activation of the network at time t-1 (before evaluation)
Definition at line 136 of file OnlineRNNet.h.
Referenced by resetInternalState().
|
protected |
the gradient of the hidden units with respect to every weight
The gradient \( \frac{\delta y_k(t)}{\delta w_{ij}} \) is stored in this structure. Using this gradient, the derivative of the Network can be calculated as
\[ \frac{\delta E(y(t))}{\delta w_{ij}}=\sum_{k=1}^n\frac{\delta E(y(t))}{\delta y_k} \frac{\delta y_k(t)}{\delta w_{ij}} \]
where \( y_k(t) \) is the activation of neuron \( k \) at timestep \( t \) the gradient needs to be updated after every timestep using the formula
\[ \frac{\delta y_k(t+1)}{\delta w_{ij}}= y'_k(t)= \left[\sum_{l=1}^n w_{il}\frac{\delta y_l(t)}{\delta w_{ij}} +\delta_{kl}y_l(t-1)\right]\]
so if the gradient is needed, don't forget to call weightedParameterDerivative at every timestep!
Definition at line 147 of file OnlineRNNet.h.
Referenced by resetInternalState().
|
protected |
the topology of the network.
Definition at line 131 of file OnlineRNNet.h.
Referenced by inputSize(), numberOfParameters(), outputSize(), parameterVector(), setOutputActivation(), and setParameterVector().