ada_grad.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_CORE_OPTIMIZERS_ADA_GRAD_ADA_GRAD_HPP
15 #define MLPACK_CORE_OPTIMIZERS_ADA_GRAD_ADA_GRAD_HPP
16 
17 #include <mlpack/prereqs.hpp>
19 #include "ada_grad_update.hpp"
20 
21 namespace mlpack {
22 namespace optimization {
23 
64 class AdaGrad
65 {
66  public:
84  AdaGrad(const double stepSize = 0.01,
85  const size_t batchSize = 32,
86  const double epsilon = 1e-8,
87  const size_t maxIterations = 100000,
88  const double tolerance = 1e-5,
89  const bool shuffle = true);
90 
101  template<typename DecomposableFunctionType>
102  double Optimize(DecomposableFunctionType& function, arma::mat& iterate)
103  {
104  return optimizer.Optimize(function, iterate);
105  }
106 
108  double StepSize() const { return optimizer.StepSize(); }
110  double& StepSize() { return optimizer.StepSize(); }
111 
113  size_t BatchSize() const { return optimizer.BatchSize(); }
115  size_t& BatchSize() { return optimizer.BatchSize(); }
116 
118  double Epsilon() const { return optimizer.UpdatePolicy().Epsilon(); }
120  double& Epsilon() { return optimizer.UpdatePolicy().Epsilon(); }
121 
123  size_t MaxIterations() const { return optimizer.MaxIterations(); }
125  size_t& MaxIterations() { return optimizer.MaxIterations(); }
126 
128  double Tolerance() const { return optimizer.Tolerance(); }
130  double& Tolerance() { return optimizer.Tolerance(); }
131 
133  bool Shuffle() const { return optimizer.Shuffle(); }
135  bool& Shuffle() { return optimizer.Shuffle(); }
136 
137  private:
139  SGD<AdaGradUpdate> optimizer;
140 };
141 
142 } // namespace optimization
143 } // namespace mlpack
144 
145 #endif
size_t BatchSize() const
Get the batch size.
Definition: ada_grad.hpp:113
double Optimize(DecomposableFunctionType &function, arma::mat &iterate)
Optimize the given function using AdaGrad.
Definition: ada_grad.hpp:102
.hpp
Definition: add_to_po.hpp:21
double & Epsilon()
Modify the value used to initialise the squared gradient parameter.
Definition: ada_grad.hpp:120
The core includes that mlpack expects; standard C++ includes and Armadillo.
double & Tolerance()
Modify the tolerance for termination.
Definition: ada_grad.hpp:130
double & StepSize()
Modify the step size.
Definition: ada_grad.hpp:110
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
Definition: ada_grad.hpp:123
size_t & BatchSize()
Modify the batch size.
Definition: ada_grad.hpp:115
AdaGrad(const double stepSize=0.01, const size_t batchSize=32, const double epsilon=1e-8, const size_t maxIterations=100000, const double tolerance=1e-5, const bool shuffle=true)
Construct the AdaGrad optimizer with the given function and parameters.
AdaGrad is a modified version of stochastic gradient descent which performs larger updates for more s...
Definition: ada_grad.hpp:64
double Epsilon() const
Get the value used to initialise the squared gradient parameter.
Definition: ada_grad.hpp:118
double Tolerance() const
Get the tolerance for termination.
Definition: ada_grad.hpp:128
Stochastic Gradient Descent is a technique for minimizing a function which can be expressed as a sum ...
Definition: sgd.hpp:86
double StepSize() const
Get the step size.
Definition: ada_grad.hpp:108
bool Shuffle() const
Get whether or not the individual functions are shuffled.
Definition: ada_grad.hpp:133
bool & Shuffle()
Modify whether or not the individual functions are shuffled.
Definition: ada_grad.hpp:135
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).
Definition: ada_grad.hpp:125