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