GSLMinimizer1D.h

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: GSLMinimizer1D.h 32583 2010-03-12 09:57:42Z moneta $
00002 // Author: L. Moneta, A. Zsenei   08/2005
00003  /**********************************************************************
00004   *                                                                    *
00005   * Copyright (c) 2004 moneta,  CERN/PH-SFT                            *
00006   *                                                                    *
00007   * This library is free software; you can redistribute it and/or      *
00008   * modify it under the terms of the GNU General Public License        *
00009   * as published by the Free Software Foundation; either version 2     *
00010   * of the License, or (at your option) any later version.             *
00011   *                                                                    *
00012   * This library is distributed in the hope that it will be useful,    *
00013   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00014   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00015   * General Public License for more details.                           *
00016   *                                                                    *
00017   * You should have received a copy of the GNU General Public License  *
00018   * along with this library (see file COPYING); if not, write          *
00019   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00020   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00021   *                                                                    *
00022   **********************************************************************/
00023 
00024 // Header file for class GSLMinimizer1D
00025 // 
00026 // Created by: moneta  at Wed Dec  1 15:04:51 2004
00027 // 
00028 // Last update: Wed Dec  1 15:04:51 2004
00029 // 
00030 
00031 #ifndef ROOT_Math_GSLMinimizer1D
00032 #define ROOT_Math_GSLMinimizer1D
00033 
00034 #include "Math/IMinimizer1D.h"
00035 #include "Math/GSLFunctionAdapter.h"
00036 
00037 
00038 namespace ROOT { 
00039 namespace Math { 
00040 
00041    namespace Minim1D {
00042       
00043       /** 
00044           Enumeration with One Dimensional Minimizer Algorithms. 
00045           The algorithms are implemented using GSL, see the 
00046           <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_33.html#SEC447">GSL manual</A>.
00047           
00048           The algorithms available are: 
00049           <ul>
00050           <li><em>Golden Section Algorithm</em>, simplest method of bracketing the minimum of a function 
00051           <li><em>Brent Algorithm</em>, which combines a parabolic interpolation with the golden section algorithm
00052           </ul>
00053           @ingroup Min1D
00054       */
00055       
00056       enum Type {kGOLDENSECTION, 
00057                  kBRENT
00058       };
00059    }
00060    
00061    class GSL1DMinimizerWrapper; 
00062    class GSLFunctionWrapper;
00063 
00064 //______________________________________________________________________________________
00065 /** 
00066 
00067 Minimizer for arbitrary one dimensional functions. 
00068 
00069 Implemented using GSL, for detailed description see: 
00070 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/One-dimensional-Minimization.html">GSL online doc</A>
00071 
00072 The algorithms uspported are only bracketing algorithm which do not use derivatives information. 
00073 The algorithms which can be choosen at construction time are  GOLDENSECTION, whic is the simplest method 
00074 but the slowest and BRENT (the default one) which combines the golden section with a parabolic interpolation. 
00075 
00076 
00077 This class does not support copying
00078 @ingroup Min1D
00079 */
00080 
00081    class GSLMinimizer1D: public IMinimizer1D {
00082 
00083    public: 
00084 
00085       /**
00086          Construct the minimizer passing the minimizer type using the Minim1D::Algorithm enumeration
00087       */
00088       
00089       explicit GSLMinimizer1D(Minim1D::Type type=Minim1D::kBRENT);
00090  
00091       /**
00092          Destructor: free allocated resources
00093       */
00094       virtual ~GSLMinimizer1D(); 
00095 
00096    private:
00097       // usually copying is non trivial, so we make this unaccessible
00098       GSLMinimizer1D(const GSLMinimizer1D &); 
00099       GSLMinimizer1D & operator = (const GSLMinimizer1D &); 
00100     
00101    public: 
00102       
00103      
00104       /** 
00105           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.
00106           The condition : \f$ f(xlow) > f(xmin) < f(xup)\f$  must be satisfied
00107       */
00108       template <class UserFunc> 
00109       void SetFunction( const UserFunc & f, double xmin, double xlow, double xup) { 
00110          const void * p = &f; 
00111          SetFunction(  &GSLFunctionAdapter<UserFunc>::F, const_cast<void *>(p), xmin, xlow, xup ); 
00112       }
00113     
00114       /** 
00115           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.
00116           The condition : \f$ f(xlow) > f(xmin) < f(xup) \f$ must be satisfied
00117         
00118           Method specialized on the GSL function type 
00119       */
00120       void SetFunction( GSLFuncPointer  f, void * params, double xmin, double xlow, double xup); 
00121     
00122       /** 
00123           Perform a minimizer iteration and  
00124           if an unexepcted problem occurr then an error code will be returned
00125       */
00126       int Iterate(); 
00127 
00128 
00129       /** 
00130           Return current estimate of the position of the minimum
00131       */
00132       double XMinimum() const; 
00133 
00134       /**
00135          Return current lower bound of the minimization interval
00136       */
00137       double XLower() const; 
00138     
00139       /**
00140          Return current upper bound of the minimization interval
00141       */
00142       double XUpper() const; 
00143 
00144       /** 
00145           Return function value at current estimate of the minimum
00146       */
00147       double FValMinimum() const; 
00148 
00149       /**
00150          Return function value at current lower bound of the minimization interval
00151       */
00152       double FValLower() const; 
00153     
00154       /**
00155          Return function value at current upper bound of the minimization interval
00156       */
00157       double FValUpper() const; 
00158         
00159     
00160       /**
00161          Find minimum position iterating until convergence specified by the absolute and relative tolerance or 
00162          the maximum number of iteration is reached 
00163          Return true is result is successfull
00164          \@param maxIter maximum number of iteration
00165          \@param absTol desired absolute error in the minimum position
00166          \@param absTol desired relative error in the minimum position
00167       */
00168       bool Minimize( int maxIter, double absTol, double relTol); 
00169 
00170 
00171       /**
00172          Return number of iteration used to find minimum
00173       */
00174       int Iterations() const {
00175          return fIter; 
00176       }
00177 
00178       /**
00179          Return status of last minimization
00180        */
00181       int Status() const { return fStatus; }
00182 
00183       /**
00184          Return name of minimization algorithm
00185       */
00186       const char * Name() const;  
00187 
00188       /**
00189          Test convergence of the interval. 
00190          The test returns success if 
00191          \f[
00192          |x_{min}-x_{truemin}| < epsAbs + epsRel *x_{truemin}
00193          \f]
00194       */
00195       static int TestInterval( double xlow, double xup, double epsAbs, double epsRel); 
00196 
00197 
00198    protected: 
00199 
00200 
00201    private: 
00202 
00203       double fXmin; 
00204       double fXlow;
00205       double fXup; 
00206       double fMin; 
00207       double fLow;
00208       double fUp; 
00209       int fIter; 
00210       int fStatus;    // status of last minimization (==0 ok =1 failed)
00211       bool fIsSet; 
00212 
00213 
00214       GSL1DMinimizerWrapper * fMinimizer; 
00215       GSLFunctionWrapper * fFunction;  
00216 
00217    }; 
00218 
00219 } // end namespace Math
00220 
00221 } // end namespace ROOT
00222 
00223 
00224 #endif /* ROOT_Math_GSLMinimizer1D */

Generated on Tue Jul 5 14:25:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1