MLPACK  1.0.11
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 #include <mlpack/core.hpp>
26 
27 namespace mlpack {
28 namespace optimization {
29 
85 template<typename DecomposableFunctionType>
86 class SGD
87 {
88  public:
100  SGD(DecomposableFunctionType& function,
101  const double stepSize = 0.01,
102  const size_t maxIterations = 100000,
103  const double tolerance = 1e-5,
104  const bool shuffle = true);
105 
114  double Optimize(arma::mat& iterate);
115 
117  const DecomposableFunctionType& Function() const { return function; }
119  DecomposableFunctionType& Function() { return function; }
120 
122  double StepSize() const { return stepSize; }
124  double& StepSize() { return stepSize; }
125 
127  size_t MaxIterations() const { return maxIterations; }
129  size_t& MaxIterations() { return maxIterations; }
130 
132  double Tolerance() const { return tolerance; }
134  double& Tolerance() { return tolerance; }
135 
137  bool Shuffle() const { return shuffle; }
139  bool& Shuffle() { return shuffle; }
140 
141  // convert the obkect into a string
142  std::string ToString() const;
143 
144  private:
146  DecomposableFunctionType& function;
147 
149  double stepSize;
150 
153 
155  double tolerance;
156 
159  bool shuffle;
160 };
161 
162 }; // namespace optimization
163 }; // namespace mlpack
164 
165 // Include implementation.
166 #include "sgd_impl.hpp"
167 
168 #endif