Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TUnuranContDist.h
Go to the documentation of this file.
1// @(#)root/unuran:$Id$
2// Authors: L. Moneta, J. Leydold Wed Feb 28 2007
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class TUnuranContDist
12
13
14#ifndef ROOT_Math_TUnuranContDist
15#define ROOT_Math_TUnuranContDist
16
17#include "TUnuranBaseDist.h"
18
19#include "Math/IFunctionfwd.h"
20
21class TF1;
22
23
24
25
26/**
27 \class TUnuranContDist
28 \ingroup Unuran
29
30 TUnuranContDist class describing one dimensional continuous distribution.
31 It is used by TUnuran to generate random numbers according to this distribution via
32 TUnuran::Sample()
33
34 The class can be constructed from a function (TF1) representing the probability density
35 function of the distribution. Optionally the derivative of the pdf can also be passed.
36
37 It provides a method to set the domain of the distribution ( SetDomain ) which will correspond to the range
38 of the generated random numbers. By default the domain is (-inf, + inf), indipendently of the
39 range set in the TF1 class used to construct the distribution.
40
41 In addition, some UNURAN methods requires extra information (cdf function, distribution mode,
42 area of pdf, etc...). This information can as well be set.
43 Some methods require instead of the pdf the log of the pdf.
44 This can also be controlled by setting a flag when constructing this class.
45*/
46
47
49
50public:
51
52
53 /**
54 Constructor from a TF1 objects specifying the pdf and optionally from another function
55 representing the derivative of the pdf. The flag isLogPdf can be used to pass instead of the pdf
56 (and its derivative) the log (and the derivative of the log) of the pdf.
57 By default the distribution has not domain set (it is defined between [-inf,+inf], no mode, no pdf area and no
58 cdf explicity defined. UnuRan, if needed, can compute some of this quantities, but the user if they know them can
59 set them in order to speed up the algorithm. For example in case of the Cdf, if the user has not set it, a numerical
60 integration algorithm is used to estimate the Cdf from the Pdf.
61 */
62 explicit TUnuranContDist (TF1 * pdf = 0, TF1 * deriv = 0, bool isLogPdf = false );
63 /**
64 Constructor as above but with the possibility to pass also the Cdf.
65 In case an algorithm requiring only the Cdf (no Pdf), one can use this contructor passing nullptr for Pdf and derivative of
66 the Pdf
67 */
68 TUnuranContDist (TF1 * pdf, TF1 * deriv, TF1 * cdf, bool isLogPdf = false );
69 /**
70 Constructor as before but from a generic function object interface for one-dim functions
71 */
72 explicit TUnuranContDist (const ROOT::Math::IGenFunction & pdf, const ROOT::Math::IGenFunction * dpdf = 0, bool isLogPdf = false, bool copyFunc = false);
73 /**
74 Constructor as before from pointers to generic function object interface for one-dim functions
75 which can be use for all algorithms including those requiring only the Cdf
76 */
78 const ROOT::Math::IGenFunction * cdf, bool isLogPdf = false, bool copyFunc = false );
79
80 /**
81 Destructor
82 */
83 virtual ~TUnuranContDist ();
84
85
86 /**
87 Copy constructor
88 */
90
91 /**
92 Assignment operator
93 */
95
96 /**
97 Clone (required by base class)
98 */
99 virtual TUnuranContDist * Clone() const { return new TUnuranContDist(*this); }
100
101
102 /**
103 set cdf distribution. If a method requires it
104 and is not set it is then estimated using numerical
105 integration from the pdf
106 */
107 void SetCdf(TF1 * cdf);
108
109 /**
110 set cdf distribution using a generic function interface
111 */
112 void SetCdf(const ROOT::Math::IGenFunction & cdf);
113
114 /**
115 Set the distribution domain. If min < max a domain is defined otherwise is undefined
116 */
117 void SetDomain(double xmin, double xmax) {
118 fXmin = xmin;
119 fXmax = xmax;
120 if (fXmin < fXmax)
121 fHasDomain = true;
122 else
123 fHasDomain = false;
124 }
125
126 /**
127 set the distribution mode (x position of its maximum)
128 */
129 void SetMode(double mode) { fMode = mode; fHasMode=true;}
130
131 /**
132 set the area below the pdf
133 */
134 void SetPdfArea(double area) { fArea = area; fHasArea=true;}
135
136 /**
137 check if distribution has a defined domain and return in case its domain
138 */
139 bool GetDomain(double & xmin, double & xmax) const {
140 xmin = fXmin;
141 xmax = fXmax;
142 return fHasDomain;
143 }
144
145 /**
146 check if a cdf function is provided for the distribution
147 */
148 bool HasCdf() const { return fCdf != 0; }
149
150 /**
151 check if distribution has a pre-computed mode
152 */
153 bool HasMode() const { return fHasMode; }
154
155
156 /**
157 check if distribution has a pre-computed area below the Pdf
158 */
159 bool HasPdfArea() const { return fHasArea; }
160
161 /**
162 return the mode (x location of maximum of the pdf)
163 */
164 double Mode() const { return fMode; }
165
166 /**
167 return area below the pdf
168 */
169 double PdfArea() const { return fArea; }
170
171
172 /**
173 flag to control if given function represent the log of a pdf
174 */
175 bool IsLogPdf() const { return fIsLogPdf; }
176
177 /**
178 evaluate the Probability Density function. Used by the UnuRan algorithms
179 */
180 double Pdf ( double x) const;
181
182 /**
183 evaluate the derivative of the pdf. Used by UnuRan
184 */
185 double DPdf( double x) const;
186
187 /**
188 evaluate the integral (cdf) on the domain. Used by Unuran algorithm
189 */
190 double Cdf(double x) const;
191
192
193protected:
194
195
196private:
197
198
199 const ROOT::Math::IGenFunction * fPdf; // pointer to the pdf
200 const ROOT::Math::IGenFunction * fDPdf; //pointer to the derivative of the pdf
201 const ROOT::Math::IGenFunction * fCdf; //pointer to the cdf (cumulative dist.)
202
203 double fXmin; //lower value of the domain
204 double fXmax; //upper value of the domain
205 double fMode; //mode of the distribution
206 double fArea; //area below pdf
207
208 // flags
209 bool fIsLogPdf; //flag to control if function pointer represent log of pdf
210 bool fHasDomain; //flag to control if distribution has a defined domain (otherwise is [-inf,+inf]
211 bool fHasMode; //flag to control if distribution has a pre-computed mode
212 bool fHasArea; //flag to control if distribution has a pre-computed area below the pdf
213 bool fOwnFunc; // flag to indicate if class manages the function pointers
214 //mutable double fX[1]; //! cached vector for using TF1::EvalPar
215
216 ClassDef(TUnuranContDist,1) //Wrapper class for one dimensional continuous distribution
217
218
219};
220
221
222
223#endif /* ROOT_Math_TUnuranContDist */
#define ClassDef(name, id)
Definition Rtypes.h:325
float xmin
float xmax
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition IFunction.h:135
1-Dim function class
Definition TF1.h:213
TUnuranBaseDist, base class for Unuran distribution classees such as TUnuranContDist (for one-dimensi...
TUnuranContDist class describing one dimensional continuous distribution.
const ROOT::Math::IGenFunction * fDPdf
double Mode() const
return the mode (x location of maximum of the pdf)
bool HasPdfArea() const
check if distribution has a pre-computed area below the Pdf
double DPdf(double x) const
evaluate the derivative of the pdf.
const ROOT::Math::IGenFunction * fPdf
double Pdf(double x) const
evaluate the Probability Density function.
virtual TUnuranContDist * Clone() const
Clone (required by base class)
const ROOT::Math::IGenFunction * fCdf
void SetMode(double mode)
set the distribution mode (x position of its maximum)
double Cdf(double x) const
evaluate the integral (cdf) on the domain.
double PdfArea() const
return area below the pdf
bool GetDomain(double &xmin, double &xmax) const
check if distribution has a defined domain and return in case its domain
void SetCdf(TF1 *cdf)
set cdf distribution.
void SetDomain(double xmin, double xmax)
Set the distribution domain.
virtual ~TUnuranContDist()
Destructor.
bool IsLogPdf() const
flag to control if given function represent the log of a pdf
void SetPdfArea(double area)
set the area below the pdf
bool HasMode() const
check if distribution has a pre-computed mode
TUnuranContDist & operator=(const TUnuranContDist &rhs)
Assignment operator.
bool HasCdf() const
check if a cdf function is provided for the distribution
Double_t x[n]
Definition legend1.C:17