virtual_batch_norm.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LAYER_VIRTUALBATCHNORM_HPP
13 #define MLPACK_METHODS_ANN_LAYER_VIRTUALBATCHNORM_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace ann {
19 
42 template <
43  typename InputDataType = arma::mat,
44  typename OutputDataType = arma::mat
45 >
46 class VirtualBatchNorm
47 {
48  public:
51 
60  template<typename eT>
61  VirtualBatchNorm(const arma::Mat<eT>& referenceBatch,
62  const size_t size,
63  const double eps = 1e-8);
64 
68  void Reset();
69 
78  template<typename eT>
79  void Forward(const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
80 
88  template<typename eT>
89  void Backward(const arma::Mat<eT>&& /* input */,
90  arma::Mat<eT>&& gy,
91  arma::Mat<eT>&& g);
92 
100  template<typename eT>
101  void Gradient(const arma::Mat<eT>&& /* input */,
102  arma::Mat<eT>&& error,
103  arma::Mat<eT>&& gradient);
104 
106  OutputDataType const& Parameters() const { return weights; }
108  OutputDataType& Parameters() { return weights; }
109 
111  OutputDataType const& OutputParameter() const { return outputParameter; }
113  OutputDataType& OutputParameter() { return outputParameter; }
114 
116  OutputDataType const& Delta() const { return delta; }
118  OutputDataType& Delta() { return delta; }
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 size;
134 
136  double eps;
137 
139  bool loading;
140 
142  OutputDataType gamma;
143 
145  OutputDataType beta;
146 
148  OutputDataType weights;
149 
151  OutputDataType referenceBatchMean;
152 
154  OutputDataType referenceBatchMeanSquared;
155 
157  double oldCoefficient;
158 
160  double newCoefficient;
161 
163  OutputDataType mean;
164 
166  OutputDataType variance;
167 
169  OutputDataType gradient;
170 
172  OutputDataType delta;
173 
175  OutputDataType outputParameter;
176 
178  OutputDataType inputParameter;
179 
181  OutputDataType normalized;
182 
184  OutputDataType inputSubMean;
185 }; // class VirtualBatchNorm
186 
187 } // namespace ann
188 } // namespace mlpack
189 
190 // Include the implementation.
191 #include "virtual_batch_norm_impl.hpp"
192 
193 #endif
strip_type.hpp
Definition: add_to_po.hpp:21
OutputDataType const & OutputParameter() const
Get the output parameter.
void Backward(const arma::Mat< eT > &&, arma::Mat< eT > &&gy, arma::Mat< eT > &&g)
Backward pass through the layer.
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType const & Gradient() const
Get the gradient.
void Forward(const arma::Mat< eT > &&input, arma::Mat< eT > &&output)
Forward pass of the Virtual Batch Normalization layer.
void Reset()
Reset the layer parameters.
OutputDataType & Gradient()
Modify the gradient.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
VirtualBatchNorm()
Create the VirtualBatchNorm object.
OutputDataType & Delta()
Modify the delta.
OutputDataType const & Delta() const
Get the delta.
OutputDataType const & Parameters() const
Get the parameters.
OutputDataType & Parameters()
Modify the parameters.
OutputDataType & OutputParameter()
Modify the output parameter.