15 #ifndef MLPACK_CORE_OPTIMIZERS_SGD_SGD_HPP 16 #define MLPACK_CORE_OPTIMIZERS_SGD_SGD_HPP 25 namespace optimization {
84 template<
typename UpdatePolicyType = VanillaUpdate,
85 typename DecayPolicyType = NoDecay>
110 SGD(
const double stepSize = 0.01,
111 const size_t batchSize = 32,
112 const size_t maxIterations = 100000,
113 const double tolerance = 1e-5,
114 const bool shuffle =
true,
115 const UpdatePolicyType& updatePolicy = UpdatePolicyType(),
116 const DecayPolicyType& decayPolicy = DecayPolicyType(),
117 const bool resetPolicy =
true);
129 template<
typename DecomposableFunctionType>
130 double Optimize(DecomposableFunctionType&
function,
171 const DecayPolicyType&
DecayPolicy()
const {
return decayPolicy; }
183 size_t maxIterations;
193 UpdatePolicyType updatePolicy;
196 DecayPolicyType decayPolicy;
213 #include "sgd_impl.hpp"
const DecayPolicyType & DecayPolicy() const
Get the step size decay policy.
bool Shuffle() const
Get whether or not the individual functions are shuffled.
const UpdatePolicyType & UpdatePolicy() const
Get the update policy.
size_t BatchSize() const
Get the batch size.
bool & Shuffle()
Modify whether or not the individual functions are shuffled.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Tolerance() const
Get the tolerance for termination.
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
double StepSize() const
Get the step size.
DecayPolicyType & DecayPolicy()
Modify the step size decay policy.
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).
double & StepSize()
Modify the step size.
UpdatePolicyType & UpdatePolicy()
Modify the update policy.
bool ResetPolicy() const
Get whether or not the update policy parameters are reset before Optimize call.
SGD(const double stepSize=0.01, const size_t batchSize=32, const size_t maxIterations=100000, const double tolerance=1e-5, const bool shuffle=true, const UpdatePolicyType &updatePolicy=UpdatePolicyType(), const DecayPolicyType &decayPolicy=DecayPolicyType(), const bool resetPolicy=true)
Construct the SGD optimizer with the given function and parameters.
Stochastic Gradient Descent is a technique for minimizing a function which can be expressed as a sum ...
size_t & BatchSize()
Modify the batch size.
bool & ResetPolicy()
Modify whether or not the update policy parameters are reset before Optimize call.
double Optimize(DecomposableFunctionType &function, arma::mat &iterate)
Optimize the given function using stochastic gradient descent.
double & Tolerance()
Modify the tolerance for termination.