ENM 307 SIMULATION - eskisehir.edu.trendustri.eskisehir.edu.tr/zkamisli/ENM307/icerik...•Random...
Transcript of ENM 307 SIMULATION - eskisehir.edu.trendustri.eskisehir.edu.tr/zkamisli/ENM307/icerik...•Random...
ENM 307 SIMULATION
Anadolu Üniversitesi,
Endüstri Mühendisliği Bölümü 2012-2013, Spring
Zehra Kamışlı Öztürk
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, …
Random Variate Generation
≤≤
=otherwise,0
10,1)(
xxfR
>
≤≤
<
=
1x,1
10,
0,0
)( xx
x
xFR
Inverse-Transform Technique
• Inverse-transform technique can be used to sample from ◦ Exponential
◦ Uniform
◦ Weibull
◦ Triangular
◦ Empirical
◦ Et
• It is underlying principle for sampling from a wide variety of discrete distributions.
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λλ
pdfs for several exponential distributions
f(x)
0,0
0,2
0,4
0,6
0,8
1,1
1,3
1,5
1,7
1,9
2,1
0,0 0,2 0,4 0,6 0,8 1,0 1,2 1,4 1,7 1,9 2,1 2,3 2,5 2,7 2,9 3,1
0.511.52
λ
1)( =iXE
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λ
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)( ≥−=−
xexFxλ
.0,1 ≥=−−
xReXλ
)1ln(1
)1ln(
1
1
RX
RX
Re
Re
X
X
−−=
−=−
−=
=−
−
−
λ
λ
λ
λ
iiRX ln
1
λ−=)1ln(
1iiRX −−=
λ
)(1iiRFX
−=
or
Example 8.1i 1 2 3 4 5
Ri
0.130
6
0.042
2
0.659
7
0.796
5
0.769
6X
i 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
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
Inverse-Transform Technique
Weibull Distribution• Probability density function (pdf)
• Step1: The is given by F(X)=1-e-(x/α)β , x≥0
• Step2: Set F(X)=1-e-(x/α)β=R.
• Step3: Solving for X in terms of R yields
X=α[-ln(1-R)]1/β
≥
=
−−
otherwise,0
0,)(
)/(1 xexxf
ax ββ
βα
β
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
2x
R =
2
)2(1
2x
R−
−=
≤≤−−
≤≤=
1,)1(22
0,2
21
21
RR
RRX
0,0
0,2
0,4
0,7
0,9
1,1
-0,8 0,0 0,8 1,5 2,3 3,0
0,0
0,2
0,4
0,7
0,9
1,1
0 1 1 2 2
Inverse-Transform Technique
Empirical Continuous Distribution• If the modeler has been unableto find a theoretical distribution that
provides a good model for the input data, then it may be necessary to use the emprical distribution of the data.
• Finite number of values !
• Otherwise, interpolate between the observed data
points to fill in the gaps !
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 ≤ 1.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,3
0,5
0,8
1,0
0,0 0,8 1,5 2,3 3,0
Inverse-Transform Technique
Empirical Continuous Distribution-Example 8.2i 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,3
0,5
0,8
1,0
0,00 0,75 1,50 2,25 3,00
R1
X1
66.1
)60.071.0(90.145.1
)/)14(( 14)14(1
=
−+=
−−+= − nRaxX
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,
1795.0
)1()(
135.0135.01 RRRFX
−−≈=
−
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
Discrete Distributions
• All discrete distributions can be generated via inverse transform technique, ◦ 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.
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
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=≤<
−=−
1
1 RkXRkiRkiRki =⇒+≤≤⇒<≤−⇒ 11
Discrete Distributions
Geometric Distribution
• Geometric distribution with ◦ pmf
◦ Cdf
◦ Inverse transform
...,2,1,0,)1()( =−= xppxpx
{ }
1
1
0
)1(1)(
)1(1
)1(1)1()(
+
+
=
−−=
−−
−−=−=∑
x
xx
j
j
pxF
p
ppppxF
)()1(1)1(1)1( 1xFpRpxF
xx=−−≤<−−=−
+
xxpRp )1(1)1( 1
−<−≤−+
)1ln()1ln()1ln()1( pxRpx −<−≤−+
)1ln(
)1ln(1
)1ln(
)1ln(
p
Rx
p
R
−
−<≤−
−
−
−
−
−= 1
)1ln(
)1ln(
p
RX
Acceptance-Rejection Technique
• X uniformly distributed between 1/4 and 1 ◦ Step1: Generate a random number R
◦ Step2a: if R≥1/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.
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
121211 +++++<≤+++
nnnAAAAAAA ΛΛ
∏∏
∏∑∏ ∑
∑∑
+
==
−
+
=
+
== =
+
==
>≥
=>−≥=
−<≤−
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
α
α
αα
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)
Discrete Distributions
Poisson Distribution
◦ … ◦ Step1: n=0, P=1 ◦ Step2: R1=0.8353, P=1. R1=0.8353
◦ Step3: since P=0.8353≥e-α =0.8187, reject, and return step 2 with n=1.
◦ Step2: R2=0.9952, P=R1. R2=0.8313
◦ Step3: since P=0.8313 ≥e-α =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=1
0 0.8353 0.8353 P ≥e-α reject
1 0.9952 0.8313 P ≥e-α reject
2 0.8004 0.6654 P<e-α accept N=2