Logo ROOT   6.08/07
Reference Guide
BrentMinimizer1D.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: David Gonzalez Maline 2/2008
3  /**********************************************************************
4  * *
5  * Copyright (c) 2004 Maline, CERN/PH-SFT *
6  * *
7  * This library is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU General Public License *
9  * as published by the Free Software Foundation; either version 2 *
10  * of the License, or (at your option) any later version. *
11  * *
12  * This library is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this library (see file COPYING); if not, write *
19  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
20  * 330, Boston, MA 02111-1307 USA, or contact the author. *
21  * *
22  **********************************************************************/
23 
24 // Header file for class BrentMinimizer1D
25 //
26 // Created by: Maline at Mon Feb 4 09:32:36 2008
27 //
28 //
29 
30 
31 #ifndef ROOT_Math_BrentMinimizer1D
32 #define ROOT_Math_BrentMinimizer1D
33 
34 #ifndef ROOT_Math_IMinimizer1D
35 #include "Math/IMinimizer1D.h"
36 #endif
37 
38 #ifndef ROOT_Math_IFunctionfwd
39 #include "Math/IFunctionfwd.h"
40 #endif
41 
42 
43 namespace ROOT {
44 namespace Math {
45 
46 //___________________________________________________________________________________________
47 /**
48  User class for performing function minimization
49 
50  It will use the Brent Method for function minimization in a given interval.
51  First, a grid search is used to bracket the minimum value
52  with the a step size = (xmax-xmin)/npx. The step size
53  can be controlled via the SetNpx() function. A default value of npx = 100 is used.
54  The default value con be changed using the static method SetDefaultNpx.
55  If the function is unimodal or if its extrema are far apart, setting the fNpx to
56  a small value speeds the algorithm up many times.
57  Then, Brent's method is applied on the bracketed interval.
58  If the Brent method fails to converge the bracketing is repeted on the latest best estimate of the
59  interval. The procedure is repeted with a maximum value (default =10) which can be set for all
60  BrentRootFinder classes with the method SetDefaultNSearch
61 
62 
63 
64  This class is implemented from TF1::GetMinimum.
65 
66  To use the class, three steps have to be taken:
67  1. Create the class.
68  2. Set a function within an interval to look for the minimum.
69  3. Call the Minimize function with the error parameters.
70 
71  If another minimization is to be performed, repeat the last two steps.
72 
73  @ingroup Min1D
74 
75  */
76 
78 
79  public:
80 
81  /** Default Constructor. */
83 
84  /** Default Destructor. */
85  virtual ~BrentMinimizer1D() {}
86 
87  public:
88 
89  /** Return current estimate of the position of the minimum. */
90  virtual double XMinimum() const { return fXMinimum; }
91 
92  /** Return current lower bound of the minimization interval. */
93  virtual double XLower() const { return fXMin; }
94 
95  /** Return current upper bound of the minimization interval. */
96  virtual double XUpper() const { return fXMax; }
97 
98  /** Return function value at current estimate of the minimum. */
99  virtual double FValMinimum() const;
100 
101  /** Return function value at current lower bound of the minimization interval. */
102  virtual double FValLower() const;
103 
104  /** Return function value at current upper bound of the minimization interval. */
105  virtual double FValUpper() const;
106 
107  /** Find minimum position iterating until convergence specified by the absolute and relative tolerance or
108  the maximum number of iteration is reached.
109  Return true if iterations converged successfully
110  \@param maxIter maximum number of iterations.
111  \@param absTol desired absolute error in the minimum position (default 1.E-8)
112  \@param absTol desired relative error in the minimum position (default = 1.E-10)
113  */
114  virtual bool Minimize( int maxIter, double absTol = 1.E-8, double relTol = 1.E-10);
115 
116  /** Return number of iteration used to find minimum */
117  virtual int Iterations() const { return fNIter; }
118 
119  /** Return name of minimization algorithm ("BrentMinimizer1D") */
120  virtual const char * Name() const;
121 
122  /** Sets function to be minimized.
123 
124  \@param f Function to be minimized.
125  \@param xlow Lower bound of the search interval.
126  \@param xup Upper bound of the search interval.
127  */
128  void SetFunction(const ROOT::Math::IGenFunction& f, double xlow, double xup);
129 
130  /** Set the number of point used to bracket root using a grid */
131  void SetNpx(int npx) { fNpx = npx; }
132 
133  /**
134  Set a log grid scan (default is equidistant bins)
135  will work only if xlow > 0
136  */
137  void SetLogScan(bool on) { fLogScan = on; }
138 
139 
140  /** Returns status of last estimate. If = 0 is OK */
141  int Status() const { return fStatus; }
142 
143  // static function used to modify the default parameters
144 
145  /** set number of default Npx used at construction time (when SetNpx is not called)
146  Default value is 100
147  */
148  static void SetDefaultNpx(int npx);
149 
150  /** set number of times the bracketing search in combination with is done to find a good interval
151  Default value is 10
152  */
153  static void SetDefaultNSearch(int n);
154 
155  private:
156 
157  const IGenFunction* fFunction; // Pointer to the function.
158  bool fLogScan; // flag to control usage of a log scan
159  int fNIter; // Number of iterations needed for the last estimation.
160  int fNpx; // Number of points to bracket minimum with grid (def is 100)
161  int fStatus; // Status of code of the last estimate
162  double fXMin; // Lower bound of the search interval.
163  double fXMax; // Upper bound of the search interval
164  double fXMinimum; // Position of the stimated minimum.
165 
166  }; // end class BrentMinimizer1D
167 
168 } // end namespace Math
169 
170 } // end namespace ROOT
171 
172 #endif /* ROOT_Math_BrentMinimizer1D */
virtual ~BrentMinimizer1D()
Default Destructor.
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:133
int Status() const
Returns status of last estimate.
const double absTol
virtual double XUpper() const
Return current upper bound of the minimization interval.
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
void SetLogScan(bool on)
Set a log grid scan (default is equidistant bins) will work only if xlow > 0.
static void SetDefaultNSearch(int n)
set number of times the bracketing search in combination with is done to find a good interval Default...
const IGenFunction * fFunction
User class for performing function minimization.
virtual double FValUpper() const
Return function value at current upper bound of the minimization interval.
virtual double FValLower() const
Return function value at current lower bound of the minimization interval.
virtual const char * Name() const
Return name of minimization algorithm ("BrentMinimizer1D")
void SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup)
Sets function to be minimized.
Double_t E()
Definition: TMath.h:54
virtual double XLower() const
Return current lower bound of the minimization interval.
double f(double x)
virtual double FValMinimum() const
Return function value at current estimate of the minimum.
Interface class for numerical methods for one-dimensional minimization.
Definition: IMinimizer1D.h:50
Namespace for new Math classes and functions.
virtual double XMinimum() const
Return current estimate of the position of the minimum.
static void SetDefaultNpx(int npx)
set number of default Npx used at construction time (when SetNpx is not called) Default value is 100 ...
virtual int Iterations() const
Return number of iteration used to find minimum.
void SetNpx(int npx)
Set the number of point used to bracket root using a grid.
virtual bool Minimize(int maxIter, double absTol=1.E-8, double relTol=1.E-10)
Find minimum position iterating until convergence specified by the absolute and relative tolerance or...
BrentMinimizer1D()
Default Constructor.
const Int_t n
Definition: legend1.C:16