A simple method for generating gamma variables

被引:114
作者
Marsaglia, G [1 ]
Tsang, WW
机构
[1] Florida State Univ, Dept Stat, Tallahassee, FL 32306 USA
[2] Univ Hong Kong, Dept Informat Syst & Comp Sci, Hong Kong, Hong Kong, Peoples R China
来源
ACM TRANSACTIONS ON MATHEMATICAL SOFTWARE | 2000年 / 26卷 / 03期
关键词
algorithms; performance; random number generation; gamma distribution; ziggurat method;
D O I
10.1145/358407.358414
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
We offer a procedure for generating a gamma variate as the cube of a suitably scaled normal variate. It is fast and simple, assuming one has a fast way to generate normal variables. In brief: generate a normal variate x and a uniform variate U until ln(U) < 0.5x(2) + d - dv + dln(v), then return dv. Here, the gamma parameter is <alpha> greater than or equal to 1, and v = (1 + x/ root 9d)(3), with d = alpha - 1/3. The efficiency is high, exceeding 0.951, 0.981, 0.992, 0.996 at alpha = 1, 2, 4, 8. The procedure can be made to run faster by means of a simple squeeze that avoids the two logarithms most of the time: return dv if U < 1 - 0.0331x(4). We give a short C program for any <alpha> greater than or equal to 1, and show how to boost an alpha < 1 into an <alpha> > 1. The gamma procedure is particularly fast for C implementation if the normal variate is generated in-line, via the #define feature. We include such an inline version, leased on our ziggurat method. With it, and an inline uniform generator, gamma variates can be produced in 400MHz CPUs at better than 1.3 million per second, with the parameter alpha changing from call to call.
引用
收藏
页码:363 / 372
页数:10
相关论文
共 14 条
[1]   GENERATING GAMMA-VARIATES BY A MODIFIED REJECTION TECHNIQUE [J].
AHRENS, JH ;
DIETER, U .
COMMUNICATIONS OF THE ACM, 1982, 25 (01) :47-54
[2]   AN ALIAS METHOD FOR SAMPLING FROM THE NORMAL-DISTRIBUTION [J].
AHRENS, JH ;
DIETER, U .
COMPUTING, 1989, 42 (2-3) :159-170
[3]  
[Anonymous], 1996, MARSAGLIA RANDOM NUM
[4]  
CHENG RCH, 1979, APPL STAT, V28, P290
[5]  
Devroye L., 1986, NONUNIFORM RANDOM VA
[6]   A FAST, EASILY IMPLEMENTED METHOD FOR SAMPLING FROM DECREASING OR SYMMETRIC UNIMODAL DENSITY-FUNCTIONS [J].
MARSAGLIA, G ;
TSANG, WW .
SIAM JOURNAL ON SCIENTIFIC AND STATISTICAL COMPUTING, 1984, 5 (02) :349-359
[7]  
Marsaglia G., 1977, Computers & Mathematics with Applications, V3, P321, DOI 10.1016/0898-1221(77)90089-X
[8]  
MARSAGLIA G, 1984, J AM STAT ASSOC, V79, P218
[9]   The Monty Python']Python method for generating random variables [J].
Marsaglia, G ;
Tsang, WW .
ACM TRANSACTIONS ON MATHEMATICAL SOFTWARE, 1998, 24 (03) :341-350
[10]  
Marsaglia G., 2000, Journal of Statistical Soft- ware, V5