mlpack  master
Public Member Functions | Private Attributes | List of all members
mlpack::optimization::GradientDescent< FunctionType > Class Template Reference

Gradient Descent is a technique to minimize a function. More...

Public Member Functions

 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. More...
 
const FunctionType & Function () const
 Get the instantiated function to be optimized. More...
 
FunctionType & Function ()
 Modify the instantiated function. More...
 
size_t MaxIterations () const
 Get the maximum number of iterations (0 indicates no limit). More...
 
size_t & MaxIterations ()
 Modify the maximum number of iterations (0 indicates no limit). More...
 
double Optimize (arma::mat &iterate)
 Optimize the given function using gradient descent. More...
 
double StepSize () const
 Get the step size. More...
 
double & StepSize ()
 Modify the step size. More...
 
double Tolerance () const
 Get the tolerance for termination. More...
 
double & Tolerance ()
 Modify the tolerance for termination. More...
 

Private Attributes

FunctionType & function
 The instantiated function. More...
 
size_t maxIterations
 The maximum number of allowed iterations. More...
 
double stepSize
 The step size for each example. More...
 
double tolerance
 The tolerance for termination. More...
 

Detailed Description

template<typename FunctionType>
class mlpack::optimization::GradientDescent< FunctionType >

Gradient Descent is a technique to minimize a function.

To find a local minimum of a function using gradient descent, one takes steps proportional to the negative of the gradient of the function at the current point, producing the following update scheme:

\[ A_{j + 1} = A_j + \alpha \nabla F(A) \]

where $ \alpha $ is a parameter which specifies the step size. $ F $ is the function being optimized. The algorithm continues until $ j $ reaches the maximum number of iterations—or when an update produces an improvement within a certain tolerance $ \epsilon $. That is,

\[ | F(A_{j + 1}) - F(A_j) | < \epsilon. \]

The parameter $\epsilon$ is specified by the tolerance parameter to the constructor.

For Gradient Descent to work, a FunctionType template parameter is required. This class must implement the following function:

double Evaluate(const arma::mat& coordinates); void Gradient(const arma::mat& coordinates, arma::mat& gradient);

Template Parameters
FunctionTypeDecomposable objective function type to be minimized.

Definition at line 53 of file gradient_descent.hpp.

Constructor & Destructor Documentation

template<typename FunctionType >
mlpack::optimization::GradientDescent< FunctionType >::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.

The defaults here are not necessarily good for the given problem, so it is suggested that the values used be tailored to the task at hand.

Parameters
functionFunction to be optimized (minimized).
stepSizeStep size for each iteration.
maxIterationsMaximum number of iterations allowed (0 means no limit).
toleranceMaximum absolute tolerance to terminate algorithm.

Member Function Documentation

template<typename FunctionType >
const FunctionType& mlpack::optimization::GradientDescent< FunctionType >::Function ( ) const
inline

Get the instantiated function to be optimized.

Definition at line 84 of file gradient_descent.hpp.

template<typename FunctionType >
FunctionType& mlpack::optimization::GradientDescent< FunctionType >::Function ( )
inline

Modify the instantiated function.

Definition at line 86 of file gradient_descent.hpp.

template<typename FunctionType >
size_t mlpack::optimization::GradientDescent< FunctionType >::MaxIterations ( ) const
inline

Get the maximum number of iterations (0 indicates no limit).

Definition at line 94 of file gradient_descent.hpp.

References mlpack::optimization::GradientDescent< FunctionType >::maxIterations.

template<typename FunctionType >
size_t& mlpack::optimization::GradientDescent< FunctionType >::MaxIterations ( )
inline

Modify the maximum number of iterations (0 indicates no limit).

Definition at line 96 of file gradient_descent.hpp.

References mlpack::optimization::GradientDescent< FunctionType >::maxIterations.

template<typename FunctionType >
double mlpack::optimization::GradientDescent< FunctionType >::Optimize ( arma::mat &  iterate)

Optimize the given function using gradient descent.

The given starting point will be modified to store the finishing point of the algorithm, and the final objective value is returned.

Parameters
iterateStarting point (will be modified).
Returns
Objective value of the final point.
template<typename FunctionType >
double mlpack::optimization::GradientDescent< FunctionType >::StepSize ( ) const
inline

Get the step size.

Definition at line 89 of file gradient_descent.hpp.

References mlpack::optimization::GradientDescent< FunctionType >::stepSize.

template<typename FunctionType >
double& mlpack::optimization::GradientDescent< FunctionType >::StepSize ( )
inline

Modify the step size.

Definition at line 91 of file gradient_descent.hpp.

References mlpack::optimization::GradientDescent< FunctionType >::stepSize.

template<typename FunctionType >
double mlpack::optimization::GradientDescent< FunctionType >::Tolerance ( ) const
inline

Get the tolerance for termination.

Definition at line 99 of file gradient_descent.hpp.

References mlpack::optimization::GradientDescent< FunctionType >::tolerance.

template<typename FunctionType >
double& mlpack::optimization::GradientDescent< FunctionType >::Tolerance ( )
inline

Modify the tolerance for termination.

Definition at line 101 of file gradient_descent.hpp.

References mlpack::optimization::GradientDescent< FunctionType >::tolerance.

Member Data Documentation

template<typename FunctionType >
FunctionType& mlpack::optimization::GradientDescent< FunctionType >::function
private

The instantiated function.

Definition at line 105 of file gradient_descent.hpp.

template<typename FunctionType >
size_t mlpack::optimization::GradientDescent< FunctionType >::maxIterations
private

The maximum number of allowed iterations.

Definition at line 111 of file gradient_descent.hpp.

Referenced by mlpack::optimization::GradientDescent< FunctionType >::MaxIterations().

template<typename FunctionType >
double mlpack::optimization::GradientDescent< FunctionType >::stepSize
private

The step size for each example.

Definition at line 108 of file gradient_descent.hpp.

Referenced by mlpack::optimization::GradientDescent< FunctionType >::StepSize().

template<typename FunctionType >
double mlpack::optimization::GradientDescent< FunctionType >::tolerance
private

The tolerance for termination.

Definition at line 114 of file gradient_descent.hpp.

Referenced by mlpack::optimization::GradientDescent< FunctionType >::Tolerance().


The documentation for this class was generated from the following file: