92
h(·),
then
STOCHASTIC
SIMULATION
E (g(X)) = L
g(x)f(x)
dx
~-
= {
g(x)f(x)
h(x) dx
lx h(x)
and so E (g(X)) may
be
approximated by
E (g(X))
~
~
:t g(yi)f(yi).
n
i=l
h(yi)
This procedure is known as importance sampling, and it can be very useful when
there is reasonable agreement between
fO
and h(·).
The above examples show that it is possible to compute summaries
of
interest such
as
expectations provided we have a mechanism for simulating realisations
of
random
quantities.
It
turns out that doing this is a rather non-trivial problem. We begin first
by
thinking about the generation
of
uniform random quantities, and then move on to
thinking about the generation
of
random quantities from other standard distributions.
4.3 Uniform random number generation
4.3.1 Discrete uniform random numbers
Most stochastic simulation begins with a uniform random number generator (Ripley
1987). Computers are essentially deterministic, so most random number generation
strategies begin with the development
of
algorithms which produce a deterministic
sequence
of
numbers that appears to
be
random. Consequently, such generators are
often referred to as
pseudo-random
number
generators.
Typically, a number theoretic method is used to generate an apparently random
integer from
0 to
2N-
1 (often, N = 16, 32,
or
64). The methods employed these
days are often very sophisticated, as modern cryptographic algorithms rely heavily
on the availability
of
"good" random numbers. A detailed discussion would be out
of
place
in
the context
of
this book, but a brief explanation
of
a very simple algorithm
is perhaps instructive.
Linear
congruential generators are the simplest class
of
algorithm used for pseudo-
random number generation. The algorithm begins
with a
seed
x
0
then generates new
values according to the (deterministic) rule
Xn+l =
(axn
+ b
mod
2N)
for carefully chosen a and
b.
Clearly such a procedure must return to a previous
,value at some point and then cycle indefinitely. However,
if
a "good" choice
of
a,
b,
and N are used, this deterministic sequence
of
numbers will have a very large
cyCle
length (significantly larger than the number
of
random quantities one is likely to
want
to
generate in a particular simulation study) and give every appearance
of
being
uniformly random.
One reasonable choice is
N = 59, b =
0,
a =
13
13
•