The rejection method can create any type of distribution,
even discontinuous non-analytical kinds, but requires the generation
of two values from the uniform generator for each value in the desired
distribution. The technique is best explained graphically. In figure
7.1 the double humped curves show the desired distribution
g(y)
.
Figure Tech.7.1 This arbitrary two humped curve shows
the desired shape for our
g(y)
distribution. For the rejection method we can use a flat, uniform
random
number generator to give each pair of random values between
0 to 1.0. The random y1
value is not accepted because a second random value x1
lies above the curve. The random value y2
is accepted because its x2
value lies below the curve.
A uniform random number generator first provides a
y value
and then an x
value. If the x
value is below the desired curve g(y),
the y is
accepted, otherwise it is rejected. The figure shows two examples.
First a random value y1
is generated and then a second random value x1
is generated and compared to the value of
g(y1)
curve. The x1
value is greater than g(y1),
so the y1
value is rejected. On the other hand, x2
lies below g(y2),
so y2
is accepted. The process is repeated and eventually the distribution
of y values will follow the desired shape. Note than g(y)
must be normalized such that the maximum value for the second random
number must be at least as large as the maximum possible value of
g(y).
With this approach, any distribution shape could be
generated, even one that is discontinuous and non-analytical. However,
the above approach can be quite inefficient if a high percentage
of the second "throws" are unaccepted. This will occur
if the area between the desired curve and the maximum vertical value
is large compared to the curve.
An alternative (see Press)
is to find a transformation function g(x)
that produces a distribution C(y),
called the comparison function, that is as similar to the
desired distribution f(y)
as possible, but equal or greater than the desired distribution
at all y
values. Then the first "throw" can come from the transformation
function g(x)
to produce a prospective y value. A second random value x
is generated between 0 and C(y).
If the x<=f(y)
the y is accepted, otherwise it is rejected. In this approach,
the inefficiency of the random pair acceptance goes as the percentage
of the area between the comparison function C(y)and
f(y).
In Chapter
7 : Physics : Generating Custom Distributions we discuss situations
where custom distributions may be required and give an applet
demonstration of the rejection method. We also discuss how to
use a histogram
to provide the custom distribution f(y)
and provide a demonstration
applet.
References& Web Resources
Last Update: Feb.15.04
|