mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gradient_descent.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_GRADIENT_DESCENT_GRADIENT_DESCENT_HPP
13 #define MLPACK_CORE_OPTIMIZERS_GRADIENT_DESCENT_GRADIENT_DESCENT_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace optimization {
19 
52 template<typename FunctionType>
54 {
55  public:
68  GradientDescent(FunctionType& function,
69  const double stepSize = 0.01,
70  const size_t maxIterations = 100000,
71  const double tolerance = 1e-5);
72 
81  double Optimize(arma::mat& iterate);
82 
84  const FunctionType& Function() const { return function; }
86  FunctionType& Function() { return function; }
87 
89  double StepSize() const { return stepSize; }
91  double& StepSize() { return stepSize; }
92 
94  size_t MaxIterations() const { return maxIterations; }
96  size_t& MaxIterations() { return maxIterations; }
97 
99  double Tolerance() const { return tolerance; }
101  double& Tolerance() { return tolerance; }
102 
103  private:
105  FunctionType& function;
106 
108  double stepSize;
109 
111  size_t maxIterations;
112 
114  double tolerance;
115 };
116 
117 } // namespace optimization
118 } // namespace mlpack
119 
120 // Include implementation.
121 #include "gradient_descent_impl.hpp"
122 
123 #endif
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
The core includes that mlpack expects; standard C++ includes and Armadillo.
double & Tolerance()
Modify the tolerance for termination.
Gradient Descent is a technique to minimize a function.
FunctionType & Function()
Modify the instantiated function.
GradientDescent(FunctionType &function, const double stepSize=0.01, const size_t maxIterations=100000, const double tolerance=1e-5)
Construct the Gradient Descent optimizer with the given function and parameters.
double Optimize(arma::mat &iterate)
Optimize the given function using gradient descent.
double StepSize() const
Get the step size.
const FunctionType & Function() const
Get the instantiated function to be optimized.
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).
double Tolerance() const
Get the tolerance for termination.
double & StepSize()
Modify the step size.