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  InputDataType const& InputParameter() const { return inputParameter; }
86  InputDataType& InputParameter() { return inputParameter; }
87 
89  OutputDataType const& OutputParameter() const { return outputParameter; }
91  OutputDataType& OutputParameter() { return outputParameter; }
92 
94  OutputDataType const& Delta() const { return delta; }
96  OutputDataType& Delta() { return delta; }
97 
99  bool Deterministic() const { return deterministic; }
101  bool& Deterministic() { return deterministic; }
102 
104  double Ratio() const { return ratio; }
105 
107  void Ratio(const double r)
108  {
109  ratio = r;
110  scale = 1.0 / (1.0 - ratio);
111  }
112 
116  template<typename Archive>
117  void serialize(Archive& ar, const unsigned int /* version */);
118 
119  private:
121  OutputDataType delta;
122 
124  InputDataType inputParameter;
125 
127  OutputDataType outputParameter;
128 
130  OutputDataType mask;
131 
133  double ratio;
134 
136  double scale;
137 
139  bool deterministic;
140 }; // class Dropout
141 
142 } // namespace ann
143 } // namespace mlpack
144 
145 // Include implementation.
146 #include "dropout_impl.hpp"
147 
148 #endif
InputDataType const & InputParameter() const
Get the input parameter.
Definition: dropout.hpp:84
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:107
OutputDataType & Delta()
Modify the delta.
Definition: dropout.hpp:96
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool & Deterministic()
Modify the value of the deterministic parameter.
Definition: dropout.hpp:101
OutputDataType const & Delta() const
Get the detla.
Definition: dropout.hpp:94
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:104
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: dropout.hpp:89
InputDataType & InputParameter()
Modify the input parameter.
Definition: dropout.hpp:86
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:91
bool Deterministic() const
The value of the deterministic parameter.
Definition: dropout.hpp:99