mlpack  master
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>
17 
18 #include "layer_types.hpp"
19 
20 namespace mlpack {
21 namespace ann {
22 
32 template <
33  typename InputDataType = arma::mat,
34  typename OutputDataType = arma::mat
35 >
36 class LinearNoBias
37 {
38  public:
40  LinearNoBias();
47  LinearNoBias(const size_t inSize, const size_t outSize);
48 
49  /*
50  * Reset the layer parameter.
51  */
52  void Reset();
53 
61  template<typename eT>
62  void Forward(const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
63 
73  template<typename eT>
74  void Backward(const arma::Mat<eT>&& /* input */,
75  arma::Mat<eT>&& gy,
76  arma::Mat<eT>&& g);
77 
78  /*
79  * Calculate the gradient using the output delta and the input activation.
80  *
81  * @param input The input parameter used for calculating the gradient.
82  * @param error The calculated error.
83  * @param gradient The calculated gradient.
84  */
85  template<typename eT>
86  void Gradient(const arma::Mat<eT>&& input,
87  arma::Mat<eT>&& error,
88  arma::Mat<eT>&& gradient);
89 
91  OutputDataType const& Parameters() const { return weights; }
93  OutputDataType& Parameters() { return weights; }
94 
96  InputDataType const& InputParameter() const { return inputParameter; }
98  InputDataType& InputParameter() { return inputParameter; }
99 
101  OutputDataType const& OutputParameter() const { return outputParameter; }
103  OutputDataType& OutputParameter() { return outputParameter; }
104 
106  OutputDataType const& Delta() const { return delta; }
108  OutputDataType& Delta() { return delta; }
109 
111  OutputDataType const& Gradient() const { return gradient; }
113  OutputDataType& Gradient() { return gradient; }
114 
118  template<typename Archive>
119  void Serialize(Archive& ar, const unsigned int /* version */);
120 
121  private:
122 
124  size_t inSize;
125 
127  size_t outSize;
128 
130  OutputDataType weights;
131 
133  OutputDataType weight;
134 
136  OutputDataType delta;
137 
139  OutputDataType gradient;
140 
142  InputDataType inputParameter;
143 
145  OutputDataType outputParameter;
146 }; // class LinearNoBias
147 
148 } // namespace ann
149 } // namespace mlpack
150 
151 // Include implementation.
152 #include "linear_no_bias_impl.hpp"
153 
154 #endif
OutputDataType delta
Locally-stored delta object.
OutputDataType const & Delta() const
Get the delta.
OutputDataType & Delta()
Modify the delta.
InputDataType & InputParameter()
Modify the input parameter.
OutputDataType & Gradient()
Modify the gradient.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
OutputDataType weights
Locally-stored weight object.
size_t inSize
Locally-stored number of input units.
The core includes that mlpack expects; standard C++ includes and Armadillo.
InputDataType inputParameter
Locally-stored input parameter object.
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 weight
Locally-stored weight parameter.
OutputDataType const & Gradient() const
Get the gradient.
OutputDataType & Parameters()
Modify the parameters.
LinearNoBias()
Create the LinearNoBias object.
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 gradient
Locally-stored gradient object.
OutputDataType const & OutputParameter() const
Get the output parameter.
InputDataType const & InputParameter() const
Get the input parameter.
OutputDataType outputParameter
Locally-stored output parameter object.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t outSize
Locally-stored number of output units.
OutputDataType const & Parameters() const
Get the parameters.
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.