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 
19 namespace mlpack {
20 namespace ann {
21 
49 template <
50  typename InputDataType = arma::mat,
51  typename OutputDataType = arma::mat
52 >
53 class MiniBatchDiscrimination
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 
138  size_t InputShape() const
139  {
140  return A;
141  }
142 
146  template<typename Archive>
147  void serialize(Archive& ar, const uint32_t /* version */);
148 
149  private:
151  size_t A, B, C;
152 
154  size_t batchSize;
155 
157  arma::mat tempM;
158 
160  OutputDataType weights;
161 
163  OutputDataType weight;
164 
166  arma::cube M;
167 
169  arma::cube deltaM;
170 
172  arma::cube distances;
173 
175  OutputDataType delta;
176 
178  OutputDataType deltaTemp;
179 
181  OutputDataType gradient;
182 
184  InputDataType inputParameter;
185 
187  OutputDataType outputParameter;
188 }; // class MiniBatchDiscrimination
189 
190 } // namespace ann
191 } // namespace mlpack
192 
193 // Include implementation.
194 #include "minibatch_discrimination_impl.hpp"
195 
196 #endif
OutputDataType const & Gradient() const
Get the gradient.
MiniBatchDiscrimination()
Create the MiniBatchDiscrimination object.
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...
void Reset()
Reset the layer parameter.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType const & Parameters() const
Get the parameters.
OutputDataType const & OutputParameter() const
Get the output parameter.
OutputDataType & OutputParameter()
Modify the output parameter.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
OutputDataType & Delta()
Modify the delta.
size_t InputShape() const
Get the shape of the input.
OutputDataType & Parameters()
Modify the parameters.
InputDataType & InputParameter()
Modify the input parameter.
OutputDataType const & Delta() const
Get the delta.
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 const & InputParameter() const
Get the input parameter.