Introduction to Simulation Stat 430

advertisement
Introduction to
Simulation
Stat 430
Outline
• Basic Simulation Setup
• Random number generators
Simulation
• Basic idea:
to get handle on functionality of a “black
box” (or a complicated function, model, ...
analyze output based on generated input
input
output
black box
Simulation
• Random variables X,Y, ..., Z
• black box function g
• output value g(X,Y, ..., Z) =: G
• interested in moments of G, distribution of
G, probabilities e.g. P(G > 0)
Steps of Simulation
• Simulate values X ,Y , ..., Z
• compute G = g(X ,Y , ..., Z )
• then P(a < G < b) :=
i
E[G] :=
Var[G] :=
i
i
i
i
i
i
“Generating” Random
Numbers
• Trade-off:
real random numbers vs pseudo random
numbers
• reproducibility / security
• correct distribution?
• volume? speed versus number
“Real” Randomness
• e.g. based on atmospheric noise
www.random.org
• volume: 6K bits per sec
www.random.org
• Atmospheric noise “read” by computer,
digitized to 0/1 based on decibel threshold
• important: adjust threshold, so that 0/1
have same probability
• convert 01 sequences to numbers, e.g.
8 bit sequences give values x between 0
and 255
x/255 = u in [0,1] has uniform distribution
Pseudo Random
Numbers
• 1 3 8 15 24 35 ...
• 1 -1 3 -5 7 -9 ....
• 3 1 4 1 5 9 ...
• 79 48 95 56 99
• How random are you?
http://faculty.rhodes.edu/wetzel/random/mainbody.html#summary%20table
•
•
Linear Congruential
Method
seed X0
xn+1 = (p1 xn + p2) mod N
•
•
N large, p1, p2 large primes
•
very fast, but easily breakable
•
u = x/N again in [0,1], has uniform distribution
choice of parameters is crucial (bad counter
example is minimal standard)
Transforming from
Uniform
• Idea: all continuous distribution functions
are monotonic non-decreasing with values
between 0 and 1
• assume outcome is random (uniform), get
random number by finding inverse
•
x := FX-1(u)
⇐⇒ ln(1 − u) = −λx
1
−1
⇐⇒ x = − ln(1 − u) =: FX
(u)
λ
If FX
-1 doesn’t
exist
hen X := − λ1 ln(1 − U ) has an exponential distribution with rate λ.
n fact, since 1 − U is uniform, if U is uniform, we could also have used X := − λ1 ln U
.1.3
Acceptance/Rejection Method
or a lot of distributions the inverse method will not be an option - either because the inver
istribution function is too complicated to be calculated or there does not even exist a closed for
istribution function.
he Acceptance/Rejection Method will work when we are dealing
with a3.distribution
F , that
has
68
CHAPTER
ELEMENTARY
SIMUL
unction f which is zero outside of a finite interval and has an upper bound C on this interval. Th
may look like this:
• Acceptance/Rejection Sampling
• Assume density f
Reject
C
f(x)
a
b
Accept
et us assume, that f (x) is zero outside the
interval [a, b] and has a maximal value less tha
max
f (x) lines
≤ CofThe
basiccode
ideadescribe
of the the
Acceptance/Rejection
Method
is to randomly Metho
”shoot
Thex∈[a,b]
following
pseudo
algorithm behind the
Acceptance/Rejection
ectangle
byU[a,
accept
those random
randomnumber
numbersbetween
underneath
1. get given
x from
[a,b]b] and [0, C] and only
# get
uniform
a and the
b graph
2. get y from U [0, C]
# get uniform random number between 0 and C
Example
• Hits X on Website:
assume that hits happen at a rate of 3 per
hour
• Assume X is Poisson with lambda = 3
• Alternatively, we could observe time
between hits Y
• Y is Exponential with lambda = 3
Download