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