nesterov_momentum_update.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_SGD_NESTEROV_MOMENTUM_UPDATE_HPP
13 #define MLPACK_CORE_OPTIMIZERS_SGD_NESTEROV_MOMENTUM_UPDATE_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace optimization {
19 
39 {
40  public:
45  NesterovMomentumUpdate(const double momentum = 0.5) :
46  momentum(momentum)
47  {
48  // Nothing to do.
49  }
50 
60  void Initialize(const size_t rows, const size_t cols)
61  {
62  // Initialize an empty velocity matrix.
63  velocity = arma::zeros<arma::mat>(rows, cols);
64  }
65 
75  void Update(arma::mat& iterate,
76  const double stepSize,
77  const arma::mat& gradient)
78  {
79  velocity = momentum * velocity - stepSize * gradient;
80 
81  iterate += momentum * velocity - stepSize * gradient;
82  }
83 
85  double Momentum() const { return momentum; }
87  double& Momentum() { return momentum; }
88 
89  private:
90  // The velocity matrix.
91  arma::mat velocity;
92 
93  // The Momentum coefficient.
94  double momentum;
95 };
96 
97 } // namespace optimization
98 } // namespace mlpack
99 
100 #endif
.hpp
Definition: add_to_po.hpp:21
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...
void Update(arma::mat &iterate, const double stepSize, const arma::mat &gradient)
Update step for SGD.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Momentum() const
Get the value used to initialize the momentum coefficient.
double & Momentum()
Modify the value used to initialize the momentum coefficient.
Nesterov Momentum update policy for Stochastic Gradient Descent (SGD).
NesterovMomentumUpdate(const double momentum=0.5)
Construct the Nesterov Momentum update policy with the given parameters.