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 
55  LinearNoBias(const LinearNoBias& layer);
56 
59 
61  LinearNoBias& operator=(const LinearNoBias& layer);
62 
65 
66  /*
67  * Reset the layer parameter.
68  */
69  void Reset();
70 
78  template<typename eT>
79  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
80 
90  template<typename eT>
91  void Backward(const arma::Mat<eT>& /* input */,
92  const arma::Mat<eT>& gy,
93  arma::Mat<eT>& g);
94 
95  /*
96  * Calculate the gradient using the output delta and the input activation.
97  *
98  * @param input The input parameter used for calculating the gradient.
99  * @param error The calculated error.
100  * @param gradient The calculated gradient.
101  */
102  template<typename eT>
103  void Gradient(const arma::Mat<eT>& input,
104  const arma::Mat<eT>& error,
105  arma::Mat<eT>& gradient);
106 
108  OutputDataType const& Parameters() const { return weights; }
110  OutputDataType& Parameters() { return weights; }
111 
113  InputDataType const& InputParameter() const { return inputParameter; }
115  InputDataType& InputParameter() { return inputParameter; }
116 
118  OutputDataType const& OutputParameter() const { return outputParameter; }
120  OutputDataType& OutputParameter() { return outputParameter; }
121 
123  OutputDataType const& Delta() const { return delta; }
125  OutputDataType& Delta() { return delta; }
126 
128  size_t InputSize() const { return inSize; }
129 
131  size_t OutputSize() const { return outSize; }
132 
134  OutputDataType const& Gradient() const { return gradient; }
136  OutputDataType& Gradient() { return gradient; }
137 
139  size_t WeightSize() const
140  {
141  return inSize * outSize;
142  }
143 
145  size_t InputShape() const
146  {
147  return inSize;
148  }
149 
153  template<typename Archive>
154  void serialize(Archive& ar, const uint32_t /* version */);
155 
156  private:
158  size_t inSize;
159 
161  size_t outSize;
162 
164  OutputDataType weights;
165 
167  OutputDataType weight;
168 
170  OutputDataType delta;
171 
173  OutputDataType gradient;
174 
176  InputDataType inputParameter;
177 
179  OutputDataType outputParameter;
180 
182  RegularizerType regularizer;
183 }; // class LinearNoBias
184 
185 } // namespace ann
186 } // namespace mlpack
187 
188 // Include implementation.
189 #include "linear_no_bias_impl.hpp"
190 
191 #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.
LinearNoBias & operator=(const LinearNoBias &layer)
Copy assignment operator.
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.