Molassembler  3.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize > Class Template Reference

LBFGS optimizer with optional boxing. More...

#include <Lbfgs.h>

Data Structures

struct  Box
 Type storing boundaries for parameter values. More...
 
struct  CollectiveRingBuffer
 Class containing hessian information for LBFGS update. More...
 
struct  OptimizationReturnType
 Type returned from an optimization. More...
 
struct  StepValues
 Class carrying proposed parameter updates in an optimization. More...
 

Public Types

using MatrixType = Eigen::Matrix< FloatType, Eigen::Dynamic, Eigen::Dynamic >
 
using VectorType = Eigen::Matrix< FloatType, Eigen::Dynamic, 1 >
 

Public Member Functions

template<typename UpdateFunction , typename Checker , typename Observer = Detail::DoNothingObserver>
OptimizationReturnType minimize (Eigen::Ref< VectorType > parameters, UpdateFunction &&function, Checker &&check, Observer &&observer=Observer{})
 Find parameters to minimize an objective function. More...
 
template<typename UpdateFunction , typename Checker , typename Observer = Detail::DoNothingObserver>
OptimizationReturnType maximize (Eigen::Ref< VectorType > parameters, UpdateFunction &&function, Checker &&check, Observer &&observer=Observer{})
 Find parameters to maximize an objective function. More...
 
template<typename UpdateFunction , typename Checker , typename Observer = Detail::DoNothingObserver>
OptimizationReturnType minimize (Eigen::Ref< VectorType > parameters, const Box &box, UpdateFunction &&function, Checker &&check, Observer &&observer=Observer{})
 Find parameters to minimize an objective function within bounds. More...
 
template<typename UpdateFunction , typename Checker , typename Observer = Detail::DoNothingObserver>
OptimizationReturnType maximize (Eigen::Ref< VectorType > parameters, const Box &box, UpdateFunction &&function, Checker &&check, Observer &&observer=Observer{})
 Find parameters to maximize an objective function within bounds. More...
 

Static Public Member Functions

static constexpr bool isPowerOfTwo (unsigned x)
 

Data Fields

FloatType c1 = 0.0001
 1st parameter for the Wolfe conditions.
 
FloatType c2 = 0.9
 2nd parameter for the Wolfe conditions. More...
 
FloatType stepLength = 1.0
 The initial step length used in the L-BFGS. More...
 

Private Member Functions

template<typename UpdateFunction , typename Observer , typename... Boxes>
unsigned adjustStepAlongDirection (UpdateFunction &&function, Observer &&observer, StepValues &step, const VectorType &direction, const Boxes &...boxes)
 Adjusts stepLength member and ensures the proposed parameter adjustment lowers the function value. More...
 
template<typename UpdateFunction , typename Checker , typename Observer , typename... Boxes>
OptimizationReturnType minimizeBase (Eigen::Ref< VectorType > parameters, UpdateFunction &&function, Checker &&check, Observer &&observer, Boxes &&...boxes)
 

Detailed Description

template<typename FloatType = double, unsigned ringBufferSize = 16>
class Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize >

LBFGS optimizer with optional boxing.

Template Parameters
FloatTypeType to represent floating point numbers
ringBufferSizeNumber of gradients to use in Hessian approximation, this is akin to memory

Member Function Documentation

template<typename FloatType = double, unsigned ringBufferSize = 16>
template<typename UpdateFunction , typename Observer , typename... Boxes>
unsigned Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize >::adjustStepAlongDirection ( UpdateFunction &&  function,
Observer &&  observer,
StepValues step,
const VectorType &  direction,
const Boxes &...  boxes 
)
inlineprivate

Adjusts stepLength member and ensures the proposed parameter adjustment lowers the function value.

The chosen direction and step length may overshoot or undershoot, and the function value might increase. We try to adapt the step length in order to ensure the function value decreases and step length is more or less optimal.

Parameters
functionObjective function generating value and gradients from parameters
observerObserver called with parameter updates
stepSuggested step in parameters, values and gradients
directionSuggested step direction
boxesBoxes (if present)
Returns
Number of function evaluations made in adjusting the step
template<typename FloatType = double, unsigned ringBufferSize = 16>
template<typename UpdateFunction , typename Checker , typename Observer = Detail::DoNothingObserver>
OptimizationReturnType Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize >::maximize ( Eigen::Ref< VectorType >  parameters,
UpdateFunction &&  function,
Checker &&  check,
Observer &&  observer = Observer {} 
)
inline

Find parameters to maximize an objective function.

Template Parameters
UpdateFunctionA callable object taking arguments (const VectorType&, double&, Ref<VectorType>). Any return values are ignored.
CheckerAn object implementing one methods:
  • shouldContinue: (const unsigned iterations, const StepValues& step) -> bool
ObserverAn observer callable object taking parameters. Return values are ignored.
Parameters
parametersThe initial parameters to optimize. Resulting optimization parameters are written to this argument.
functionThe objective function to optimize.
checkThe Checker instance
observerThe Observer instance
Returns
The number of calls to function made during optimization
template<typename FloatType = double, unsigned ringBufferSize = 16>
template<typename UpdateFunction , typename Checker , typename Observer = Detail::DoNothingObserver>
OptimizationReturnType Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize >::maximize ( Eigen::Ref< VectorType >  parameters,
const Box box,
UpdateFunction &&  function,
Checker &&  check,
Observer &&  observer = Observer {} 
)
inline

Find parameters to maximize an objective function within bounds.

Template Parameters
UpdateFunctionA callable object taking arguments (const VectorType&, double&, Ref<VectorType>). Any return values are ignored.
CheckerAn object implementing one methods:
  • shouldContinue: (const unsigned iterations, const StepValues& step) -> bool
ObserverAn observer callable object taking parameters. Return values are ignored.
Parameters
parametersThe initial parameters to optimize. Resulting optimization parameters are written to this argument.
boxBounds on the parameters
functionThe objective function to optimize.
checkThe Checker instance
observerThe Observer instance
Returns
The number of calls to function made during optimization
template<typename FloatType = double, unsigned ringBufferSize = 16>
template<typename UpdateFunction , typename Checker , typename Observer = Detail::DoNothingObserver>
OptimizationReturnType Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize >::minimize ( Eigen::Ref< VectorType >  parameters,
UpdateFunction &&  function,
Checker &&  check,
Observer &&  observer = Observer {} 
)
inline

Find parameters to minimize an objective function.

Template Parameters
UpdateFunctionA callable object taking arguments (const VectorType&, double&, Ref<VectorType>). Any return values are ignored.
CheckerAn object implementing one methods:
  • shouldContinue: (const unsigned iterations, const StepValues& step) -> bool
ObserverAn observer callable object taking parameters. Return values are ignored.
Parameters
parametersThe initial parameters to optimize. Resulting optimization parameters are written to this argument.
functionThe objective function to optimize.
checkThe Checker instance
observerThe Observer instance
Returns
A OptimizationReturnType instance
template<typename FloatType = double, unsigned ringBufferSize = 16>
template<typename UpdateFunction , typename Checker , typename Observer = Detail::DoNothingObserver>
OptimizationReturnType Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize >::minimize ( Eigen::Ref< VectorType >  parameters,
const Box box,
UpdateFunction &&  function,
Checker &&  check,
Observer &&  observer = Observer {} 
)
inline

Find parameters to minimize an objective function within bounds.

Template Parameters
UpdateFunctionA callable object taking arguments (const VectorType&, double&, Ref<VectorType>). Any return values are ignored.
CheckerAn object implementing one methods:
  • shouldContinue: (const unsigned iterations, const StepValues& step) -> bool
ObserverAn observer callable object taking parameters. Return values are ignored.
Parameters
parametersThe initial parameters to optimize. Resulting optimization parameters are written to this argument.
boxBounds on the parameters
functionThe objective function to optimize.
checkThe Checker instance
observerThe Observer instance
Note
Gradients passed to check do not contain bounded components
Returns
The number of calls to function made during optimization

Field Documentation

template<typename FloatType = double, unsigned ringBufferSize = 16>
FloatType Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize >::c2 = 0.9

2nd parameter for the Wolfe conditions.

A value as low as 0.1 can be used.

template<typename FloatType = double, unsigned ringBufferSize = 16>
FloatType Scine::Molassembler::Temple::Lbfgs< FloatType, ringBufferSize >::stepLength = 1.0

The initial step length used in the L-BFGS.

Note: the first step is a gradient descent with 0.1 times the steplength.


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