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=nullptr, unsigned int log=0) | |
Constructor with a generator instance and given level of log output. | |
~TUnuran () | |
Destructor. | |
int | GetDimension () const |
Return the dimension of unuran generator method. | |
int | GetDistType () const |
Return the type of the distribution. | |
std::string | GetGenId () const |
Return an ID string about the unuran generator method. | |
std::string | GetInfo (bool extended=false) |
Return an information string about the used Unuran generator method. | |
TRandom * | GetRandom () |
Return instance of the random engine used. | |
bool | Init (const std::string &distr, const std::string &method) |
Initialize with Unuran string API interface. | |
bool | Init (const TUnuranContDist &distr, const std::string &method="auto") |
Initialize method for continuous one-dimensional distribution. | |
bool | Init (const TUnuranDiscrDist &distr, const std::string &method="auto") |
Initialize method for continuous one-dimensional discrete distribution. | |
bool | Init (const TUnuranEmpDist &distr, const std::string &method="empk") |
Initialize method for continuous empirical distribution. | |
bool | Init (const TUnuranMultiContDist &distr, const std::string &method="vnrou") |
Initialize method for continuous multi-dimensional distribution. | |
bool | InitBinomial (unsigned int ntot, double prob, const std::string &method="dstd") |
Initialize method for the Binomial distribution. | |
bool | InitPoisson (double mu, const std::string &method="dstd") |
Initialize method for the Poisson distribution. | |
bool | IsDistCont () const |
Return true for a univariate continuous distribution. | |
bool | IsDistDiscrete () const |
Return true for a discrete distribution. | |
bool | IsDistEmpirical () const |
Return true for an empirical distribution. | |
bool | IsDistMultiCont () const |
Return true for a multivariate continuous distribution. | |
const std::string & | MethodName () const |
used Unuran method | |
bool | ReInitDiscrDist (unsigned int npar, double *params) |
Reinitialize UNURAN by changing the distribution parameters but maintaining same distribution and method. | |
double | Sample () |
Sample 1D distribution. | |
int | SampleDiscr () |
Sample discrete distributions. | |
bool | SampleMulti (double *x) |
Sample multidimensional distributions. | |
bool | SetLogLevel (unsigned int iflag=1) |
set log level | |
bool | SetLogStream () |
set stream for log and error (not yet implemented) | |
void | SetRandom (TRandom *r) |
Set the random engine. | |
void | SetSeed (unsigned int seed) |
set the seed for the random number generator | |
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 | |
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. | |
TUnuran & | operator= (const TUnuran &rhs) |
Assignment operator. | |
#include <TUnuran.h>
Constructor with a generator instance and given level of log output.
Definition at line 32 of file TUnuran.cxx.
TUnuran::~TUnuran | ( | ) |
Destructor.
Definition at line 53 of file TUnuran.cxx.
|
private |
Copy constructor.
Definition at line 63 of file TUnuran.cxx.
int TUnuran::GetDimension | ( | ) | const |
Return the dimension of unuran generator method.
For 1D method returns 1 and for the multi-dimensional case must be equal to the distribution dimension.
Definition at line 389 of file TUnuran.cxx.
int TUnuran::GetDistType | ( | ) | const |
Return the type of the distribution.
See documentation of unuran_distr_get_type
for the possible types of distributions.
Definition at line 396 of file TUnuran.cxx.
std::string TUnuran::GetGenId | ( | ) | const |
Return an ID string about the unuran generator method.
Definition at line 382 of file TUnuran.cxx.
std::string TUnuran::GetInfo | ( | bool | extended = false | ) |
Return an information string about the used Unuran generator method.
extended | : if true return some helper information about the existing options of the method. |
Definition at line 375 of file TUnuran.cxx.
|
inline |
bool TUnuran::Init | ( | const std::string & | distr, |
const std::string & | method | ||
) |
Initialize with Unuran string API interface.
See https://statmath.wu.ac.at/unuran/doc/unuran.html#StringAPI
distr | : UNU.RAN distribution string |
method | : UNU.RAN method string |
Here is an example using the string API:
Definition at line 75 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. Note that the method string can contain in addition to the method name all the specific method parameters specified using the UNURAN method string API. For example a valid string can be "method=arou; max_segments=1000; max_sqhratio = 0.9"
Definition at line 89 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 121 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 135 of file TUnuran.cxx.
bool TUnuran::Init | ( | const TUnuranMultiContDist & | distr, |
const std::string & | method = "vnrou" |
||
) |
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.
The default method used for multi-dimensional distributions is "vnrou" Note that some of the multi-dimensional continuous distribution methods like "hitro" are based on Markov-CHain sampler and they are much faster for sampling but require more time to converge. Furthermore, since they are Markov-Chain methods their generated sample values are correlated and cannot be used as i.i.d., one can instead use the obtained sample distribution. (see also the ROOT issue: #10222 ).
Definition at line 105 of file TUnuran.cxx.
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 475 of file TUnuran.cxx.
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 461 of file TUnuran.cxx.
bool TUnuran::IsDistCont | ( | ) | const |
Return true for a univariate continuous distribution.
Definition at line 403 of file TUnuran.cxx.
bool TUnuran::IsDistDiscrete | ( | ) | const |
Return true for a discrete distribution.
Definition at line 411 of file TUnuran.cxx.
bool TUnuran::IsDistEmpirical | ( | ) | const |
Return true for an empirical distribution.
Definition at line 415 of file TUnuran.cxx.
bool TUnuran::IsDistMultiCont | ( | ) | const |
Return true for a multivariate continuous distribution.
Definition at line 407 of file TUnuran.cxx.
|
inline |
Assignment operator.
Definition at line 68 of file TUnuran.cxx.
Reinitialize UNURAN by changing the distribution parameters but maintaining same distribution and method.
It is implemented now only for predefined discrete distributions like the poisson or the binomial
Definition at line 490 of file TUnuran.cxx.
double TUnuran::Sample | ( | ) |
Sample 1D distribution.
User is responsible for having previously correctly initialized with TUnuran::Init
Definition at line 427 of file TUnuran.cxx.
int TUnuran::SampleDiscr | ( | ) |
Sample discrete distributions.
User is responsible for having previously correctly initialized with TUnuran::Init
Definition at line 420 of file TUnuran.cxx.
Sample multidimensional distributions.
User is responsible for having previously correctly initialized with TUnuran::Init
Definition at line 434 of file TUnuran.cxx.
|
protected |
Definition at line 169 of file TUnuran.cxx.
|
protected |
Definition at line 300 of file TUnuran.cxx.
|
protected |
Definition at line 259 of file TUnuran.cxx.
set log level
Definition at line 446 of file TUnuran.cxx.
|
inline |
|
protected |
change the method and initialize Unuran with the previously given distribution
Definition at line 345 of file TUnuran.cxx.
|
protected |
Definition at line 215 of file TUnuran.cxx.
|
inline |
|
protected |
Definition at line 152 of file TUnuran.cxx.
void TUnuran::SetSeed | ( | unsigned int | seed | ) |
set the seed for the random number generator
Definition at line 442 of file TUnuran.cxx.
|
protected |
|
protected |