smorms3_update.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_SMORMS3_SMORMS3_UPDATE_HPP
13 #define MLPACK_CORE_OPTIMIZERS_SMORMS3_SMORMS3_UPDATE_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace optimization {
19 
38 {
39  public:
46  SMORMS3Update(const double epsilon = 1e-16) : epsilon(epsilon)
47  { /* Do nothing. */ }
48 
56  void Initialize(const size_t rows, const size_t cols)
57  {
58  // Initialise the parameters mem, g and g2.
59  mem = arma::ones<arma::mat>(rows, cols);
60  g = arma::zeros<arma::mat>(rows, cols);
61  g2 = arma::zeros<arma::mat>(rows, cols);
62  }
63 
71  void Update(arma::mat& iterate,
72  const double stepSize,
73  const arma::mat& gradient)
74  {
75  // Update the iterate.
76  arma::mat r = 1 / (mem + 1);
77 
78  g = (1 - r) % g;
79  g += r % gradient;
80 
81  g2 = (1 - r) % g2;
82  g2 += r % (gradient % gradient);
83 
84  arma::mat x = (g % g) / (g2 + epsilon);
85 
86  x.transform( [stepSize](double &v) { return std::min(v, stepSize); } );
87 
88  iterate -= gradient % x / (arma::sqrt(g2) + epsilon);
89 
90  mem %= (1 - x);
91  mem += 1;
92  }
93 
95  double Epsilon() const { return epsilon; }
97  double& Epsilon() { return epsilon; }
98 
99  private:
101  double epsilon;
102 
103  // The parameters mem, g and g2.
104  arma::mat mem, g, g2;
105 };
106 
107 } // namespace optimization
108 } // namespace mlpack
109 
110 #endif
.hpp
Definition: add_to_po.hpp:21
SMORMS3 is an optimizer that estimates a safe and optimal distance based on curvature and normalizing...
SMORMS3Update(const double epsilon=1e-16)
Construct the SMORMS3 update policy with given epsilon parameter.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Update(arma::mat &iterate, const double stepSize, const arma::mat &gradient)
Update step for SMORMS3.
double & Epsilon()
Modify the value used to initialise the mean squared gradient parameter.
void Initialize(const size_t rows, const size_t cols)
The Initialize method is called by SGD::Optimize method with UpdatePolicy SMORMS3Update before the st...
double Epsilon() const
Get the value used to initialise the mean squared gradient parameter.