Beruflich Dokumente
Kultur Dokumente
while ~r(] + 1 ) = 1 do
(i ~--j + 1;
j (--j + nl;
nl ~ cr(i, j)) ;
stop;
Iteration
M a n a g e m e n t Science/
Operations Research
nl ~ 4;
T h e n 0-(4) = 1; thus
i <-- 4;
j(-7;
nl ~-- 12;
T h e n 0-(8) = 1; thus
i~8;
j~19;
D. F. Shanno
Editor
Generating Beta
Variates with
Nonintegral Shape
Parameters
R. C. H. Cheng
University of Wales Institute of Science and
Technology
n1#--2761;
/3 = a(j + 2, j + nl + 1).
Notice that the algorithm stops on the last c h a r a c t e r of
3 + ~ ni + ~ l(R(nO)
1(0"(01~1) 0/)2, . . . ,
0~))
i=1
i=1
i=l
i=1
<-1+
3+2
LG(nO + 4m
i=1
n~
i=1
References
1. Bentley, J. L., and Yao, A.C. An almost optical algorithm for
unbounded searching. Inform. Processing Letters 5 (1976), 82-87.
2. Elias, P. Universal codeword sets and representations of the
integers. IEEE Trans. Inform. Theory 2 1 , 2 (March 1975), 194203.
3. Levenshtein, V.E. On the redundancy and delay of separable
codes for the natural numbers. Problems of Cybernetics 20 (1968),
173-179.
317
April 1978
Volume 21
Number 4
1. Introduction
A new method is described below for generating
beta variates with density function
April 1978
Volume 21
Number 4
2. D e s c r i p t i o n o f Basic M e t h o d
(2.1)
(2.2)
Then, if
R(X) -- f ( X ) / A g ( X )
>- U2,
(2.3)
3. Modifications to Basic A l g o r i t h m
if min (a, b) - 1,
(2.4)
if min (a, b) > 1.
Looking at algorithm BA, one sees that the computation time per trial is largely taken up by the four
log/exponential evaluations of steps 1 and 2. When
the rejection rate is low, which is the case when min
(a, b) > 1, the evaluations at step 1 cannot very well
be avoided. However, those at step 2 can often be
avoided by use of a simple preliminary test.
We use the result that, as log z is a concave
function of z, a tangent always lies above its graph.
Thus Oz - log 0 - 1 -> log z for all z > 0 and any fixed
0 > 0. This result can be applied at step 2 of algorithm
B A with z -- b + W. We then have that, if the
preliminary test
a log a - log 4 + y V - a{O(b + W)
(3.1.1)
319
Communications
of
the ACM
April 1978
Volume 21
Number 4
0.0+
0.0+
0.1
0.5
1.0
2.0
5.0
10.0
oc
2.00
4.00
4.00
4.00
4.00
4.00
4.00
4.00
0.1
1.77
2.70
2.86
2.94
2.99
3.01
3.02
0.5
1.0
2.0
5.0
1.00
1.19
1.34
1.40
1.47
1.06
1.13
1.18
1.25
2/./1) -2,
1_ [
kl >- 4 \
/ L
1.11
1.15
4.)
2. If S + 2.609438 -> 5Z, go to 5. (The constant is 1
+ log 5.)
3. Set T = l o g Z . I f S > _ T, g o t o 5 .
4. I f R + a log{ct/(b + IV)} < T, go to 1.
5. I f a = a0 d e l i v e r X = W/(b + W) ; otherwise deliver
X = b/(b + W).
(a, b) -
provided
k2 -> {(a + b)/a} a+b.
320
i.
(3.2.4)
.
The only p r o b l e m is to find suitable values for kl
and k2. T h e best choice is kx = go and ks = {(a +
b)/a} a+b (with Ko calculated, say, by solving (3.2.3) for
~ and then using ~: to find Ko). U n f o r t u n a t e l y the
evaluation of b o t h of these values is time c o n s u m i n g ,
making it only practical if the p a r a m e t e r s a and b are
fixed so that kl and k2 only have to be evaluated once.
A simpler alternative is to use a p p r o x i m a t e values for
kl and kz satisfying (3.2.2) and (3.2.4). Suggested
easily calculated values are
14),
/~2 = 1 + ( 2 + 8 - 1 ) b ,
(3.2.3)
k~ = 8 ( 1 + 3 b ) / ( 1 8 a / b Min
3.2
(3.2.1)
provided
10.0
April 1978
Volume 21
Number 4
Table II. Time (in ~sec) to Generate One Beta Variate on a CDC
7600.
a
b
1.001
b;
/3
b-~;
b;
KI
8(0.0138889+0.0416667b)/(a/3-0.777778); Kz = 0.25
+ (0.5+0.258-~)b. (Here K1 = k l / 4 , K2 = k2/4.)
1. Generate random numbers Ui, Uz, and if U1 --- go
to 3.
2. S e t Y = U~ U2, Z = UI Y. If O.25 U2 + Z - Y >- K~,
go to 1; otherwise go to 5.
3. Set Z = U21Uz. If Z --- 0.25, set V =
/3 log { U 1 / ( 1 - U 1 ) } , W = ae v, and go to 6.
4. If Z_> K2 go to 1.
5. Set V = /3 log { U I / ( 1 - U 1 ) } , W = ae v. If
a{log [ a / ( b + W ) ] + V} - 1.3862944 < log Z, go
to 1.
6. If a = a0 deliver X = W / ( b + W ) ; otherwise deliver
X = b/(b+W).
4.
Timings
10
20
1.001
10
20
BA 23.1
BB 20.0
BN 257.5
BA
BB
BN
26.5
22.9
48.4
24.2
21.1
37.9
BA
BB
BN
29.3
25.4
58.6
25.5
21.4
38.4
25.0
21.7
35.4
BA
BB
BN
BA
BB
BN
31.0
26.5
74.4
31.5
27.2
98.0
26.6
21.9
42.9
27.3
22.4
50.2
25.3
21.3
36.5
25.8
21.1
40.2
25.2
22.0
34.5
25.6
21.4
35.7
25.5
22.0
34.0
BA
BB
BN
5.6
5.6
9.9
April 1978
Volume 21
Number 4
b
0.1
0.3
0.5
0.7
0.9
1.001
2.0
5.0
20.0
BA
BC
J6hnk
Switch
BA
BC
J6hnk
Switch
BA
BC
J6hnk
Switch
BA
BC
J6hnk
Switch
BA
BC
J6hnk
Switch
BA
BC
J6hnk
Switch
BA
BC
J6hnk
Switch
BA
BC
J6hnk
Switch
BA
BC
J6hnk
Switch
.1
.3
.5
.7
.9
37.7
28.0
21.6
40.2
51.8
27.6
22.1
34.3
54.5
27.5
22.5
30.4
57.6
27.4
22.8
27.4
58.1
26.8
23.0
25.5
58.4
27.3
23.2
23.7
60.2
26.7
24.3
24.2
60.2
26.3
25.8
24.6
61.2
26.0
29.0
24.8
31.9
27.5
23.3
33.0
36.9
26.8
24.5
30.8
39.5
26.9
25.6
28.0
41.1
27.2
26.3
25.1
41.6
27.2
26.8
24.9
45.3
27.6
30.4
26.1
46.2
27.2
37.9
26.8
47.1
27.1
54.3
27.7
28.1
26.2
26.6
29.2
30.8
26.3
27.9
27.3
32.6
26.1
29.7
25.0
33.3
26.4
30.6
26.6
36.7
27.1
38.0
27.5
39.1
27.3
52.8
28.5
40.6
27.4
97.1
29.0
25.4
24.7
30.4
26.2
27.2
25.0
32.9
24.6
27.6
25.1
34.2
27.5
31.2
25.8
45.1
28.2
33.9
27.1
72.3
29.1
35.4
27.3
171.7
29.5
23.5
23.4
35.9
24.3
24.2
23.7
38.0
26.8
27.9
24.7
53.5
27.3
30.7
26.2
98.2
27.3
32.5
26.9
296.4
27.5
BA
BC
1.1
4.8
Switch 1 Switch 2
10.3
12.1
References
1. Ahrens, J.H., and Dieter, U. Computer methods for sampling
from gamma, beta, Poisson and binomial distribution. Computing
(Vienna), 12 (1974), 223-246.
2. Atkinson, A.C., and Pearce, M.C. The computer generation of
beta, gamma and normal random variables. J. Roy. Statist. Soc. Ser.
A 139 (1976), 431-461.
3. Atkinson, A.C., and Whittaker, J. A switching algorithm for
the generation of beta random variables with at least one parameter
less than 1. J. Roy. Statist. Soc. Ser. A. 139 (1976), 462-467.
4. J6hnk, M.D. Erzeugung von Betaverteilten und
Gammaverteilten Zuffallszahlen. Metrika 8 (1964), 5-15.
5. Marsaglia, G., and Bray, T.A. A convenient method for
generating normal variables. SIAM Rev. 6 (1964), 260-264.
6. Wallace, N.D. Computer generation of gamma random variates
with non-integral shape parameters. Comm. A C M 17, 12 (Dec.
1974), 691-695.
7. Whittaker, J. Generating gamma and beta random variables
with non-integral shape parameters. Appl. Statist. 23 (1974), 210214.
Communications
of
the ACM
April 1978
Volume 21
Number 4