noisylinear.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LAYER_NOISYLINEAR_HPP
13 #define MLPACK_METHODS_ANN_LAYER_NOISYLINEAR_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace ann {
19 
29 template <
30  typename InputDataType = arma::mat,
31  typename OutputDataType = arma::mat
32 >
33 class NoisyLinear
34 {
35  public:
37  NoisyLinear();
38 
45  NoisyLinear(const size_t inSize,
46  const size_t outSize);
47 
49  NoisyLinear(const NoisyLinear&);
50 
53 
55  NoisyLinear& operator=(const NoisyLinear& layer);
56 
59 
60  /*
61  * Reset the layer parameter.
62  */
63  void Reset();
64 
65  /*
66  * Reset the noise parameters(epsilons).
67  */
68  void ResetNoise();
69 
70  /*
71  * Reset the values of layer parameters (factorized gaussian noise).
72  */
73  void ResetParameters();
74 
82  template<typename eT>
83  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
84 
94  template<typename eT>
95  void Backward(const arma::Mat<eT>& /* input */,
96  const arma::Mat<eT>& gy,
97  arma::Mat<eT>& g);
98 
99  /*
100  * Calculate the gradient using the output delta and the input activation.
101  *
102  * @param input The input parameter used for calculating the gradient.
103  * @param error The calculated error.
104  * @param gradient The calculated gradient.
105  */
106  template<typename eT>
107  void Gradient(const arma::Mat<eT>& input,
108  const arma::Mat<eT>& error,
109  arma::Mat<eT>& gradient);
110 
112  OutputDataType const& Parameters() const { return weights; }
114  OutputDataType& Parameters() { return weights; }
115 
117  InputDataType const& InputParameter() const { return inputParameter; }
119  InputDataType& InputParameter() { return inputParameter; }
120 
122  OutputDataType const& OutputParameter() const { return outputParameter; }
124  OutputDataType& OutputParameter() { return outputParameter; }
125 
127  OutputDataType const& Delta() const { return delta; }
129  OutputDataType& Delta() { return delta; }
130 
132  size_t InputSize() const { return inSize; }
133 
135  size_t OutputSize() const { return outSize; }
136 
138  OutputDataType const& Gradient() const { return gradient; }
140  OutputDataType& Gradient() { return gradient; }
141 
143  size_t InputShape() const
144  {
145  return inSize;
146  }
147 
149  arma::mat& Bias() { return bias; }
150 
152  size_t WeightSize() const { return (outSize * inSize + outSize) * 2; }
156  template<typename Archive>
157  void serialize(Archive& ar, const uint32_t /* version */);
158 
159  private:
161  size_t inSize;
162 
164  size_t outSize;
165 
167  OutputDataType weights;
168 
170  OutputDataType weight;
171 
173  OutputDataType weightMu;
174 
176  OutputDataType weightSigma;
177 
179  OutputDataType weightEpsilon;
180 
182  OutputDataType bias;
183 
185  OutputDataType biasMu;
186 
188  OutputDataType biasSigma;
189 
191  OutputDataType biasEpsilon;
192 
194  OutputDataType delta;
195 
197  OutputDataType gradient;
198 
200  InputDataType inputParameter;
201 
203  OutputDataType outputParameter;
204 }; // class NoisyLinear
205 
206 } // namespace ann
207 } // namespace mlpack
208 
209 // Include implementation.
210 #include "noisylinear_impl.hpp"
211 
212 #endif
OutputDataType & Delta()
Modify the delta.
OutputDataType & OutputParameter()
Modify the output parameter.
OutputDataType const & Parameters() const
Get the parameters.
NoisyLinear & operator=(const NoisyLinear &layer)
Operator= copy constructor.
OutputDataType & Gradient()
Modify the gradient.
Linear algebra utility functions, generally performed on matrices or vectors.
OutputDataType const & Gradient() const
Get the gradient.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
The core includes that mlpack expects; standard C++ includes and Armadillo.
NoisyLinear()
Create the NoisyLinear object.
OutputDataType const & OutputParameter() const
Get the output 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...
arma::mat & Bias()
Modify the bias weights of the layer.
size_t WeightSize() const
Get size of weights.
OutputDataType & Parameters()
Modify the parameters.
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...
size_t InputSize() const
Get the input size.
size_t OutputSize() const
Get the output size.
size_t InputShape() const
Get the shape of the input.
OutputDataType const & Delta() const
Get the delta.
InputDataType const & InputParameter() const
Get the input parameter.
InputDataType & InputParameter()
Modify the input parameter.