ROOT   Reference Guide
TUnuranMultiContDist.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 TUnuranMultiContDist
12
13#ifndef ROOT_Math_TUnuranMultiContDist
14#define ROOT_Math_TUnuranMultiContDist
15
16#include "TUnuranBaseDist.h"
17
18#include "Math/IFunction.h"
19
20
21
22#include <vector>
23
24class TF1;
25
26
27
28/**
29 TUnuranMultiContDist class describing multi dimensional continuous distributions.
30 It is used by TUnuran to generate a set of random numbers according to this distribution via
31 TUnuran::Sample(double *).
32 The class can be constructed from a multi-dimensional function (TF1 pointer, which can be actually also a
33 TF2 or a TF3).
34 It provides a method to set the domain of the distribution ( SetDomain ) which will correspond to the range
35 of the generated random numbers. By default the domain is [(-inf,-inf,...)(+inf,+inf,...)], indipendently of the
36 range set in the TF1 class used to construct the distribution.
37
38 The derivatives of the pdf which are used by some UNURAN methods are estimated numerically in the
39 Derivative() method. Some extra information (like distribution mode) can be set using SetMode.
40 Some methods require instead of the pdf the log of the pdf.
41 This can also be controlled by setting a flag when constructing this class.
42
43 \ingroup Unuran
44
45*/
46
48
49public:
50
51
52 /**
53 Constructor from a TF1 object representing the Probability density function.
54 The derivatives of the Pdf are estimated, when required by the UNURAN algorithm,
55 using numerical derivation.
56 If a value of dim 0 is passed , the dimension of the function is taken from TF1::GetNdim().
57 This works only for 2D and 3D (for TF2 and TF3 objects).
58 */
59 TUnuranMultiContDist (TF1 * func = 0, unsigned int dim = 0, bool isLogPdf = false);
60
61
62 /**
63 Constructor as before but from a generic function object interface for multi-dim functions
64 */
65 TUnuranMultiContDist (const ROOT::Math::IMultiGenFunction & pdf, bool isLogPdf = false);
66
67 /**
68 Destructor
69 */
70 virtual ~TUnuranMultiContDist ();
71
72
73 /**
74 Copy constructor
75 */
77
78 /**
79 Assignment operator
80 */
82
83 /**
84 Clone (required by base class)
85 */
86 virtual TUnuranMultiContDist * Clone() const { return new TUnuranMultiContDist(*this); }
87
88
89 /**
90 get number of dimension of the distribution
91 */
92 unsigned int NDim() const {
93 return fPdf->NDim();
94 }
95
96 /**
97 set the domain of the distribution giving an array of minimum and maximum values
98 By default otherwise the domain is undefined, i.e. is [-inf,+inf]
99 To remove the domain do a SetDomain(0,0).
100 There is no possibility to have a domain defined in only one coordinate. Use instead inf or DOUBLE_MAX to
101 specify un infinite domain in that coordinate
102 */
103 void SetDomain(const double *xmin, const double *xmax) {
104 if (xmin == 0 || xmax == 0) return;
105 fXmin = std::vector<double>(xmin,xmin+NDim());
106 fXmax = std::vector<double>(xmax,xmax+NDim());
107 }
108
109 /**
110 set the mode of the distribution (coordinates of the distribution maximum values)
111 */
112 void SetMode(const double * x) {
113 fMode = std::vector<double>(x,x+NDim());
114 }
115
116 /**
117 get the distribution lower domain values. Return a null pointer if domain is not defined
118 */
119 const double * GetLowerDomain() const {
120 if (fXmin.size() == 0 || ( fXmin.size() != fXmax.size() ) ) return 0;
121 return &fXmin[0];
122 }
123 /**
124 get the distribution upper domain values. Return a null pointer if domain is not defined
125 */
126 const double * GetUpperDomain() const {
127 if (fXmax.size() == 0 || ( fXmin.size() != fXmax.size() ) ) return 0;
128 return &fXmax[0];
129 }
130
131
132 /**
133 get the mode (vector of coordinate positions of the maxima of the distribution)
134 If a mode has not defined return a NULL pointer
135 */
136 const double * GetMode( ) const {
137 if (fMode.size() == 0 ) return 0;
138 return &fMode.front();
139 }
140
141
142 /**
143 flag to control if given function represent the log of a pdf
144 */
145 bool IsLogPdf() const { return fIsLogPdf; }
146
147 /**
148 evaluate the probability density function, used by UnuRan
149 */
150 double Pdf ( const double * x) const;
151
152 /**
153 evaluate the gradient vector of the Pdf. Used by UnuRan
154 */
156
157 /**
158 evaluate the partial derivative for the given coordinate. Used by UnuRan
159 */
160 double Derivative( const double * x, int icoord) const;
161
162
163
164private:
165
166 const ROOT::Math::IMultiGenFunction * fPdf; //pointer to the pdf
167
168 std::vector<double> fXmin; //vector with lower x values of the domain
169 std::vector<double> fXmax; //vector with upper x values of the domain
170 std::vector<double> fMode; //vector representing the x coordinates of the maximum of the pdf
171
172 bool fIsLogPdf; //flag to control if function pointer represent log of pdf
173 bool fOwnFunc; // flag to indicate if class manages the function pointers
174
175
176 ClassDef(TUnuranMultiContDist,1) //Wrapper class for multi dimensional continuous distribution
177
178
179};
180
181
182
183#endif /* ROOT_Math_TUnuranMultiContDist */
#define ClassDef(name, id)
Definition: Rtypes.h:326
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
1-Dim function class
Definition: TF1.h:211
TUnuranBaseDist, base class for Unuran distribution classees such as TUnuranContDist (for one-dimensi...
TUnuranMultiContDist class describing multi dimensional continuous distributions.
void SetMode(const double *x)
set the mode of the distribution (coordinates of the distribution maximum values)
double Pdf(const double *x) const
evaluate the probability density function, used by UnuRan
double Derivative(const double *x, int icoord) const
evaluate the partial derivative for the given coordinate.
std::vector< double > fXmax
evaluate the gradient vector of the Pdf.
std::vector< double > fXmin
std::vector< double > fMode
TUnuranMultiContDist & operator=(const TUnuranMultiContDist &rhs)
Assignment operator.
const double * GetMode() const
get the mode (vector of coordinate positions of the maxima of the distribution) If a mode has not def...
void SetDomain(const double *xmin, const double *xmax)
set the domain of the distribution giving an array of minimum and maximum values By default otherwise...
const ROOT::Math::IMultiGenFunction * fPdf
unsigned int NDim() const
get number of dimension of the distribution
const double * GetUpperDomain() const
get the distribution upper domain values.
virtual ~TUnuranMultiContDist()
Destructor.
const double * GetLowerDomain() const
get the distribution lower domain values.
bool IsLogPdf() const
flag to control if given function represent the log of a pdf
virtual TUnuranMultiContDist * Clone() const
Clone (required by base class)
TUnuranMultiContDist(TF1 *func=0, unsigned int dim=0, bool isLogPdf=false)
Constructor from a TF1 object representing the Probability density function.
Double_t x[n]
Definition: legend1.C:17