BrentMinimizer1D.h

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: BrentMinimizer1D.h 36905 2010-11-24 15:44:34Z moneta $
00002 // Author: David Gonzalez Maline 2/2008
00003  /**********************************************************************
00004   *                                                                    *
00005   * Copyright (c) 2004 Maline,  CERN/PH-SFT                            *
00006   *                                                                    *
00007   * This library is free software; you can redistribute it and/or      *
00008   * modify it under the terms of the GNU General Public License        *
00009   * as published by the Free Software Foundation; either version 2     *
00010   * of the License, or (at your option) any later version.             *
00011   *                                                                    *
00012   * This library is distributed in the hope that it will be useful,    *
00013   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00014   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00015   * General Public License for more details.                           *
00016   *                                                                    *
00017   * You should have received a copy of the GNU General Public License  *
00018   * along with this library (see file COPYING); if not, write          *
00019   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00020   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00021   *                                                                    *
00022   **********************************************************************/
00023 
00024 // Header file for class BrentMinimizer1D
00025 // 
00026 // Created by: Maline  at Mon Feb  4 09:32:36 2008
00027 // 
00028 //
00029 
00030 
00031 #ifndef ROOT_Math_BrentMinimizer1D
00032 #define ROOT_Math_BrentMinimizer1D
00033 
00034 #ifndef ROOT_Math_IMinimizer1D
00035 #include "Math/IMinimizer1D.h"
00036 #endif
00037 
00038 #ifndef ROOT_Math_IFunctionfwd
00039 #include "Math/IFunctionfwd.h"
00040 #endif
00041 
00042 
00043 namespace ROOT { 
00044 namespace Math { 
00045 
00046 //___________________________________________________________________________________________
00047 /**
00048    User class for performing function minimization 
00049 
00050    It will use the Brent Method for function minimization in a given interval.
00051    First, a grid search is used to bracket the minimum value
00052    with the a step size = (xmax-xmin)/npx. The step size
00053    can be controlled via the SetNpx() function. A default value of npx = 100 is used. 
00054    The default value con be changed using the static method SetDefaultNpx.
00055    If the function is unimodal or if its extrema are far apart, setting the fNpx to 
00056    a small value speeds the algorithm up many times.  
00057    Then, Brent's method is applied on the bracketed interval. 
00058    If the Brent method fails to converge the bracketing is repeted on the latest best estimate of the 
00059    interval. The procedure is repeted with a maximum value (default =10) which can be set for all
00060    BrentRootFinder classes with the method SetDefaultNSearch
00061 
00062 
00063  
00064    This class is implemented from TF1::GetMinimum.
00065 
00066    To use the class, three steps have to be taken:
00067        1. Create the class.
00068        2. Set a function within an interval to look for the minimum.
00069        3. Call the Minimize function with the error parameters.
00070 
00071    If another minimization is to be performed, repeat the last two steps.
00072 
00073    @ingroup Min1D
00074   
00075  */
00076 
00077    class BrentMinimizer1D: ROOT::Math::IMinimizer1D {
00078       
00079    public: 
00080 
00081       /** Default Constructor. */
00082       BrentMinimizer1D(); 
00083 
00084       /** Default Destructor. */
00085       virtual ~BrentMinimizer1D() {}
00086       
00087    public: 
00088       
00089       /** Return current estimate of the position of the minimum. */
00090       virtual double XMinimum() const {   return fXMinimum;  }
00091 
00092       /** Return current lower bound of the minimization interval. */
00093       virtual double XLower() const {   return fXMin;  }
00094 
00095       /** Return current upper bound of the minimization interval. */
00096       virtual double XUpper() const {   return fXMax;  }
00097 
00098       /** Return function value at current estimate of the minimum. */
00099       virtual double FValMinimum() const; 
00100 
00101       /** Return function value at current lower bound of the minimization interval. */
00102       virtual double FValLower() const; 
00103 
00104       /** Return function value at current upper bound of the minimization interval. */
00105       virtual double FValUpper() const; 
00106 
00107       /** Find minimum position iterating until convergence specified by the absolute and relative tolerance or
00108           the maximum number of iteration is reached.
00109           Return true if iterations converged successfully
00110           \@param maxIter maximum number of iterations.
00111           \@param absTol desired absolute error in the minimum position (default 1.E-8)
00112           \@param absTol desired relative error in the minimum position (default = 1.E-10)
00113       */
00114       virtual bool Minimize( int maxIter, double absTol = 1.E-8, double relTol = 1.E-10); 
00115 
00116       /** Return number of iteration used to find minimum */
00117       virtual int Iterations() const { return fNIter; }
00118 
00119       /** Return name of minimization algorithm ("BrentMinimizer1D") */
00120       virtual const char * Name() const;  
00121 
00122       /** Sets function to be minimized. 
00123 
00124           \@param f Function to be minimized.
00125           \@param xlow Lower bound of the search interval.
00126           \@param xup Upper bound of the search interval.
00127       */
00128       void SetFunction(const ROOT::Math::IGenFunction& f, double xlow, double xup);
00129 
00130       /** Set the number of point used to bracket root using a grid */
00131       void SetNpx(int npx) { fNpx = npx; }
00132 
00133       /** 
00134           Set a log grid scan (default is equidistant bins) 
00135           will work only if xlow > 0
00136       */ 
00137       void SetLogScan(bool on) { fLogScan = on; }
00138           
00139 
00140       /** Returns status of last estimate. If = 0 is OK */
00141       int Status() const { return fStatus; }
00142 
00143       // static function used to modify the default parameters 
00144 
00145       /** set number of default Npx used at construction time (when SetNpx is not called) 
00146           Default value is 100
00147        */ 
00148       static void SetDefaultNpx(int npx); 
00149 
00150       /** set number of  times the bracketing search in combination with is done to find a good interval  
00151           Default value is 10
00152        */       
00153       static void SetDefaultNSearch(int n);
00154 
00155    private:
00156 
00157       const IGenFunction* fFunction; // Pointer to the function.
00158       bool fLogScan;                 // flag to control usage of a log scan
00159       int fNIter;                    // Number of iterations needed for the last estimation.
00160       int fNpx;                      // Number of points to bracket minimum with grid (def is 100)
00161       int fStatus;                   // Status of code of the last estimate
00162       double fXMin;                  // Lower bound of the search interval.
00163       double fXMax;                  // Upper bound of the search interval
00164       double fXMinimum;              // Position of the stimated minimum.
00165  
00166    };  // end class BrentMinimizer1D
00167    
00168 } // end namespace Math
00169    
00170 } // end namespace ROOT
00171 
00172 #endif /* ROOT_Math_BrentMinimizer1D */

Generated on Tue Jul 5 14:25:09 2011 for ROOT_528-00b_version by  doxygen 1.5.1