7.1.3 Generating Samples From Probability Distributions
7.1.3 Generating Samples From Probability Distributions
ys=Fy-1(r) (7.2)
or, equivalently,
where [a] denotes "the smallest integer that is greater than or equal to
a."
Note how in Examples 3-5 the inversion method (for generating sample
values of
negative exponential or of Bernoulli random variables) is used
as a building block
(or "subroutine") in the overall procedure.
STEP Enclose the pdf fx(x) in the smallest rectangle that fully
contains it and
1: whose sides are parallel to the x and y axes. This is a
(b - a) x c rectangle.4
STEP Using two random numbers, r1 and r2, and scaling each to the
appropriate
2: dimension of the rectangle [by multiplying one by (b - a)
and the other by
c] generate a point that is uniformly distributed over
the rectangle.
STEP If this point is "below" the pdf, accept the x-coordinate of
the point as an
3: appropriate sample value of X. Otherwise, reject and
return to Step 2.
The validity of the foregoing procedure is not intuitively obvious on a
first reading.
We illustrate it first through an example and then
explain why it works.
The reason why this method works is quite simple. The points (x, y)
obtained
through the procedure of Step 2 are uniformly distributed over
the area of the
rectangle, (b - a) x c. Therefore, for any point whose
x-coordinate is between x0
and x0 + dx (see Figure 7. 10), we have
Example 7
Solution
Z=R1+R2+R3...+Rk+1+Rk
Now from the CLT we know that for large k, Z has approximately a
Gaussian distribution. Since for each Ri we have E[Ri] = 1/2 and
the
mean value of Z is k/2 and its standard deviation
Final comment. Methods for generating samples from some of the standard
pdf's
and pmf's have been the subject of much research in recent years.
Our main
purpose above was to present some typical (and correct)
approaches rather than the
most accurate or efficient method in each
example. For instance, excellent
alternatives to (7.5) exist for
simulating negative exponential pdf's [NEUM 51],
[FISH 78].
This method is exact and requires only two random numbers. It can be
derived
from the analysis described in Example 3 of Chapter 3 (that
involved the Rayleigh
distribution) and is further developed in Problem
7.2.
Many of the more advanced
simulation languages/systems (e.g., GPSS,
SIMSCRIPT) provide standard internal
subroutines for the generation of
samples from some of the most common pdf's and
pmf's (e.g., the
Gaussian, the negative exponential, the Poisson, and the uniform):
all
that a user of the language/system must do is provide the necessary
input
parameters. The subroutine then automatically returns a sample
value from the
specified random variable.
where r1 and r2 are the usual random numbers obtained through the
random-number generator. This is equivalent to generating samples
of the
distance traveled in the x-direction, Dx, and in the y-
direction, Dy,
and adding the two.
3. In using the rejection method, suppose that the first pair of
random
numbers drawn are r1 = 0.84 and r2 = 0.27. This results in the
point
(xi, y1) = [1 · (0.84), 2· (0.27)] (0.84, 0.54) in the x-y plane.
Since
at x1 = 0.84, fx(O.84) = 4(l 0.84) 0.64 (> 0.54), the sample
observation is acceptable and we set xs 0.84. Note that in this case
50
percent of the pairs will be accepted on the average.
4. "Most natural": Generate a random point (x = r1, y = r2) in the
square and compute
4 The method will actually work with any rectangle that contains this
smallest rectangle. However the probability of rejection will then be
greater than with the (b - a) x c rectangle.