mlpack
dropconnect.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_METHODS_ANN_LAYER_DROPCONNECT_HPP
15 #define MLPACK_METHODS_ANN_LAYER_DROPCONNECT_HPP
16 
17 #include <mlpack/prereqs.hpp>
18 
19 #include "layer_types.hpp"
20 #include "add_merge.hpp"
21 #include "linear.hpp"
22 #include "sequential.hpp"
23 
24 namespace mlpack {
25 namespace ann {
26 
59 template<
60  typename InputDataType = arma::mat,
61  typename OutputDataType = arma::mat
62 >
64 {
65  public:
67  DropConnect();
68 
77  DropConnect(const size_t inSize,
78  const size_t outSize,
79  const double ratio = 0.5);
80 
87  template<typename eT>
88  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
89 
97  template<typename eT>
98  void Backward(const arma::Mat<eT>& input,
99  const arma::Mat<eT>& gy,
100  arma::Mat<eT>& g);
101 
109  template<typename eT>
110  void Gradient(const arma::Mat<eT>& input,
111  const arma::Mat<eT>& error,
112  arma::Mat<eT>& /* gradient */);
113 
115  std::vector<LayerTypes<> >& Model() { return network; }
116 
118  OutputDataType const& Parameters() const { return weights; }
120  OutputDataType& Parameters() { return weights; }
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  bool Deterministic() const { return deterministic; }
139 
141  bool &Deterministic() { return deterministic; }
142 
144  double Ratio() const { return ratio; }
145 
147  void Ratio(const double r)
148  {
149  ratio = r;
150  scale = 1.0 / (1.0 - ratio);
151  }
152 
154  size_t WeightSize() const { return 0; }
155 
159  template<typename Archive>
160  void serialize(Archive& ar, const uint32_t /* version */);
161 
162  private:
164  double ratio;
165 
167  double scale;
168 
170  OutputDataType weights;
171 
173  OutputDataType delta;
174 
176  OutputDataType gradient;
177 
179  OutputDataType outputParameter;
180 
182  OutputDataType mask;
183 
185  bool deterministic;
186 
188  OutputDataType denoise;
189 
191  LayerTypes<> baseLayer;
192 
194  std::vector<LayerTypes<> > network;
195 }; // class DropConnect.
196 
197 } // namespace ann
198 } // namespace mlpack
199 
200 // Include implementation.
201 #include "dropconnect_impl.hpp"
202 
203 #endif
double Ratio() const
The probability of setting a value to zero.
Definition: dropconnect.hpp:144
OutputDataType const & Gradient() const
Get the gradient.
Definition: dropconnect.hpp:133
bool Deterministic() const
The value of the deterministic parameter.
Definition: dropconnect.hpp:138
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
std::vector< LayerTypes<> > & Model()
Get the model modules.
Definition: dropconnect.hpp:115
OutputDataType & Parameters()
Modify the parameters.
Definition: dropconnect.hpp:120
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType & Delta()
Modify the delta.
Definition: dropconnect.hpp:130
void Backward(const arma::Mat< eT > &input, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of the DropConnect layer.
Definition: dropconnect_impl.hpp:84
size_t WeightSize() const
Return the size of the weight matrix.
Definition: dropconnect.hpp:154
void Ratio(const double r)
Modify the probability of setting a value to zero.
Definition: dropconnect.hpp:147
DropConnect()
Create the DropConnect object.
Definition: dropconnect_impl.hpp:31
OutputDataType & Gradient()
Modify the gradient.
Definition: dropconnect.hpp:135
OutputDataType const & Delta() const
Get the delta.
Definition: dropconnect.hpp:128
bool & Deterministic()
Modify the value of the deterministic parameter.
Definition: dropconnect.hpp:141
The DropConnect layer is a regularizer that randomly with probability ratio sets the connection value...
Definition: dropconnect.hpp:63
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: dropconnect.hpp:125
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of the DropConnect layer.
Definition: dropconnect_impl.hpp:53
OutputDataType const & Parameters() const
Get the parameters.
Definition: dropconnect.hpp:118
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: dropconnect.hpp:123
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: dropconnect_impl.hpp:108