Professional Documents
Culture Documents
Develop understanding of generating samples from a specified distribution as input to a simulation model. Illustrate some widely-used techniques for generating random variates.
Inverse-transform technique Convolution technique Acceptance-rejection technique A special technique for normal distribution
Inverse-transform Technique
The concept:
For cdf function: r = F(x) Generate R sample from uniform (0,1) Find X sample:
r = F(x)
r1
X = F-1(R)
x1
Exponential Distribution
[Inverse-transform]
Exponential Distribution:
Exponential cdf:
r = F(x) = 1 e-Px
for x u0
Exponential Distribution
[Inverse-transform]
Uniform Distribution
[Inverse-transform]
Uniform Distribution:
Uniform cdf:
0 a x r ! F ( x) ! b a 1
xea a b xeb x
X i ! a (b a ) Ri
6
Uniform Distribution
[Inverse-transform]
Example: Generate 500 variates Xi with distribution Uniform (3,8) Matlab Code
Discrete Distribution
[Inverse-transform]
x
a b c
p(x)
p1 p2 p3
p1 + p2 + p3 p1 + p2 R1 p1
General Form
X ! min{x : ( x) u r}
8
Discrete Distribution
[Inverse-transform]
Example: Suppose the number of shipments, x, on the loading dock of IHW company is either 0, 1, or 2
Data - Probability distribution:
x
0 1
p(x)
0. 0 0.30 0. 0
F(x)
0. 0 0.80 1.00
Consider R1 = 0.73: F(xi-1) < R <= F(xi) F(x0) < 0.73 <= F(x1) Hence, x1 = 1
9
[Inverse-transform]
x (i-1) e x e x (i)
X ! F 1 ( R ) ! x( i 1)
where
ai ! x(i ) x(i 1) 1 / n (i 1) / n
!
(i 1) ai R n
x(i ) x(i 1) 1/ n
10
[Inverse-transform]
Example: Suppose the data collected for 100 brokenwidget repair times are:
i 1 2 3 4 0. Interval (Hours) 0. 1.0 1.5 2.0 0. 1.0 1.5 requency 1 10 25 34 Relative Frequency 0. 1 0.10 0.25 0.34 Cumulative Slope, Frequency, c i ai 0. 1 0.41 0.66 1.00 0. 1 5.0 2.0 1.4
Consider R1 = 0. 3: c3 = 0.66 < R1 < c4 = 1.00 X1 = (4-1) + a4(R1 c(4-1)) = 1.5 + 1.4 (0. 3-0.66) = 1. 5
11
Convolution Technique
Generate samples for Y1 , Y2 , , Yn and then add these samples to get a sample of X.
12
Erlang Distribution
[Convolution]
Example: Generate 500 variates Xi with distribution Erlang-3 (mean: k/P! Matlab Code
13
Acceptance-Rejection technique
Useful particularly when inverse cdf does not exist in closed form a.k.a. thinning Steps to generate X with pdf f(x)
Step 0: Identify a majorizing function g(x) and a pdf h(x) satisfying x , g ( x ) u f ( x )
Efficiency parameter is c
c ! g ( x ) dx
g
g
Generate Y,U no Condition yes Output X=Y
g ( x) h( x) ! c
Step 1: Generate Y with pdf h(x) Step 2: Generate U ~ Uniform(0,1) independent of Y f (Y ) Step 3: Ue set X ! Y
14
Triangular Distribution
[Acceptance-Rejection]
no
yes
Output X = Y
15
Triangular Distribution
Matlab Code: (for exactly 1000 samples)
i=0; while i<1000, Y=0.5*rand(1); U=rand(1); if Y<=0.25 & U<= *Y | Y>0.25 & U<=2- *Y i=i+1; X(i)=Y; end end
[Acceptance-Rejection]
180 160 140 120 100 80 60 40 20 0 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
16
Poisson Distribution
[Acceptance-Rejection]
e E E n p (n) ! P ( N ! n) ! , n ! 0 , 1, 2 , . . . n! N can be interpreted as number of arrivals from a Poisson arrival process during one unit of time Then, the time between the arrivals in the process are exponentially distributed with rate E N !n
n
A
i !1
e1
n 1
A
i !1
Poisson Distribution
n
[Acceptance-Rejection]
A
i !1
e1
n 1
A
i !1
i !1 n i !1
1 ln R i e 1 E
n 1 i
n 1
i !1 i
1 ln R i E
ue
E
"
R
i !1
Step 1. Set n = 0, and P = 1 Step 2. Generate a random number Rn+1 and let P = P. Rn+1 Step 3. If P < e-E, then accept N = n. Otherwise, reject current n, increase n by one, and return to step 2 How many random numbers will be used on the average to generate one Poisson variate?
Normal Distribution
[Special Technique]
B2 = Z21 + Z22 ~ chi-square distribution with 2 degrees of freedom B ! (2 ln R )1/ 2 = Exp(P = 1/2). Hence, The radius B and angle U are mutually independent.
Z1 ! ( 2 ln R1 )1/ 2 cos(2T R2 ) Z 2 ! (2 ln R1 )1/ 2 sin(2T R2 )
19
Normal Distribution
[Special Technique]
20
Normal Distribution
Generate 1000 samples of Normal(7, ) Matlab Code for i=1:500, R1=rand(1); R2=rand(1); Z(2*i-1)=sqrt(-2*log(R1))*cos(2*pi*R2); Z(2*i)=sqrt(-2*log(R1))*sin(2*pi*R2); end
[Special Technique]
21