|
|
|||
File indexing completed on 2025-12-08 10:35:56
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 // usually copying is non trivial, so we delete this 0097 GSLMinimizer1D(const GSLMinimizer1D &) = delete; 0098 GSLMinimizer1D & operator = (const GSLMinimizer1D &) = delete; 0099 GSLMinimizer1D(GSLMinimizer1D &&) = delete; 0100 GSLMinimizer1D & operator = (GSLMinimizer1D &&) = delete; 0101 0102 0103 /** 0104 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. 0105 The condition : \f$ f(xlow) > f(xmin) < f(xup)\f$ must be satisfied 0106 */ 0107 template <class UserFunc> 0108 void SetFunction( const UserFunc & f, double xmin, double xlow, double xup) { 0109 const void * p = &f; 0110 SetFunction( &GSLFunctionAdapter<UserFunc>::F, const_cast<void *>(p), xmin, xlow, xup ); 0111 } 0112 0113 /** 0114 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. 0115 The condition : \f$ f(xlow) > f(xmin) < f(xup) \f$ must be satisfied 0116 0117 Method specialized on the GSL function type 0118 */ 0119 void SetFunction( GSLFuncPointer f, void * params, double xmin, double xlow, double xup); 0120 0121 /** 0122 Perform a minimizer iteration and 0123 if an unexpected problem occurs then an error code will be returned 0124 */ 0125 int Iterate(); 0126 0127 0128 /** 0129 Return current estimate of the position of the minimum 0130 */ 0131 double XMinimum() const override; 0132 0133 /** 0134 Return current lower bound of the minimization interval 0135 */ 0136 double XLower() const override; 0137 0138 /** 0139 Return current upper bound of the minimization interval 0140 */ 0141 double XUpper() const override; 0142 0143 /** 0144 Return function value at current estimate of the minimum 0145 */ 0146 double FValMinimum() const override; 0147 0148 /** 0149 Return function value at current lower bound of the minimization interval 0150 */ 0151 double FValLower() const override; 0152 0153 /** 0154 Return function value at current upper bound of the minimization interval 0155 */ 0156 double FValUpper() const override; 0157 0158 0159 /** 0160 Find minimum position iterating until convergence specified by the absolute and relative tolerance or 0161 the maximum number of iteration is reached 0162 Return true is result is successful 0163 \@param maxIter maximum number of iteration 0164 \@param absTol desired absolute error in the minimum position 0165 \@param absTol desired relative error in the minimum position 0166 */ 0167 bool Minimize( int maxIter, double absTol, double relTol) override; 0168 0169 0170 /** 0171 Return number of iteration used to find minimum 0172 */ 0173 int Iterations() const override { 0174 return fIter; 0175 } 0176 0177 /** 0178 Return status of last minimization 0179 */ 0180 int Status() const override { return fStatus; } 0181 0182 /** 0183 Return name of minimization algorithm 0184 */ 0185 const char * Name() const override; 0186 0187 /** 0188 Test convergence of the interval. 0189 The test returns success if 0190 \f[ 0191 |x_{min}-x_{truemin}| < epsAbs + epsRel *x_{truemin} 0192 \f] 0193 */ 0194 static int TestInterval( double xlow, double xup, double epsAbs, double epsRel); 0195 0196 0197 protected: 0198 0199 0200 private: 0201 0202 double fXmin; 0203 double fXlow; 0204 double fXup; 0205 double fMin; 0206 double fLow; 0207 double fUp; 0208 int fIter; 0209 int fStatus; // status of last minimization (==0 ok =1 failed) 0210 bool fIsSet; 0211 0212 0213 GSL1DMinimizerWrapper * fMinimizer; 0214 GSLFunctionWrapper * fFunction; 0215 0216 }; 0217 0218 } // end namespace Math 0219 0220 } // end namespace ROOT 0221 0222 0223 #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 |
|