Logo ROOT   6.13/01
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 
58  };
59  }
60 
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
99  GSLMinimizer1D & operator = (const GSLMinimizer1D &);
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 */
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
int Status() const
Return status of last minimization.
GSL1DMinimizerWrapper * fMinimizer
int Iterations() const
Return number of iteration used to find minimum.
double(* GSLFuncPointer)(double, void *)
Function pointer corresponding to gsl_function signature.
int TestInterval(double xlow, double xup, double epsAbs, double epsRel)
Class for adapting any C++ functor class to C function pointers used by GSL.
Minimizer for arbitrary one dimensional functions.
Interface class for numerical methods for one-dimensional minimization.
Definition: IMinimizer1D.h:50
Namespace for new Math classes and functions.
Wrapper class to the gsl_function C structure.
Type
Enumeration with One Dimensional Minimizer Algorithms.
GSLFunctionWrapper * fFunction
wrapper class for gsl_min_fminimizer structure
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, xup], with a guess for the location of the minimum xmin.