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 
51  /*
52  * Reset the layer parameter.
53  */
54  void Reset();
55 
56  /*
57  * Reset the noise parameters(epsilons).
58  */
59  void ResetNoise();
60 
61  /*
62  * Reset the values of layer parameters (factorized gaussian noise).
63  */
64  void ResetParameters();
65 
73  template<typename eT>
74  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
75 
85  template<typename eT>
86  void Backward(const arma::Mat<eT>& /* input */,
87  const arma::Mat<eT>& gy,
88  arma::Mat<eT>& g);
89 
90  /*
91  * Calculate the gradient using the output delta and the input activation.
92  *
93  * @param input The input parameter used for calculating the gradient.
94  * @param error The calculated error.
95  * @param gradient The calculated gradient.
96  */
97  template<typename eT>
98  void Gradient(const arma::Mat<eT>& input,
99  const arma::Mat<eT>& error,
100  arma::Mat<eT>& gradient);
101 
103  OutputDataType const& Parameters() const { return weights; }
105  OutputDataType& Parameters() { return weights; }
106 
108  InputDataType const& InputParameter() const { return inputParameter; }
110  InputDataType& InputParameter() { return inputParameter; }
111 
113  OutputDataType const& OutputParameter() const { return outputParameter; }
115  OutputDataType& OutputParameter() { return outputParameter; }
116 
118  OutputDataType const& Delta() const { return delta; }
120  OutputDataType& Delta() { return delta; }
121 
123  size_t InputSize() const { return inSize; }
124 
126  size_t OutputSize() const { return outSize; }
127 
129  OutputDataType const& Gradient() const { return gradient; }
131  OutputDataType& Gradient() { return gradient; }
132 
134  arma::mat& Bias() { return bias; }
135 
139  template<typename Archive>
140  void serialize(Archive& ar, const unsigned int /* version */);
141 
142  private:
144  size_t inSize;
145 
147  size_t outSize;
148 
150  OutputDataType weights;
151 
153  OutputDataType weight;
154 
156  OutputDataType weightMu;
157 
159  OutputDataType weightSigma;
160 
162  OutputDataType weightEpsilon;
163 
165  OutputDataType bias;
166 
168  OutputDataType biasMu;
169 
171  OutputDataType biasSigma;
172 
174  OutputDataType biasEpsilon;
175 
177  OutputDataType delta;
178 
180  OutputDataType gradient;
181 
183  InputDataType inputParameter;
184 
186  OutputDataType outputParameter;
187 }; // class NoisyLinear
188 
189 } // namespace ann
190 } // namespace mlpack
191 
192 // Include implementation.
193 #include "noisylinear_impl.hpp"
194 
195 #endif
OutputDataType & Delta()
Modify the delta.
OutputDataType & OutputParameter()
Modify the output parameter.
OutputDataType const & Parameters() const
Get the parameters.
OutputDataType & Gradient()
Modify the gradient.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_po.hpp:21
OutputDataType const & Gradient() const
Get the gradient.
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.
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.
OutputDataType const & Delta() const
Get the delta.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
InputDataType const & InputParameter() const
Get the input parameter.
InputDataType & InputParameter()
Modify the input parameter.