The RecurrentLayer
provides a base layer for all layers that have recurrent functionality and store state between steps in a recurrent network.
More...
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... | |
RecurrentLayer & | operator= (const RecurrentLayer &other) |
Copy the given RecurrentLayer. More... | |
RecurrentLayer & | operator= (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... | |
![]() | |
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 Layer * | Clone () 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 Layer & | operator= (const Layer &layer) |
Copy assignment operator. This is not responsible for copying weights! More... | |
virtual Layer & | operator= (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 | |
![]() | |
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... | |
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.
MatType | Matrix representation to accept as input and use for computation. |
Definition at line 36 of file recurrent_layer.hpp.
RecurrentLayer | ( | ) |
Create the RecurrentLayer.
Referenced by RecurrentLayer< MatType >::~RecurrentLayer().
|
inlinevirtual |
Definition at line 45 of file recurrent_layer.hpp.
References RecurrentLayer< MatType >::ClearRecurrentState(), RecurrentLayer< MatType >::operator=(), and RecurrentLayer< MatType >::RecurrentLayer().
RecurrentLayer | ( | const RecurrentLayer< MatType > & | other | ) |
Copy the given RecurrentLayer.
RecurrentLayer | ( | RecurrentLayer< MatType > && | other | ) |
Take ownership of the given RecurrentLayer.
|
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().
|
inline |
Get the current step index to use in a forward or backward pass.
Definition at line 69 of file recurrent_layer.hpp.
|
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.
|
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().
RecurrentLayer& operator= | ( | const RecurrentLayer< MatType > & | other | ) |
Copy the given RecurrentLayer.
Referenced by RecurrentLayer< MatType >::~RecurrentLayer().
RecurrentLayer& operator= | ( | RecurrentLayer< MatType > && | other | ) |
Take ownership of the given RecurrentLayer.
|
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.
|
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.
void serialize | ( | Archive & | ar, |
const uint32_t | |||
) |
Serialize the recurrent layer.
Referenced by RecurrentLayer< MatType >::HasPreviousStep().