RecurrentLayer< MatType > Class Template Referenceabstract

The RecurrentLayer provides a base layer for all layers that have recurrent functionality and store state between steps in a recurrent network. More...

Inheritance diagram for RecurrentLayer< MatType >:

Public Member Functions

 RecurrentLayer ()
 Create the RecurrentLayer. More...

 
 RecurrentLayer (const RecurrentLayer &other)
 Copy the given RecurrentLayer. More...

 
 RecurrentLayer (RecurrentLayer &&other)
 Take ownership of the given RecurrentLayer. More...

 
virtual ~RecurrentLayer ()
 
virtual void ClearRecurrentState (const size_t bpttSteps, const size_t batchSize)=0
 ClearRecurrentState() is called before any forward pass of a recurrent network. More...

 
size_t CurrentStep () const
 Get the current step index to use in a forward or backward pass. More...

 
size_t & CurrentStep ()
 Modify the current step index to use in a forward or backward pass. More...

 
bool HasPreviousStep () const
 If Forward() or Backward() has been called since ClearRecurrentState(), this will return true. More...

 
RecurrentLayeroperator= (const RecurrentLayer &other)
 Copy the given RecurrentLayer. More...

 
RecurrentLayeroperator= (RecurrentLayer &&other)
 Take ownership of the given RecurrentLayer. More...

 
size_t PreviousStep () const
 Get the previous step index, representing the value of CurrentStep() in the previous call to Forward() or Backward(). More...

 
size_t & PreviousStep ()
 Modify the previous step index, representing the value of CurrentStep() in the previous call to Forward() or Backward(). More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
 Serialize the recurrent layer. More...

 
- Public Member Functions inherited from Layer< MatType >
 Layer ()
 Default constructor. More...

 
 Layer (const Layer &layer)
 Copy constructor. This is not responsible for copying weights! More...

 
 Layer (Layer &&layer)
 Move constructor. This is not responsible for moving weights! More...

 
virtual ~Layer ()
 Default deconstructor. More...

 
virtual void Backward (const MatType &, const MatType &, MatType &)
 Performs a backpropagation step through the layer, with respect to the given input. More...

 
virtual LayerClone () const =0
 Make a copy of the object. More...

 
virtual void ComputeOutputDimensions ()
 Compute the output dimensions. More...

 
virtual void CustomInitialize (MatType &, const size_t)
 Override the weight matrix of the layer. More...

 
virtual void Forward (const MatType &, MatType &)
 Takes an input object, and computes the corresponding output of the layer. More...

 
virtual void Forward (const MatType &, const MatType &)
 Takes an input and output object, and computes the corresponding loss of the layer. More...

 
virtual void Gradient (const MatType &, const MatType &, MatType &)
 Computing the gradient of the layer with respect to its own input. More...

 
const std::vector< size_t > & InputDimensions () const
 Get the input dimensions. More...

 
std::vector< size_t > & InputDimensions ()
 Modify the input dimensions. More...

 
virtual double Loss ()
 Get the layer loss. More...

 
virtual Layeroperator= (const Layer &layer)
 Copy assignment operator. This is not responsible for copying weights! More...

 
virtual Layeroperator= (Layer &&layer)
 Move assignment operator. This is not responsible for moving weights! More...

 
const std::vector< size_t > & OutputDimensions ()
 Get the output dimensions. More...

 
virtual size_t OutputSize () final
 Get the number of elements in the output from this layer. More...

 
virtual const MatType & Parameters () const
 Get the parameters. More...

 
virtual MatType & Parameters ()
 Set the parameters. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
 Serialize the layer. More...

 
virtual void SetWeights (typename MatType::elem_type *)
 Reset the layer parameter. More...

 
virtual bool const & Training () const
 Get whether the layer is currently in training mode. More...

 
virtual bool & Training ()
 Modify whether the layer is currently in training mode. More...

 
virtual size_t WeightSize () const
 Get the total number of trainable weights in the layer. More...

 

Additional Inherited Members

- Protected Attributes inherited from Layer< MatType >
std::vector< size_t > inputDimensions
 Logical input dimensions of each point. More...

 
std::vector< size_t > outputDimensions
 Logical output dimensions of each point. More...

 
bool training
 If true, the layer is in training mode; otherwise, it is in testing mode. More...

 
bool validOutputDimensions
 This is true if ComputeOutputDimensions() has been called, and outputDimensions can be considered to be up-to-date. More...

 

Detailed Description


template
<
typename
MatType
=
arma::mat
>

class mlpack::ann::RecurrentLayer< MatType >

The RecurrentLayer provides a base layer for all layers that have recurrent functionality and store state between steps in a recurrent network.

Any RecurrentLayer should only be used with a network type such as RNN that supports recurrent layers.

Any recurrent layer that inherits from RecurrentLayer must implement the ClearRecurrentState(bpttSteps, batchSize) function; this function should allocate space to store previous states with the given batch size. See the documentation for that function for more details.

Template Parameters
MatTypeMatrix representation to accept as input and use for computation.

Definition at line 36 of file recurrent_layer.hpp.

Constructor & Destructor Documentation

◆ RecurrentLayer() [1/3]

◆ ~RecurrentLayer()

◆ RecurrentLayer() [2/3]

RecurrentLayer ( const RecurrentLayer< MatType > &  other)

Copy the given RecurrentLayer.

◆ RecurrentLayer() [3/3]

RecurrentLayer ( RecurrentLayer< MatType > &&  other)

Take ownership of the given RecurrentLayer.

Member Function Documentation

◆ ClearRecurrentState()

virtual void ClearRecurrentState ( const size_t  bpttSteps,
const size_t  batchSize 
)
pure virtual

ClearRecurrentState() is called before any forward pass of a recurrent network.

This function is responsible for allocating any memory necessary to store bpttSteps steps of previous forward and backward passes, with a batch size of batchSize.

Any internal state of the recurrent layer should be set to 0.

Implemented in LSTMType< MatType >.

Referenced by RecurrentLayer< MatType >::~RecurrentLayer().

◆ CurrentStep() [1/2]

size_t CurrentStep ( ) const
inline

Get the current step index to use in a forward or backward pass.

Definition at line 69 of file recurrent_layer.hpp.

◆ CurrentStep() [2/2]

size_t& CurrentStep ( )
inline

Modify the current step index to use in a forward or backward pass.

(Don't do this inside of your recurrent layer's implementation! This is meant to be done by the enclosing network.)

Definition at line 73 of file recurrent_layer.hpp.

◆ HasPreviousStep()

bool HasPreviousStep ( ) const
inline

If Forward() or Backward() has been called since ClearRecurrentState(), this will return true.

This should be used to determine if recurrent state should be considered in computations.

Definition at line 87 of file recurrent_layer.hpp.

References RecurrentLayer< MatType >::serialize().

◆ operator=() [1/2]

RecurrentLayer& operator= ( const RecurrentLayer< MatType > &  other)

◆ operator=() [2/2]

RecurrentLayer& operator= ( RecurrentLayer< MatType > &&  other)

Take ownership of the given RecurrentLayer.

◆ PreviousStep() [1/2]

size_t PreviousStep ( ) const
inline

Get the previous step index, representing the value of CurrentStep() in the previous call to Forward() or Backward().

Definition at line 77 of file recurrent_layer.hpp.

◆ PreviousStep() [2/2]

size_t& PreviousStep ( )
inline

Modify the previous step index, representing the value of CurrentStep() in the previous call to Forward() or Backward().

(Don't modify this inside of your recurrent layer's implementation! This is meant to be done by the enclosing network.)

Definition at line 82 of file recurrent_layer.hpp.

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t   
)

Serialize the recurrent layer.

Referenced by RecurrentLayer< MatType >::HasPreviousStep().


The documentation for this class was generated from the following file:
  • /home/jenkins-mlpack/mlpack.org/_src/mlpack-git/src/mlpack/methods/ann/layer/recurrent_layer.hpp