Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
ENM307 2012 Bahar
ENM 307 SIMULATION
Anadolu Üniversitesi,
Endüstri Mühendisliği Bölümü Yrd. Doç. Dr. Gürkan ÖZTÜRK
Random Variate Generation
ENM307 2012 Bahar
Random Variate Generation
• Random variate generation is about procedures for sampling from a variety of widely-used continuous and discrete distributions.
• Widely-used techniques are considered.
• Routines in programming libraries or built into simulation language
• Inverse transform technique, acceptance-rejection technique
• All techniques use a source of uniform [0,1] random numbers R1, R2, …
otherwise,0
10,1)(
xxfR
1x,1
10,
0,0
)( xx
x
xFR
ENM307 2012 Bahar
Inverse-Transform Technique
• Inverse-transform technique can be used to sample from – Exponential
– Uniform
– Weibull
– Triangular
– Empirical
– Etc.
• It is underlying principle for sampling from a wide variety of discrete distributions.
ENM307 2012 Bahar
Inverse-Transform Technique
Exponential Distribution • Probability density function (pdf)
– The parameter can be interpreted as the mean number of occurrence per time unit. – If the interarrival time X1, X2, X3,… had an exponential distribution with rate , then could
be interpreted as the mean number of arrivals per time unit.
– Expected value of Xi , is the mean of interarrival time.
otherwise,0
0,)(
xexf
x
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0
f(x)
x
pdfs for several exponential distributions
0.5
1
1.5
2
1)( iXE
ENM307 2012 Bahar
Inverse-Transform Technique
Exponential Distribution
• Cumulative distribution function (cdf)
• The goal is to develop a procedure for generating values X1, X2, X3,… that have an exponential distribution.
• Inverse-transform technique can be utilized for any distribution
• If F-1 can be computed easily then it is most useful
x
dttfxF )()(
00
0,0
x
xdte
x
t
0,0
0,1)(
x
xexF
x
ENM307 2012 Bahar
Inverse-Transform Technique Step-by-step procedure on
Exponential Distribution
• Step 1: Compute the cdf of the desired random variable X. – For the exponential distribution, cdf
• Step 2: Set F(x)=R on the range of X. – For the exponential distribution,
• Step 3: Solve the equation F(x)=R for X in terms of R. – For the exponential distribution, the solution proceeds as follows:
• Step 4: Generate (as needed) random variables R1,R2,… and compute the desired random variates by – For the exponential case
.0,1)( xexF x
.0,1 xRe X
)1ln(1
)1ln(
1
1
RX
RX
Re
Re
X
X
ii RX ln1
)1ln(
1ii RX
)(1
ii RFX
or
ENM307 2012 Bahar
Example 8.1 i 1 2 3 4 5
Ri 0.1306 0.0422 0.6597 0.7965 0.7696
Xi 0.1400 0.0431 1.0779 1.5921 1.4679
=1
111
XeR
)1ln( 11 RX
1400.0
8694.0ln
)1306.01ln(1
X
F(x)=1-e-x
x
R1=1-e-X1
R2
X2 X1 =-ln(1- R1) x0
F(x0 )
0
1
ENM307 2012 Bahar
Inverse-Transform Technique
Uniform Distribution
• Probability density function (pdf)
• Step1: Cumulative distribution function (cdf) is given by
• Step2: Set F(X)=(X-a)/(b-a)=R
• Step3: Solving for X in terms of R yields X=a+(b-a)R
otherwise,0
,1
)(bxa
abxf
bx
bxaab
ax
ax
xF
,1
,
,0
)(
x
f(x)
a b
x
F(x)
a b
0
1
ENM307 2012 Bahar
Inverse-Transform Technique
Weibull Distribution
• Probability density function (pdf)
• Step1: The is given by F(X)=1-e-(x/) , x0
• Step2: Set 𝐹 𝑋 = 1 − 𝑒−
𝑥
𝛼
𝛽
= 𝑅
• Step3: Solving for X in terms of R yields
𝑋 = 𝛼 − ln 1 − 𝑅 1/𝛽
otherwise,0
0,)(
)/(1 xexxf
ax
ENM307 2012 Bahar
Inverse-Transform Technique
Triangular Distribution
• Probability density function (pdf)
• Cumulative distribution function
• For 0 x 1,
• For 1 x 2,
otherwise,0
21,2
10,
)( xx
xx
xf
2,1
21,2
)2(1
10,2
0,0
)(2
2
x
xx
xx
x
xF
2
2xR
2
)2(1
2xR
1,)1(22
0,2
21
21
RR
RRX
0.0
0.2
0.4
0.6
0.8
1.0
-1 0 1 2 3
0.0
0.2
0.4
0.6
0.8
1.0
0 1 2 3
ENM307 2012 Bahar
Inverse-Transform Technique
Empirical Continuous Distribution-Example 8.2
• Five observations of fire-crew response time (in minutes) to incoming alarms: – 2.76 1.83 0.80 1.45 1.24
Arrange the data from smallest to largest x(1) x(2) x(3) … x(n)
Smallest value is considerd as 0, so x(0)=0
n
xx
nini
xxa
iiii
i/1/)1(/
)1()()1()(
i Interval x(i-1) x x(i)
Probability 1/n
Cumulative Probability,
i/n
Slope ai
1 0.0 x 0.80 0.2 0.2 4
2 0.80 x 1.24 0.2 0.4 2.25
3 1.24 x 0.45 0.2 0.6 1.05
4 1.45 x 1.83 0.2 0.8 1.90
5 1.83 x 2.76 0.2 1.0 4.65
n
iRaxRFX ii
)1()(ˆ
)1(
1
0; 0
0.8; 0.2
1.24; 0.4
1.45; 0.6
1.83; 0.8
2.76; 1 3; 1
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0 1 2 3 4
ENM307 2012 Bahar
Inverse-Transform Technique
Empirical Continuous Distribution-Example 8.2 i Interval
x(i-1) x x(i)
Probability 1/n
Cumulative Probability, i/n
Slope ai
1 0.0 x 0.80 0.2 0.2 4
2 0.80 x 1.24 0.2 0.4 2.25
3 1.24 x 0.45 0.2 0.6 1.05
4 1.45 x 1.83 0.2 0.8 1.90
5 1.83 x 2.76 0.2 1.0 4.65
0; 0
0.8; 0.2
1.24; 0.4
1.45; 0.6
1.83; 0.8
2.76; 1 3; 1
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0 0.5 1 1.5 2 2.5 3 3.5
R1
X1
66.1
)60.071.0(90.145.1
)/)14(( 14)14(1
nRaxX
ENM307 2012 Bahar
Continuous distributions without Closed-Form Inverse
• A number of continuous distributions do not have closed form expression for their cdf or its inverse: – For example
• Normal
• Gamma
• Beta
– Inverse transform technique for random variete generation is not available for these distributions.
– An approximation for inverse transform can be used.
– Simple approximation to the inverse cdf of standard normal distribution, (Schmeiser [1979])
1795.0
)1()(
135.0135.01 RR
RFX
R Approximate Inverse Exact Inverse
0.01 -2.3263 -2.3373
0.10 -1.2816 -1.2813
0.25 -0.6745 -0.6713
0.50 0.0000 0.0000
0.75 0.6745 0.6713
0.90 1.2816 1.2813
0.99 2.3263 2.3373
ENM307 2012 Bahar
Discrete Distributions
• All discrete distributions can be generated via inverse transform tecnique, – Numerically , through table-lookup procedure
– Algebraically, final generation scheme being in terms of a formula
• Other techniques are sometime used for certain distributions, e.g. – Convolution technique for binomial distribution.
ENM307 2012 Bahar
Discrete Distribution
An Empirical Discrete distribution Example 8.4.
• Distribution of number of Shipments, X
• The probability mass function (pmf) – P(0)=P(X=0)=0.5
– P(1)=P(X=1)=0.3
– P(2)=P(X=2)=0.2
• Cumulative distribution function
x p(x) F(x)
0 0.50 0.50
1 0.30 0.80
2 0.20 1.00
x
x
x
x
xF
21
218.0
105.0
00
)(
x
F(x)
0 1 2 3
R1=0.73
X1=1
0.18.02
8.05.01
5.00
R
R
R
X
ENM307 2012 Bahar
Discrete Distributions
Uniform Distribution
• Discrete uniform distribution on {1,2,…,k} – pmf
– Cdf
– xi=i and ri=p(1)+p(2)+…+p(xi)=F(xi)=1/k for i=1,2,…,k
kxk
xp ,...,2,1,1
)(
xk
kxkk
k
xk
xk
x
xF
,1
1,1
32,2
21,1
1,0
)(
k
irR
k
ir ii
11
RkXRkiRkiRki 11
ENM307 2012 Bahar
Discrete Distributions
Geometric Distribution
• Geometric distribution with – pmf
– Cdf
– Inverse transform
...,2,1,0,)1()( xppxp x
1
1
0
)1(1)(
)1(1
)1(1)1()(
x
xx
j
j
pxF
p
ppppxF
)()1(1)1(1)1( 1 xFpRpxF xx
xx pRp )1(1)1( 1
)1ln()1ln()1ln()1( pxRpx
)1ln(
)1ln(1
)1ln(
)1ln(
p
Rx
p
R
1
)1ln(
)1ln(
p
RX
ENM307 2012 Bahar
Acceptance-Rejection Technique
• X uniformly distributed between 1/4 and 1 – Step1: Generate a random number R
– Step2a: if R1/4, accept X=R then go to Step 3.
– Step2b: if R<1/4, reject R then return to Step 1.
– Step3: if another uniform vaiete on [1/4,1] is needed, go to Step 1 else stop.
ENM307 2012 Bahar
Discrete Distributions
Poisson Distribution
• A Poisson random variable, N, with mean >0 has – pmf
– N=n
,...2,1,!
)()(
nn
enNPnp
n
t=0 t=1 t=2
A1 A2 A3 A… An An+1
12121 1 nnn AAAAAAA
1
11
1
1
1
11 1
1
11
lnlnlnln
ln1
1ln1
n
i
i
n
i
i
n
i
i
n
i
i
n
i
n
i
ii
n
i
i
n
i
i
ReR
RRRR
RR
ENM307 2012 Bahar
Discrete Distributions
Poisson Distribution
• The procedure for generating a Poisson random variate, N, is given by following steps – Step1: Set n=0, P=1
– Step2: Generate a random number Rn+1 and replace P by P.Rn+1
– Step3: if P<e- , then N=n. Otherwise, reject n, increase n by one, and return to step 2.
• Example 8.8 : =0.2 First compute e-=e-2=0.8187. – Step1: n=0, P=1
– Step2: R1=0.4357, P=1. R1=0.4357
– Step3: since P=0.4357<e- =0.8187, accept N=0.
– Step1-3: (R1=0.4146, leads to N=0)
ENM307 2012 Bahar
Discrete Distributions
Poisson Distribution
– …
– Step1: n=0, P=1
– Step2: R1=0.8353, P=1. R1=0.8353
– Step3: since P=0.8353e- =0.8187, reject, and return step 2 with n=1.
– Step2: R2=0.9952, P=R1. R2=0.8313
– Step3: since P=0.8313e- =0.8187, reject, and return step 2 with n=2.
– Step2: R3=0.8004, P=R1. R2.R3=0.6654
– Step3: since P=0.8313<e- =0.8187, accept, N=2.
n Rn+1 P Accept/reject Result
0 0.4357 0.4357 P<e- accept N=0
0 0.4146 0.4146 P<e- accept N=0
0 0.8353 0.8353 Pe- reject
1 0.9952 0.8313 Pe- reject
2 0.8004 0.6654 P<e- accept N=2
ENM307 2012 Bahar
Discrete Distributions
Poisson Distribution
=4 buses per hour Pe-4 0.0183
When is large, say ≥ 15 the rejection technique becomes quite expensive.
Z is approximately normal distributed with mean zero and variance 1.
Then possion variate can be generated
n Rn+1 P Accept/reject Result
0 0.4357 0.4357 Pe- reject
1 0.4146 0.1806 Pe- reject
2 0.8353 0.1508 Pe- reject
3 0.9952 0.1502 Pe- reject
4 0.8004 0.1202 Pe- reject
5 0.7945 0.0955 Pe- reject
6 0.1530 0.0146 P<e- accept N=6
NZ
5.0 ZN