13 #ifndef MLPACK_METHODS_ANN_LAYER_SEQUENTIAL_HPP 14 #define MLPACK_METHODS_ANN_LAYER_SEQUENTIAL_HPP 18 #include "../visitor/delete_visitor.hpp" 19 #include "../visitor/copy_visitor.hpp" 20 #include "../visitor/delta_visitor.hpp" 21 #include "../visitor/output_height_visitor.hpp" 22 #include "../visitor/output_parameter_visitor.hpp" 23 #include "../visitor/output_width_visitor.hpp" 24 #include "../visitor/input_shape_visitor.hpp" 66 typename InputDataType = arma::mat,
67 typename OutputDataType = arma::mat,
68 bool Residual =
false,
69 typename... CustomLayers
88 Sequential(
const bool model,
const bool ownsLayers);
106 template<
typename eT>
107 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
118 template<
typename eT>
119 void Backward(
const arma::Mat<eT>& ,
120 const arma::Mat<eT>& gy,
130 template<
typename eT>
131 void Gradient(
const arma::Mat<eT>& input,
132 const arma::Mat<eT>& error,
140 template <
class LayerType,
class... Args>
141 void Add(Args... args) { network.push_back(
new LayerType(args...)); }
148 void Add(LayerTypes<CustomLayers...> layer) { network.push_back(layer); }
151 std::vector<LayerTypes<CustomLayers...> >&
Model()
177 arma::mat
const&
Delta()
const {
return delta; }
179 arma::mat&
Delta() {
return delta; }
182 arma::mat
const&
Gradient()
const {
return gradient; }
186 size_t InputShape()
const;
191 template<
typename Archive>
192 void serialize(Archive& ar,
const uint32_t );
202 std::vector<LayerTypes<CustomLayers...> > network;
205 arma::mat parameters;
217 std::vector<LayerTypes<CustomLayers...> > empty;
223 arma::mat inputParameter;
226 arma::mat outputParameter;
254 typename InputDataType = arma::mat,
255 typename OutputDataType = arma::mat,
256 typename... CustomLayers
259 InputDataType, OutputDataType,
true, CustomLayers...>;
arma::mat const & OutputParameter() const
Get the output parameter.
Definition: sequential.hpp:172
~Sequential()
Destroy the Sequential object.
Definition: sequential_impl.hpp:89
DeleteVisitor executes the destructor of the instantiated object.
Definition: delete_visitor.hpp:27
OutputHeightVisitor exposes the OutputHeight() method of the given module.
Definition: output_height_visitor.hpp:27
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
This visitor is to support copy constructor for neural network module.
Definition: copy_visitor.hpp:26
The core includes that mlpack expects; standard C++ includes and Armadillo.
arma::mat & Parameters()
Modify the initial point for the optimization.
Definition: sequential.hpp:164
arma::mat & Delta()
Modify the delta.
Definition: sequential.hpp:179
arma::mat & InputParameter()
Modify the input parameter.
Definition: sequential.hpp:169
OutputParameterVisitor exposes the output parameter of the given module.
Definition: output_parameter_visitor.hpp:27
Sequential(const bool model=true)
Create the Sequential object using the specified parameters.
Definition: sequential_impl.hpp:32
arma::mat const & Gradient() const
Get the gradient.
Definition: sequential.hpp:182
Sequential & operator=(const Sequential &layer)
Copy assignment operator.
Definition: sequential_impl.hpp:64
arma::mat const & InputParameter() const
Get the input parameter.
Definition: sequential.hpp:167
const arma::mat & Parameters() const
Return the initial point for the optimization.
Definition: sequential.hpp:162
std::vector< LayerTypes< CustomLayers... > > & Model()
Return the model modules.
Definition: sequential.hpp:151
arma::mat & OutputParameter()
Modify the output parameter.
Definition: sequential.hpp:174
arma::mat const & Delta() const
Get the delta.
Definition: sequential.hpp:177
DeltaVisitor exposes the delta parameter of the given module.
Definition: delta_visitor.hpp:27
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &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.
Definition: sequential_impl.hpp:194
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
Definition: sequential_impl.hpp:120
OutputWidthVisitor exposes the OutputWidth() method of the given module.
Definition: output_width_visitor.hpp:27
arma::mat & Gradient()
Modify the gradient.
Definition: sequential.hpp:184
Implementation of the Sequential class.
Definition: layer_types.hpp:145
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: sequential_impl.hpp:249