mlpack  master
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 
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
double stepSize
The step size for each example.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
double Tolerance() const
Get the tolerance for termination.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Optimize(arma::mat &iterate)
Optimize the given function using gradient descent.
Gradient Descent is a technique to minimize a function.
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
double tolerance
The tolerance for termination.
size_t maxIterations
The maximum number of allowed iterations.
double StepSize() const
Get the step size.
double & Tolerance()
Modify the tolerance for termination.
const FunctionType & Function() const
Get the instantiated function to be optimized.
double & StepSize()
Modify the step size.
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.
FunctionType & Function()
Modify the instantiated function.
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).