12 #ifndef MLPACK_METHODS_ANN_LAYER_MULTI_LAYER_HPP 13 #define MLPACK_METHODS_ANN_LAYER_MULTI_LAYER_HPP 15 #include "../make_alias.hpp" 33 template<
typename MatType>
55 for (
size_t i = 0; i <
network.size(); ++i)
70 virtual void Forward(
const MatType& input, MatType& output);
83 void Forward(
const MatType& input,
106 virtual void Backward(
const MatType& input,
124 virtual void Gradient(
const MatType& input,
125 const MatType& error,
131 virtual void SetWeights(
typename MatType::elem_type* weightsPtr);
141 const size_t elements);
159 virtual double Loss()
const;
166 template <
typename LayerType,
typename... Args>
169 network.push_back(
new LayerType(args...));
189 const std::vector<Layer<MatType>*>&
Network()
const 198 template<
typename Archive>
199 void serialize(Archive& ar,
const uint32_t );
260 #include "multi_layer_impl.hpp" std::vector< Layer< MatType > * > & Network()
Modify the network (series of layers) held by this MultiLayer.
void InitializeBackwardPassMemory(const size_t batchSize)
Initialize memory that will be used by each layer for the backwards pass, assuming that the input wil...
std::vector< MatType > layerOutputs
These are aliases of layerOutputMatrix for each layer.
std::vector< MatType > layerGradients
Gradient aliases for each layer.
Linear algebra utility functions, generally performed on matrices or vectors.
MultiLayer()
Create an empty MultiLayer that holds no layers of its own.
virtual void ComputeOutputDimensions()
Compute the output dimensions of the MultiLayer using InputDimensions().
void Add(Layer< MatType > *layer)
Add a new module to the model.
virtual void SetWeights(typename MatType::elem_type *weightsPtr)
Set the weights of the layer to use the memory given as weightsPtr.
const std::vector< Layer< MatType > * > & Network() const
Get the network (series of layers) held by this MultiLayer.
virtual void Backward(const MatType &input, const MatType &gy, MatType &g)
Perform a backward pass with the given data.
virtual MultiLayer * Clone() const
Create a copy of the MultiLayer (this is safe for polymorphic use).
virtual void Forward(const MatType &input, MatType &output)
Perform a forward pass with the given input data.
virtual ~MultiLayer()
Virtual destructor: delete all held layers.
A "multi-layer" is a layer that is a wrapper around other layers.
void Add(Args... args)
Add a new module to the model.
void InitializeForwardPassMemory(const size_t batchSize)
Initialize memory that will be used by each layer for the forward pass, assuming that the input will ...
virtual void Gradient(const MatType &input, const MatType &error, MatType &gradient)
Compute the gradients of each layer.
virtual double Loss() const
Compute the loss that should be added to the objective.
virtual size_t WeightSize() const
Return the number of weights in the MultiLayer.
virtual void CustomInitialize(MatType &W, const size_t elements)
Initialize the weight matrix of the layer.
A layer is an abstract class implementing common neural networks operations, such as convolution...
MatType layerOutputMatrix
This matrix stores all of the outputs of each layer when Forward() is called.
std::vector< Layer< MatType > * > network
The internally-held network.
std::vector< MatType > layerDeltas
These are aliases of layerDeltaMatrix for each layer.
void InitializeGradientPassMemory(MatType &gradient)
Initialize memory for the gradient pass.
void serialize(Archive &ar, const uint32_t)
Serialize the MultiLayer.
MultiLayer & operator=(const MultiLayer &other)
Copy the given MultiLayer.
MatType layerDeltaMatrix
This matrix stores all of the backwards pass results of each layer when Backward() is called...