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