RDCode: BFGSOpt.h Source File

# BFGSOpt.h

Go to the documentation of this file.

    00001 //
    00002 // Copyright (C)  2004-2008 Greg Landrum and Rational Discovery LLC
    00003 //
    00004 //   @@ All Rights Reserved  @@
    00005 //
    00006
    00007 namespace BFGSOpt {
    00008   const double FUNCTOL=1e-4;  //!< Default tolerance for function convergence in the minimizer
    00009   const double MOVETOL=1e-7;  //!< Default tolerance for x changes in the minimizer
    00010   const int    MAXITS=200;    //!< Default maximum number of iterations
    00011   const double EPS=3e-8;      //!< Default gradient tolerance in the minimizer
    00012   const double TOLX=4.*EPS;   //!< Default direction vector tolerance in the minimizer
    00013   const double MAXSTEP=100.0; //!< Default maximim step size in the minimizer
    00014
    00015   //! Do a Quasi-Newton minimization along a line.
    00016   /*!
    00017     See Numerical Recipes in C, Section 9.7 for a description of the algorithm.
    00018
    00019      \param dim     the dimensionality of the space.
    00020      \param oldPt   the current position, as an array.
    00021      \param oldVal  the current function value.
    00022      \param grad    the value of the function gradient at oldPt
    00023      \param dir     the minimization direction
    00024      \param newPt   used to return the final position
    00025      \param newVal  used to return the final function value
    00026      \param func    the function to minimize
    00027      \param maxStep the maximum allowable step size
    00028      \param resCode used to return the results of the search.
    00029
    00030      Possible values for resCode are on return are:
    00031       -  0: success
    00032       -  1: the stepsize got too small.  This probably indicates success.
    00033       - -1: the direction is bad (orthogonal to the gradient)
    00034   */
    00035   void linearSearch(unsigned int dim,double *oldPt,double oldVal,
    00036                     double *grad,double *dir,double *newPt,
    00037                     double &newVal,
    00038                     double (*func)(double *),
    00039                     double maxStep,int &resCode);
    00040
    00041   //! Do a BFGS minimization of a function.
    00042   /*!
    00043      See Numerical Recipes in C, Section 10.7 for a description of the algorithm.
    00044
    00045      \param dim     the dimensionality of the space.
    00046      \param pos   the starting position, as an array.
    00047      \param gradTol tolerance for gradient convergence
    00048      \param numIters used to return the number of iterations required
    00049      \param funcVal  used to return the final function value
    00050      \param func    the function to minimize
    00051      \param gradFunc  calculates the gradient of func
    00052      \param funcTol tolerance for changes in the function value for convergence.
    00053      \param maxIts   maximum number of iterations allowed
    00054
    00055      \return a flag indicating success (or type of failure). Possible values are:
    00056       -  0: success
    00057       -  1: too many iterations were required
    00058   */
    00059   int minimize(unsigned int dim,double *pos,
    00060                double gradTol,
    00061                unsigned int &numIters,
    00062                double &funcVal,
    00063                double (*func)(double *),
    00064                void (*gradFunc)(double *,double*),
    00065                double funcTol=TOLX,
    00066                unsigned int maxIts=MAXITS);
    00067 }