Implementation of the MultiplyMerge module class. More...
Public Member Functions | |
MultiplyMergeType (const bool model=false, const bool run=true) | |
Create the MultiplyMerge object using the specified parameters. More... | |
~MultiplyMergeType () | |
Destructor to release allocated memory. More... | |
void | Backward (const InputType &, const OutputType &gy, OutputType &g) |
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backwards trough f, using the results from the feed forward pass. More... | |
MultiplyMergeType * | Clone () const |
Clone the MultiplyMergeType object. This handles polymorphism correctly. More... | |
void | Forward (const InputType &, OutputType &output) |
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f. More... | |
void | Gradient (const InputType &input, const OutputType &error, OutputType &gradient) |
MultiplyMerge (const MultiplyMerge &layer) | |
Copy Constructor. More... | |
MultiplyMerge (MultiplyMerge &&layer) | |
Move Constructor. More... | |
MultiplyMerge & | operator= (const MultiplyMerge &layer) |
Copy assignment operator. More... | |
MultiplyMerge & | operator= (MultiplyMerge &&layer) |
Move assignment operator. More... | |
OutputType const & | Parameters () const |
Get the parameters. More... | |
OutputType & | Parameters () |
Modify the parameters. More... | |
template < typename Archive > | |
void | serialize (Archive &ar, const uint32_t) |
Serialize the layer. More... | |
size_t | WeightSize () const |
Get the size of the weights. More... | |
![]() | |
MultiLayer () | |
Create an empty MultiLayer that holds no layers of its own. More... | |
MultiLayer (const MultiLayer &other) | |
Copy the given MultiLayer. More... | |
MultiLayer (MultiLayer &&other) | |
Take ownership of the layers of the given MultiLayer. More... | |
virtual | ~MultiLayer () |
Virtual destructor: delete all held layers. More... | |
void | Add (Args... args) |
void | Add (Layer< InputType > *layer) |
virtual void | Backward (const InputType &input, const InputType &gy, InputType &g) |
Perform a backward pass with the given data. More... | |
virtual void | ComputeOutputDimensions () |
Compute the output dimensions of the MultiLayer using InputDimensions() . More... | |
virtual void | Forward (const InputType &input, InputType &output) |
Perform a forward pass with the given input data. More... | |
void | Forward (const InputType &input, InputType &output, const size_t start, const size_t end) |
Perform a forward pass with the given input data, but only on a subset of the layers in the MultiLayer. More... | |
virtual void | Gradient (const InputType &input, const InputType &error, InputType &gradient) |
Compute the gradients of each layer. More... | |
virtual double | Loss () const |
Compute the loss that should be added to the objective. More... | |
const std::vector< Layer< InputType > *> | Network () const |
Get the network (series of layers) held by this MultiLayer. More... | |
std::vector< Layer< InputType > *> & | Network () |
Modify the network (series of layers) held by this MultiLayer. More... | |
MultiLayer & | operator= (const MultiLayer &other) |
Copy the given MultiLayer. More... | |
MultiLayer & | operator= (MultiLayer &&other) |
Take ownership of the given MultiLayer. More... | |
void | serialize (Archive &ar, const uint32_t) |
Serialize the MultiLayer. More... | |
virtual void | SetWeights (typename InputType ::elem_type *weightsPtr) |
Set the weights of the layer to use the memory given as weightsPtr . 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 | Forward (const InputType &, const InputType &) |
Takes an input and output object, and computes the corresponding loss of the layer. 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... | |
void | serialize (Archive &ar, const uint32_t) |
Serialize the layer. 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... | |
Additional Inherited Members | |
![]() | |
void | InitializeBackwardPassMemory (const size_t batchSize) |
Initialize memory that will be used by each layer for the backwards pass, assuming that the input will have the given batchSize . More... | |
void | InitializeForwardPassMemory (const size_t batchSize) |
Initialize memory that will be used by each layer for the forward pass, assuming that the input will have the given batchSize . More... | |
void | InitializeGradientPassMemory (InputType &gradient) |
Initialize memory for the gradient pass. More... | |
![]() | |
size_t | inSize |
InputType | layerDeltaMatrix |
This matrix stores all of the backwards pass results of each layer when Backward() is called. More... | |
std::vector< InputType > | layerDeltas |
These are aliases of layerDeltaMatrix for each layer. More... | |
std::vector< InputType > | layerGradients |
Gradient aliases for each layer. More... | |
InputType | layerOutputMatrix |
This matrix stores all of the outputs of each layer when Forward() is called. More... | |
std::vector< InputType > | layerOutputs |
These are aliases of layerOutputMatrix for each layer. More... | |
std::vector< Layer< InputType > *> | network |
The internally-held network. More... | |
size_t | totalInputSize |
size_t | totalOutputSize |
![]() | |
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... | |
Implementation of the MultiplyMerge module class.
The MultiplyMerge class multiplies the output of various modules element-wise.
InputType | Type of the input data (arma::colvec, arma::mat, arma::sp_mat or arma::cube). |
OutputType | Type of the output data (arma::colvec, arma::mat, arma::sp_mat or arma::cube). |
Definition at line 40 of file multiply_merge.hpp.
MultiplyMergeType | ( | const bool | model = false , |
const bool | run = true |
||
) |
Create the MultiplyMerge object using the specified parameters.
model | Expose all the network modules. |
run | Call the Forward/Backward method before the output is merged. |
Referenced by MultiplyMergeType< InputType, OutputType >::Clone().
~MultiplyMergeType | ( | ) |
Destructor to release allocated memory.
void Backward | ( | const InputType & | , |
const OutputType & | gy, | ||
OutputType & | g | ||
) |
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backwards trough f, using the results from the feed forward pass.
* | (input) The propagated input activation. |
gy | The backpropagated error. |
g | The calculated gradient. |
Referenced by MultiplyMergeType< InputType, OutputType >::Clone().
|
inlinevirtual |
Clone the MultiplyMergeType object. This handles polymorphism correctly.
Reimplemented from MultiLayer< InputType, OutputType >.
Definition at line 67 of file multiply_merge.hpp.
References MultiplyMergeType< InputType, OutputType >::Backward(), MultiplyMergeType< InputType, OutputType >::Forward(), MultiplyMergeType< InputType, OutputType >::Gradient(), and MultiplyMergeType< InputType, OutputType >::MultiplyMergeType().
void Forward | ( | const InputType & | , |
OutputType & | output | ||
) |
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f.
* | (input) Input data used for evaluating the specified function. |
output | Resulting output activation. |
Referenced by MultiplyMergeType< InputType, OutputType >::Clone().
void Gradient | ( | const InputType & | input, |
const OutputType & | error, | ||
OutputType & | gradient | ||
) |
Referenced by MultiplyMergeType< InputType, OutputType >::Clone().
MultiplyMerge | ( | const MultiplyMerge & | layer | ) |
Copy Constructor.
MultiplyMerge | ( | MultiplyMerge && | layer | ) |
Move Constructor.
MultiplyMerge& operator= | ( | const MultiplyMerge & | layer | ) |
Copy assignment operator.
MultiplyMerge& operator= | ( | MultiplyMerge && | layer | ) |
Move assignment operator.
|
inlinevirtual |
Get the parameters.
Reimplemented from Layer< InputType >.
Definition at line 103 of file multiply_merge.hpp.
|
inlinevirtual |
Modify the parameters.
Reimplemented from Layer< InputType >.
Definition at line 105 of file multiply_merge.hpp.
void serialize | ( | Archive & | ar, |
const uint32_t | |||
) |
Serialize the layer.
Referenced by MultiplyMergeType< InputType, OutputType >::WeightSize().
|
inlinevirtual |
Get the size of the weights.
Reimplemented from MultiLayer< InputType, OutputType >.
Definition at line 108 of file multiply_merge.hpp.
References MultiplyMergeType< InputType, OutputType >::serialize().