mlpack  master
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 
50 template <
51  typename InputDataType = arma::mat,
52  typename OutputDataType = arma::mat
53 >
54 class Dropout
55 {
56  public:
64  Dropout(const double ratio = 0.5, const bool rescale = true);
65 
72  template<typename eT>
73  void Forward(const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
74 
82  template<typename eT>
83  void Backward(const arma::Mat<eT>&& /* input */,
84  arma::Mat<eT>&& gy,
85  arma::Mat<eT>&& g);
86 
88  InputDataType const& InputParameter() const { return inputParameter; }
90  InputDataType& InputParameter() { return inputParameter; }
91 
93  OutputDataType const& OutputParameter() const { return outputParameter; }
95  OutputDataType& OutputParameter() { return outputParameter; }
96 
98  OutputDataType const& Delta() const { return delta; }
100  OutputDataType& Delta() { return delta; }
101 
103  bool Deterministic() const { return deterministic; }
105  bool& Deterministic() { return deterministic; }
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 
118  bool Rescale() const {return rescale; }
120  bool& Rescale() {return rescale; }
121 
125  template<typename Archive>
126  void Serialize(Archive& ar, const unsigned int /* version */);
127 
128  private:
130  OutputDataType delta;
131 
133  InputDataType inputParameter;
134 
136  OutputDataType outputParameter;
137 
139  OutputDataType mask;
140 
142  double ratio;
143 
145  double scale;
146 
149 
151  bool rescale;
152 }; // class Dropout
153 
154 } // namespace ann
155 } // namespace mlpack
156 
157 // Include implementation.
158 #include "dropout_impl.hpp"
159 
160 #endif
Dropout(const double ratio=0.5, const bool rescale=true)
Create the Dropout object using the specified ratio and rescale parameter.
OutputDataType const & Delta() const
Get the detla.
Definition: dropout.hpp:98
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
OutputDataType mask
Locally-stored mast object.
Definition: dropout.hpp:139
InputDataType inputParameter
Locally-stored input parameter object.
Definition: dropout.hpp:133
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool & Deterministic()
Modify the value of the deterministic parameter.
Definition: dropout.hpp:105
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: dropout.hpp:95
InputDataType const & InputParameter() const
Get the input parameter.
Definition: dropout.hpp:88
bool deterministic
If true dropout and scaling is disabled, see notes above.
Definition: dropout.hpp:148
OutputDataType delta
Locally-stored delta object.
Definition: dropout.hpp:130
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: dropout.hpp:93
void Ratio(const double r)
Modify the probability of setting a value to zero.
Definition: dropout.hpp:111
InputDataType & InputParameter()
Modify the input parameter.
Definition: dropout.hpp:90
void Backward(const arma::Mat< eT > &&, arma::Mat< eT > &&gy, arma::Mat< eT > &&g)
Ordinary feed backward pass of the dropout layer.
The dropout layer is a regularizer that randomly with probability ratio sets input values to zero and...
Definition: dropout.hpp:54
double scale
The scale fraction.
Definition: dropout.hpp:145
bool & Rescale()
Modify the value of the rescale parameter.
Definition: dropout.hpp:120
double Ratio() const
The probability of setting a value to zero.
Definition: dropout.hpp:108
OutputDataType & Delta()
Modify the delta.
Definition: dropout.hpp:100
OutputDataType outputParameter
Locally-stored output parameter object.
Definition: dropout.hpp:136
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
bool Rescale() const
The value of the rescale parameter.
Definition: dropout.hpp:118
bool Deterministic() const
The value of the deterministic parameter.
Definition: dropout.hpp:103
void Forward(const arma::Mat< eT > &&input, arma::Mat< eT > &&output)
Ordinary feed forward pass of the dropout layer.
bool rescale
If true the input is rescaled when deterministic is False.
Definition: dropout.hpp:151
double ratio
The probability of setting a value to zero.
Definition: dropout.hpp:142