mlpack  git-master
svrg.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_SVRG_SVRG_HPP
13 #define MLPACK_CORE_OPTIMIZERS_SVRG_SVRG_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 
18 #include "svrg_update.hpp"
20 
21 namespace mlpack {
22 namespace optimization {
23 
99 template<typename UpdatePolicyType = SVRGUpdate,
100  typename DecayPolicyType = NoDecay>
101 class SVRGType
102 {
103  public:
128  SVRGType(const double stepSize = 0.01,
129  const size_t batchSize = 32,
130  const size_t maxIterations = 1000,
131  const size_t innerIterations = 0,
132  const double tolerance = 1e-5,
133  const bool shuffle = true,
134  const UpdatePolicyType& updatePolicy = UpdatePolicyType(),
135  const DecayPolicyType& decayPolicy = DecayPolicyType(),
136  const bool resetPolicy = true);
137 
148  template<typename DecomposableFunctionType>
149  double Optimize(DecomposableFunctionType& function, arma::mat& iterate);
150 
152  double StepSize() const { return stepSize; }
154  double& StepSize() { return stepSize; }
155 
157  size_t BatchSize() const { return batchSize; }
159  size_t& BatchSize() { return batchSize; }
160 
162  size_t MaxIterations() const { return maxIterations; }
164  size_t& MaxIterations() { return maxIterations; }
165 
167  size_t InnerIterations() const { return innerIterations; }
169  size_t& InnerIterations() { return innerIterations; }
170 
172  double Tolerance() const { return tolerance; }
174  double& Tolerance() { return tolerance; }
175 
177  bool Shuffle() const { return shuffle; }
179  bool& Shuffle() { return shuffle; }
180 
183  bool ResetPolicy() const { return resetPolicy; }
186  bool& ResetPolicy() { return resetPolicy; }
187 
189  const UpdatePolicyType& UpdatePolicy() const { return updatePolicy; }
191  UpdatePolicyType& UpdatePolicy() { return updatePolicy; }
192 
194  const DecayPolicyType& DecayPolicy() const { return decayPolicy; }
196  DecayPolicyType& DecayPolicy() { return decayPolicy; }
197 
198  private:
200  double stepSize;
201 
203  size_t batchSize;
204 
206  size_t maxIterations;
207 
209  size_t innerIterations;
210 
212  double tolerance;
213 
216  bool shuffle;
217 
219  UpdatePolicyType updatePolicy;
220 
222  DecayPolicyType decayPolicy;
223 
226  bool resetPolicy;
227 };
228 
229 // Convenience typedefs.
230 
235 
240 
241 } // namespace optimization
242 } // namespace mlpack
243 
244 // Include implementation.
245 #include "svrg_impl.hpp"
246 
247 #endif
double & Tolerance()
Modify the tolerance for termination.
Definition: svrg.hpp:174
double & StepSize()
Modify the step size.
Definition: svrg.hpp:154
.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & BatchSize()
Modify the batch size.
Definition: svrg.hpp:159
bool ResetPolicy() const
Get whether or not the update policy parameters are reset before Optimize call.
Definition: svrg.hpp:183
bool & ResetPolicy()
Modify whether or not the update policy parameters are reset before Optimize call.
Definition: svrg.hpp:186
DecayPolicyType & DecayPolicy()
Modify the step size decay policy.
Definition: svrg.hpp:196
double Tolerance() const
Get the tolerance for termination.
Definition: svrg.hpp:172
bool & Shuffle()
Modify whether or not the individual functions are shuffled.
Definition: svrg.hpp:179
double Optimize(DecomposableFunctionType &function, arma::mat &iterate)
Optimize the given function using SVRG.
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
Definition: svrg.hpp:162
SVRGType(const double stepSize=0.01, const size_t batchSize=32, const size_t maxIterations=1000, const size_t innerIterations=0, const double tolerance=1e-5, const bool shuffle=true, const UpdatePolicyType &updatePolicy=UpdatePolicyType(), const DecayPolicyType &decayPolicy=DecayPolicyType(), const bool resetPolicy=true)
Construct the SVRG optimizer with the given function and parameters.
size_t BatchSize() const
Get the batch size.
Definition: svrg.hpp:157
bool Shuffle() const
Get whether or not the individual functions are shuffled.
Definition: svrg.hpp:177
size_t InnerIterations() const
Get the maximum number of iterations (0 indicates default n / b).
Definition: svrg.hpp:167
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).
Definition: svrg.hpp:164
double StepSize() const
Get the step size.
Definition: svrg.hpp:152
Stochastic Variance Reduced Gradient is a technique for minimizing a function which can be expressed ...
Definition: svrg.hpp:101
const UpdatePolicyType & UpdatePolicy() const
Get the update policy.
Definition: svrg.hpp:189
UpdatePolicyType & UpdatePolicy()
Modify the update policy.
Definition: svrg.hpp:191
const DecayPolicyType & DecayPolicy() const
Get the step size decay policy.
Definition: svrg.hpp:194
size_t & InnerIterations()
Modify the maximum number of iterations (0 indicates default n / b).
Definition: svrg.hpp:169