barzilai_borwein_decay.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_SVRG_BARZILIA_BORWEIN_DECAY_HPP
13 #define MLPACK_CORE_OPTIMIZERS_SVRG_BARZILIA_BORWEIN_DECAY_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace optimization {
19 
41 {
42  public:
43  /*
44  * Construct the Barzilai-Borwein decay policy.
45  *
46  * @param maxStepSize The maximum step size.
47  * @param eps The eps coefficient to avoid division by zero (numerical
48  * stability).
49  */
50  BarzilaiBorweinDecay(const double maxStepSize = DBL_MAX,
51  const double eps = 1e-7) :
52  eps(eps),
53  maxStepSize(maxStepSize)
54  { /* Nothing to do. */}
55 
63  void Initialize(const size_t /* rows */, const size_t /* cols */)
64  { /* Do nothing. */ }
65 
76  void Update(const arma::mat& iterate,
77  const arma::mat& iterate0,
78  const arma::mat& /* gradient */,
79  const arma::mat& fullGradient,
80  const size_t numBatches,
81  double& stepSize)
82  {
83  if (!fullGradient0.is_empty())
84  {
85  // Step size selection based on Barzilai-Borwein (BB).
86  stepSize = std::pow(arma::norm(iterate - iterate0), 2.0) /
87  (arma::dot(iterate - iterate0, fullGradient - fullGradient0) + eps) /
88  (double) numBatches;
89 
90  stepSize = std::min(stepSize, maxStepSize);
91  }
92 
93  fullGradient0 = std::move(fullGradient);
94  }
95 
96  private:
98  arma::mat fullGradient0;
99 
101  double eps;
102 
104  double maxStepSize;
105 };
106 
107 } // namespace optimization
108 } // namespace mlpack
109 
110 #endif // MLPACK_CORE_OPTIMIZERS_SVRG_BARZILIA_BORWEIN_DECAY_HPP
BarzilaiBorweinDecay(const double maxStepSize=DBL_MAX, const double eps=1e-7)
.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
Barzilai-Borwein decay policy for Stochastic variance reduced gradient (SVRG).
void Update(const arma::mat &iterate, const arma::mat &iterate0, const arma::mat &, const arma::mat &fullGradient, const size_t numBatches, double &stepSize)
Barzilai-Borwein update step for SVRG.
void Initialize(const size_t, const size_t)
The Initialize method is called by SVRG Optimizer method before the start of the iteration update pro...