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.hpp"
20 
21 namespace mlpack {
22 namespace ann {
23 
49 template<typename MatType = arma::mat>
50 class DropConnectType : public Layer<MatType>
51 {
52  public:
55 
63  DropConnectType(const size_t outSize,
64  const double ratio = 0.5);
65 
67  DropConnectType* Clone() const { return new DropConnectType(*this); }
68 
69  // Virtual destructor.
70  virtual ~DropConnectType();
71 
73  DropConnectType(const DropConnectType& other);
80 
87  void Forward(const MatType& input, MatType& output);
88 
96  void Backward(const MatType& input, const MatType& gy, MatType& g);
97 
105  void Gradient(const MatType& input, const MatType& error, MatType& gradient);
106 
108  double Ratio() const { return ratio; }
109 
111  void Ratio(const double r)
112  {
113  ratio = r;
114  scale = 1.0 / (1.0 - ratio);
115  }
116 
119 
121  size_t WeightSize() const { return baseLayer->WeightSize(); }
122 
123  // Set the weights to use the given memory `weightsPtr`.
124  void SetWeights(typename MatType::elem_type* weightsPtr);
125 
129  template<typename Archive>
130  void serialize(Archive& ar, const uint32_t /* version */);
131 
132  private:
134  double ratio;
135 
137  double scale;
138 
140  MatType mask;
141 
143  MatType denoise;
144 
146  Layer<MatType>* baseLayer;
147 }; // class DropConnect.
148 
149 // Convenience typedefs.
150 
151 // Standard DropConnect layer.
153 
154 } // namespace ann
155 } // namespace mlpack
156 
157 // Include implementation.
158 #include "dropconnect_impl.hpp"
159 
160 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
void Ratio(const double r)
Modify the probability of setting a value to zero.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t WeightSize() const
Return the size of the weights.
void SetWeights(typename MatType::elem_type *weightsPtr)
Reset the layer parameter.
The DropConnect layer is a regularizer that randomly with probability ratio sets the connection value...
Definition: dropconnect.hpp:50
DropConnectType< arma::mat > DropConnect
void ComputeOutputDimensions()
Compute the output dimensions of the layer based on InputDimensions().
void Gradient(const MatType &input, const MatType &error, MatType &gradient)
Calculate the gradient using the output delta and the input activation.
void Forward(const MatType &input, MatType &output)
Ordinary feed forward pass of the DropConnect layer.
DropConnectType * Clone() const
Clone the DropConnectType object. This handles polymorphism correctly.
Definition: dropconnect.hpp:67
DropConnectType()
Create the DropConnect object.
A layer is an abstract class implementing common neural networks operations, such as convolution...
Definition: layer.hpp:52
double Ratio() const
The probability of setting a value to zero.
void Backward(const MatType &input, const MatType &gy, MatType &g)
Ordinary feed backward pass of the DropConnect layer.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
DropConnectType & operator=(const DropConnectType &other)
Copy the given DropConnectType (except for weights).