linear_no_bias.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_LINEAR_NO_BIAS_HPP
14 #define MLPACK_METHODS_ANN_LAYER_LINEAR_NO_BIAS_HPP
15 
16 #include <mlpack/prereqs.hpp>
18 
19 #include "layer_types.hpp"
20 
21 namespace mlpack {
22 namespace ann {
23 
33 template <
34  typename InputDataType = arma::mat,
35  typename OutputDataType = arma::mat,
36  typename RegularizerType = NoRegularizer
37 >
38 class LinearNoBias
39 {
40  public:
42  LinearNoBias();
50  LinearNoBias(const size_t inSize,
51  const size_t outSize,
52  RegularizerType regularizer = RegularizerType());
53 
54  /*
55  * Reset the layer parameter.
56  */
57  void Reset();
58 
66  template<typename eT>
67  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
68 
78  template<typename eT>
79  void Backward(const arma::Mat<eT>& /* input */,
80  const arma::Mat<eT>& gy,
81  arma::Mat<eT>& g);
82 
83  /*
84  * Calculate the gradient using the output delta and the input activation.
85  *
86  * @param input The input parameter used for calculating the gradient.
87  * @param error The calculated error.
88  * @param gradient The calculated gradient.
89  */
90  template<typename eT>
91  void Gradient(const arma::Mat<eT>& input,
92  const arma::Mat<eT>& error,
93  arma::Mat<eT>& gradient);
94 
96  OutputDataType const& Parameters() const { return weights; }
98  OutputDataType& Parameters() { return weights; }
99 
101  InputDataType const& InputParameter() const { return inputParameter; }
103  InputDataType& InputParameter() { return inputParameter; }
104 
106  OutputDataType const& OutputParameter() const { return outputParameter; }
108  OutputDataType& OutputParameter() { return outputParameter; }
109 
111  OutputDataType const& Delta() const { return delta; }
113  OutputDataType& Delta() { return delta; }
114 
116  size_t InputSize() const { return inSize; }
117 
119  size_t OutputSize() const { return outSize; }
120 
122  OutputDataType const& Gradient() const { return gradient; }
124  OutputDataType& Gradient() { return gradient; }
125 
127  size_t WeightSize() const
128  {
129  return inSize * outSize;
130  }
131 
133  size_t InputShape() const
134  {
135  return inSize;
136  }
137 
141  template<typename Archive>
142  void serialize(Archive& ar, const uint32_t /* version */);
143 
144  private:
146  size_t inSize;
147 
149  size_t outSize;
150 
152  OutputDataType weights;
153 
155  OutputDataType weight;
156 
158  OutputDataType delta;
159 
161  OutputDataType gradient;
162 
164  InputDataType inputParameter;
165 
167  OutputDataType outputParameter;
168 
170  RegularizerType regularizer;
171 }; // class LinearNoBias
172 
173 } // namespace ann
174 } // namespace mlpack
175 
176 // Include implementation.
177 #include "linear_no_bias_impl.hpp"
178 
179 #endif
OutputDataType & Gradient()
Modify the gradient.
OutputDataType & OutputParameter()
Modify the output parameter.
Linear algebra utility functions, generally performed on matrices or vectors.
InputDataType const & InputParameter() const
Get the input parameter.
OutputDataType const & OutputParameter() const
Get the output parameter.
InputDataType & InputParameter()
Modify the input parameter.
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...
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...
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType const & Gradient() const
Get the gradient.
OutputDataType const & Parameters() const
Get the parameters.
size_t WeightSize() const
Get the size of the weights.
size_t InputShape() const
Get the shape of the input.
OutputDataType & Delta()
Modify the delta.
OutputDataType & Parameters()
Modify the parameters.
LinearNoBias()
Create the LinearNoBias object.
size_t OutputSize() const
Get the output size.
OutputDataType const & Delta() const
Get the delta.
size_t InputSize() const
Get the input size.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.