mlpack 3.4.2
add.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_METHODS_ANN_LAYER_ADD_HPP
13#define MLPACK_METHODS_ANN_LAYER_ADD_HPP
14
15#include <mlpack/prereqs.hpp>
17
18namespace mlpack {
19namespace ann {
20
30template <
31 typename InputDataType = arma::mat,
32 typename OutputDataType = arma::mat
33>
34class Add
35{
36 public:
42 Add(const size_t outSize = 0);
43
51 template<typename eT>
52 void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
53
63 template<typename eT>
64 void Backward(const arma::Mat<eT>& /* input */,
65 const arma::Mat<eT>& gy,
66 arma::Mat<eT>& g);
67
75 template<typename eT>
76 void Gradient(const arma::Mat<eT>& /* input */,
77 const arma::Mat<eT>& error,
78 arma::Mat<eT>& gradient);
79
81 OutputDataType const& Parameters() const { return weights; }
83 OutputDataType& Parameters() { return weights; }
84
86 OutputDataType const& OutputParameter() const { return outputParameter; }
88 OutputDataType& OutputParameter() { return outputParameter; }
89
91 OutputDataType const& Delta() const { return delta; }
93 OutputDataType& Delta() { return delta; }
94
96 OutputDataType const& Gradient() const { return gradient; }
98 OutputDataType& Gradient() { return gradient; }
99
101 size_t OutputSize() const { return outSize; }
102
104 size_t WeightSize() const { return outSize; }
105
109 template<typename Archive>
110 void serialize(Archive& ar, const unsigned int /* version */);
111
112 private:
114 size_t outSize;
115
117 OutputDataType weights;
118
120 OutputDataType delta;
121
123 OutputDataType gradient;
124
126 OutputDataType outputParameter;
127}; // class Add
128
129} // namespace ann
130} // namespace mlpack
131
132// Include implementation.
133#include "add_impl.hpp"
134
135#endif
Implementation of the Add module class.
Definition: add.hpp:35
OutputDataType const & Delta() const
Get the delta.
Definition: add.hpp:91
OutputDataType const & Parameters() const
Get the parameters.
Definition: add.hpp:81
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...
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: add.hpp:86
size_t WeightSize() const
Get the size of weights.
Definition: add.hpp:104
size_t OutputSize() const
Get the output size.
Definition: add.hpp:101
void Gradient(const arma::Mat< eT > &, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
Calculate the gradient using the output delta and the input activation.
OutputDataType const & Gradient() const
Get the gradient.
Definition: add.hpp:96
OutputDataType & Gradient()
Modify the gradient.
Definition: add.hpp:98
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: add.hpp:88
Add(const size_t outSize=0)
Create the Add object using the specified number of output units.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
Definition: add.hpp:83
OutputDataType & Delta()
Modify the delta.
Definition: add.hpp:93
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.