mlpack  master
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  InputDataType const& InputParameter() const { return inputParameter; }
126  InputDataType& InputParameter() { return inputParameter; }
127 
129  OutputDataType const& OutputParameter() const { return outputParameter; }
131  OutputDataType& OutputParameter() { return outputParameter; }
132 
134  OutputDataType const& Delta() const { return delta; }
136  OutputDataType& Delta() { return delta; }
137 
139  OutputDataType const& Gradient() const { return gradient; }
141  OutputDataType& Gradient() { return gradient; }
142 
144  bool Deterministic() const { return deterministic; }
145 
147  bool &Deterministic() { return deterministic; }
148 
150  double Ratio() const { return ratio; }
151 
153  void Ratio(const double r)
154  {
155  ratio = r;
156  scale = 1.0 / (1.0 - ratio);
157  }
158 
162  template<typename Archive>
163  void Serialize(Archive& ar, const unsigned int /* version */);
164 
165 private:
167  double ratio;
168 
170  double scale;
171 
173  OutputDataType parameters;
174 
176  OutputDataType delta;
177 
179  OutputDataType gradient;
180 
182  InputDataType inputParameter;
183 
185  OutputDataType outputParameter;
186 
188  OutputDataType mask;
189 
192 
194  OutputDataType denoise;
195 
198 
200  std::vector<LayerTypes> network;
201 }; // class DropConnect.
202 
203 } // namespace ann
204 } // namespace mlpack
205 
206 // Include implementation.
207 #include "dropconnect_impl.hpp"
208 
209 #endif
OutputDataType outputParameter
Locally-stored output parameter object.
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.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
OutputDataType & Parameters()
Modify the parameters.
OutputDataType const & Parameters() const
Get the parameters.
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType gradient
Locally-stored gradient object.
OutputDataType & Delta()
Modify the delta.
OutputDataType const & OutputParameter() const
Get the output parameter.
double scale
The scale fraction.
void Ratio(const double r)
Modify the probability of setting a value to zero.
double ratio
The probability of setting a value to zero.
DropConnect()
Create the DropConnect object.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType delta
Locally-stored delta object.
double Ratio() const
The probability of setting a value to zero.
boost::variant< Add< arma::mat, arma::mat > *, AddMerge< 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 > *, Concat< 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 > *, DropConnect< arma::mat, arma::mat > *, Dropout< arma::mat, arma::mat > *, Glimpse< arma::mat, arma::mat > *, HardTanH< arma::mat, arma::mat > *, Join< arma::mat, arma::mat > *, LeakyReLU< arma::mat, arma::mat > *, Linear< arma::mat, arma::mat > *, LinearNoBias< arma::mat, arma::mat > *, 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 > *, MeanSquaredError< arma::mat, arma::mat > *, MultiplyConstant< arma::mat, arma::mat > *, NegativeLogLikelihood< arma::mat, arma::mat > *, PReLU< arma::mat, arma::mat > *, Recurrent< arma::mat, arma::mat > *, RecurrentAttention< arma::mat, arma::mat > *, ReinforceNormal< arma::mat, arma::mat > *, Select< arma::mat, arma::mat > *, Sequential< arma::mat, arma::mat > *, VRClassReward< arma::mat, arma::mat > * > LayerTypes
LayerTypes baseLayer
Locally-stored layer module.
InputDataType const & InputParameter() const
Get the input parameter.
bool & Deterministic()
Modify the value of the deterministic parameter.
The DropConnect layer is a regularizer that randomly with probability ratio sets the connection value...
Definition: dropconnect.hpp:62
OutputDataType & OutputParameter()
Modify the output parameter.
bool deterministic
If true dropout and scaling is disabled, see notes above.
bool Deterministic() const
The value of the deterministic parameter.
InputDataType inputParameter
Locally-stored input parameter object.
OutputDataType const & Gradient() const
Get the gradient.
std::vector< LayerTypes > network
Locally-stored network modules.
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType parameters
Locally-stored weight object.
OutputDataType const & Delta() const
Get the delta.
InputDataType & InputParameter()
Modify the input parameter.
OutputDataType denoise
Denoise mask for the weights.
OutputDataType mask
Locally-stored mask object.
void Backward(arma::Mat< eT > &&input, arma::Mat< eT > &&gy, arma::Mat< eT > &&g)
Ordinary feed backward pass of the DropConnect layer.