mlpack 3.4.2
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
18namespace mlpack {
19namespace ann {
20
21
51template<typename InputDataType = arma::mat,
52 typename OutputDataType = arma::mat>
54{
55 public:
61 Dropout(const double ratio = 0.5);
62
69 template<typename eT>
70 void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
71
79 template<typename eT>
80 void Backward(const arma::Mat<eT>& /* input */,
81 const arma::Mat<eT>& gy,
82 arma::Mat<eT>& g);
83
85 OutputDataType const& OutputParameter() const { return outputParameter; }
87 OutputDataType& OutputParameter() { return outputParameter; }
88
90 OutputDataType const& Delta() const { return delta; }
92 OutputDataType& Delta() { return delta; }
93
95 bool Deterministic() const { return deterministic; }
97 bool& Deterministic() { return deterministic; }
98
100 double Ratio() const { return ratio; }
101
103 void Ratio(const double r)
104 {
105 ratio = r;
106 scale = 1.0 / (1.0 - ratio);
107 }
108
112 template<typename Archive>
113 void serialize(Archive& ar, const unsigned int /* version */);
114
115 private:
117 OutputDataType delta;
118
120 OutputDataType outputParameter;
121
123 OutputDataType mask;
124
126 double ratio;
127
129 double scale;
130
132 bool deterministic;
133}; // class Dropout
134
135} // namespace ann
136} // namespace mlpack
137
138// Include implementation.
139#include "dropout_impl.hpp"
140
141#endif
The dropout layer is a regularizer that randomly with probability 'ratio' sets input values to zero a...
Definition: dropout.hpp:54
double Ratio() const
The probability of setting a value to zero.
Definition: dropout.hpp:100
OutputDataType const & Delta() const
Get the detla.
Definition: dropout.hpp:90
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of the dropout layer.
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: dropout.hpp:85
Dropout(const double ratio=0.5)
Create the Dropout object using the specified ratio parameter.
void Ratio(const double r)
Modify the probability of setting a value to zero.
Definition: dropout.hpp:103
bool & Deterministic()
Modify the value of the deterministic parameter.
Definition: dropout.hpp:97
bool Deterministic() const
The value of the deterministic parameter.
Definition: dropout.hpp:95
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of the dropout layer.
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: dropout.hpp:87
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Delta()
Modify the delta.
Definition: dropout.hpp:92
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.