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 
50 template<typename InputDataType = arma::mat,
51  typename OutputDataType = arma::mat>
52 class Dropout
53 {
54  public:
60  Dropout(const double ratio = 0.5);
61 
68  template<typename eT>
69  void Forward(const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
70 
78  template<typename eT>
79  void Backward(const arma::Mat<eT>&& /* input */,
80  arma::Mat<eT>&& gy,
81  arma::Mat<eT>&& g);
82 
84  OutputDataType const& OutputParameter() const { return outputParameter; }
86  OutputDataType& OutputParameter() { return outputParameter; }
87 
89  OutputDataType const& Delta() const { return delta; }
91  OutputDataType& Delta() { return delta; }
92 
94  bool Deterministic() const { return deterministic; }
96  bool& Deterministic() { return deterministic; }
97 
99  double Ratio() const { return ratio; }
100 
102  void Ratio(const double r)
103  {
104  ratio = r;
105  scale = 1.0 / (1.0 - ratio);
106  }
107 
111  template<typename Archive>
112  void serialize(Archive& ar, const unsigned int /* version */);
113 
114  private:
116  OutputDataType delta;
117 
119  OutputDataType outputParameter;
120 
122  OutputDataType mask;
123 
125  double ratio;
126 
128  double scale;
129 
131  bool deterministic;
132 }; // class Dropout
133 
134 } // namespace ann
135 } // namespace mlpack
136 
137 // Include implementation.
138 #include "dropout_impl.hpp"
139 
140 #endif
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
.hpp
Definition: add_to_po.hpp:21
void Ratio(const double r)
Modify the probability of setting a value to zero.
Definition: dropout.hpp:102
OutputDataType & Delta()
Modify the delta.
Definition: dropout.hpp:91
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool & Deterministic()
Modify the value of the deterministic parameter.
Definition: dropout.hpp:96
OutputDataType const & Delta() const
Get the detla.
Definition: dropout.hpp:89
void Backward(const arma::Mat< eT > &&, arma::Mat< eT > &&gy, arma::Mat< eT > &&g)
Ordinary feed backward pass of the dropout layer.
Dropout(const double ratio=0.5)
Create the Dropout object using the specified ratio parameter.
void Forward(const arma::Mat< eT > &&input, arma::Mat< eT > &&output)
Ordinary feed forward pass of the dropout layer.
double Ratio() const
The probability of setting a value to zero.
Definition: dropout.hpp:99
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: dropout.hpp:84
The dropout layer is a regularizer that randomly with probability &#39;ratio&#39; sets input values to zero a...
Definition: dropout.hpp:52
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: dropout.hpp:86
bool Deterministic() const
The value of the deterministic parameter.
Definition: dropout.hpp:94