ROOT 6.13/01 Reference Guide |
TUnuran class.
Interface to the UNU.RAN package for generating non uniform random numbers. This class wraps the UNU.RAN calls in C++ methods. It provides methods for initializing Unuran and then to sample the desired distribution. It provides support for initializing UNU.RAN in these following way (various signatures for TUnuran::Init)
The sampling is provided via these methods:
In addition is possible to set the random number generator in the constructor of the class, its seed via the TUnuran::SetSeed() method.
Public Member Functions | |
TUnuran (TRandom *r=0, unsigned int log=0) | |
Constructor with a generator instance and given level of log output. More... | |
~TUnuran () | |
Destructor. More... | |
TRandom * | GetRandom () |
return instance of the random engine used More... | |
bool | Init (const std::string &distr, const std::string &method) |
initialize with Unuran string interface More... | |
bool | Init (const TUnuranContDist &distr, const std::string &method="auto") |
Initialize method for continuous one-dimensional distribution. More... | |
bool | Init (const TUnuranMultiContDist &distr, const std::string &method="hitro") |
Initialize method for continuous multi-dimensional distribution. More... | |
bool | Init (const TUnuranDiscrDist &distr, const std::string &method="auto") |
Initialize method for continuous one-dimensional discrete distribution. More... | |
bool | Init (const TUnuranEmpDist &distr, const std::string &method="empk") |
Initialize method for continuous empirical distribution. More... | |
bool | InitBinomial (unsigned int ntot, double prob, const std::string &method="dstd") |
Initialize method for the Binomial distribution Used to generate poisson numbers for a constant parameters (n,p) of the Binomial distribution. More... | |
bool | InitPoisson (double mu, const std::string &method="dstd") |
Initialize method for the Poisson distribution Used to generate poisson numbers for a constant parameter mu of the Poisson distribution. More... | |
const std::string & | MethodName () const |
used Unuran method More... | |
bool | ReInitDiscrDist (unsigned int npar, double *params) |
Reinitialize UNURAN by changing the distribution parameters but mantaining same distribution and method It is implemented now only for predefined discrete distributions like the poisson or the binomial. More... | |
double | Sample () |
Sample 1D distribution User is responsible for having previously correctly initialized with TUnuran::Init. More... | |
int | SampleDiscr () |
Sample discrete distributions User is responsible for having previously correctly initialized with TUnuran::Init. More... | |
bool | SampleMulti (double *x) |
Sample multidimensional distributions User is responsible for having previously correctly initialized with TUnuran::Init. More... | |
bool | SetLogLevel (unsigned int iflag=1) |
set log level More... | |
bool | SetLogStream () |
set stream for log and error (not yet implemented) More... | |
void | SetRandom (TRandom *r) |
set the random engine. More... | |
void | SetSeed (unsigned int seed) |
set the seed for the random number generator More... | |
Protected Member Functions | |
bool | SetContDistribution (const TUnuranContDist &dist) |
bool | SetDiscreteDistribution (const TUnuranDiscrDist &dist) |
bool | SetEmpiricalDistribution (const TUnuranEmpDist &dist) |
bool | SetMethodAndInit () |
change the method and initialize Unuran with the previously given distribution More... | |
bool | SetMultiDistribution (const TUnuranMultiContDist &dist) |
bool | SetRandomGenerator () |
Protected Attributes | |
std::unique_ptr< TUnuranBaseDist > | fDist |
UNUR_GEN * | fGen |
std::string | fMethod |
TRandom * | fRng |
UNUR_DISTR * | fUdistr |
UNUR_URNG * | fUrng |
Private Member Functions | |
TUnuran (const TUnuran &) | |
Copy constructor. More... | |
TUnuran & | operator= (const TUnuran &rhs) |
Assignment operator. More... | |
#include <TUnuran.h>
TUnuran::TUnuran | ( | TRandom * | r = 0 , |
unsigned int | log = 0 |
||
) |
Constructor with a generator instance and given level of log output.
Definition at line 36 of file TUnuran.cxx.
TUnuran::~TUnuran | ( | ) |
Destructor.
Definition at line 57 of file TUnuran.cxx.
|
private |
Copy constructor.
Definition at line 67 of file TUnuran.cxx.
|
inline |
bool TUnuran::Init | ( | const std::string & | distr, |
const std::string & | method | ||
) |
initialize with Unuran string interface
Definition at line 79 of file TUnuran.cxx.
bool TUnuran::Init | ( | const TUnuranContDist & | distr, |
const std::string & | method = "auto" |
||
) |
Initialize method for continuous one-dimensional distribution.
User must provide a distribution object (which is copied inside) and a string for a method. For the list of available method for 1D cont. distribution see the UnuRan doc. A re-initialization is needed whenever distribution parameters have been changed.
Definition at line 93 of file TUnuran.cxx.
bool TUnuran::Init | ( | const TUnuranMultiContDist & | distr, |
const std::string & | method = "hitro" |
||
) |
Initialize method for continuous multi-dimensional distribution.
User must provide a distribution object (which is copied inside) and a string for a method. For the list of available method for multivariate cont. distribution see the UnuRan doc A re-initialization is needed whenever distribution parameters have been changed.
Definition at line 109 of file TUnuran.cxx.
bool TUnuran::Init | ( | const TUnuranDiscrDist & | distr, |
const std::string & | method = "auto" |
||
) |
Initialize method for continuous one-dimensional discrete distribution.
User must provide a distribution object (which is copied inside) and a string for a method. For the list of available method for 1D discrete distribution see the UnuRan doc A re-initialization is needed whenever distribution parameters have been changed.
Definition at line 125 of file TUnuran.cxx.
bool TUnuran::Init | ( | const TUnuranEmpDist & | distr, |
const std::string & | method = "empk" |
||
) |
Initialize method for continuous empirical distribution.
User must provide a distribution object (which is copied inside) and a string for a method. The distribution object can represent binned (only 1D) or unbinned (1D or multi-dim) data The method for the unbinned empirical distribution are based on the kernel smoothing, see UnuRan doc A re-initialization is needed whenever distribution parameters have been changed.
Definition at line 139 of file TUnuran.cxx.
bool TUnuran::InitBinomial | ( | unsigned int | ntot, |
double | prob, | ||
const std::string & | method = "dstd" |
||
) |
Initialize method for the Binomial distribution Used to generate poisson numbers for a constant parameters (n,p) of the Binomial distribution.
Use after the method TUnuran::SampleDiscr to generate the numbers. The flag reinit perform a fast re-initialization when only the distribution parameters are changed in the subsequent calls. If the same TUnuran object is used to generate with other distributions it cannot be used.
Definition at line 438 of file TUnuran.cxx.
bool TUnuran::InitPoisson | ( | double | mu, |
const std::string & | method = "dstd" |
||
) |
Initialize method for the Poisson distribution Used to generate poisson numbers for a constant parameter mu of the Poisson distribution.
Use after the method TUnuran::SampleDiscr to generate the numbers. The flag reinit perform a fast re-initialization when only the distribution parameters are changed in the subsequent calls. If the same TUnuran object is used to generate with other distributions it cannot be used.
Definition at line 423 of file TUnuran.cxx.
|
inline |
Assignment operator.
Definition at line 72 of file TUnuran.cxx.
bool TUnuran::ReInitDiscrDist | ( | unsigned int | npar, |
double * | params | ||
) |
Reinitialize UNURAN by changing the distribution parameters but mantaining same distribution and method It is implemented now only for predefined discrete distributions like the poisson or the binomial.
Definition at line 453 of file TUnuran.cxx.
double TUnuran::Sample | ( | ) |
Sample 1D distribution User is responsible for having previously correctly initialized with TUnuran::Init.
Definition at line 389 of file TUnuran.cxx.
int TUnuran::SampleDiscr | ( | ) |
Sample discrete distributions User is responsible for having previously correctly initialized with TUnuran::Init.
Definition at line 382 of file TUnuran.cxx.
bool TUnuran::SampleMulti | ( | double * | x | ) |
Sample multidimensional distributions User is responsible for having previously correctly initialized with TUnuran::Init.
Definition at line 396 of file TUnuran.cxx.
|
protected |
Definition at line 173 of file TUnuran.cxx.
|
protected |
Definition at line 304 of file TUnuran.cxx.
|
protected |
Definition at line 263 of file TUnuran.cxx.
bool TUnuran::SetLogLevel | ( | unsigned int | iflag = 1 | ) |
set log level
Definition at line 408 of file TUnuran.cxx.
|
inline |
|
protected |
change the method and initialize Unuran with the previously given distribution
Definition at line 351 of file TUnuran.cxx.
|
protected |
Definition at line 219 of file TUnuran.cxx.
|
inline |
|
protected |
Definition at line 156 of file TUnuran.cxx.
void TUnuran::SetSeed | ( | unsigned int | seed | ) |
set the seed for the random number generator
Definition at line 404 of file TUnuran.cxx.
|
protected |
|
protected |