ROOT   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#include "Math/IMinimizer1D.h"
35
36#include "Math/IFunctionfwd.h"
37
38
39namespace ROOT {
40namespace Math {
41
42//___________________________________________________________________________________________
43/**
44 User class for performing function minimization
45
46 It will use the Brent Method for function minimization in a given interval.
47 First, a grid search is used to bracket the minimum value
48 with the a step size = (xmax-xmin)/npx. The step size
49 can be controlled via the SetNpx() function. A default value of npx = 100 is used.
50 The default value con be changed using the static method SetDefaultNpx.
51 If the function is unimodal or if its extrema are far apart, setting the fNpx to
52 a small value speeds the algorithm up many times.
53 Then, Brent's method is applied on the bracketed interval.
54 If the Brent method fails to converge the bracketing is repeted on the latest best estimate of the
55 interval. The procedure is repeted with a maximum value (default =10) which can be set for all
56 BrentRootFinder classes with the method SetDefaultNSearch
57
58
59
60 This class is implemented from TF1::GetMinimum.
61
62 To use the class, three steps have to be taken:
63 1. Create the class.
64 2. Set a function within an interval to look for the minimum.
65 3. Call the Minimize function with the error parameters.
66
67 If another minimization is to be performed, repeat the last two steps.
68
69 @ingroup Min1D
70
71 */
72
74
75 public:
76
77 /** Default Constructor. */
79
80 /** Default Destructor. */
81 virtual ~BrentMinimizer1D() {}
82
83 public:
84
85 /** Return current estimate of the position of the minimum. */
86 virtual double XMinimum() const { return fXMinimum; }
87
88 /** Return current lower bound of the minimization interval. */
89 virtual double XLower() const { return fXMin; }
90
91 /** Return current upper bound of the minimization interval. */
92 virtual double XUpper() const { return fXMax; }
93
94 /** Return function value at current estimate of the minimum. */
95 virtual double FValMinimum() const;
96
97 /** Return function value at current lower bound of the minimization interval. */
98 virtual double FValLower() const;
99
100 /** Return function value at current upper bound of the minimization interval. */
101 virtual double FValUpper() const;
102
103 /** Find minimum position iterating until convergence specified by the absolute and relative tolerance or
104 the maximum number of iteration is reached.
105 Return true if iterations converged successfully
106 \@param maxIter maximum number of iterations.
107 \@param absTol desired absolute error in the minimum position (default 1.E-8)
108 \@param absTol desired relative error in the minimum position (default = 1.E-10)
109 */
110 virtual bool Minimize( int maxIter, double absTol = 1.E-8, double relTol = 1.E-10);
111
112 /** Return number of iteration used to find minimum */
113 virtual int Iterations() const { return fNIter; }
114
115 /** Return name of minimization algorithm ("BrentMinimizer1D") */
116 virtual const char * Name() const;
117
118 /** Sets function to be minimized.
119
120 \@param f Function to be minimized.
121 \@param xlow Lower bound of the search interval.
122 \@param xup Upper bound of the search interval.
123 */
124 void SetFunction(const ROOT::Math::IGenFunction& f, double xlow, double xup);
125
126 /** Set the number of point used to bracket root using a grid */
127 void SetNpx(int npx) { fNpx = npx; }
128
129 /**
130 Set a log grid scan (default is equidistant bins)
131 will work only if xlow > 0
132 */
133 void SetLogScan(bool on) { fLogScan = on; }
134
135
136 /** Returns status of last estimate. If = 0 is OK */
137 int Status() const { return fStatus; }
138
139 // static function used to modify the default parameters
140
141 /** set number of default Npx used at construction time (when SetNpx is not called)
142 Default value is 100
143 */
144 static void SetDefaultNpx(int npx);
145
146 /** set number of times the bracketing search in combination with is done to find a good interval
147 Default value is 10
148 */
149 static void SetDefaultNSearch(int n);
150
151 private:
152
153 const IGenFunction* fFunction; // Pointer to the function.
154 bool fLogScan; // flag to control usage of a log scan
155 int fNIter; // Number of iterations needed for the last estimation.
156 int fNpx; // Number of points to bracket minimum with grid (def is 100)
157 int fStatus; // Status of code of the last estimate
158 double fXMin; // Lower bound of the search interval.
159 double fXMax; // Upper bound of the search interval
160 double fXMinimum; // Position of the stimated minimum.
161
162 }; // end class BrentMinimizer1D
163
164} // end namespace Math
165
166} // end namespace ROOT
167
168#endif /* ROOT_Math_BrentMinimizer1D */
#define f(i)
Definition: RSha256.hxx:104
User class for performing function minimization.
const IGenFunction * fFunction
virtual int Iterations() const
Return number of iteration used to find minimum.
static void SetDefaultNSearch(int n)
set number of times the bracketing search in combination with is done to find a good interval Default...
virtual double XUpper() const
Return current upper bound of the minimization interval.
virtual double FValUpper() const
Return function value at current upper bound of the minimization interval.
int Status() const
Returns status of last estimate.
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...
virtual const char * Name() const
Return name of minimization algorithm ("BrentMinimizer1D")
virtual double FValLower() const
Return function value at current lower bound of the minimization interval.
virtual double XMinimum() const
Return current estimate of the position of the minimum.
void SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup)
Sets function to be minimized.
static void SetDefaultNpx(int npx)
set number of default Npx used at construction time (when SetNpx is not called) Default value is 100
void SetNpx(int npx)
Set the number of point used to bracket root using a grid.
void SetLogScan(bool on)
Set a log grid scan (default is equidistant bins) will work only if xlow > 0.
BrentMinimizer1D()
Default Constructor.
virtual double FValMinimum() const
Return function value at current estimate of the minimum.
virtual double XLower() const
Return current lower bound of the minimization interval.
virtual ~BrentMinimizer1D()
Default Destructor.
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Interface class for numerical methods for one-dimensional minimization.
Definition: IMinimizer1D.h:50
const Int_t n
Definition: legend1.C:16
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21