Implementation of the Concat class. More...
Public Member Functions | |
ConcatType () | |
Create the Concat object. More... | |
ConcatType (const size_t axis) | |
Create the Concat object, specifying a particular axis on which the layer outputs should be concatenated. More... | |
ConcatType (const ConcatType &other) | |
Copy the given ConcatType layer. More... | |
ConcatType (ConcatType &&other) | |
Take ownership of the given ConcatType layer. More... | |
virtual | ~ConcatType () |
Destroy the layers held by the model. More... | |
size_t | Axis () const |
Get the axis of concatenation. More... | |
void | Backward (const MatType &, const MatType &gy, MatType &g) |
Ordinary feed backward pass of a neural network, using 3rd-order tensors as input, calculating the function f(x) by propagating x backwards through f. More... | |
void | Backward (const MatType &, const MatType &gy, MatType &g, const size_t index) |
This is the overload of Backward() that runs only a specific layer with the given input. More... | |
ConcatType * | Clone () const |
Clone the ConcatType object. This handles polymorphism correctly. More... | |
void | ComputeOutputDimensions () |
Compute the output dimensions of the MultiLayer using InputDimensions() . More... | |
void | Forward (const MatType &input, MatType &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 MatType &, const MatType &error, MatType &) |
Calculate the gradient using the output delta and the input activation. More... | |
void | Gradient (const MatType &input, const MatType &error, MatType &gradient, const size_t index) |
This is the overload of Gradient() that runs a specific layer with the given input. More... | |
ConcatType & | operator= (const ConcatType &other) |
Copy the given ConcatType layer. More... | |
ConcatType & | operator= (ConcatType &&other) |
Take ownership of the given ConcatType layer. More... | |
template < typename Archive > | |
void | serialize (Archive &ar, const uint32_t) |
Serialize the layer. 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... | |
template<typename LayerType , typename... Args> | |
void | Add (Args... args) |
void | Add (Layer< MatType > *layer) |
void | Forward (const MatType &input, MatType &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 double | Loss () const |
Compute the loss that should be added to the objective. More... | |
const std::vector< Layer< MatType > * > | Network () const |
Get the network (series of layers) held by this MultiLayer. More... | |
std::vector< Layer< MatType > * > & | 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... | |
template < typename Archive > | |
void | serialize (Archive &ar, const uint32_t) |
Serialize the MultiLayer. More... | |
virtual void | SetWeights (typename MatType::elem_type *weightsPtr) |
Set the weights of the layer to use the memory given as weightsPtr . More... | |
virtual size_t | WeightSize () const |
Return the number of weights in the MultiLayer. 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 MatType &, const MatType &) |
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... | |
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 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 (MatType &gradient) |
Initialize memory for the gradient pass. More... | |
![]() | |
size_t | inSize |
MatType | layerDeltaMatrix |
This matrix stores all of the backwards pass results of each layer when Backward() is called. More... | |
std::vector< MatType > | layerDeltas |
These are aliases of layerDeltaMatrix for each layer. More... | |
std::vector< MatType > | layerGradients |
Gradient aliases for each layer. More... | |
MatType | layerOutputMatrix |
This matrix stores all of the outputs of each layer when Forward() is called. More... | |
std::vector< MatType > | layerOutputs |
These are aliases of layerOutputMatrix for each layer. More... | |
std::vector< Layer< MatType > * > | 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 Concat class.
The Concat class works as a feed-forward fully connected network container which plugs various layers together.
NOTE: this class is not intended to exist for long! It will be replaced with a more flexible DAG network type.
MatType | Matrix representation to accept as input and use for computation. |
Definition at line 35 of file concat.hpp.
ConcatType | ( | ) |
Create the Concat object.
The axis used for concatenation will be the last one.
Referenced by ConcatType< MatType >::Clone().
ConcatType | ( | const size_t | axis | ) |
Create the Concat object, specifying a particular axis on which the layer outputs should be concatenated.
axis | Concat axis. |
|
virtual |
Destroy the layers held by the model.
ConcatType | ( | const ConcatType< MatType > & | other | ) |
Copy the given ConcatType layer.
ConcatType | ( | ConcatType< MatType > && | other | ) |
Take ownership of the given ConcatType layer.
|
inline |
Get the axis of concatenation.
Definition at line 131 of file concat.hpp.
|
virtual |
Ordinary feed backward pass of a neural network, using 3rd-order tensors as input, calculating the function f(x) by propagating x backwards through f.
Using the results from the feed forward pass.
* | (input) The propagated input activation. |
gy | The backpropagated error. |
g | The calculated gradient. |
Reimplemented from MultiLayer< MatType >.
Referenced by ConcatType< MatType >::Clone().
void Backward | ( | const MatType & | , |
const MatType & | gy, | ||
MatType & | g, | ||
const size_t | index | ||
) |
This is the overload of Backward() that runs only a specific layer with the given input.
* | (input) The propagated input activation. |
gy | The backpropagated error. |
g | The calculated gradient. |
index | The index of the layer to run. |
|
inlinevirtual |
Clone the ConcatType object. This handles polymorphism correctly.
Reimplemented from MultiLayer< MatType >.
Definition at line 58 of file concat.hpp.
References ConcatType< MatType >::Backward(), ConcatType< MatType >::ConcatType(), ConcatType< MatType >::Forward(), ConcatType< MatType >::Gradient(), and ConcatType< MatType >::operator=().
|
inlinevirtual |
Compute the output dimensions of the MultiLayer using InputDimensions()
.
This computes the dimensions of each layer held by the MultiLayer, and the output dimensions are set to the output dimensions of the last layer.
Reimplemented from MultiLayer< MatType >.
Definition at line 136 of file concat.hpp.
References Layer< MatType >::inputDimensions, MultiLayer< MatType >::network, Layer< MatType >::OutputDimensions(), Layer< MatType >::outputDimensions, ConcatType< MatType >::serialize(), MultiLayer< MatType >::totalInputSize, and MultiLayer< MatType >::totalOutputSize.
|
virtual |
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. |
Reimplemented from MultiLayer< MatType >.
Referenced by ConcatType< MatType >::Clone().
|
virtual |
Calculate the gradient using the output delta and the input activation.
input | The input parameter used for calculating the gradient. |
error | The calculated error. |
gradient | The calculated gradient. |
Reimplemented from MultiLayer< MatType >.
Referenced by ConcatType< MatType >::Clone().
void Gradient | ( | const MatType & | input, |
const MatType & | error, | ||
MatType & | gradient, | ||
const size_t | index | ||
) |
This is the overload of Gradient() that runs a specific layer with the given input.
input | The input parameter used for calculating the gradient. |
error | The calculated error. |
gradient | The calculated gradient. |
The | index of the layer to run. |
ConcatType& operator= | ( | const ConcatType< MatType > & | other | ) |
Copy the given ConcatType layer.
Referenced by ConcatType< MatType >::Clone().
ConcatType& operator= | ( | ConcatType< MatType > && | other | ) |
Take ownership of the given ConcatType layer.
void serialize | ( | Archive & | ar, |
const uint32_t | |||
) |
Serialize the layer.
Referenced by ConcatType< MatType >::ComputeOutputDimensions().