13 #ifndef MLPACK_METHODS_ANN_LAYER_CONCAT_HPP 14 #define MLPACK_METHODS_ANN_LAYER_CONCAT_HPP 34 template <
typename MatType = arma::mat>
76 void Forward(
const MatType& input, MatType& output);
113 const MatType& error,
126 const MatType& error,
131 size_t Axis()
const {
return axis; }
139 for (
size_t i = 0; i < this->
network.size(); ++i)
142 this->
network[i]->ComputeOutputDimensions();
145 const size_t numOutputDimensions = (this->
network.size() == 0) ?
147 this->
network[0]->OutputDimensions().size();
156 else if (axis >= numOutputDimensions)
158 std::ostringstream oss;
159 oss <<
"Concat::ComputeOutputDimensions(): cannot concatenate outputs " 160 <<
"along axis " << axis <<
" when input only has " 162 throw std::invalid_argument(oss.str());
167 for (
size_t i = 0; i < this->outputDimensions.size(); ++i)
172 for (
size_t n = 0; n < this->
network.size(); ++n)
178 const size_t axisDim = this->
network[0]->OutputDimensions()[i];
179 for (
size_t n = 1; n < this->
network.size(); ++n)
181 const size_t axisDim2 = this->
network[n]->OutputDimensions()[i];
182 if (axisDim != axisDim2)
184 std::ostringstream oss;
185 oss <<
"Concat::ComputeOutputDimensions(): cannot concatenate " 186 <<
"outputs along axis " << axis <<
"; held layer " << n
187 <<
" has output size " << axisDim2 <<
" along axis " << i
188 <<
", but the first held layer has output size " << axisDim
189 <<
"! All layers must have identical output size in any " 190 <<
"axis other than the concatenated axis.";
191 throw std::invalid_argument(oss.str());
195 this->outputDimensions[i] = axisDim;
209 for (
size_t i = 0; i < this->outputDimensions.size(); ++i)
216 template<
typename Archive>
217 void serialize(Archive& ar,
const uint32_t );
234 #include "concat_impl.hpp" std::vector< size_t > inputDimensions
Logical input dimensions of each point.
void ComputeOutputDimensions()
Compute the output dimensions of the MultiLayer using InputDimensions().
Linear algebra utility functions, generally performed on matrices or vectors.
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.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const std::vector< size_t > & OutputDimensions()
Get the output dimensions.
virtual ~ConcatType()
Destroy the layers held by the model.
ConcatType< arma::mat > Concat
std::vector< size_t > outputDimensions
Logical output dimensions of each point.
void Forward(const MatType &input, MatType &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
A "multi-layer" is a layer that is a wrapper around other layers.
ConcatType()
Create the Concat object.
ConcatType * Clone() const
Clone the ConcatType object. This handles polymorphism correctly.
size_t Axis() const
Get the axis of concatenation.
std::vector< Layer< MatType > * > network
The internally-held network.
Implementation of the Concat class.
ConcatType & operator=(const ConcatType &other)
Copy the given ConcatType layer.
void Gradient(const MatType &, const MatType &error, MatType &)
Calculate the gradient using the output delta and the input activation.