Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Unuran

Universal Non Uniform Random number generator for generating non uniform pseudo-random numbers.

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:

TUnuran unr;
//initialize unuran to generate normal random numbers using a "arou" method
unr.Init("normal()","method=arou");
//......
// sample distributions N times (generate N random numbers)
for (int i = 0; i < N; ++i)
double x = unr.Sample();
#define N
TUnuran class.
Definition TUnuran.h:79
bool Init(const std::string &distr, const std::string &method)
Initialize with Unuran string API interface.
Definition TUnuran.cxx:62
double Sample()
Sample 1D distribution.
Definition TUnuran.cxx:414
Double_t x[n]
Definition legend1.C:17

Some of this information is required depending on the chosen UNURAN generation method.

//1D case: create a distribution from two TF1 object pointers pdfFunc
TUnuranContDist dist( pdfFunc);
//initialize unuran passing the distribution and a string defining the method
unr.Init(dist, "method=hinv");
// sample distribution N times (generate N random numbers)
for (int i = 0; i < N; ++i)
double x = unr.Sample();
TUnuranContDist class describing one dimensional continuous distribution.
//Multi-Dim case from a TF1 (or TF2 or TF3) object describing a multi-dimensional function
TUnuranMultiContDist dist( pdfFuncMulti);
// the recommended method for multi-dimensional function is "hitro"
unr.Init(dist, "method=hitro");
// sample distribution N times (generate N random numbers)
double x[NDIM];
for (int i = 0; i < N; ++i)
TUnuranMultiContDist class describing multi dimensional continuous distributions.
bool SampleMulti(double *x)
Sample multidimensional distributions.
Definition TUnuran.cxx:421
// create distribution from a vector of probabilities
double pv[NSize] = {0.1,0.2,.......};
TUnuranDiscrDist dist(pv, pv+NSize);
// the recommended method for discrete distribution is
unr.Init(dist, "method=dgt");
// sample N times (generate N random numbers)
for (int i = 0; i < N; ++i)
int k = unr.SampleDiscr();
TUnuranDiscrDist class for one dimensional discrete distribution.
int SampleDiscr()
Sample discrete distributions.
Definition TUnuran.cxx:407
// create distribution from a set of data 1D
// vdata is an std::vector containing the data
TUnuranEmpDist dist( vdata.begin(),vdata.end());
unr.Init(dist);
// sample N times (generate N random numbers)
for (int i = 0; i < N; ++i)
double x = unr.Sample();
TUnuranEmpDist class for describing empirical distributions.
// create an empirical distribution from an histogram
// if the histogram has a buffer one must use TUnuranEmpDist(h1,false)
TH1 * h1 = ... // histogram pointer
TUnuranEmpDist binDist( h1);
unr.Init(binDist);
// sample N times (generate N random numbers)
for (int i = 0; i < N; ++i)
double x = unr.Sample();
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
TH1F * h1
Definition legend1.C:5

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.

Classes

class  TUnuran
 TUnuran class. More...
 
class  TUnuranBaseDist
 TUnuranBaseDist, base class for Unuran distribution classes such as TUnuranContDist (for one-dimension) or TUnuranMultiContDist (multi-dimension) More...
 
class  TUnuranContDist
 TUnuranContDist class describing one dimensional continuous distribution. More...
 
class  TUnuranDiscrDist
 TUnuranDiscrDist class for one dimensional discrete distribution. More...
 
class  TUnuranEmpDist
 TUnuranEmpDist class for describing empirical distributions. More...
 
class  TUnuranMultiContDist
 TUnuranMultiContDist class describing multi dimensional continuous distributions. More...
 
class  TUnuranSampler
 TUnuranSampler class class implementing the ROOT::Math::DistSampler interface using the UNU.RAN package for sampling distributions. More...