sgdr.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_CORE_OPTIMIZERS_SGDR_SGDR_HPP
15 #define MLPACK_CORE_OPTIMIZERS_SGDR_SGDR_HPP
16 
17 #include <mlpack/prereqs.hpp>
18 
21 #include "cyclical_decay.hpp"
22 
23 namespace mlpack {
24 namespace optimization {
25 
47 template<typename UpdatePolicyType = MomentumUpdate>
48 class SGDR
49 {
50  public:
53 
72  SGDR(const size_t epochRestart = 50,
73  const double multFactor = 2.0,
74  const size_t batchSize = 1000,
75  const double stepSize = 0.01,
76  const size_t maxIterations = 100000,
77  const double tolerance = 1e-5,
78  const bool shuffle = true,
79  const UpdatePolicyType& updatePolicy = UpdatePolicyType());
80 
91  template<typename DecomposableFunctionType>
92  double Optimize(DecomposableFunctionType& function, arma::mat& iterate);
93 
95  size_t BatchSize() const { return optimizer.BatchSize(); }
97  size_t& BatchSize() { return optimizer.BatchSize(); }
98 
100  double StepSize() const { return optimizer.StepSize(); }
102  double& StepSize() { return optimizer.StepSize(); }
103 
105  size_t MaxIterations() const { return optimizer.MaxIterations(); }
107  size_t& MaxIterations() { return optimizer.MaxIterations(); }
108 
110  double Tolerance() const { return optimizer.Tolerance(); }
112  double& Tolerance() { return optimizer.Tolerance(); }
113 
115  bool Shuffle() const { return optimizer.Shuffle(); }
117  bool& Shuffle() { return optimizer.Shuffle(); }
118 
120  const UpdatePolicyType& UpdatePolicy() const
121  {
122  return optimizer.UpdatePolicy();
123  }
125  UpdatePolicyType& UpdatePolicy()
126  {
127  return optimizer.UpdatePolicy();
128  }
129 
130  private:
132  size_t batchSize;
133 
135  OptimizerType optimizer;
136 };
137 
138 } // namespace optimization
139 } // namespace mlpack
140 
141 // Include implementation.
142 #include "sgdr_impl.hpp"
143 
144 #endif
bool Shuffle() const
Get whether or not the individual functions are shuffled.
Definition: sgd.hpp:154
const UpdatePolicyType & UpdatePolicy() const
Get the update policy.
Definition: sgd.hpp:166
.hpp
Definition: add_to_po.hpp:21
size_t BatchSize() const
Get the batch size.
Definition: sgd.hpp:139
size_t & BatchSize()
Modify the batch size.
Definition: sgdr.hpp:97
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Tolerance() const
Get the tolerance for termination.
Definition: sgd.hpp:149
double & Tolerance()
Modify the tolerance for termination.
Definition: sgdr.hpp:112
bool Shuffle() const
Get whether or not the individual functions are shuffled.
Definition: sgdr.hpp:115
double & StepSize()
Modify the step size.
Definition: sgdr.hpp:102
bool & Shuffle()
Modify whether or not the individual functions are shuffled.
Definition: sgdr.hpp:117
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
Definition: sgd.hpp:144
double StepSize() const
Get the step size.
Definition: sgd.hpp:134
UpdatePolicyType & UpdatePolicy()
Modify the update policy.
Definition: sgdr.hpp:125
double Optimize(DecomposableFunctionType &function, arma::mat &iterate)
Optimize the given function using SGDR.
size_t BatchSize() const
Get the batch size.
Definition: sgdr.hpp:95
This class is based on Mini-batch Stochastic Gradient Descent class and simulates a new warm-started ...
Definition: sgdr.hpp:48
double Tolerance() const
Get the tolerance for termination.
Definition: sgdr.hpp:110
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
Definition: sgdr.hpp:105
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).
Definition: sgdr.hpp:107
SGDR(const size_t epochRestart=50, const double multFactor=2.0, const size_t batchSize=1000, const double stepSize=0.01, const size_t maxIterations=100000, const double tolerance=1e-5, const bool shuffle=true, const UpdatePolicyType &updatePolicy=UpdatePolicyType())
Construct the SGDR optimizer with the given function and parameters.
const UpdatePolicyType & UpdatePolicy() const
Get the update policy.
Definition: sgdr.hpp:120
double StepSize() const
Get the step size.
Definition: sgdr.hpp:100