Logo ROOT  
Reference Guide
GSLMinimizer1D.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Author: L. Moneta, A. Zsenei 08/2005
3  /**********************************************************************
4  * *
5  * Copyright (c) 2004 moneta, 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 GSLMinimizer1D
25 //
26 // Created by: moneta at Wed Dec 1 15:04:51 2004
27 //
28 // Last update: Wed Dec 1 15:04:51 2004
29 //
30 
31 #ifndef ROOT_Math_GSLMinimizer1D
32 #define ROOT_Math_GSLMinimizer1D
33 
34 #include "Math/IMinimizer1D.h"
36 
37 
38 namespace ROOT {
39 namespace Math {
40 
41  namespace Minim1D {
42 
43  /**
44  Enumeration with One Dimensional Minimizer Algorithms.
45  The algorithms are implemented using GSL, see the
46  <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_33.html#SEC447">GSL manual</A>.
47 
48  The algorithms available are:
49  <ul>
50  <li><em>Golden Section Algorithm</em>, simplest method of bracketing the minimum of a function
51  <li><em>Brent Algorithm</em>, which combines a parabolic interpolation with the golden section algorithm
52  </ul>
53  @ingroup Min1D
54  */
55 
57  kBRENT
58  };
59  }
60 
61  class GSL1DMinimizerWrapper;
62  class GSLFunctionWrapper;
63 
64 //______________________________________________________________________________________
65 /**
66 
67 Minimizer for arbitrary one dimensional functions.
68 
69 Implemented using GSL, for detailed description see:
70 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/One-dimensional-Minimization.html">GSL online doc</A>
71 
72 The algorithms uspported are only bracketing algorithm which do not use derivatives information.
73 The algorithms which can be chosen at construction time are GOLDENSECTION, whic is the simplest method
74 but the slowest and BRENT (the default one) which combines the golden section with a parabolic interpolation.
75 
76 
77 This class does not support copying
78 @ingroup Min1D
79 */
80 
81  class GSLMinimizer1D: public IMinimizer1D {
82 
83  public:
84 
85  /**
86  Construct the minimizer passing the minimizer type using the Minim1D::Algorithm enumeration
87  */
88 
90 
91  /**
92  Destructor: free allocated resources
93  */
94  virtual ~GSLMinimizer1D();
95 
96  private:
97  // usually copying is non trivial, so we make this unaccessible
100 
101  public:
102 
103 
104  /**
105  Set, or reset, minimizer to use the function f and the initial search interval [xlow, xup], with a guess for the location of the minimum xmin.
106  The condition : \f$ f(xlow) > f(xmin) < f(xup)\f$ must be satisfied
107  */
108  template <class UserFunc>
109  void SetFunction( const UserFunc & f, double xmin, double xlow, double xup) {
110  const void * p = &f;
111  SetFunction( &GSLFunctionAdapter<UserFunc>::F, const_cast<void *>(p), xmin, xlow, xup );
112  }
113 
114  /**
115  Set, or reset, minimizer to use the function f and the initial search interval [xlow, xup], with a guess for the location of the minimum xmin.
116  The condition : \f$ f(xlow) > f(xmin) < f(xup) \f$ must be satisfied
117 
118  Method specialized on the GSL function type
119  */
120  void SetFunction( GSLFuncPointer f, void * params, double xmin, double xlow, double xup);
121 
122  /**
123  Perform a minimizer iteration and
124  if an unexepcted problem occurr then an error code will be returned
125  */
126  int Iterate();
127 
128 
129  /**
130  Return current estimate of the position of the minimum
131  */
132  double XMinimum() const;
133 
134  /**
135  Return current lower bound of the minimization interval
136  */
137  double XLower() const;
138 
139  /**
140  Return current upper bound of the minimization interval
141  */
142  double XUpper() const;
143 
144  /**
145  Return function value at current estimate of the minimum
146  */
147  double FValMinimum() const;
148 
149  /**
150  Return function value at current lower bound of the minimization interval
151  */
152  double FValLower() const;
153 
154  /**
155  Return function value at current upper bound of the minimization interval
156  */
157  double FValUpper() const;
158 
159 
160  /**
161  Find minimum position iterating until convergence specified by the absolute and relative tolerance or
162  the maximum number of iteration is reached
163  Return true is result is successfull
164  \@param maxIter maximum number of iteration
165  \@param absTol desired absolute error in the minimum position
166  \@param absTol desired relative error in the minimum position
167  */
168  bool Minimize( int maxIter, double absTol, double relTol);
169 
170 
171  /**
172  Return number of iteration used to find minimum
173  */
174  int Iterations() const {
175  return fIter;
176  }
177 
178  /**
179  Return status of last minimization
180  */
181  int Status() const { return fStatus; }
182 
183  /**
184  Return name of minimization algorithm
185  */
186  const char * Name() const;
187 
188  /**
189  Test convergence of the interval.
190  The test returns success if
191  \f[
192  |x_{min}-x_{truemin}| < epsAbs + epsRel *x_{truemin}
193  \f]
194  */
195  static int TestInterval( double xlow, double xup, double epsAbs, double epsRel);
196 
197 
198  protected:
199 
200 
201  private:
202 
203  double fXmin;
204  double fXlow;
205  double fXup;
206  double fMin;
207  double fLow;
208  double fUp;
209  int fIter;
210  int fStatus; // status of last minimization (==0 ok =1 failed)
211  bool fIsSet;
212 
213 
216 
217  };
218 
219 } // end namespace Math
220 
221 } // end namespace ROOT
222 
223 
224 #endif /* ROOT_Math_GSLMinimizer1D */
GSLFunctionAdapter.h
f
#define f(i)
Definition: RSha256.hxx:104
ROOT::Math::GSLMinimizer1D::XUpper
double XUpper() const
Return current upper bound of the minimization interval.
Definition: GSLMinimizer1D.cxx:151
ROOT::Math::Minim1D::Type
Type
Enumeration with One Dimensional Minimizer Algorithms.
Definition: GSLMinimizer1D.h:56
ROOT::Math::GSLMinimizer1D::XMinimum
double XMinimum() const
Return current estimate of the position of the minimum.
Definition: GSLMinimizer1D.cxx:141
ROOT::Math::GSL1DMinimizerWrapper
wrapper class for gsl_min_fminimizer structure
Definition: GSL1DMinimizerWrapper.h:44
ROOT::Math::GSLFunctionWrapper
Wrapper class to the gsl_function C structure.
Definition: GSLFunctionWrapper.h:57
ROOT::Math::GSLMinimizer1D::Name
const char * Name() const
Return name of minimization algorithm.
Definition: GSLMinimizer1D.cxx:171
ROOT::Math::GSLMinimizer1D::fIter
int fIter
Definition: GSLMinimizer1D.h:209
ROOT::Math::Minim1D::kBRENT
@ kBRENT
Definition: GSLMinimizer1D.h:57
ROOT::Math::IMinimizer1D
Interface class for numerical methods for one-dimensional minimization.
Definition: IMinimizer1D.h:50
ROOT::Math::GSLMinimizer1D::Iterations
int Iterations() const
Return number of iteration used to find minimum.
Definition: GSLMinimizer1D.h:174
ROOT::Math::GSLMinimizer1D::fXmin
double fXmin
Definition: GSLMinimizer1D.h:203
ROOT::Math::GSLMinimizer1D::SetFunction
void SetFunction(const UserFunc &f, double xmin, double xlow, double xup)
Set, or reset, minimizer to use the function f and the initial search interval [xlow,...
Definition: GSLMinimizer1D.h:109
ROOT::Math::GSLMinimizer1D::fUp
double fUp
Definition: GSLMinimizer1D.h:208
ROOT::Math::GSLMinimizer1D::fStatus
int fStatus
Definition: GSLMinimizer1D.h:210
ROOT::Math::GSLMinimizer1D::XLower
double XLower() const
Return current lower bound of the minimization interval.
Definition: GSLMinimizer1D.cxx:146
ROOT::Math::GSLMinimizer1D::fMin
double fMin
Definition: GSLMinimizer1D.h:206
IMinimizer1D.h
ROOT::Math::GSLMinimizer1D::TestInterval
static int TestInterval(double xlow, double xup, double epsAbs, double epsRel)
Test convergence of the interval.
Definition: GSLMinimizer1D.cxx:214
ROOT::Math::GSLMinimizer1D::FValUpper
double FValUpper() const
Return function value at current upper bound of the minimization interval.
Definition: GSLMinimizer1D.cxx:166
xmin
float xmin
Definition: THbookFile.cxx:95
ROOT::Math::GSLMinimizer1D::Minimize
bool Minimize(int maxIter, double absTol, double relTol)
Find minimum position iterating until convergence specified by the absolute and relative tolerance or...
Definition: GSLMinimizer1D.cxx:176
ROOT::Math::GSLMinimizer1D::~GSLMinimizer1D
virtual ~GSLMinimizer1D()
Destructor: free allocated resources.
Definition: GSLMinimizer1D.cxx:78
ROOT::Math::GSLMinimizer1D::fFunction
GSLFunctionWrapper * fFunction
Definition: GSLMinimizer1D.h:215
ROOT::Math::GSLMinimizer1D::Iterate
int Iterate()
Perform a minimizer iteration and if an unexepcted problem occurr then an error code will be returned...
Definition: GSLMinimizer1D.cxx:122
ROOT::Math::GSLMinimizer1D::fXlow
double fXlow
Definition: GSLMinimizer1D.h:204
ROOT::Math::GSLMinimizer1D::operator=
GSLMinimizer1D & operator=(const GSLMinimizer1D &)
Definition: GSLMinimizer1D.cxx:91
ROOT::Math::GSLFuncPointer
double(* GSLFuncPointer)(double, void *)
Function pointer corresponding to gsl_function signature.
Definition: GSLFunctionAdapter.h:45
ROOT::Math::GSLMinimizer1D::FValLower
double FValLower() const
Return function value at current lower bound of the minimization interval.
Definition: GSLMinimizer1D.cxx:161
ROOT::Math::Minim1D::kGOLDENSECTION
@ kGOLDENSECTION
Definition: GSLMinimizer1D.h:56
ROOT::Math::GSLMinimizer1D::fIsSet
bool fIsSet
Definition: GSLMinimizer1D.h:211
ROOT::Math::GSLMinimizer1D
Minimizer for arbitrary one dimensional functions.
Definition: GSLMinimizer1D.h:81
ROOT::Math::GSLMinimizer1D::fLow
double fLow
Definition: GSLMinimizer1D.h:207
type
int type
Definition: TGX11.cxx:121
ROOT::Math::GSLMinimizer1D::fXup
double fXup
Definition: GSLMinimizer1D.h:205
ROOT::Math::GSLMinimizer1D::fMinimizer
GSL1DMinimizerWrapper * fMinimizer
Definition: GSLMinimizer1D.h:214
ROOT::Math::GSLMinimizer1D::Status
int Status() const
Return status of last minimization.
Definition: GSLMinimizer1D.h:181
ROOT::Math::GSLFunctionAdapter
Class for adapting any C++ functor class to C function pointers used by GSL.
Definition: GSLFunctionAdapter.h:63
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
Math
Namespace for new Math classes and functions.
ROOT::Math::GSLMinimizer1D::GSLMinimizer1D
GSLMinimizer1D(Minim1D::Type type=Minim1D::kBRENT)
Construct the minimizer passing the minimizer type using the Minim1D::Algorithm enumeration.
Definition: GSLMinimizer1D.cxx:51
ROOT::Math::GSLMinimizer1D::FValMinimum
double FValMinimum() const
Return function value at current estimate of the minimum.
Definition: GSLMinimizer1D.cxx:156