MLPACK  1.0.8
sgd.hpp
Go to the documentation of this file.
1 
22 #ifndef __MLPACK_CORE_OPTIMIZERS_SGD_SGD_HPP
23 #define __MLPACK_CORE_OPTIMIZERS_SGD_SGD_HPP
24 
25 namespace mlpack {
26 namespace optimization {
27 
83 template<typename DecomposableFunctionType>
84 class SGD
85 {
86  public:
98  SGD(DecomposableFunctionType& function,
99  const double stepSize = 0.01,
100  const size_t maxIterations = 100000,
101  const double tolerance = 1e-5,
102  const bool shuffle = true);
103 
112  double Optimize(arma::mat& iterate);
113 
115  const DecomposableFunctionType& Function() const { return function; }
117  DecomposableFunctionType& Function() { return function; }
118 
120  double StepSize() const { return stepSize; }
122  double& StepSize() { return stepSize; }
123 
125  size_t MaxIterations() const { return maxIterations; }
127  size_t& MaxIterations() { return maxIterations; }
128 
130  double Tolerance() const { return tolerance; }
132  double& Tolerance() { return tolerance; }
133 
135  bool Shuffle() const { return shuffle; }
137  bool& Shuffle() { return shuffle; }
138 
139  private:
141  DecomposableFunctionType& function;
142 
144  double stepSize;
145 
148 
150  double tolerance;
151 
154  bool shuffle;
155 };
156 
157 }; // namespace optimization
158 }; // namespace mlpack
159 
160 // Include implementation.
161 #include "sgd_impl.hpp"
162 
163 #endif
bool Shuffle() const
Get whether or not the individual functions are shuffled.
Definition: sgd.hpp:135
double tolerance
The tolerance for termination.
Definition: sgd.hpp:150
double & Tolerance()
Modify the tolerance for termination.
Definition: sgd.hpp:132
double Tolerance() const
Get the tolerance for termination.
Definition: sgd.hpp:130
double stepSize
The step size for each example.
Definition: sgd.hpp:144
size_t maxIterations
The maximum number of allowed iterations.
Definition: sgd.hpp:147
SGD(DecomposableFunctionType &function, const double stepSize=0.01, const size_t maxIterations=100000, const double tolerance=1e-5, const bool shuffle=true)
Construct the SGD optimizer with the given function and parameters.
double StepSize() const
Get the step size.
Definition: sgd.hpp:120
const DecomposableFunctionType & Function() const
Get the instantiated function to be optimized.
Definition: sgd.hpp:115
bool & Shuffle()
Modify whether or not the individual functions are shuffled.
Definition: sgd.hpp:137
double & StepSize()
Modify the step size.
Definition: sgd.hpp:122
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).
Definition: sgd.hpp:127
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
Definition: sgd.hpp:125
bool shuffle
Controls whether or not the individual functions are shuffled when iterating.
Definition: sgd.hpp:154
DecomposableFunctionType & Function()
Modify the instantiated function.
Definition: sgd.hpp:117
Stochastic Gradient Descent is a technique for minimizing a function which can be expressed as a sum ...
Definition: sgd.hpp:84
double Optimize(arma::mat &iterate)
Optimize the given function using stochastic gradient descent.