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();
49  LinearNoBias(const size_t inSize,
50  const size_t outSize,
51  RegularizerType regularizer = RegularizerType());
52 
53  /*
54  * Reset the layer parameter.
55  */
56  void Reset();
57 
65  template<typename eT>
66  void Forward(const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
67 
77  template<typename eT>
78  void Backward(const arma::Mat<eT>&& /* input */,
79  arma::Mat<eT>&& gy,
80  arma::Mat<eT>&& g);
81 
82  /*
83  * Calculate the gradient using the output delta and the input activation.
84  *
85  * @param input The input parameter used for calculating the gradient.
86  * @param error The calculated error.
87  * @param gradient The calculated gradient.
88  */
89  template<typename eT>
90  void Gradient(const arma::Mat<eT>&& input,
91  arma::Mat<eT>&& error,
92  arma::Mat<eT>&& gradient);
93 
95  OutputDataType const& Parameters() const { return weights; }
97  OutputDataType& Parameters() { return weights; }
98 
100  InputDataType const& InputParameter() const { return inputParameter; }
102  InputDataType& InputParameter() { return inputParameter; }
103 
105  OutputDataType const& OutputParameter() const { return outputParameter; }
107  OutputDataType& OutputParameter() { return outputParameter; }
108 
110  OutputDataType const& Delta() const { return delta; }
112  OutputDataType& Delta() { return delta; }
113 
115  size_t InputSize() const { return inSize; }
116 
118  size_t OutputSize() const { return outSize; }
119 
121  OutputDataType const& Gradient() const { return gradient; }
123  OutputDataType& Gradient() { return gradient; }
124 
128  template<typename Archive>
129  void serialize(Archive& ar, const unsigned int /* version */);
130 
131  private:
133  size_t inSize;
134 
136  size_t outSize;
137 
139  OutputDataType weights;
140 
142  OutputDataType weight;
143 
145  OutputDataType delta;
146 
148  OutputDataType gradient;
149 
151  InputDataType inputParameter;
152 
154  OutputDataType outputParameter;
155 
157  RegularizerType regularizer;
158 }; // class LinearNoBias
159 
160 } // namespace ann
161 } // namespace mlpack
162 
163 // Include implementation.
164 #include "linear_no_bias_impl.hpp"
165 
166 #endif
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...
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType & OutputParameter()
Modify the output parameter.
strip_type.hpp
Definition: add_to_po.hpp:21
InputDataType const & InputParameter() const
Get the input parameter.
OutputDataType const & OutputParameter() const
Get the output parameter.
InputDataType & InputParameter()
Modify the input parameter.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Backward(const arma::Mat< eT > &&, 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 const & Gradient() const
Get the gradient.
OutputDataType const & Parameters() const
Get the parameters.
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.