|
||||
File indexing completed on 2025-01-18 10:10:17
0001 // @(#)root/mathmore:$Id$ 0002 // Author: L. Moneta, A. Zsenei 08/2005 0003 /********************************************************************** 0004 * * 0005 * Copyright (c) 2004 moneta, CERN/PH-SFT * 0006 * * 0007 * This library is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License * 0009 * as published by the Free Software Foundation; either version 2 * 0010 * of the License, or (at your option) any later version. * 0011 * * 0012 * This library is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0015 * General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU General Public License * 0018 * along with this library (see file COPYING); if not, write * 0019 * to the Free Software Foundation, Inc., 59 Temple Place, Suite * 0020 * 330, Boston, MA 02111-1307 USA, or contact the author. * 0021 * * 0022 **********************************************************************/ 0023 0024 // Header file for class GSLMinimizer1D 0025 // 0026 // Created by: moneta at Wed Dec 1 15:04:51 2004 0027 // 0028 // Last update: Wed Dec 1 15:04:51 2004 0029 // 0030 0031 #ifndef ROOT_Math_GSLMinimizer1D 0032 #define ROOT_Math_GSLMinimizer1D 0033 0034 #include "Math/IMinimizer1D.h" 0035 #include "Math/GSLFunctionAdapter.h" 0036 0037 0038 namespace ROOT { 0039 namespace Math { 0040 0041 namespace Minim1D { 0042 0043 /** 0044 Enumeration with One Dimensional Minimizer Algorithms. 0045 The algorithms are implemented using GSL, see the 0046 <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_33.html#SEC447">GSL manual</A>. 0047 0048 The algorithms available are: 0049 <ul> 0050 <li><em>Golden Section Algorithm</em>, simplest method of bracketing the minimum of a function 0051 <li><em>Brent Algorithm</em>, which combines a parabolic interpolation with the golden section algorithm 0052 </ul> 0053 @ingroup Min1D 0054 */ 0055 0056 enum Type {kGOLDENSECTION, 0057 kBRENT 0058 }; 0059 } 0060 0061 class GSL1DMinimizerWrapper; 0062 class GSLFunctionWrapper; 0063 0064 //______________________________________________________________________________________ 0065 /** 0066 0067 Minimizer for arbitrary one dimensional functions. 0068 0069 Implemented using GSL, for detailed description see: 0070 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/One-dimensional-Minimization.html">GSL online doc</A> 0071 0072 The algorithms uspported are only bracketing algorithm which do not use derivatives information. 0073 The algorithms which can be chosen at construction time are GOLDENSECTION, which is the simplest method 0074 but the slowest and BRENT (the default one) which combines the golden section with a parabolic interpolation. 0075 0076 0077 This class does not support copying 0078 @ingroup Min1D 0079 */ 0080 0081 class GSLMinimizer1D: public IMinimizer1D { 0082 0083 public: 0084 0085 /** 0086 Construct the minimizer passing the minimizer type using the Minim1D::Algorithm enumeration 0087 */ 0088 0089 explicit GSLMinimizer1D(Minim1D::Type type=Minim1D::kBRENT); 0090 0091 /** 0092 Destructor: free allocated resources 0093 */ 0094 ~GSLMinimizer1D() override; 0095 0096 private: 0097 // usually copying is non trivial, so we make this unaccessible 0098 GSLMinimizer1D(const GSLMinimizer1D &); 0099 GSLMinimizer1D & operator = (const GSLMinimizer1D &); 0100 0101 public: 0102 0103 0104 /** 0105 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. 0106 The condition : \f$ f(xlow) > f(xmin) < f(xup)\f$ must be satisfied 0107 */ 0108 template <class UserFunc> 0109 void SetFunction( const UserFunc & f, double xmin, double xlow, double xup) { 0110 const void * p = &f; 0111 SetFunction( &GSLFunctionAdapter<UserFunc>::F, const_cast<void *>(p), xmin, xlow, xup ); 0112 } 0113 0114 /** 0115 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. 0116 The condition : \f$ f(xlow) > f(xmin) < f(xup) \f$ must be satisfied 0117 0118 Method specialized on the GSL function type 0119 */ 0120 void SetFunction( GSLFuncPointer f, void * params, double xmin, double xlow, double xup); 0121 0122 /** 0123 Perform a minimizer iteration and 0124 if an unexpected problem occurs then an error code will be returned 0125 */ 0126 int Iterate(); 0127 0128 0129 /** 0130 Return current estimate of the position of the minimum 0131 */ 0132 double XMinimum() const override; 0133 0134 /** 0135 Return current lower bound of the minimization interval 0136 */ 0137 double XLower() const override; 0138 0139 /** 0140 Return current upper bound of the minimization interval 0141 */ 0142 double XUpper() const override; 0143 0144 /** 0145 Return function value at current estimate of the minimum 0146 */ 0147 double FValMinimum() const override; 0148 0149 /** 0150 Return function value at current lower bound of the minimization interval 0151 */ 0152 double FValLower() const override; 0153 0154 /** 0155 Return function value at current upper bound of the minimization interval 0156 */ 0157 double FValUpper() const override; 0158 0159 0160 /** 0161 Find minimum position iterating until convergence specified by the absolute and relative tolerance or 0162 the maximum number of iteration is reached 0163 Return true is result is successful 0164 \@param maxIter maximum number of iteration 0165 \@param absTol desired absolute error in the minimum position 0166 \@param absTol desired relative error in the minimum position 0167 */ 0168 bool Minimize( int maxIter, double absTol, double relTol) override; 0169 0170 0171 /** 0172 Return number of iteration used to find minimum 0173 */ 0174 int Iterations() const override { 0175 return fIter; 0176 } 0177 0178 /** 0179 Return status of last minimization 0180 */ 0181 int Status() const override { return fStatus; } 0182 0183 /** 0184 Return name of minimization algorithm 0185 */ 0186 const char * Name() const override; 0187 0188 /** 0189 Test convergence of the interval. 0190 The test returns success if 0191 \f[ 0192 |x_{min}-x_{truemin}| < epsAbs + epsRel *x_{truemin} 0193 \f] 0194 */ 0195 static int TestInterval( double xlow, double xup, double epsAbs, double epsRel); 0196 0197 0198 protected: 0199 0200 0201 private: 0202 0203 double fXmin; 0204 double fXlow; 0205 double fXup; 0206 double fMin; 0207 double fLow; 0208 double fUp; 0209 int fIter; 0210 int fStatus; // status of last minimization (==0 ok =1 failed) 0211 bool fIsSet; 0212 0213 0214 GSL1DMinimizerWrapper * fMinimizer; 0215 GSLFunctionWrapper * fFunction; 0216 0217 }; 0218 0219 } // end namespace Math 0220 0221 } // end namespace ROOT 0222 0223 0224 #endif /* ROOT_Math_GSLMinimizer1D */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |