ada_grad_update.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_ADA_GRAD_ADA_GRAD_UPDATE_HPP
13 #define MLPACK_CORE_OPTIMIZERS_ADA_GRAD_ADA_GRAD_UPDATE_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace optimization {
19 
42 {
43  public:
50  AdaGradUpdate(const double epsilon = 1e-8) : epsilon(epsilon)
51  {
52  // Nothing to do.
53  }
54 
64  void Initialize(const size_t rows, const size_t cols)
65  {
66  // Initialize an empty matrix for sum of squares of parameter gradient.
67  squaredGradient = arma::zeros<arma::mat>(rows, cols);
68  }
69 
79  void Update(arma::mat& iterate,
80  const double stepSize,
81  const arma::mat& gradient)
82  {
83  squaredGradient += (gradient % gradient);
84  iterate -= (stepSize * gradient) / (arma::sqrt(squaredGradient) + epsilon);
85  }
86 
88  double Epsilon() const { return epsilon; }
90  double& Epsilon() { return epsilon; }
91 
92  private:
93  // The epsilon value used to initialise the squared gradient parameter.
94  double epsilon;
95 
96  // The squared gradient matrix.
97  arma::mat squaredGradient;
98 };
99 
100 } // namespace optimization
101 } // namespace mlpack
102 
103 #endif
.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
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...
Implementation of the AdaGrad update policy.
double & Epsilon()
Modify the value used to initialise the squared gradient parameter.
AdaGradUpdate(const double epsilon=1e-8)
Construct the AdaGrad update policy with given epsilon parameter.
double Epsilon() const
Get the value used to initialise the squared gradient parameter.
void Update(arma::mat &iterate, const double stepSize, const arma::mat &gradient)
Update step for SGD.