dropout.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_DROPOUT_HPP
14 #define MLPACK_METHODS_ANN_LAYER_DROPOUT_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace ann {
20 
21 
51 template<typename InputDataType = arma::mat,
52  typename OutputDataType = arma::mat>
53 class Dropout
54 {
55  public:
61  Dropout(const double ratio = 0.5);
62 
64  Dropout(const Dropout& layer);
65 
67  Dropout(const Dropout&&);
68 
70  Dropout& operator=(const Dropout& layer);
71 
73  Dropout& operator=(Dropout&& layer);
74 
81  template<typename eT>
82  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
83 
91  template<typename eT>
92  void Backward(const arma::Mat<eT>& /* input */,
93  const arma::Mat<eT>& gy,
94  arma::Mat<eT>& g);
95 
97  OutputDataType const& OutputParameter() const { return outputParameter; }
99  OutputDataType& OutputParameter() { return outputParameter; }
100 
102  OutputDataType const& Delta() const { return delta; }
104  OutputDataType& Delta() { return delta; }
105 
107  bool Deterministic() const { return deterministic; }
109  bool& Deterministic() { return deterministic; }
110 
112  double Ratio() const { return ratio; }
113 
115  void Ratio(const double r)
116  {
117  ratio = r;
118  scale = 1.0 / (1.0 - ratio);
119  }
120 
124  template<typename Archive>
125  void serialize(Archive& ar, const uint32_t /* version */);
126 
127  private:
129  OutputDataType delta;
130 
132  OutputDataType outputParameter;
133 
135  OutputDataType mask;
136 
138  double ratio;
139 
141  double scale;
142 
144  bool deterministic;
145 }; // class Dropout
146 
147 } // namespace ann
148 } // namespace mlpack
149 
150 // Include implementation.
151 #include "dropout_impl.hpp"
152 
153 #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.
Definition: dropout.hpp:115
OutputDataType & Delta()
Modify the delta.
Definition: dropout.hpp:104
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool & Deterministic()
Modify the value of the deterministic parameter.
Definition: dropout.hpp:109
OutputDataType const & Delta() const
Get the detla.
Definition: dropout.hpp:102
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Dropout(const double ratio=0.5)
Create the Dropout object using the specified ratio parameter.
double Ratio() const
The probability of setting a value to zero.
Definition: dropout.hpp:112
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of the dropout layer.
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: dropout.hpp:97
The dropout layer is a regularizer that randomly with probability &#39;ratio&#39; sets input values to zero a...
Definition: dropout.hpp:53
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: dropout.hpp:99
bool Deterministic() const
The value of the deterministic parameter.
Definition: dropout.hpp:107
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of the dropout layer.
Dropout & operator=(const Dropout &layer)
Copy assignment operator.