ada_delta_update.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_OPTIMIZERS_ADA_DELTA_UPDATE_HPP
14 #define MLPACK_CORE_OPTIMIZERS_ADA_DELTA_UPDATE_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace optimization {
20 
41 {
42  public:
50  AdaDeltaUpdate(const double rho = 0.95, const double epsilon = 1e-6) :
51  rho(rho),
52  epsilon(epsilon)
53  {
54  // Nothing to do.
55  }
56 
67  void Initialize(const size_t rows, const size_t cols)
68  {
69  // Initialize empty matrices for mean sum of squares of parameter gradient.
70  meanSquaredGradient = arma::zeros<arma::mat>(rows, cols);
71  meanSquaredGradientDx = arma::zeros<arma::mat>(rows, cols);
72  }
73 
83  void Update(arma::mat& iterate,
84  const double stepSize,
85  const arma::mat& gradient)
86  {
87  // Accumulate gradient.
88  meanSquaredGradient *= rho;
89  meanSquaredGradient += (1 - rho) * (gradient % gradient);
90  arma::mat dx = arma::sqrt((meanSquaredGradientDx + epsilon) /
91  (meanSquaredGradient + epsilon)) % gradient;
92 
93  // Accumulate updates.
94  meanSquaredGradientDx *= rho;
95  meanSquaredGradientDx += (1 - rho) * (dx % dx);
96 
97  // Apply update.
98  iterate -= (stepSize * dx);
99  }
100 
102  double Rho() const { return rho; }
104  double& Rho() { return rho; }
105 
107  double Epsilon() const { return epsilon; }
109  double& Epsilon() { return epsilon; }
110 
111  private:
112  // The smoothing parameter.
113  double rho;
114 
115  // The epsilon value used to initialise the mean squared gradient parameter.
116  double epsilon;
117 
118  // The mean squared gradient matrix.
119  arma::mat meanSquaredGradient;
120 
121  // The delta mean squared gradient matrix.
122  arma::mat meanSquaredGradientDx;
123 };
124 
125 } // namespace optimization
126 } // namespace mlpack
127 
128 #endif
.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
double & Epsilon()
Modify the value used to initialise the mean squared gradient parameter.
Implementation of the AdaDelta update policy.
void Update(arma::mat &iterate, const double stepSize, const arma::mat &gradient)
Update step for SGD.
double Epsilon() const
Get the value used to initialise the mean squared gradient parameter.
double & Rho()
Modify the smoothing parameter.
AdaDeltaUpdate(const double rho=0.95, const double epsilon=1e-6)
Construct the AdaDelta update policy with given rho and epsilon parameters.
double Rho() const
Get the smoothing parameter.
void Initialize(const size_t rows, const size_t cols)
The Initialize method is called by SGD Optimizer method before the start of the iteration update proc...