RANDOM-DISTRIBUTIONS - A library for random numbers generation


 

Abstract

This a manual translation from C to common lisp of some random number generation functions of GSL library.

This package also include the alias method implementation of Mario S. Mommer and my implementation of cut point method for discrete random variable generation.

The code comes with a BSD-style license so you can basically do with it whatever you want.

Download shortcut: http://cl-randist.googlecode.com/files/cl-randist.tar.gz.

Latest development version can by download with git: git clone http://lambdatau.com/git/cl-randist


 

Contents

  1. Download
  2. The RANDOM-DISTRIBUTIONS dictionary
    1. make-discrete-monotone-random-var
    2. make-discrete-random-var
    3. random-beta
    4. random-binomial
    5. random-chi-square
    6. random-exponential
    7. random-f
    8. random-gamma
    9. random-gamma-int
    10. random-gamma-mt
    11. random-gamma1
    12. random-multinomial
    13. random-negative-binomial
    14. random-normal
    15. random-normal-ziggurat
    16. random-pareto
    17. random-poisson
    18. random-uniform
  3. Acknowledgements

 

Download

RANDOM-DISTRIBUTIONS together with this documentation can be downloaded from http://cl-randist.googlecode.com/files/cl-randist.tar.gz. The current version is 0.3.0.
 

The RANDOM-DISTRIBUTIONS dictionary


[Function]
make-discrete-monotone-random-var p => result


The function MAKE-DISCRETE-MONOTONE-RANDOM-VAR takes an array of probabilities. Produces a function which returns each of the corresponding integer with the specified probability.


[Function]
make-discrete-random-var probabilities &optional values => result


The function MAKE-DISCRETE-RANDOM-VAR takes an array of probabilities and an (optional) array of values. Produces a function which returns each of the values with the specified probability (or the corresponding integer no values have been given).


[Function]
random-beta a b => result


The beta distribution has the form p(x) dx = (Gamma(a + b)/(Gamma(a) Gamma(b))) x^(a-1) (1-x)^(b-1) dx The method used here is the one described in Knuth


[Function]
random-binomial => result


The binomial distribution has the form, prob(k) = n!/(k!(n-k)!) * p^k (1-p)^(n-k) for k = 0, 1, ..., n This is the algorithm from Knuth


[Function]
random-chi-square => result


Generate random variable for chi square distribution: p(x) dx = (1/(2*Gamma(nu/2))) (x/2)^(nu/2 - 1) exp(-x/2) dx


[Function]
random-exponential => result


Random values for: p(x) dx = exp(-x/mu) dx/mu


[Function]
random-f => result


Random value for: p(x) dx = (nu1^(nu1/2) nu2^(nu2/2) Gamma((nu1 + nu2)/2) / Gamma(nu1/2) Gamma(nu2/2)) * x^(nu1/2 - 1) (nu2 + nu1 * x)^(-nu1/2 -nu2/2) dx


[Function]
random-gamma a &optional b => result


[syntax suggar] Generate a random variable with gamma distribution using the MT method (see random-gamma-mt)


[Function]
random-gamma-int a => result


Random variable with gamma distribution with integer parameter.


[Function]
random-gamma-mt a b => result


New version based on Marsaglia and Tsang, 'A Simple Method for generating gamma variables', ACM Transactions on Mathematical Software, Vol 26, No 3 (2000), p363-372.


[Function]
random-gamma1 a b => result


The Gamma distribution of order a>0 is defined by: p(x) dx = {1 / Gamma(a) b^a } x^{a-1} e^{-x/b} dx for x>0. If X and Y are independent gamma-distributed random variables of order a1 and a2 with the same scale parameter b, then X+Y has gamma distribution of order a1+a2. The algorithms below are from Knuth, vol 2, 2nd ed, p. 129. Works only if a > 1, and is most efficient if a is large This algorithm, reported in Knuth, is attributed to Ahrens. A faster one, we are told, can be found in: J. H. Ahrens and U. Dieter, Computing 12 (1974) 223-246.


[Function]
random-multinomial nn p => result


The multinomial distribution has the form N! n_1 n_2 n_K prob(n_1, n_2, ... n_K) = -------------------- p_1 p_2 ... p_K (n_1! n_2! ... n_K!) where n_1, n_2, ... n_K are nonnegative integers, sum_{k=1,K} n_k = N, and p = (p_1, p_2, ..., p_K) is a probability distribution. Random variates are generated using the conditional binomial method. This scales well with N and does not require a setup step. Ref: C.S. David, The computer generation of multinomial random variates, Comp. Stat. Data Anal. 16 (1993) 205-217


[Function]
random-negative-binomial p n => result


The negative binomial distribution has the form, prob(k) = Gamma(n + k)/(Gamma(n) Gamma(k + 1)) p^n (1-p)^k for k = 0, 1, ... . Note that n does not have to be an integer. This is the Leger's algorithm (given in the answers in Knuth)


[Function]
random-normal &optional mean sigma => result


[sintax suggar] Generate random variable with normal distribution using ziggurat method


[Function]
random-normal-ziggurat mean sigma => result


This routine is based on the following article, with a couple of modifications which simplify the implementation. George Marsaglia, Wai Wan Tsang The Ziggurat Method for Generating Random Variables Journal of Statistical Software, vol. 5 (2000), no. 8 http://www.jstatsoft.org/v05/i08/ The modifications are: 1) use 128 steps instead of 256 to decrease the amount of static data necessary. 2) use an acceptance sampling from an exponential wedge exp(-R*(x-R/2)) for the tail of the base strip to simplify the implementation. The area of exponential wedge is used in calculating 'v' and the coefficients in ziggurat table, so the coefficients differ slightly from those in the Marsaglia and Tsang paper. See also Leong et al, 'A Comment on the Implementation of the Ziggurat Method', Journal of Statistical Software, vol 5 (2005), no 7.


[Function]
random-pareto => result


Random value for parato distribution: p(x) dx = (a/b) / (x/b)^(a+1) dx for x >= b


[Function]
random-poisson mu => result


The poisson distribution has the form p(n) = (mu^n / n!) exp(-mu) for n = 0, 1, 2, ... . The method used here is the one from Knuth.


[Macro]
random-uniform => result


[syntax suggar] Random variable with uniform distribution in interval [0,1]

 

Acknowledgements

This documentation was prepared with DOCUMENTATION-TEMPLATE.

$Header: /usr/local/cvsrep/documentation-template/output.lisp,v 1.13 2007/04/17 19:29:52 edi Exp $

BACK TO MY HOMEPAGE