adaptive_stepsize.hpp
Go to the documentation of this file.
1 
15 #ifndef MLPACK_CORE_OPTIMIZERS_BIGBATCH_SGD_ADAPTIVE_STEPSIZE_HPP
16 #define MLPACK_CORE_OPTIMIZERS_BIGBATCH_SGD_ADAPTIVE_STEPSIZE_HPP
17 
18 namespace mlpack {
19 namespace optimization {
20 
41 {
42  public:
53  AdaptiveStepsize(const double backtrackStepSize = 0.1,
54  const double searchParameter = 0.1) :
55  backtrackStepSize(backtrackStepSize),
56  searchParameter(searchParameter)
57  { /* Nothing to do here. */ }
58 
74  template<typename DecomposableFunctionType>
75  void Update(DecomposableFunctionType& function,
76  double& stepSize,
77  arma::mat& iterate,
78  const arma::mat& gradient,
79  const double gradientNorm,
80  const double sampleVariance,
81  const size_t offset,
82  const size_t batchSize,
83  const size_t backtrackingBatchSize,
84  const bool /* reset */)
85  {
86  Backtracking(function, stepSize, iterate, gradient, gradientNorm, offset,
87  backtrackingBatchSize);
88 
89  // Update the iterate.
90  iterate -= stepSize * gradient;
91 
92  double stepSizeDecay = 0;
93  if (batchSize < function.NumFunctions())
94  {
95  stepSizeDecay = (1 - (1 / ((double) batchSize - 1) * sampleVariance) /
96  (batchSize * gradientNorm)) / batchSize;
97  }
98  else
99  {
100  stepSizeDecay = 1 / function.NumFunctions();
101  }
102 
103  // Stepsize smoothing.
104  stepSize *= (1 - ((double) batchSize / function.NumFunctions()));
105  stepSize += stepSizeDecay * ((double) batchSize / function.NumFunctions());
106 
107  Backtracking(function, stepSize, iterate, gradient, gradientNorm, offset,
108  backtrackingBatchSize);
109  }
110 
112  double BacktrackStepSize() const { return backtrackStepSize; }
114  double& BacktrackStepSize() { return backtrackStepSize; }
115 
117  double SearchParameter() const { return searchParameter; }
119  double& SearchParameter() { return searchParameter; }
120 
121  private:
136  template<typename DecomposableFunctionType>
137  void Backtracking(DecomposableFunctionType& function,
138  double& stepSize,
139  const arma::mat& iterate,
140  const arma::mat& gradient,
141  const double gradientNorm,
142  const size_t offset,
143  const size_t backtrackingBatchSize)
144  {
145  double overallObjective = function.Evaluate(iterate, offset,
146  backtrackingBatchSize);
147 
148  arma::mat iterateUpdate = iterate - (stepSize * gradient);
149  double overallObjectiveUpdate = function.Evaluate(iterateUpdate, offset,
150  backtrackingBatchSize);
151 
152  while (overallObjectiveUpdate >
153  (overallObjective + searchParameter * stepSize * gradientNorm))
154  {
155  stepSize *= backtrackStepSize;
156 
157  iterateUpdate = iterate - (stepSize * gradient);
158  overallObjectiveUpdate = function.Evaluate(iterateUpdate, offset,
159  backtrackingBatchSize);
160  }
161  }
162 
164  double backtrackStepSize;
165 
167  double searchParameter;
168 };
169 
170 } // namespace optimization
171 } // namespace mlpack
172 
173 #endif // MLPACK_CORE_OPTIMIZERS_BIGBATCH_SGD_ADAPTIVE_STEPSIZE_HPP
Definition of the adaptive stepize technique, a non-monotonic stepsize scheme that uses curvature est...
AdaptiveStepsize(const double backtrackStepSize=0.1, const double searchParameter=0.1)
Construct the AdaptiveStepsize object with the given function and parameters.
.hpp
Definition: add_to_po.hpp:21
double BacktrackStepSize() const
Get the backtracking step size.
double & BacktrackStepSize()
Modify the backtracking step size.
double SearchParameter() const
Get the search parameter.
void Update(DecomposableFunctionType &function, double &stepSize, arma::mat &iterate, const arma::mat &gradient, const double gradientNorm, const double sampleVariance, const size_t offset, const size_t batchSize, const size_t backtrackingBatchSize, const bool)
This function is called in each iteration.
double & SearchParameter()
Modify the search parameter.