mlpack  master
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 
18 namespace mlpack {
19 namespace ann {
20 
30 template <
31  typename InputDataType = arma::mat,
32  typename OutputDataType = arma::mat
33 >
34 class Add
35 {
36  public:
42  Add(const size_t outSize);
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 
68  /*
69  * Calculate the gradient using the output delta and the input activation.
70  *
71  * @param input The propagated input.
72  * @param error The calculated error.
73  * @param gradient The calculated gradient.
74  */
75  template<typename eT>
76  void Gradient(const arma::Mat<eT>&& /* input */,
77  arma::Mat<eT>&& error,
78  arma::Mat<eT>&& gradient);
79 
81  OutputDataType const& Parameters() const { return weights; }
83  OutputDataType& Parameters() { return weights; }
84 
86  InputDataType const& InputParameter() const { return inputParameter; }
88  InputDataType& InputParameter() { return inputParameter; }
89 
91  OutputDataType const& OutputParameter() const { return outputParameter; }
93  OutputDataType& OutputParameter() { return outputParameter; }
94 
96  OutputDataType const& Delta() const { return delta; }
98  OutputDataType& Delta() { return delta; }
99 
101  OutputDataType const& Gradient() const { return gradient; }
103  OutputDataType& Gradient() { return gradient; }
104 
108  template<typename Archive>
109  void Serialize(Archive& ar, const unsigned int /* version */);
110 
111  private:
113  size_t outSize;
114 
116  OutputDataType weights;
117 
119  OutputDataType delta;
120 
122  OutputDataType gradient;
123 
125  InputDataType inputParameter;
126 
128  OutputDataType outputParameter;
129 }; // class Add
130 
131 } // namespace ann
132 } // namespace mlpack
133 
134 // Include implementation.
135 #include "add_impl.hpp"
136 
137 #endif
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
Implementation of the Add module class.
Definition: add.hpp:34
InputDataType & InputParameter()
Modify the input parameter.
Definition: add.hpp:88
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
InputDataType inputParameter
Locally-stored input parameter object.
Definition: add.hpp:125
The core includes that mlpack expects; standard C++ includes and Armadillo.
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 gradient
Locally-stored gradient object.
Definition: add.hpp:122
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: add.hpp:91
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: add.hpp:93
OutputDataType & Gradient()
Modify the gradient.
Definition: add.hpp:103
OutputDataType & Parameters()
Modify the parameters.
Definition: add.hpp:83
OutputDataType const & Gradient() const
Get the gradient.
Definition: add.hpp:101
Add(const size_t outSize)
Create the Add object using the specified number of output units.
OutputDataType const & Parameters() const
Get the parameters.
Definition: add.hpp:81
size_t outSize
Locally-stored number of output units.
Definition: add.hpp:113
OutputDataType outputParameter
Locally-stored output parameter object.
Definition: add.hpp:128
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 & Delta() const
Get the delta.
Definition: add.hpp:96
OutputDataType weights
Locally-stored weight object.
Definition: add.hpp:116
OutputDataType delta
Locally-stored delta object.
Definition: add.hpp:119
OutputDataType & Delta()
Modify the delta.
Definition: add.hpp:98
InputDataType const & InputParameter() const
Get the input parameter.
Definition: add.hpp:86