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 
58 template<
59  typename InputDataType = arma::mat,
60  typename OutputDataType = arma::mat
61 >
63 {
64  public:
66  DropConnect();
67 
76  DropConnect(const size_t inSize,
77  const size_t outSize,
78  const double ratio = 0.5);
79 
80  ~DropConnect();
81 
88  template<typename eT>
89  void Forward(arma::Mat<eT>&& input, arma::Mat<eT>&& output);
90 
98  template<typename eT>
99  void Backward(arma::Mat<eT>&& input,
100  arma::Mat<eT>&& gy,
101  arma::Mat<eT>&& g);
102 
110  template<typename eT>
111  void Gradient(arma::Mat<eT>&& input,
112  arma::Mat<eT>&& error,
113  arma::Mat<eT>&& /* gradient */);
114 
116  std::vector<LayerTypes<> >& Model() { return network; }
117 
119  OutputDataType const& Parameters() const { return parameters; }
121  OutputDataType& Parameters() { return parameters; }
122 
124  OutputDataType const& OutputParameter() const { return outputParameter; }
126  OutputDataType& OutputParameter() { return outputParameter; }
127 
129  OutputDataType const& Delta() const { return delta; }
131  OutputDataType& Delta() { return delta; }
132 
134  OutputDataType const& Gradient() const { return gradient; }
136  OutputDataType& Gradient() { return gradient; }
137 
139  bool Deterministic() const { return deterministic; }
140 
142  bool &Deterministic() { return deterministic; }
143 
145  double Ratio() const { return ratio; }
146 
148  void Ratio(const double r)
149  {
150  ratio = r;
151  scale = 1.0 / (1.0 - ratio);
152  }
153 
157  template<typename Archive>
158  void serialize(Archive& ar, const unsigned int /* version */);
159 
160  private:
162  double ratio;
163 
165  double scale;
166 
168  OutputDataType parameters;
169 
171  OutputDataType delta;
172 
174  OutputDataType gradient;
175 
177  OutputDataType outputParameter;
178 
180  OutputDataType mask;
181 
183  bool deterministic;
184 
186  OutputDataType denoise;
187 
189  LayerTypes<> baseLayer;
190 
192  std::vector<LayerTypes<> > network;
193 }; // class DropConnect.
194 
195 } // namespace ann
196 } // namespace mlpack
197 
198 // Include implementation.
199 #include "dropconnect_impl.hpp"
200 
201 #endif
OutputDataType & OutputParameter()
Modify the output parameter.
bool & Deterministic()
Modify the value of the deterministic parameter.
OutputDataType & Parameters()
Modify the parameters.
.hpp
Definition: add_to_po.hpp:21
OutputDataType & Delta()
Modify the delta.
The core includes that mlpack expects; standard C++ includes and Armadillo.
boost::variant< Add< arma::mat, arma::mat > *, AddMerge< 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< RectifierFunction, arma::mat, arma::mat > *, BaseLayer< SoftplusFunction, arma::mat, arma::mat > *, BatchNorm< arma::mat, arma::mat > *, BilinearInterpolation< 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 > *, TransposedConvolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, DropConnect< arma::mat, arma::mat > *, Dropout< arma::mat, arma::mat > *, AlphaDropout< arma::mat, arma::mat > *, ELU< arma::mat, arma::mat > *, FlexibleReLU< arma::mat, arma::mat > *, Glimpse< arma::mat, arma::mat > *, HardTanH< arma::mat, arma::mat > *, Highway< arma::mat, arma::mat > *, Join< arma::mat, arma::mat > *, LayerNorm< arma::mat, arma::mat > *, LeakyReLU< arma::mat, arma::mat > *, CReLU< 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 > *, GRU< arma::mat, arma::mat > *, FastLSTM< 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 > *, Padding< arma::mat, arma::mat > *, PReLU< arma::mat, arma::mat > *, MoreTypes, CustomLayers *... > LayerTypes
void serialize(Archive &ar, const unsigned int)
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.
void Backward(arma::Mat< eT > &&input, arma::Mat< eT > &&gy, arma::Mat< eT > &&g)
Ordinary feed backward pass of the DropConnect layer.
void Forward(arma::Mat< eT > &&input, arma::Mat< eT > &&output)
Ordinary feed forward pass of the DropConnect layer.
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:62
void Ratio(const double r)
Modify the probability of setting a value to zero.
OutputDataType const & Parameters() const
Get the parameters.
DropConnect()
Create the DropConnect object.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType const & OutputParameter() const
Get the output parameter.