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
void Backward(const arma::Mat< eT > &input, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of the DropConnect layer.
OutputDataType & OutputParameter()
Modify the output parameter.
bool & Deterministic()
Modify the value of the deterministic parameter.
OutputDataType & Parameters()
Modify the parameters.
Linear algebra utility functions, generally performed on matrices or vectors.
OutputDataType & Delta()
Modify the delta.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
OutputDataType const & Gradient() const
Get the gradient.
double Ratio() const
The probability of setting a value to zero.
bool Deterministic() const
The value of the deterministic parameter.
OutputDataType const & Delta() const
Get the delta.
size_t WeightSize() const
Return the size of the weight matrix.
std::vector< LayerTypes<> > & Model()
Get the model modules.
The DropConnect layer is a regularizer that randomly with probability ratio sets the connection value...
Definition: dropconnect.hpp:63
void Ratio(const double r)
Modify the probability of setting a value to zero.
OutputDataType const & Parameters() const
Get the parameters.
boost::variant< AdaptiveMaxPooling< arma::mat, arma::mat > *, AdaptiveMeanPooling< arma::mat, arma::mat > *, Add< arma::mat, arma::mat > *, AddMerge< arma::mat, arma::mat > *, AlphaDropout< arma::mat, arma::mat > *, AtrousConvolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, BaseLayer< LogisticFunction, arma::mat, arma::mat > *, BaseLayer< IdentityFunction, arma::mat, arma::mat > *, BaseLayer< TanhFunction, arma::mat, arma::mat > *, BaseLayer< SoftplusFunction, arma::mat, arma::mat > *, BaseLayer< RectifierFunction, arma::mat, arma::mat > *, BatchNorm< arma::mat, arma::mat > *, BilinearInterpolation< arma::mat, arma::mat > *, CELU< arma::mat, arma::mat > *, Concat< arma::mat, arma::mat > *, Concatenate< arma::mat, arma::mat > *, ConcatPerformance< NegativeLogLikelihood< arma::mat, arma::mat >, arma::mat, arma::mat > *, Constant< arma::mat, arma::mat > *, Convolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, CReLU< arma::mat, arma::mat > *, DropConnect< arma::mat, arma::mat > *, Dropout< arma::mat, arma::mat > *, ELU< arma::mat, arma::mat > *, FastLSTM< arma::mat, arma::mat > *, GRU< arma::mat, arma::mat > *, HardTanH< arma::mat, arma::mat > *, Join< arma::mat, arma::mat > *, LayerNorm< arma::mat, arma::mat > *, LeakyReLU< arma::mat, arma::mat > *, Linear< arma::mat, arma::mat, NoRegularizer > *, LinearNoBias< arma::mat, arma::mat, NoRegularizer > *, LogSoftMax< arma::mat, arma::mat > *, Lookup< arma::mat, arma::mat > *, LSTM< arma::mat, arma::mat > *, MaxPooling< arma::mat, arma::mat > *, MeanPooling< arma::mat, arma::mat > *, MiniBatchDiscrimination< arma::mat, arma::mat > *, MultiplyConstant< arma::mat, arma::mat > *, MultiplyMerge< arma::mat, arma::mat > *, NegativeLogLikelihood< arma::mat, arma::mat > *, NoisyLinear< arma::mat, arma::mat > *, Padding< arma::mat, arma::mat > *, PReLU< arma::mat, arma::mat > *, Sequential< arma::mat, arma::mat, false > *, Sequential< arma::mat, arma::mat, true > *, Softmax< arma::mat, arma::mat > *, TransposedConvolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< ValidConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, WeightNorm< arma::mat, arma::mat > *, MoreTypes, CustomLayers *... > LayerTypes
DropConnect()
Create the DropConnect object.
OutputDataType & Gradient()
Modify the gradient.
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of the DropConnect layer.
OutputDataType const & OutputParameter() const
Get the output parameter.