Chemical Data Processing Library Python API - Version 1.4.0
Classes | Public Member Functions | Properties | List of all members
CDPL.Math.DVectorBFGSMinimizer Class Reference

Fletcher's implementation of the BFGS method. More...

+ Inheritance diagram for CDPL.Math.DVectorBFGSMinimizer:

Classes

class  Status
 Status bitmask reported by minimize() and getStatus(). More...
 

Public Member Functions

None __init__ (DoubleDVectorFunctor func, object grad_func)
 Constructs the BFGSMinimizer instance with the given objective and gradient functions. More...
 
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
float getGradientNorm ()
 Returns the L2 norm of the gradient at the end of the most recent iterate() call. More...
 
float getFunctionDelta ()
 Returns the magnitude of the function-value decrease produced by the most recent iterate() call. More...
 
float getFunctionValue ()
 Returns the function value at the end of the most recent iterate() call. More...
 
int getNumIterations ()
 Returns the number of iterations performed by the most recent minimize() or iterate() loop. More...
 
Status getStatus ()
 Returns the current status of the minimizer. More...
 
Status minimize (DVector x, DVector g, int max_iter, float g_norm, float delta_f, bool do_setup=True)
 Runs the BFGS minimization loop on x. More...
 
float setup (DVector x, DVector g, float step_size=0.001, float tol=0.15)
 Initializes the minimizer state for a subsequent iterate() / minimize() loop. More...
 
tuple iterate (float f, DVector x, DVector g)
 Performs a single BFGS iteration: line search along the current search direction, BFGS update of the inverse Hessian approximation, and selection of the new search direction. More...
 

Properties

 objectID = property(getObjectID)
 
 gradientNorm = property(getGradientNorm)
 
 functionDelta = property(getFunctionDelta)
 
 functionValue = property(getFunctionValue)
 
 numIterations = property(getNumIterations)
 
 status = property(getStatus)
 

Detailed Description

Fletcher's implementation of the BFGS method.

The implementation has been taken from the GNU Scientific Library.

See also
R. Fletcher, "Practical Method's of Optimization", Second Edition, ISBN 0471915475. Algorithms 2.6.2 and 2.6.4.

Constructor & Destructor Documentation

◆ __init__()

None CDPL.Math.DVectorBFGSMinimizer.__init__ ( DoubleDVectorFunctor  func,
object  grad_func 
)

Constructs the BFGSMinimizer instance with the given objective and gradient functions.

Parameters
funcThe objective function.
grad_funcThe gradient function (also computes the objective value).

Member Function Documentation

◆ getObjectID()

int CDPL.Math.DVectorBFGSMinimizer.getObjectID ( )

Returns the numeric identifier (ID) of the wrapped C++ class instance.

Different Python DVectorBFGSMinimizer instances may reference the same underlying C++ class instance. The commonly used Python expression a is not b thus cannot tell reliably whether the two DVectorBFGSMinimizer instances a and b reference different C++ objects. The numeric identifier returned by this method allows to correctly implement such an identity test via the simple expression a.getObjectID() != b.getObjectID().

Returns
The numeric ID of the internally referenced C++ class instance.

◆ getGradientNorm()

float CDPL.Math.DVectorBFGSMinimizer.getGradientNorm ( )

Returns the L2 norm of the gradient at the end of the most recent iterate() call.

Returns
The gradient norm.

◆ getFunctionDelta()

float CDPL.Math.DVectorBFGSMinimizer.getFunctionDelta ( )

Returns the magnitude of the function-value decrease produced by the most recent iterate() call.

Returns
The function-value delta (positive when the function decreased).

◆ getFunctionValue()

float CDPL.Math.DVectorBFGSMinimizer.getFunctionValue ( )

Returns the function value at the end of the most recent iterate() call.

Returns
The function value.

◆ getNumIterations()

int CDPL.Math.DVectorBFGSMinimizer.getNumIterations ( )

Returns the number of iterations performed by the most recent minimize() or iterate() loop.

Returns
The iteration count.

◆ getStatus()

Status CDPL.Math.DVectorBFGSMinimizer.getStatus ( )

Returns the current status of the minimizer.

Returns
The Status bitmask.

◆ minimize()

Status CDPL.Math.DVectorBFGSMinimizer.minimize ( DVector  x,
DVector  g,
int  max_iter,
float  g_norm,
float  delta_f,
bool   do_setup = True 
)

Runs the BFGS minimization loop on x.

Parameters
xThe variable vector to be minimized (modified in place).
gThe gradient vector (modified in place).
max_iterThe maximum number of iterations (0 means unlimited).
g_normThe gradient-norm threshold below which the minimization is stopped (negative values disable this stop condition).
delta_fThe function-value-delta threshold below which the minimization is stopped (negative values disable this stop condition).
do_setupIf True, setup() is invoked at the start to initialize the minimizer.
Returns
The terminal Status bitmask of the minimization.

◆ setup()

float CDPL.Math.DVectorBFGSMinimizer.setup ( DVector  x,
DVector  g,
float   step_size = 0.001,
float   tol = 0.15 
)

Initializes the minimizer state for a subsequent iterate() / minimize() loop.

Parameters
xThe starting variable vector.
gThe gradient vector (filled with the gradient at x).
step_sizeThe initial step-size guess.
tolThe line-search tolerance.
Returns
The objective-function value at x.

◆ iterate()

tuple CDPL.Math.DVectorBFGSMinimizer.iterate ( float  f,
DVector  x,
DVector  g 
)

Performs a single BFGS iteration: line search along the current search direction, BFGS update of the inverse Hessian approximation, and selection of the new search direction.

Parameters
fThe current function value (updated in place).
xThe current variable vector (updated in place).
gThe current gradient vector (updated in place).
Returns
Status.SUCCESS if the iteration produced a step, otherwise the bitmask of stop conditions met.