mlpack 3.4.2
minibatch_discrimination.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_METHODS_ANN_LAYER_MINIBATCH_DISCRIMINATION_HPP
13#define MLPACK_METHODS_ANN_LAYER_MINIBATCH_DISCRIMINATION_HPP
14
15#include <mlpack/prereqs.hpp>
16
17#include "layer_types.hpp"
18
19namespace mlpack {
20namespace ann {
21
49template <
50 typename InputDataType = arma::mat,
51 typename OutputDataType = arma::mat
52>
54{
55 public:
58
67 MiniBatchDiscrimination(const size_t inSize,
68 const size_t outSize,
69 const size_t features);
70
74 void Reset();
75
83 template<typename eT>
84 void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
85
95 template<typename eT>
96 void Backward(const arma::Mat<eT>& /* input */,
97 const arma::Mat<eT>& gy,
98 arma::Mat<eT>& g);
99
107 template<typename eT>
108 void Gradient(const arma::Mat<eT>& input,
109 const arma::Mat<eT>& /* error */,
110 arma::Mat<eT>& gradient);
111
113 OutputDataType const& Parameters() const { return weights; }
115 OutputDataType& Parameters() { return weights; }
116
118 InputDataType const& InputParameter() const { return inputParameter; }
120 InputDataType& InputParameter() { return inputParameter; }
121
123 OutputDataType const& OutputParameter() const { return outputParameter; }
125 OutputDataType& OutputParameter() { return outputParameter; }
126
128 OutputDataType const& Delta() const { return delta; }
130 OutputDataType& Delta() { return delta; }
131
133 OutputDataType const& Gradient() const { return gradient; }
135 OutputDataType& Gradient() { return gradient; }
136
140 template<typename Archive>
141 void serialize(Archive& ar, const unsigned int /* version */);
142
143 private:
145 size_t A, B, C;
146
148 size_t batchSize;
149
151 arma::mat tempM;
152
154 OutputDataType weights;
155
157 OutputDataType weight;
158
160 arma::cube M;
161
163 arma::cube deltaM;
164
166 arma::cube distances;
167
169 OutputDataType delta;
170
172 OutputDataType deltaTemp;
173
175 OutputDataType gradient;
176
178 InputDataType inputParameter;
179
181 OutputDataType outputParameter;
182}; // class MiniBatchDiscrimination
183
184} // namespace ann
185} // namespace mlpack
186
187// Include implementation.
188#include "minibatch_discrimination_impl.hpp"
189
190#endif
Implementation of the MiniBatchDiscrimination layer.
OutputDataType const & Delta() const
Get the delta.
OutputDataType const & Parameters() const
Get the parameters.
void Reset()
Reset the layer parameter.
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...
InputDataType & InputParameter()
Modify the input parameter.
OutputDataType const & OutputParameter() const
Get the output parameter.
void Gradient(const arma::Mat< eT > &input, const arma::Mat< eT > &, arma::Mat< eT > &gradient)
Calculate the gradient using the output delta and the input activation.
MiniBatchDiscrimination()
Create the MiniBatchDiscrimination object.
OutputDataType const & Gradient() const
Get the gradient.
InputDataType const & InputParameter() const
Get the input parameter.
MiniBatchDiscrimination(const size_t inSize, const size_t outSize, const size_t features)
Create the MiniBatchDiscrimination layer object using the specified number of units.
OutputDataType & Gradient()
Modify the gradient.
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...
OutputDataType & OutputParameter()
Modify the output parameter.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
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.