Stochastic Simulation Generation of random variables Discrete sample space
Bo Friis Nielsen
Applied Mathematics and Computer Science Technical University of Denmark 2800 Kgs. Lyngby – Denmark Email: bfn@imm.dtu.dk
Stochastic Simulation Generation of random variables Discrete - - PowerPoint PPT Presentation
Stochastic Simulation Generation of random variables Discrete sample space Bo Friis Nielsen Applied Mathematics and Computer Science Technical University of Denmark 2800 Kgs. Lyngby Denmark Email: bfn@imm.dtu.dk Plan W1.1-2 Plan W1.1-2
Applied Mathematics and Computer Science Technical University of Denmark 2800 Kgs. Lyngby – Denmark Email: bfn@imm.dtu.dk
02443 – lecture 3 2
DTU
Random number generation Independent Random variable Output Independent, uniformly distributed RN Model Distribution
02443 – lecture 3 3
DTU
X1, X2, ... Xn with a given distribution, Fx(x), (or probability density function [pdf]).
independent samples from the uniform distribution on ]0, 1[.
02443 – lecture 3 4
DTU
Our norm distribution or building block, U(0, 1) f(x) = 1 F(x) = x for 0 ≤ x ≤ 1
1 1
E(X) = 1
2
Var(X) =
1 12
02443 – lecture 3 5
DTU
1 1 1/2 1 1/2
1/2 1
X = 0, 1 P(X = i) = 1 2 X :=
2
02443 – lecture 3 6
DTU
Toss a coin with P(X = 1) = p and P(X = 0) = 1 − p. F(x) = P (X ≤ x) X = U > 1 − p X = 0 ≤ U ≤ 1 − p X = 1 1 − p < U ≤ 1
1 1−p
PDF CDF
1 p 1−p 1 1 1−p 1
02443 – lecture 3 7
DTU
4 5 6 3 2 1 1/6 1/6 1 4 5 6 3 2 1
1 1 3 5 2 4 6
X = 1, 2, ... 6 P(X = i) = 1/6 X = ⌊(6U)⌋ + 1 Can be generalized 6 → k.
02443 – lecture 3 8
DTU
Suppose X can take k distinct values x1 < x2 < ... xk with pi = P(X = xi), i = 1, 2, ... , k Then X takes the value xi with probability pi if U falls in an interval with length pi. That is if
i−1
pj < U ≤
i
pj
X = xi if F(xi−1) < U ≤ F(xi)
02443 – lecture 3 9
DTU
The discrete time version of waiting time. Memory-less.
f(n) = P(X = n) = (1 − p)n−1p n = 1, 2, ... F(n) = P(X ≤ n) = 1 − (1 − p)n X = n if F(n−1) < U ≤ F(n) 1−(1−p)n−1 < U ≤ 1−(1−p)n n − 1 < log (1 − U) log (1 − p) ≤ n X =
log (1−p)
02443 – lecture 3 10
DTU
3 6 7 5 4 1 P1 P2 1
02443 – lecture 3 11
DTU
Assume P(X = i) = pi for i = 1, 2, ... k.
2 3 4 p(i)
Let c ≥ pi (then pi/c ≤ 1).
Else goto 1. frequency for i :
1 k pi c
k
j=1 1 k pj c
= pi
02443 – lecture 3 12
02443
type
02443 – lecture 3 13
DTU
P(X = 1) = 17 96 P(X = 2) = 1 12 P(X = 3) = 1 3 P(X = 4) = 1 4 P(X = 5) = 1 24 P(X = 6) = 11 96
⋄ Generate the table of F(I)-values, (which part of the mass belongs to I itself. ⋄ Generate the table of L(I)-values, (the alias of class I)
⋄ Generate I:I = ⌊k ∗ U1⌋+1 ⋄ Test against F(I).If U2 ≤ F(I) then return X = I else return X = L(I). The L, F tables for the six-point distribution
F(1) = 1 F(2) = 1 2 F(3) = 15 16 F(4) = 1 F(5) = 1 4 F(6) = 11 16 L(1) = 1 L(2) = 4 L(3) = 1 L(4) = 4 L(5) = 3 L(6) = 3
02443 – lecture 3 15
DTU
p(i)
2 3 4
On setup: generate F and L. Generation:
else output L(I).
Pseudo code. p is a vector containing the probabilities.
(a) i=G(1) and j=S(1) (b) L(j)=i and F(i)=F(i)-(1-F(j)) (c) if F(i)<1-eps then G(1)=[] and S=[S i] (d) S(1)=[]
02443 – lecture 3 17
DTU
Aim: We will generate X with probabilities pi = P (X = i). Assume Y with probabilities qi = P (Y = i) is easily generated and C ≥ pi
qi for all i = 1, . . . .
If U2 ≤
pX⋆ CqX⋆ output X = X⋆
else reject.
02443 – lecture 3 18
DTU
P(X = i) = P(X⋆ = i|accept) = P(X⋆ = i, accept) P(accept) = P(X⋆ = i)P(accept)|X⋆ = i) P(accept) = qi ·
pi Cqi
pj Cqj
= pi
In the excercise you can use a build in procedure for generating random
Use histograms (and tests).
stribution and simulate 10,000 outcomes. You can experiment with a small, moderate and large value if you like.
X 1 2 3 4 5 6 pi 7/48 5/48 1/8 1/16 1/4 5/16 (a) by applying a direct (crude) method (b) by using the the rejction method (c) by using the Alias method