mlpack  3.4.2
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 >
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 unsigned int /* 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
mlpack::ann::VirtualBatchNorm::Backward
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Backward pass through the layer.
prereqs.hpp
The core includes that mlpack expects; standard C++ includes and Armadillo.
mlpack::ann::VirtualBatchNorm::OutputParameter
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: virtual_batch_norm.hpp:111
mlpack::ann::VirtualBatchNorm::Parameters
OutputDataType & Parameters()
Modify the parameters.
Definition: virtual_batch_norm.hpp:108
mlpack::ann::VirtualBatchNorm::Gradient
OutputDataType & Gradient()
Modify the gradient.
Definition: virtual_batch_norm.hpp:123
mlpack::ann::VirtualBatchNorm::Delta
OutputDataType & Delta()
Modify the delta.
Definition: virtual_batch_norm.hpp:118
mlpack::ann::VirtualBatchNorm::Delta
OutputDataType const & Delta() const
Get the delta.
Definition: virtual_batch_norm.hpp:116
mlpack::ann::VirtualBatchNorm::VirtualBatchNorm
VirtualBatchNorm(const arma::Mat< eT > &referenceBatch, const size_t size, const double eps=1e-8)
Create the VirtualBatchNorm layer object for a specified number of input units.
mlpack::ann::VirtualBatchNorm::Gradient
OutputDataType const & Gradient() const
Get the gradient.
Definition: virtual_batch_norm.hpp:121
mlpack::ann::VirtualBatchNorm::Parameters
OutputDataType const & Parameters() const
Get the parameters.
Definition: virtual_batch_norm.hpp:106
mlpack::ann::VirtualBatchNorm::Gradient
void Gradient(const arma::Mat< eT > &, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
Calculate the gradient using the output delta and the input activations.
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
mlpack::ann::VirtualBatchNorm::OutputParameter
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: virtual_batch_norm.hpp:113
mlpack::ann::VirtualBatchNorm::Reset
void Reset()
Reset the layer parameters.
mlpack::ann::VirtualBatchNorm::Forward
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Forward pass of the Virtual Batch Normalization layer.
mlpack::ann::VirtualBatchNorm::serialize
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
mlpack::ann::VirtualBatchNorm::InSize
size_t InSize() const
Get the number of input units.
Definition: virtual_batch_norm.hpp:126
mlpack::ann::VirtualBatchNorm::VirtualBatchNorm
VirtualBatchNorm()
Create the VirtualBatchNorm object.
mlpack::ann::VirtualBatchNorm::Epsilon
double Epsilon() const
Get the epsilon value.
Definition: virtual_batch_norm.hpp:129
mlpack::ann::VirtualBatchNorm
Declaration of the VirtualBatchNorm layer class.
Definition: virtual_batch_norm.hpp:47