|
||||
Warning, file /include/root/TUnuranMultiContDist.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // @(#)root/unuran:$Id$ 0002 // Authors: L. Moneta, J. Leydold Wed Feb 28 2007 0003 0004 /********************************************************************** 0005 * * 0006 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT * 0007 * * 0008 * * 0009 **********************************************************************/ 0010 0011 // Header file for class TUnuranMultiContDist 0012 0013 #ifndef ROOT_Math_TUnuranMultiContDist 0014 #define ROOT_Math_TUnuranMultiContDist 0015 0016 #include "TUnuranBaseDist.h" 0017 0018 #include "Math/IFunction.h" 0019 0020 0021 0022 #include <vector> 0023 0024 class TF1; 0025 0026 0027 0028 /** 0029 TUnuranMultiContDist class describing multi dimensional continuous distributions. 0030 It is used by TUnuran to generate a set of random numbers according to this distribution via 0031 TUnuran::Sample(double *). 0032 The class can be constructed from a multi-dimensional function (TF1 pointer, which can be actually also a 0033 TF2 or a TF3). 0034 It provides a method to set the domain of the distribution ( SetDomain ) which will correspond to the range 0035 of the generated random numbers. By default the domain is [(-inf,-inf,...)(+inf,+inf,...)], independently of the 0036 range set in the TF1 class used to construct the distribution. 0037 0038 The derivatives of the pdf which are used by some UNURAN methods are estimated numerically in the 0039 Derivative() method. Some extra information (like distribution mode) can be set using SetMode. 0040 Some methods require instead of the pdf the log of the pdf. 0041 This can also be controlled by setting a flag when constructing this class. 0042 0043 \ingroup Unuran 0044 0045 */ 0046 0047 class TUnuranMultiContDist : public TUnuranBaseDist { 0048 0049 public: 0050 0051 0052 /** 0053 Constructor from a TF1 object representing the Probability density function. 0054 The derivatives of the Pdf are estimated, when required by the UNURAN algorithm, 0055 using numerical derivation. 0056 If a value of dim 0 is passed , the dimension of the function is taken from TF1::GetNdim(). 0057 This works only for 2D and 3D (for TF2 and TF3 objects). 0058 */ 0059 TUnuranMultiContDist (TF1 * func = nullptr, unsigned int dim = 0, bool isLogPdf = false); 0060 0061 0062 /** 0063 Constructor as before but from a generic function object interface for multi-dim functions 0064 */ 0065 TUnuranMultiContDist (const ROOT::Math::IMultiGenFunction & pdf, bool isLogPdf = false); 0066 0067 /** 0068 Destructor 0069 */ 0070 ~TUnuranMultiContDist () override; 0071 0072 0073 /** 0074 Copy constructor 0075 */ 0076 TUnuranMultiContDist(const TUnuranMultiContDist &); 0077 0078 /** 0079 Assignment operator 0080 */ 0081 TUnuranMultiContDist & operator = (const TUnuranMultiContDist & rhs); 0082 0083 /** 0084 Clone (required by base class) 0085 */ 0086 TUnuranMultiContDist * Clone() const override { return new TUnuranMultiContDist(*this); } 0087 0088 0089 /** 0090 get number of dimension of the distribution 0091 */ 0092 unsigned int NDim() const { 0093 return fPdf->NDim(); 0094 } 0095 0096 /** 0097 set the domain of the distribution giving an array of minimum and maximum values 0098 By default otherwise the domain is undefined, i.e. is [-inf,+inf] 0099 To remove the domain do a SetDomain(0,0). 0100 There is no possibility to have a domain defined in only one coordinate. Use instead inf or DOUBLE_MAX to 0101 specify un infinite domain in that coordinate 0102 */ 0103 void SetDomain(const double *xmin, const double *xmax) { 0104 if (!xmin || !xmax) return; 0105 fXmin = std::vector<double>(xmin,xmin+NDim()); 0106 fXmax = std::vector<double>(xmax,xmax+NDim()); 0107 } 0108 0109 /** 0110 set the mode of the distribution (coordinates of the distribution maximum values) 0111 */ 0112 void SetMode(const double * x) { 0113 fMode = std::vector<double>(x,x+NDim()); 0114 } 0115 0116 /** 0117 get the distribution lower domain values. Return a null pointer if domain is not defined 0118 */ 0119 const double * GetLowerDomain() const { 0120 if (fXmin.empty() || ( fXmin.size() != fXmax.size() ) ) return nullptr; 0121 return &fXmin[0]; 0122 } 0123 /** 0124 get the distribution upper domain values. Return a null pointer if domain is not defined 0125 */ 0126 const double * GetUpperDomain() const { 0127 if (fXmax.empty() || ( fXmin.size() != fXmax.size() ) ) return nullptr; 0128 return &fXmax[0]; 0129 } 0130 0131 0132 /** 0133 get the mode (vector of coordinate positions of the maxima of the distribution) 0134 If a mode has not defined return a NULL pointer 0135 */ 0136 const double * GetMode() const { 0137 if (fMode.empty()) return nullptr; 0138 return &fMode.front(); 0139 } 0140 0141 0142 /** 0143 flag to control if given function represent the log of a pdf 0144 */ 0145 bool IsLogPdf() const { return fIsLogPdf; } 0146 0147 /** 0148 evaluate the probability density function, used by UnuRan 0149 */ 0150 double Pdf (const double * x) const; 0151 0152 /** 0153 evaluate the gradient vector of the Pdf. Used by UnuRan 0154 */ 0155 void Gradient( const double * x, double * grad) const; 0156 0157 /** 0158 evaluate the partial derivative for the given coordinate. Used by UnuRan 0159 */ 0160 double Derivative( const double * x, int icoord) const; 0161 0162 0163 0164 private: 0165 0166 const ROOT::Math::IMultiGenFunction * fPdf; //pointer to the pdf 0167 0168 std::vector<double> fXmin; ///< vector with lower x values of the domain 0169 std::vector<double> fXmax; ///< vector with upper x values of the domain 0170 std::vector<double> fMode; ///< vector representing the x coordinates of the maximum of the pdf 0171 0172 bool fIsLogPdf; ///< flag to control if function pointer represent log of pdf 0173 bool fOwnFunc; ///< flag to indicate if class manages the function pointers 0174 0175 0176 ClassDefOverride(TUnuranMultiContDist,1) //Wrapper class for multi dimensional continuous distribution 0177 0178 0179 }; 0180 0181 0182 0183 #endif /* ROOT_Math_TUnuranMultiContDist */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |