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  arma::Mat<eT>&& gy,
98  arma::Mat<eT>&& g);
99 
107  template<typename eT>
108  void Gradient(const arma::Mat<eT>&& input,
109  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
OutputDataType const & Gradient() const
Get the gradient.
MiniBatchDiscrimination()
Create the MiniBatchDiscrimination object.
void Reset()
Reset the layer parameter.
strip_type.hpp
Definition: add_to_po.hpp:21
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 unsigned int)
Serialize the layer.
OutputDataType & Delta()
Modify the delta.
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...
void Backward(const arma::Mat< eT > &&, 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...
InputDataType const & InputParameter() const
Get the input parameter.