|
||||
File indexing completed on 2025-01-18 10:10:13
0001 // @(#)root/mathcore:$Id$ 0002 // Author: M. Slawinska 08/2007 0003 0004 /********************************************************************** 0005 * * 0006 * Copyright (c) 2007 , LCG ROOT MathLib Team * 0007 * * 0008 * * 0009 **********************************************************************/ 0010 0011 // Header source file for class AdaptiveIntegratorMultiDim 0012 0013 0014 #ifndef ROOT_Math_AdaptiveIntegratorMultiDim 0015 #define ROOT_Math_AdaptiveIntegratorMultiDim 0016 0017 #include "Math/IFunctionfwd.h" 0018 0019 #include "Math/VirtualIntegrator.h" 0020 0021 namespace ROOT { 0022 namespace Math { 0023 0024 /** \class AdaptiveIntegratorMultiDim 0025 \ingroup Integration 0026 0027 Class for adaptive quadrature integration in multi-dimensions using rectangular regions. 0028 Algorithm from A.C. Genz, A.A. Malik, An adaptive algorithm for numerical integration over 0029 an N-dimensional rectangular region, J. Comput. Appl. Math. 6 (1980) 295-302. 0030 0031 Converted/adapted by R.Brun to C++ from Fortran CERNLIB routine RADMUL (D120) 0032 The new code features many changes compared to the Fortran version. 0033 0034 Control parameters are: 0035 0036 - \f$ minpts \f$: Minimum number of function evaluations requested. Must not exceed maxpts. 0037 if minpts < 1 minpts is set to \f$ 2^n +2n(n+1) +1 \f$ where n is the function dimension 0038 - \f$ maxpts \f$: Maximum number of function evaluations to be allowed. 0039 \f$ maxpts >= 2^n +2n(n+1) +1 \f$ 0040 if \f$ maxpts<minpts \f$, \f$ maxpts \f$ is set to \f$ 10minpts \f$ 0041 - \f$ epstol \f$, \f$ epsrel \f$ : Specified relative and absolute accuracy. 0042 0043 The integral will stop if the relative error is less than relative tolerance OR the 0044 absolute error is less than the absolute tolerance 0045 0046 The class computes in addition to the integral of the function in the desired interval: 0047 0048 - an estimation of the relative accuracy of the result. 0049 - number of function evaluations performed. 0050 - status code: 0051 0. Normal exit. . At least minpts and at most maxpts calls to the function were performed. 0052 1. maxpts is too small for the specified accuracy eps. 0053 The result and relerr contain the values obtainable for the 0054 specified value of maxpts. 0055 2. size is too small for the specified number MAXPTS of function evaluations. 0056 3. n<2 or n>15 0057 0058 ### Method: 0059 0060 An integration rule of degree seven is used together with a certain 0061 strategy of subdivision. 0062 For a more detailed description of the method see References. 0063 0064 ### Notes: 0065 0066 1..Multi-dimensional integration is time-consuming. For each rectangular 0067 subregion, the routine requires function evaluations. 0068 Careful programming of the integrand might result in substantial saving 0069 of time. 0070 2..Numerical integration usually works best for smooth functions. 0071 Some analysis or suitable transformations of the integral prior to 0072 numerical work may contribute to numerical efficiency. 0073 0074 ### References: 0075 0076 1. A.C. Genz and A.A. Malik, Remarks on algorithm 006: 0077 An adaptive algorithm for numerical integration over 0078 an N-dimensional rectangular region, J. Comput. Appl. Math. 6 (1980) 295-302. 0079 2. A. van Doren and L. de Ridder, An adaptive algorithm for numerical 0080 integration over an n-dimensional cube, J.Comput. Appl. Math. 2 (1976) 207-217. 0081 0082 */ 0083 0084 class AdaptiveIntegratorMultiDim : public VirtualIntegratorMultiDim { 0085 0086 public: 0087 0088 /** 0089 Construct given optionally tolerance (absolute and relative), maximum number of function evaluation (maxpts) and 0090 size of the working array. 0091 The integration will stop when the absolute error is less than the absolute tolerance OR when the relative error is less 0092 than the relative tolerance. The absolute tolerance by default is not used (it is equal to zero). 0093 The size of working array represents the number of sub-division used for calculating the integral. 0094 Higher the dimension, larger sizes are required for getting the same accuracy. 0095 The size must be larger than 0096 \f$ (2n + 3) (1 + maxpts/(2^n + 2n(n + 1) + 1))/2) \f$. 0097 For smaller value passed, the minimum allowed will be used 0098 */ 0099 explicit 0100 AdaptiveIntegratorMultiDim(double absTol = 0.0, double relTol = 1E-9, unsigned int maxpts = 100000, unsigned int size = 0); 0101 0102 /** 0103 Construct with a reference to the integrand function and given optionally 0104 tolerance (absolute and relative), maximum number of function evaluation (maxpts) and 0105 size of the working array. 0106 */ 0107 explicit 0108 AdaptiveIntegratorMultiDim(const IMultiGenFunction &f, double absTol = 0.0, double relTol = 1E-9, unsigned int maxcall = 100000, unsigned int size = 0); 0109 0110 /** 0111 destructor (no operations) 0112 */ 0113 ~AdaptiveIntegratorMultiDim() override {} 0114 0115 0116 /** 0117 evaluate the integral with the previously given function between xmin[] and xmax[] 0118 */ 0119 double Integral(const double* xmin, const double * xmax) override { 0120 return DoIntegral(xmin,xmax, false); 0121 } 0122 0123 0124 /// evaluate the integral passing a new function 0125 double Integral(const IMultiGenFunction &f, const double* xmin, const double * xmax); 0126 0127 /// set the integration function (must implement multi-dim function interface: IBaseFunctionMultiDim) 0128 void SetFunction(const IMultiGenFunction &f) override; 0129 0130 /// return result of integration 0131 double Result() const override { return fResult; } 0132 0133 /// return integration error 0134 double Error() const override { return fError; } 0135 0136 /// return relative error 0137 double RelError() const { return fRelError; } 0138 0139 /// return status of integration 0140 /// - status = 0 successful integration 0141 /// - status = 1 0142 /// MAXPTS is too small for the specified accuracy EPS. 0143 /// The result contain the values 0144 /// obtainable for the specified value of MAXPTS. 0145 /// - status = 2 0146 /// size is too small for the specified number MAXPTS of function evaluations. 0147 /// - status = 3 0148 /// wrong dimension , N<2 or N > 15. Returned result and error are zero 0149 int Status() const override { return fStatus; } 0150 0151 /// return number of function evaluations in calculating the integral 0152 int NEval() const override { return fNEval; } 0153 0154 /// set relative tolerance 0155 void SetRelTolerance(double relTol) override; 0156 0157 /// set absolute tolerance 0158 void SetAbsTolerance(double absTol) override; 0159 0160 ///set workspace size 0161 void SetSize(unsigned int size) { fSize = size; } 0162 0163 ///set min points 0164 void SetMinPts(unsigned int n) { fMinPts = n; } 0165 0166 ///set max points 0167 void SetMaxPts(unsigned int n) { fMaxPts = n; } 0168 0169 /// set the options 0170 void SetOptions(const ROOT::Math::IntegratorMultiDimOptions & opt) override; 0171 0172 /// get the option used for the integration 0173 ROOT::Math::IntegratorMultiDimOptions Options() const override; 0174 0175 protected: 0176 0177 // internal function to compute the integral (if absVal is true compute abs value of function integral 0178 double DoIntegral(const double* xmin, const double * xmax, bool absVal = false); 0179 0180 private: 0181 0182 unsigned int fDim; ///< dimensionality of integrand 0183 unsigned int fMinPts; ///< minimum number of function evaluation requested 0184 unsigned int fMaxPts; ///< maximum number of function evaluation requested 0185 unsigned int fSize; ///< max size of working array (explode with dimension) 0186 double fAbsTol; ///< absolute tolerance 0187 double fRelTol; ///< relative tolerance 0188 0189 double fResult; ///< last integration result 0190 double fError; ///< integration error 0191 double fRelError; ///< Relative error 0192 int fNEval; ///< number of function evaluation 0193 int fStatus; ///< status of algorithm (error if not zero) 0194 0195 const IMultiGenFunction* fFun; // pointer to integrand function 0196 0197 }; 0198 0199 }//namespace Math 0200 }//namespace ROOT 0201 0202 #endif /* ROOT_Math_AdaptiveIntegratorMultiDim */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |