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

Adam is an optimizer that computes individual adaptive learning rates for different parameters from estimates of first and second moments of the gradients. More...

Public Member Functions

 Adam (DecomposableFunctionType &function, const double stepSize=0.001, const double beta1=0.9, const double beta2=0.999, const double eps=1e-8, const size_t maxIterations=100000, const double tolerance=1e-5, const bool shuffle=true)
 Construct the Adam optimizer with the given function and parameters. More...
 
double Beta1 () const
 Get the smoothing parameter. More...
 
double & Beta1 ()
 Modify the smoothing parameter. More...
 
double Beta2 () const
 Get the second moment coefficient. More...
 
double & Beta2 ()
 Modify the second moment coefficient. More...
 
double Epsilon () const
 Get the value used to initialise the mean squared gradient parameter. More...
 
double & Epsilon ()
 Modify the value used to initialise the mean squared gradient parameter. More...
 
const DecomposableFunctionType & Function () const
 Get the instantiated function to be optimized. More...
 
DecomposableFunctionType & 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 Adam. More...
 
bool Shuffle () const
 Get whether or not the individual functions are shuffled. More...
 
bool & Shuffle ()
 Modify whether or not the individual functions are shuffled. 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

double beta1
 Exponential decay rate for the first moment estimates. More...
 
double beta2
 Exponential decay rate for the weighted infinity norm estimates. More...
 
double eps
 The value used to initialise the mean squared gradient parameter. More...
 
DecomposableFunctionType & function
 The instantiated function. More...
 
size_t maxIterations
 The maximum number of allowed iterations. More...
 
bool shuffle
 Controls whether or not the individual functions are shuffled when iterating. More...
 
double stepSize
 The step size for each example. More...
 
double tolerance
 The tolerance for termination. More...
 

Detailed Description

template<typename DecomposableFunctionType>
class mlpack::optimization::Adam< DecomposableFunctionType >

Adam is an optimizer that computes individual adaptive learning rates for different parameters from estimates of first and second moments of the gradients.

For more information, see the following.

@article{Kingma2014,
author = {Diederik P. Kingma and Jimmy Ba},
title = {Adam: {A} Method for Stochastic Optimization},
journal = {CoRR},
year = {2014}
}

For Adam to work, a DecomposableFunctionType template parameter is required. This class must implement the following function:

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

NumFunctions() should return the number of functions ( $n$), and in the other two functions, the parameter i refers to which individual function (or gradient) is being evaluated. So, for the case of a data-dependent function, such as NCA (see mlpack::nca::NCA), NumFunctions() should return the number of points in the dataset, and Evaluate(coordinates, 0) will evaluate the objective function on the first point in the dataset (presumably, the dataset is held internally in the DecomposableFunctionType).

Template Parameters
DecomposableFunctionTypeDecomposable objective function type to be minimized.

Definition at line 62 of file adam.hpp.

Constructor & Destructor Documentation

template<typename DecomposableFunctionType >
mlpack::optimization::Adam< DecomposableFunctionType >::Adam ( DecomposableFunctionType &  function,
const double  stepSize = 0.001,
const double  beta1 = 0.9,
const double  beta2 = 0.999,
const double  eps = 1e-8,
const size_t  maxIterations = 100000,
const double  tolerance = 1e-5,
const bool  shuffle = true 
)

Construct the Adam 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. The maximum number of iterations refers to the maximum number of points that are processed (i.e., one iteration equals one point; one iteration does not equal one pass over the dataset).

Parameters
functionFunction to be optimized (minimized).
stepSizeStep size for each iteration.
beta1Exponential decay rate for the first moment estimates.
beta2Exponential decay rate for the weighted infinity norm estimates.
epsValue used to initialise the mean squared gradient parameter.
maxIterationsMaximum number of iterations allowed (0 means no limit).
toleranceMaximum absolute tolerance to terminate algorithm.
shuffleIf true, the function order is shuffled; otherwise, each function is visited in linear order.

Member Function Documentation

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::Beta1 ( ) const
inline

Get the smoothing parameter.

Definition at line 115 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::beta1.

template<typename DecomposableFunctionType >
double& mlpack::optimization::Adam< DecomposableFunctionType >::Beta1 ( )
inline

Modify the smoothing parameter.

Definition at line 117 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::beta1.

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::Beta2 ( ) const
inline

Get the second moment coefficient.

Definition at line 120 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::beta2.

template<typename DecomposableFunctionType >
double& mlpack::optimization::Adam< DecomposableFunctionType >::Beta2 ( )
inline

Modify the second moment coefficient.

Definition at line 122 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::beta2.

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::Epsilon ( ) const
inline

Get the value used to initialise the mean squared gradient parameter.

Definition at line 125 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::eps.

template<typename DecomposableFunctionType >
double& mlpack::optimization::Adam< DecomposableFunctionType >::Epsilon ( )
inline

Modify the value used to initialise the mean squared gradient parameter.

Definition at line 127 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::eps.

template<typename DecomposableFunctionType >
const DecomposableFunctionType& mlpack::optimization::Adam< DecomposableFunctionType >::Function ( ) const
inline

Get the instantiated function to be optimized.

Definition at line 105 of file adam.hpp.

template<typename DecomposableFunctionType >
DecomposableFunctionType& mlpack::optimization::Adam< DecomposableFunctionType >::Function ( )
inline

Modify the instantiated function.

Definition at line 107 of file adam.hpp.

template<typename DecomposableFunctionType >
size_t mlpack::optimization::Adam< DecomposableFunctionType >::MaxIterations ( ) const
inline

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

Definition at line 130 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::maxIterations.

template<typename DecomposableFunctionType >
size_t& mlpack::optimization::Adam< DecomposableFunctionType >::MaxIterations ( )
inline

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

Definition at line 132 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::maxIterations.

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::Optimize ( arma::mat &  iterate)

Optimize the given function using Adam.

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 DecomposableFunctionType >
bool mlpack::optimization::Adam< DecomposableFunctionType >::Shuffle ( ) const
inline

Get whether or not the individual functions are shuffled.

Definition at line 140 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::shuffle.

template<typename DecomposableFunctionType >
bool& mlpack::optimization::Adam< DecomposableFunctionType >::Shuffle ( )
inline

Modify whether or not the individual functions are shuffled.

Definition at line 142 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::shuffle.

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::StepSize ( ) const
inline

Get the step size.

Definition at line 110 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::stepSize.

template<typename DecomposableFunctionType >
double& mlpack::optimization::Adam< DecomposableFunctionType >::StepSize ( )
inline

Modify the step size.

Definition at line 112 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::stepSize.

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::Tolerance ( ) const
inline

Get the tolerance for termination.

Definition at line 135 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::tolerance.

template<typename DecomposableFunctionType >
double& mlpack::optimization::Adam< DecomposableFunctionType >::Tolerance ( )
inline

Modify the tolerance for termination.

Definition at line 137 of file adam.hpp.

References mlpack::optimization::Adam< DecomposableFunctionType >::tolerance.

Member Data Documentation

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::beta1
private

Exponential decay rate for the first moment estimates.

Definition at line 152 of file adam.hpp.

Referenced by mlpack::optimization::Adam< DecomposableFunctionType >::Beta1().

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::beta2
private

Exponential decay rate for the weighted infinity norm estimates.

Definition at line 155 of file adam.hpp.

Referenced by mlpack::optimization::Adam< DecomposableFunctionType >::Beta2().

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::eps
private

The value used to initialise the mean squared gradient parameter.

Definition at line 158 of file adam.hpp.

Referenced by mlpack::optimization::Adam< DecomposableFunctionType >::Epsilon().

template<typename DecomposableFunctionType >
DecomposableFunctionType& mlpack::optimization::Adam< DecomposableFunctionType >::function
private

The instantiated function.

Definition at line 146 of file adam.hpp.

template<typename DecomposableFunctionType >
size_t mlpack::optimization::Adam< DecomposableFunctionType >::maxIterations
private

The maximum number of allowed iterations.

Definition at line 161 of file adam.hpp.

Referenced by mlpack::optimization::Adam< DecomposableFunctionType >::MaxIterations().

template<typename DecomposableFunctionType >
bool mlpack::optimization::Adam< DecomposableFunctionType >::shuffle
private

Controls whether or not the individual functions are shuffled when iterating.

Definition at line 168 of file adam.hpp.

Referenced by mlpack::optimization::Adam< DecomposableFunctionType >::Shuffle().

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::stepSize
private

The step size for each example.

Definition at line 149 of file adam.hpp.

Referenced by mlpack::optimization::Adam< DecomposableFunctionType >::StepSize().

template<typename DecomposableFunctionType >
double mlpack::optimization::Adam< DecomposableFunctionType >::tolerance
private

The tolerance for termination.

Definition at line 164 of file adam.hpp.

Referenced by mlpack::optimization::Adam< DecomposableFunctionType >::Tolerance().


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