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
17namespace mlpack {
18namespace ann {
19
42template <
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
Declaration of the VirtualBatchNorm layer class.
OutputDataType const & Delta() const
Get the delta.
OutputDataType const & Parameters() const
Get the parameters.
VirtualBatchNorm()
Create the VirtualBatchNorm object.
void Reset()
Reset the layer parameters.
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Forward pass of the Virtual Batch Normalization layer.
OutputDataType const & OutputParameter() const
Get the output parameter.
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.
OutputDataType const & Gradient() const
Get the gradient.
OutputDataType & Gradient()
Modify the gradient.
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.
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Backward pass through the layer.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t InSize() const
Get the number of input units.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
double Epsilon() const
Get the epsilon value.
OutputDataType & Delta()
Modify the delta.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.