shark::OnlineRNNet Class Reference

A recurrent neural network regression model optimized for online learning. More...

#include <shark/Models/OnlineRNNet.h>

+ Inheritance diagram for shark::OnlineRNNet:

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...
 
- Public Member Functions inherited from shark::AbstractModel< RealVector, RealVector >
 AbstractModel ()
 
virtual ~AbstractModel ()
 
const Featuresfeatures () 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< StatecreateState () 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< OutputTypeoperator() (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 &parameterDerivative, BatchInputType &inputDerivative) const
 calculates weighted input and parameter derivative at the same time More...
 
- Public Member Functions inherited from shark::IParameterizable
virtual ~IParameterizable ()
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
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

RecurrentStructurempe_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...
 
- Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector >
Features m_features
 

Additional Inherited Members

- Public Types inherited from shark::AbstractModel< RealVector, RealVector >
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< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 

Detailed Description

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.

Constructor & Destructor Documentation

§ OnlineRNNet()

SHARK_EXPORT_SYMBOL shark::OnlineRNNet::OnlineRNNet ( RecurrentStructure structure)

creates a configured neural network

Member Function Documentation

§ eval()

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.

Parameters
patternInput patterns for the network.
outputUsed to store the outputs of the network.

Referenced by shark::GruauPole::balanceFit(), shark::GruauPole::generalFit(), shark::GruauPole::gruauFit(), and name().

§ inputSize()

std::size_t shark::OnlineRNNet::inputSize ( ) const
inline

obtain the input dimension

Definition at line 71 of file OnlineRNNet.h.

References shark::RecurrentStructure::inputs(), and mpe_structure.

§ name()

std::string shark::OnlineRNNet::name ( ) const
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.

§ numberOfParameters()

std::size_t shark::OnlineRNNet::numberOfParameters ( ) const
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().

§ outputSize()

std::size_t shark::OnlineRNNet::outputSize ( ) const
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().

§ parameterVector()

RealVector shark::OnlineRNNet::parameterVector ( ) const
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().

§ resetInternalState()

void shark::OnlineRNNet::resetInternalState ( )
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().

§ setOutputActivation()

void shark::OnlineRNNet::setOutputActivation ( RealVector const &  activation)
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.

Parameters
activationInput 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().

§ setParameterVector()

void shark::OnlineRNNet::setParameterVector ( RealVector const &  newParameters)
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().

§ weightedParameterDerivative()

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!

Parameters
patternthe pattern to evaluate
coefficientsthe oefficients which are used to calculate the weighted sum
gradientthe calculated gradient

Referenced by outputSize().

Member Data Documentation

§ m_activation

RealVector shark::OnlineRNNet::m_activation
protected

the activation of the network at time t (after evaluation)

Definition at line 134 of file OnlineRNNet.h.

Referenced by resetInternalState(), and setOutputActivation().

§ m_lastActivation

RealVector shark::OnlineRNNet::m_lastActivation
protected

the activation of the network at time t-1 (before evaluation)

Definition at line 136 of file OnlineRNNet.h.

Referenced by resetInternalState().

§ m_unitGradient

RealMatrix shark::OnlineRNNet::m_unitGradient
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().

§ mpe_structure

RecurrentStructure* shark::OnlineRNNet::mpe_structure
protected

the topology of the network.

Definition at line 131 of file OnlineRNNet.h.

Referenced by inputSize(), numberOfParameters(), outputSize(), parameterVector(), setOutputActivation(), and setParameterVector().


The documentation for this class was generated from the following file: