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:
123  size_t inSize;
124 
126  size_t outSize;
127 
129  OutputDataType weights;
130 
132  OutputDataType weight;
133 
135  OutputDataType delta;
136 
138  OutputDataType gradient;
139 
141  InputDataType inputParameter;
142 
144  OutputDataType outputParameter;
145 }; // class LinearNoBias
146 
147 } // namespace ann
148 } // namespace mlpack
149 
150 // Include implementation.
151 #include "linear_no_bias_impl.hpp"
152 
153 #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.
.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.
OutputDataType const & Delta() const
Get the delta.