RanLip - universal nonuniform random variate generator

for Lipschitz- continuous densities

Welcome to the home of RanLip. This page describes generation of multivariate nonuniform random variates using the method of acceptance/rejection, and freely available RanLip library which implements this method.

RanLip generates random variates with an arbitrary multivariate Lipschitz density.

Downloads: Unix/Linux, Windows, Matlb toolbox, Maple toolbox.


While generation of random numbers from a variety of distributions is implemented in many packages (like GSL library http://www.gnu.org/software/gsl/  and UNURAN library http://statistik.wu-wien.ac.at/unuran/), generation of random variate with an arbitrary distribution, especially in the multivariate case, is a very challenging task. RanLip is a method of generation of random variates with arbitrary Lipschitz-continuous densities,  which works in the univariate and multivariate cases, if the dimension is not very large (say 3-5 variables). The detailed description is in the references below.

Lipschitz condition implies that the rate of change of the function (in this case, probability density p(x)) is bounded:
|p(x)-p(y)|<M||x-y||.

From this condition, we can build an overestimate of the density, so called hat function h(x)>=p(x), using a number of values of p(x) at some points. The more values we use, the better is the hat function. The method of acceptance/rejection then works as follows: generatea  random variate X with density h(x); generate an independent uniform on (0,1) random number Z; if p(X)<=Z h(X), then return X, otherwise repeat all the above steps.

RanLip constructs a piecewise constant hat function of the required density p(x) by subdividing the domain of p (an n-dimensional rectangle) into many smaller rectangles, and computes the upper bound on p(x) within each of these rectangles, and uses this upper bound as the value of the hat function.

A detailed description of the method used to construct the hat function, and the description of RanLip library is available here.


RanLip library is implemented in C++ language. The user needs to supply his/her density function using a simple syntaxis, and then call the methods of construction and generation provided in RanLip. Here is an example of the user's code:
class MyRnumGen:public CRanLip { // derive your own class from CRanLip 
public: virtual double Distribution(double* p) ;
};
// implement calculation of the density
double MyRnumGen::Distribution(double* p)
{ // example: multivariate normal distribution
double r=0;
for(int j=0;j<Dimension;j++) r += p[j]*p[j];
return exp(-r);
}
#define DIM 3 // dimension
void main(int argc, char *argv[])
{
int i,j,dim=3, timesgen=10000;
MyRnumGen MyGen;
double p[DIM], a[DIM], b[DIM];
for(i=0;i<dim;i++) {a[i]=-2; b[i]=2;} // specify the domain bondaries

MyGen.Init(dim,a,b);
MyGen.PrepareHatFunction(10,8,1.0); // subdivisions, Lipschitz constant
MyGen.Seed(10);
// generation step
for(j=0;j<timesgen;j++) MyGen.RandomVec(P);
}

Unix/Linux distribution

The source code for RanLip library is available here: libranlip-1.0.tar.gz
The user needs to install the library (running ranlipinstall script on unix) and compile the library files (executed from within ranlipinstall command). The installation script will install the static and shared libraries, documentation and the example programs. Check README file for detailed installation instructions.

Windows distribution

The source code is available here ranlip.zip
The user needs to unzip the distribution file into a separate derectory. Both the source files, static library libranlip.lib and  DLL ranlipdll.dll files will be installed.
The easiest way to use RanLip is to copy ranlipdll.dll file to a common directory specified on your path (like c:\windows), copy ranlipdll.lib file to a directory it can be easily located by your compiler, and follow the example in ranliptestdll.cpp. The user can use either C/C++ language, or call the dll from another language, like VB or Fortran.

References

[1] G. Beliakov, Class library ranlip for multivariate nonuniform random variate generation. Computer Physics Communications, 170 (2005) p. 93-108.pdf
[2] G. Beliakov, Universal nonuniform random vector generator based on acceptance-rejection. ACM Trans. on Modelling and Computer Simulation, 15 (2005) p. 205-232.pdf
[3] Beliakov, G., A review of applications of the Cutting Angle methods, in Continuous Optimization, A. Rubinov and V. Jeyakumar, Editors. 2005, Springer: New York. p. 209-248.Preprint


RanLip is copyright subject to GNU Lesser General Public License conditions (see the distribution files for details).

Copyright (C) Gleb Beliakov, 2004
Please send your comments/requests to the author at gleb@deakin.edu.au