adamax_update.hpp
Go to the documentation of this file.
1 
18 #ifndef MLPACK_CORE_OPTIMIZERS_ADAM_ADAMAX_UPDATE_HPP
19 #define MLPACK_CORE_OPTIMIZERS_ADAM_ADAMAX_UPDATE_HPP
20 
21 #include <mlpack/prereqs.hpp>
22 
23 namespace mlpack {
24 namespace optimization {
25 
45 {
46  public:
55  AdaMaxUpdate(const double epsilon = 1e-8,
56  const double beta1 = 0.9,
57  const double beta2 = 0.999) :
58  epsilon(epsilon),
59  beta1(beta1),
60  beta2(beta2),
61  iteration(0)
62  {
63  // Nothing to do.
64  }
65 
73  void Initialize(const size_t rows, const size_t cols)
74  {
75  m = arma::zeros<arma::mat>(rows, cols);
76  u = arma::zeros<arma::mat>(rows, cols);
77  }
78 
86  void Update(arma::mat& iterate,
87  const double stepSize,
88  const arma::mat& gradient)
89  {
90  // Increment the iteration counter variable.
91  ++iteration;
92 
93  // And update the iterate.
94  m *= beta1;
95  m += (1 - beta1) * gradient;
96 
97  // Update the exponentially weighted infinity norm.
98  u *= beta2;
99  u = arma::max(u, arma::abs(gradient));
100 
101  const double biasCorrection1 = 1.0 - std::pow(beta1, iteration);
102 
103  if (biasCorrection1 != 0)
104  iterate -= (stepSize / biasCorrection1 * m / (u + epsilon));
105  }
106 
108  double Epsilon() const { return epsilon; }
110  double& Epsilon() { return epsilon; }
111 
113  double Beta1() const { return beta1; }
115  double& Beta1() { return beta1; }
116 
118  double Beta2() const { return beta2; }
120  double& Beta2() { return beta2; }
121 
122  private:
123  // The epsilon value used to initialise the squared gradient parameter.
124  double epsilon;
125 
126  // The smoothing parameter.
127  double beta1;
128 
129  // The second moment coefficient.
130  double beta2;
131 
132  // The exponential moving average of gradient values.
133  arma::mat m;
134 
135  // The exponentially weighted infinity norm.
136  arma::mat u;
137 
138  // The number of iterations.
139  double iteration;
140 };
141 
142 } // namespace optimization
143 } // namespace mlpack
144 
145 #endif
void Update(arma::mat &iterate, const double stepSize, const arma::mat &gradient)
Update step for Adam.
.hpp
Definition: add_to_po.hpp:21
double Epsilon() const
Get the value used to initialise the squared gradient parameter.
double & Beta2()
Modify the second moment coefficient.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Beta2() const
Get the second moment coefficient.
double Beta1() const
Get the smoothing parameter.
AdaMaxUpdate(const double epsilon=1e-8, const double beta1=0.9, const double beta2=0.999)
Construct the AdaMax update policy with the given parameters.
double & Beta1()
Modify the smoothing parameter.
AdaMax is a variant of Adam, an optimizer that computes individual adaptive learning rates for differ...
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...
double & Epsilon()
Modify the value used to initialise the squared gradient parameter.