UNU.RAN, (Universal Non Uniform Random number generator for generating non uniform pseudo-random numbers) is an ANSI C library licensed under GPL.
It contains universal (also called automatic or black-box) algorithms that can generate random numbers from large classes of continuous or discrete distributions, and also from practically all standard distributions. An extensive online documentation are available at the (UNU.RAN Web Site)[http://statistik.wu-wien.ac.at/unuran/]
New classes have been introduced to use the UNU.RAN C library from ROOT and C++ from ROOT and using C++ objects. To use UNU.RAN one needs always an instance of the class TUnuran. It can then be used in two distinct ways:
- using the UNU.RAN native string API for pre-defined distributions (seeUNU.RAN documentation for the string API):
unr.
Init(
"normal()",
"method=arou");
for (
int i = 0; i <
N; ++i)
bool Init(const std::string &distr, const std::string &method)
initialize with Unuran string interface
double Sample()
Sample 1D distribution User is responsible for having previously correctly initialized with TUnuran::...
- Using a distribution object. We have then the following cases depending on the dimension and the distribution object.
- For 1D distribution the class TUnuranContDist must be used.
- A TUnuranContDist object can be created from a function providing the pdf (probability density function) and optionally one providing the derivative of the pdf.
If the derivative is not provided and the generation method requires it, then it is estimated numerically.
- The user can optionally provide the
Some of this information is required depending on the chosen UNURAN generation method.
for (
int i = 0; i <
N; ++i)
TUnuranContDist class describing one dimensional continuous distribution.
double dist(Rotation3D const &r1, Rotation3D const &r2)
- For multi-dimensional distribution the class TUnuranMultiContDist must be used. In this case only the multi-dimensional pdf is required
for (
int i = 0; i <
N; ++i)
TUnuranMultiContDist class describing multi dimensional continuous distributions.
bool SampleMulti(double *x)
Sample multidimensional distributions User is responsible for having previously correctly initialized...
- For discrete distribution the class TUnuranDiscrDist must be used. The distribution can be initialized from a TF1 or from a vector of probabilities.
double pv[NSize] = {0.1,0.2,.......};
for (
int i = 0; i <
N; ++i)
TUnuranDiscrDist class for one dimensional discrete distribution.
int SampleDiscr()
Sample discrete distributions User is responsible for having previously correctly initialized with TU...
- For empirical distribution the class TUnuranEmpDist must be used. In this case one can generate random numbers from a set of data (un-binned) in one or multi-dimension or from a set of binned data in one dimension (similar to TH1::GetRandom() ).
- For unbin data the parent distribution is estimated by UNU.RAN using a gaussian kernel smoothing algorithm. One can create the distribution class directly from a vector of data or from the buffer of TH1.
for (
int i = 0; i <
N; ++i)
TUnuranEmpDist class for describing empiral distributions.
- In the case of multi-dimension emprical distributions one needs to pass in addition to the iterators, the data dimension. It is assumed that the data are stored in the vector in this order :
(x0,y0,...),(x1,y1,....)
.
- For binned data (only one dimensional data are supported) one uses directly the histogram
for (
int i = 0; i <
N; ++i)
- This is equivalent to TH1::GetRandom(), but sampling is faster, therefore, since it requires some initialization time, it becomes convenient when generating a large sample of random numbers.
Functionality is also provided via the C++ classes for using a different random number generator by passing a TRandom pointer when constructing the TUnuran class (by default the ROOT gRandom is passed to UNURAN).
The (UNU.RAN documentation)[http://statistik.wu-wien.ac.at/unuran/doc/unuran.html#Top] provides a detailed description of all the available methods and the possible options which one can pass to UNU.RAN for the various distributions. */