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  const arma::Mat<eT>& gy,
91  arma::Mat<eT>& g);
92 
100  template<typename eT>
101  void Gradient(const arma::Mat<eT>& /* input */,
102  const 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 
126  size_t InSize() const { return size; }
127 
129  double Epsilon() const { return eps; }
130 
134  template<typename Archive>
135  void serialize(Archive& ar, const uint32_t /* version */);
136 
137  private:
139  size_t size;
140 
142  double eps;
143 
145  bool loading;
146 
148  OutputDataType gamma;
149 
151  OutputDataType beta;
152 
154  OutputDataType weights;
155 
157  OutputDataType referenceBatchMean;
158 
160  OutputDataType referenceBatchMeanSquared;
161 
163  double oldCoefficient;
164 
166  double newCoefficient;
167 
169  OutputDataType mean;
170 
172  OutputDataType variance;
173 
175  OutputDataType gradient;
176 
178  OutputDataType delta;
179 
181  OutputDataType outputParameter;
182 
184  OutputDataType inputParameter;
185 
187  OutputDataType normalized;
188 
190  OutputDataType inputSubMean;
191 }; // class VirtualBatchNorm
192 
193 } // namespace ann
194 } // namespace mlpack
195 
196 // Include the implementation.
197 #include "virtual_batch_norm_impl.hpp"
198 
199 #endif
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Linear algebra utility functions, generally performed on matrices or vectors.
OutputDataType const & OutputParameter() const
Get the output parameter.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Forward pass of the Virtual Batch Normalization layer.
OutputDataType const & Gradient() const
Get the gradient.
void Reset()
Reset the layer parameters.
OutputDataType & Gradient()
Modify the gradient.
VirtualBatchNorm()
Create the VirtualBatchNorm object.
OutputDataType & Delta()
Modify the delta.
OutputDataType const & Delta() const
Get the delta.
OutputDataType const & Parameters() const
Get the parameters.
size_t InSize() const
Get the number of input units.
OutputDataType & Parameters()
Modify the parameters.
OutputDataType & OutputParameter()
Modify the output parameter.
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Backward pass through the layer.
double Epsilon() const
Get the epsilon value.