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

The generic L-BFGS optimizer, which uses a back-tracking line search algorithm to minimize a function. More...

Inheritance diagram for mlpack::optimization::L_BFGS< FunctionType >:
Inheritance graph
[legend]

Public Member Functions

 L_BFGS (FunctionType &function, const size_t numBasis=10, const size_t maxIterations=10000, const double armijoConstant=1e-4, const double wolfe=0.9, const double minGradientNorm=1e-6, const double factr=1e-15, const size_t maxLineSearchTrials=50, const double minStep=1e-20, const double maxStep=1e20)
 Initialize the L-BFGS object. More...
 
double ArmijoConstant () const
 Get the Armijo condition constant. More...
 
double & ArmijoConstant ()
 Modify the Armijo condition constant. More...
 
double Factr () const
 Get the factr value. More...
 
double & Factr ()
 Modify the factr value. More...
 
const FunctionType & Function () const
 Return the function that is being optimized. More...
 
FunctionType & Function ()
 Modify the function that is being optimized. More...
 
size_t MaxIterations () const
 Get the maximum number of iterations. More...
 
size_t & MaxIterations ()
 Modify the maximum number of iterations. More...
 
size_t MaxLineSearchTrials () const
 Get the maximum number of line search trials. More...
 
size_t & MaxLineSearchTrials ()
 Modify the maximum number of line search trials. More...
 
double MaxStep () const
 Return the maximum line search step size. More...
 
double & MaxStep ()
 Modify the maximum line search step size. More...
 
double MinGradientNorm () const
 Get the minimum gradient norm. More...
 
double & MinGradientNorm ()
 Modify the minimum gradient norm. More...
 
const std::pair< arma::mat, double > & MinPointIterate () const
 Return the point where the lowest function value has been found. More...
 
double MinStep () const
 Return the minimum line search step size. More...
 
double & MinStep ()
 Modify the minimum line search step size. More...
 
size_t NumBasis () const
 Get the memory size. More...
 
size_t & NumBasis ()
 Modify the memory size. More...
 
double Optimize (arma::mat &iterate)
 Use L-BFGS to optimize the given function, starting at the given iterate point and finding the minimum. More...
 
double Optimize (arma::mat &iterate, const size_t maxIterations)
 Use L-BFGS to optimize (minimize) the given function, starting at the given iterate point, and performing no more than the given maximum number of iterations (the class variable maxIterations is ignored for this run, but not modified). More...
 
double Wolfe () const
 Get the Wolfe parameter. More...
 
double & Wolfe ()
 Modify the Wolfe parameter. More...
 

Private Member Functions

double ChooseScalingFactor (const size_t iterationNum, const arma::mat &gradient)
 Calculate the scaling factor, gamma, which is used to scale the Hessian approximation matrix. More...
 
double Evaluate (const arma::mat &iterate)
 Evaluate the function at the given iterate point and store the result if it is a new minimum. More...
 
bool GradientNormTooSmall (const arma::mat &gradient)
 Check to make sure that the norm of the gradient is not smaller than 1e-5. More...
 
bool LineSearch (double &functionValue, arma::mat &iterate, arma::mat &gradient, const arma::mat &searchDirection)
 Perform a back-tracking line search along the search direction to calculate a step size satisfying the Wolfe conditions. More...
 
void SearchDirection (const arma::mat &gradient, const size_t iterationNum, const double scalingFactor, arma::mat &searchDirection)
 Find the L-BFGS search direction. More...
 
void UpdateBasisSet (const size_t iterationNum, const arma::mat &iterate, const arma::mat &oldIterate, const arma::mat &gradient, const arma::mat &oldGradient)
 Update the y and s matrices, which store the differences between the iterate and old iterate and the differences between the gradient and the old gradient, respectively. More...
 

Private Attributes

double armijoConstant
 Parameter for determining the Armijo condition. More...
 
double factr
 Minimum relative function value decrease to continue the optimization. More...
 
FunctionType & function
 Internal reference to the function we are optimizing. More...
 
size_t maxIterations
 Maximum number of iterations. More...
 
size_t maxLineSearchTrials
 Maximum number of trials for the line search. More...
 
double maxStep
 Maximum step of the line search. More...
 
double minGradientNorm
 Minimum gradient norm required to continue the optimization. More...
 
std::pair< arma::mat, double > minPointIterate
 Best point found so far. More...
 
double minStep
 Minimum step of the line search. More...
 
arma::mat newIterateTmp
 Position of the new iterate. More...
 
size_t numBasis
 Size of memory for this L-BFGS optimizer. More...
 
arma::cube s
 Stores all the s matrices in memory. More...
 
double wolfe
 Parameter for detecting the Wolfe condition. More...
 
arma::cube y
 Stores all the y matrices in memory. More...
 

Detailed Description

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

The generic L-BFGS optimizer, which uses a back-tracking line search algorithm to minimize a function.

The parameters for the algorithm (number of memory points, maximum step size, and so forth) are all configurable via either the constructor or standalone modifier functions. A function which can be optimized by this class must implement the following methods:

Definition at line 34 of file lbfgs.hpp.

Constructor & Destructor Documentation

template<typename FunctionType>
mlpack::optimization::L_BFGS< FunctionType >::L_BFGS ( FunctionType &  function,
const size_t  numBasis = 10,
const size_t  maxIterations = 10000,
const double  armijoConstant = 1e-4,
const double  wolfe = 0.9,
const double  minGradientNorm = 1e-6,
const double  factr = 1e-15,
const size_t  maxLineSearchTrials = 50,
const double  minStep = 1e-20,
const double  maxStep = 1e20 
)

Initialize the L-BFGS object.

Store a reference to the function we will be optimizing and set the size of the memory for the algorithm. There are many parameters that can be set for the optimization, but default values are given for each of them.

Parameters
functionInstance of function to be optimized.
numBasisNumber of memory points to be stored (default 5).
maxIterationsMaximum number of iterations for the optimization (0 means no limit and may run indefinitely).
armijoConstantControls the accuracy of the line search routine for determining the Armijo condition.
wolfeParameter for detecting the Wolfe condition.
minGradientNormMinimum gradient norm required to continue the optimization.
maxLineSearchTrialsThe maximum number of trials for the line search (before giving up).
minStepThe minimum step of the line search.
maxStepThe maximum step of the line search.

Member Function Documentation

template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::ArmijoConstant ( ) const
inline

Get the Armijo condition constant.

Definition at line 119 of file lbfgs.hpp.

template<typename FunctionType>
double& mlpack::optimization::L_BFGS< FunctionType >::ArmijoConstant ( )
inline

Modify the Armijo condition constant.

Definition at line 121 of file lbfgs.hpp.

template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::ChooseScalingFactor ( const size_t  iterationNum,
const arma::mat &  gradient 
)
private

Calculate the scaling factor, gamma, which is used to scale the Hessian approximation matrix.

See method M3 in Section 4 of Liu and Nocedal (1989).

Returns
The calculated scaling factor.
template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::Evaluate ( const arma::mat &  iterate)
private

Evaluate the function at the given iterate point and store the result if it is a new minimum.

Returns
The value of the function.
template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::Factr ( ) const
inline

Get the factr value.

Definition at line 134 of file lbfgs.hpp.

template<typename FunctionType>
double& mlpack::optimization::L_BFGS< FunctionType >::Factr ( )
inline

Modify the factr value.

Definition at line 136 of file lbfgs.hpp.

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

Return the function that is being optimized.

Definition at line 104 of file lbfgs.hpp.

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

Modify the function that is being optimized.

Definition at line 106 of file lbfgs.hpp.

template<typename FunctionType>
bool mlpack::optimization::L_BFGS< FunctionType >::GradientNormTooSmall ( const arma::mat &  gradient)
private

Check to make sure that the norm of the gradient is not smaller than 1e-5.

Currently that value is not configurable.

Returns
(norm < minGradientNorm).
template<typename FunctionType>
bool mlpack::optimization::L_BFGS< FunctionType >::LineSearch ( double &  functionValue,
arma::mat &  iterate,
arma::mat &  gradient,
const arma::mat &  searchDirection 
)
private

Perform a back-tracking line search along the search direction to calculate a step size satisfying the Wolfe conditions.

The parameter iterate will be modified if the method is successful.

Parameters
functionValueValue of the function at the initial point
iterateThe initial point to begin the line search from
gradientThe gradient at the initial point
searchDirectionA vector specifying the search direction
stepSizeVariable the calculated step size will be stored in
Returns
false if no step size is suitable, true otherwise.
template<typename FunctionType>
size_t mlpack::optimization::L_BFGS< FunctionType >::MaxIterations ( ) const
inline

Get the maximum number of iterations.

Definition at line 114 of file lbfgs.hpp.

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

Modify the maximum number of iterations.

Definition at line 116 of file lbfgs.hpp.

template<typename FunctionType>
size_t mlpack::optimization::L_BFGS< FunctionType >::MaxLineSearchTrials ( ) const
inline

Get the maximum number of line search trials.

Definition at line 139 of file lbfgs.hpp.

template<typename FunctionType>
size_t& mlpack::optimization::L_BFGS< FunctionType >::MaxLineSearchTrials ( )
inline

Modify the maximum number of line search trials.

Definition at line 141 of file lbfgs.hpp.

template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::MaxStep ( ) const
inline

Return the maximum line search step size.

Definition at line 149 of file lbfgs.hpp.

template<typename FunctionType>
double& mlpack::optimization::L_BFGS< FunctionType >::MaxStep ( )
inline

Modify the maximum line search step size.

Definition at line 151 of file lbfgs.hpp.

template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::MinGradientNorm ( ) const
inline

Get the minimum gradient norm.

Definition at line 129 of file lbfgs.hpp.

template<typename FunctionType>
double& mlpack::optimization::L_BFGS< FunctionType >::MinGradientNorm ( )
inline

Modify the minimum gradient norm.

Definition at line 131 of file lbfgs.hpp.

template<typename FunctionType>
const std::pair<arma::mat, double>& mlpack::optimization::L_BFGS< FunctionType >::MinPointIterate ( ) const

Return the point where the lowest function value has been found.

Returns
arma::vec representing the point and a double with the function value at that point.
template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::MinStep ( ) const
inline

Return the minimum line search step size.

Definition at line 144 of file lbfgs.hpp.

template<typename FunctionType>
double& mlpack::optimization::L_BFGS< FunctionType >::MinStep ( )
inline

Modify the minimum line search step size.

Definition at line 146 of file lbfgs.hpp.

template<typename FunctionType>
size_t mlpack::optimization::L_BFGS< FunctionType >::NumBasis ( ) const
inline

Get the memory size.

Definition at line 109 of file lbfgs.hpp.

template<typename FunctionType>
size_t& mlpack::optimization::L_BFGS< FunctionType >::NumBasis ( )
inline

Modify the memory size.

Definition at line 111 of file lbfgs.hpp.

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

Use L-BFGS to optimize the given function, starting at the given iterate point and finding the minimum.

The maximum number of iterations is set in the constructor (or with MaxIterations()). Alternately, another overload is provided which takes a maximum number of iterations as a parameter. 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::L_BFGS< FunctionType >::Optimize ( arma::mat &  iterate,
const size_t  maxIterations 
)

Use L-BFGS to optimize (minimize) the given function, starting at the given iterate point, and performing no more than the given maximum number of iterations (the class variable maxIterations is ignored for this run, but not modified).

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).
maxIterationsMaximum number of iterations (0 specifies no limit).
Returns
Objective value of the final point.
template<typename FunctionType>
void mlpack::optimization::L_BFGS< FunctionType >::SearchDirection ( const arma::mat &  gradient,
const size_t  iterationNum,
const double  scalingFactor,
arma::mat &  searchDirection 
)
private

Find the L-BFGS search direction.

Parameters
gradientThe gradient at the current point
iteration_numThe iteration number
scaling_factorScaling factor to use (see ChooseScalingFactor_())
search_directionVector to store search direction in
template<typename FunctionType>
void mlpack::optimization::L_BFGS< FunctionType >::UpdateBasisSet ( const size_t  iterationNum,
const arma::mat &  iterate,
const arma::mat &  oldIterate,
const arma::mat &  gradient,
const arma::mat &  oldGradient 
)
private

Update the y and s matrices, which store the differences between the iterate and old iterate and the differences between the gradient and the old gradient, respectively.

Parameters
iterationNumIteration number
iterateCurrent point
oldIteratePoint at last iteration
gradientGradient at current point (iterate)
oldGradientGradient at last iteration point (oldIterate)
template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::Wolfe ( ) const
inline

Get the Wolfe parameter.

Definition at line 124 of file lbfgs.hpp.

template<typename FunctionType>
double& mlpack::optimization::L_BFGS< FunctionType >::Wolfe ( )
inline

Modify the Wolfe parameter.

Definition at line 126 of file lbfgs.hpp.

Member Data Documentation

template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::armijoConstant
private
template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::factr
private

Minimum relative function value decrease to continue the optimization.

Definition at line 175 of file lbfgs.hpp.

Referenced by mlpack::optimization::L_BFGS< AugLagrangianFunction< mlpack::optimization::LRSDPFunction< optimization::SDP< arma::sp_mat > > > >::Factr().

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

Internal reference to the function we are optimizing.

Definition at line 155 of file lbfgs.hpp.

template<typename FunctionType>
size_t mlpack::optimization::L_BFGS< FunctionType >::maxIterations
private
template<typename FunctionType>
size_t mlpack::optimization::L_BFGS< FunctionType >::maxLineSearchTrials
private
template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::maxStep
private
template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::minGradientNorm
private

Minimum gradient norm required to continue the optimization.

Definition at line 173 of file lbfgs.hpp.

Referenced by mlpack::optimization::L_BFGS< AugLagrangianFunction< mlpack::optimization::LRSDPFunction< optimization::SDP< arma::sp_mat > > > >::MinGradientNorm().

template<typename FunctionType>
std::pair<arma::mat, double> mlpack::optimization::L_BFGS< FunctionType >::minPointIterate
private

Best point found so far.

Definition at line 184 of file lbfgs.hpp.

template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::minStep
private
template<typename FunctionType>
arma::mat mlpack::optimization::L_BFGS< FunctionType >::newIterateTmp
private

Position of the new iterate.

Definition at line 158 of file lbfgs.hpp.

template<typename FunctionType>
size_t mlpack::optimization::L_BFGS< FunctionType >::numBasis
private
template<typename FunctionType>
arma::cube mlpack::optimization::L_BFGS< FunctionType >::s
private

Stores all the s matrices in memory.

Definition at line 160 of file lbfgs.hpp.

template<typename FunctionType>
double mlpack::optimization::L_BFGS< FunctionType >::wolfe
private
template<typename FunctionType>
arma::cube mlpack::optimization::L_BFGS< FunctionType >::y
private

Stores all the y matrices in memory.

Definition at line 162 of file lbfgs.hpp.


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