Computer Science, Informatik 4 Communication and Distributed Systems
Simulation Simulation
Modeling and Performance Analysis with Discrete-Event Simulation g y
- Dr. Mesut Güneş
Simulation Simulation Modeling and Performance Analysis with - - PowerPoint PPT Presentation
Computer Science, Informatik 4 Communication and Distributed Systems Simulation Simulation Modeling and Performance Analysis with Discrete-Event Simulation g y Dr. Mesut Gne Computer Science, Informatik 4 Communication and Distributed
Computer Science, Informatik 4 Communication and Distributed Systems
Modeling and Performance Analysis with Discrete-Event Simulation g y
Computer Science, Informatik 4 Communication and Distributed Systems
Random-Variate Generation
Computer Science, Informatik 4 Communication and Distributed Systems
Contents Contents Inverse-transform Technique Inverse transform Technique Acceptance-Rejection Technique Special Properties p p
Chapter 7. Random-Variate Generation 3
Computer Science, Informatik 4 Communication and Distributed Systems
Purpose & Overview Purpose & Overview Develop understanding of generating samples from a Develop understanding of generating samples from a specified distribution as input to a simulation model. Illustrate some widely-used techniques for generating random variates.
I t f t h i
Special properties
Chapter 7. Random-Variate Generation 4
Computer Science, Informatik 4 Communication and Distributed Systems
Preparation Preparation It is assumed that a source of uniform [0,1] random numbers It is assumed that a source of uniform [0,1] random numbers exists.
Random numbers R, R1, R2, … with
⎩ ⎨ ⎧ ≤ ≤ = th i 1 1 ) ( x x fR
⎩ ⎨
) ( fR
⎪ ⎪ ⎨ ⎧ ≤ ≤ < = 1 ) ( x x x x FR
Chapter 7. Random-Variate Generation 5
⎪ ⎩ >1 1 x
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique Inverse transform Technique
Chapter 7. Random-Variate Generation 6
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique Inverse-transform Technique The concept: The concept:
x = F-1(r)
F(x) 1 F(x) 1 r1
r = F(x)
1 r1
r = F(x)
1
Chapter 7. Random-Variate Generation 7
x1 x x1 x
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique Inverse-transform Technique
The inverse transform technique can be used in principle for any distribution.
is easy to compute. R i d t
2 Set F(X) = R on the range of X
the desired random variate by Xi = F-1(Ri)
Chapter 7. Random-Variate Generation 8
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Example Inverse-transform Technique – Example
p
g
1, 2, 3
x
e x f
λ
λ
−
= ) (
X −
λ
x
λ −
X −
λ
1 R
−
Chapter 7. Random-Variate Generation 9
uniformly distributed on [0,1]
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Example Inverse-transform Technique – Example
Inverse-transform technique for exp(λ = 1)
Chapter 7. Random-Variate Generation 10
q p( )
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Example
Inverse-transform Technique – Example
Example: Generate 200 variates Xi with distribution exp(λ 1)
0,6 0,7 0 3 0,4 0,5 0,1 0,2 0,3 0,1 0,5 1 1,5 2 2,5 3 3,5 4 4,5 5 5,5 6 6,5 7 Empirical Histogram Theor PDF
Chapter 7. Random-Variate Generation 11
Empirical Histogram
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique Inverse-transform Technique
1
) ( )) ( ( ) (
1 1
x F x F R P x X P = ≤ = ≤
Chapter 7. Random-Variate Generation 12
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Other Distributions Inverse-transform Technique – Other Distributions Examples of other distributions for which inverse CDF works Examples of other distributions for which inverse CDF works are:
Chapter 7. Random-Variate Generation 13
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Uniform Distribution Inverse-transform Technique – Uniform Distribution Random variable X uniformly distributed over [a, b] Random variable X uniformly distributed over [a, b]
Chapter 7. Random-Variate Generation 14
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Weibull Distribution Inverse-transform Technique – Weibull Distribution
described by
( )
β
) ( R X F
X
=
( ) ( )
β α α
1 1 R e R e
X X
− = = −
− −
( )
β α
β β
α β
x
e x x f
− −
=
1
) (
β β α
) 1 ln( X R
X
− = −
α
( )
β α x
−
β β β β
α α ) 1 ln( ) 1 ln( R X R X − − =
β β β β
α α ) 1 ln( ) 1 ln( R x R X − ⋅ − = − ⋅ − =
Chapter 7. Random-Variate Generation 15
β
α ) 1 ln( R X − − ⋅ =
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Triangular Distribution Inverse-transform Technique – Triangular Distribution
g Distribution with endpoints (0, 2) is given by
⎪ ⎪ ⎧ ≤ ≤ 1
2
X X
⎪ ⎧ ≤ 0
2
x x
⎪ ⎪ ⎩ ⎪ ⎪ ⎨ ≤ ≤ − − ≤ ≤ = 2 1 2 ) 2 ( 1 1 2 ) (
2
X X X X R
⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ≤ < − − ≤ < = 2 1 ) 2 ( 1 1 2 ) (
2
x x x x x F
⎪ ⎩ 2
⎪ ⎪ ⎪ ⎩ > ≤ < 2 1 2 1 2 1 x x
⎪ ⎨ ⎧ ≤ ≤ = 2
2 1
R R X
Chapter 7. Random-Variate Generation 16
⎪ ⎩ ⎨ ≤ < − − 1 ) 1 ( 2 2
2 1
R R X
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Empirical Continuous Distributions Inverse-transform Technique – Empirical Continuous Distributions
e eo e ca d s bu o s a e
Chapter 7. Random-Variate Generation 17
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Empirical Continuous Distributions Inverse-transform Technique – Empirical Continuous Distributions
p ( )
(n) (2) (1)
x x x ≤ … ≤ ≤
n i , , 2 , 1 x x x
(i) 1)
K = ≤ ≤
The slope of each line segment is defined as
x x i i x x a
i i i i i
1 ) 1 (
) 1 ( ) ( ) 1 ( ) ( − −
− = − − − =
⎞ ⎛ i ) 1 (
n n n
i i ) 1 (
⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − − + = =
− −
n i R a x R F X
i i
) 1 ( ) ( ˆ
) 1 ( 1
n i R n i ≤ < − ) 1 (
when
Chapter 7. Random-Variate Generation 18
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Empirical Continuous Distributions Inverse-transform Technique – Empirical Continuous Distributions
i Interval PDF CDF Slope ai 1 0.0 < x ≤ 0.8 0.2 0.2 4.00 2 0.8 < x ≤ 1.24 0.2 0.4 2.20 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
) / ) 1 4 ( ( 71 .
1 4 ) 1 4 ( 1 1
− − + = =
−
n R a x X R 66 . 1 ) 6 . 71 . ( 90 . 1 45 . 1 = − + =
Chapter 7. Random-Variate Generation 19
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Empirical Continuous Distributions Inverse-transform Technique – Empirical Continuous Distributions
What happens for large samples of data What happens for large samples of data
First summarize the data into a frequency distribution with smaller number of intervals Afterwards, fit continuous empirical CDF to the frequency distribution distribution Slight modifications
Slope
) 1 ( ) ( −
− − =
i i i
c c x x a
ci cumulative probability of the first i intervals
1 −
−
i i
c c
( )
1
ˆ
Chapter 7. Random-Variate Generation 20
( )
i i i i i
c R c c R a x R F X ≤ < − + = =
− − − − 1 1 ) 1 ( 1
when ) (
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Empirical Continuous Distributions Inverse-transform Technique – Empirical Continuous Distributions
p pp g p times are:
Interval (Hours) Frequency Relative Frequency Cumulative Frequency, c i Slope, a i 0.25 ≤ x ≤ 0.5 31 0.31 0.31 0.81 0.5 ≤ x ≤ 1.0 10 0.10 0.41 5.00 1.0 ≤ x ≤ 1.5 25 0.25 0.66 2.00 1.5 ≤ x ≤ 2.0 34 0.34 1.00 1.47
Consider R1 = 0.83: c3 = 0.66 < R1 < c4 = 1.00 X1 = x(4-1) + a4(R1 – c(4-1)) = 1.5 + 1.47(0.83-0.66) = 1.75
Chapter 7. Random-Variate Generation 21
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Empirical Continuous Distributions Inverse-transform Technique – Empirical Continuous Distributions
Problems with empirical distributions Problems with empirical distributions
0.25 ≤ X ≤ 2.0
Hints for building empirical distributions based on frequency tables
Thi ill lt i t ti t
Chapter 7. Random-Variate Generation 22
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Continuous Distributions Inverse-transform Technique – Continuous Distributions A number of continuous distributions do not have a closed A number of continuous distributions do not have a closed form expression for their CDF, e.g.
( )
x
( )
x F
t
exp ) (
2 2 1 2 1
∞ − −
− =
σ μ π σ
The presented method does not work for these distributions Solution Solution
Problem
Chapter 7. Random-Variate Generation 23
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Discrete Distribution Inverse-transform Technique – Discrete Distribution All discrete distributions can be generated via inverse-transform All discrete distributions can be generated via inverse transform technique Method: numerically, table-lookup procedure, algebraically, or a formula Examples of application:
E i i l
Geometric
Chapter 7. Random-Variate Generation 24
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Discrete Distribution Inverse-transform Technique – Discrete Distribution Example: Suppose the number of shipments, x, on the p pp p , , loading dock of a company is either 0, 1, or 2
x p(x) F(x)
0,50 0,50 1 0 30 0 80
The inverse transform technique as table lookup procedure
1 0,30 0,80 2 0,20 1,00
The inverse-transform technique as table-lookup procedure
1 1 i i i i
1 1 i i i i
− −
Chapter 7. Random-Variate Generation 25
Computer Science, Informatik 4 Communication and Distributed Systems
Inverse-transform Technique – Discrete Distribution Inverse-transform Technique – Discrete Distribution
Method - Given R, the
5 ≤ ⎧ R
Method Given R, the generation scheme becomes:
. 1 8 . 8 . 5 . 5 . , 2 , 1 , ≤ < ≤ < ≤ ⎪ ⎩ ⎪ ⎨ ⎧ = R R R x
Consider R 0 73:
, ⎩
Table for generating the Consider R1 = 0.73: F(xi-1) < R ≤ F(xi) F(x0) < 0.73 ≤ F(x1) Hence, X1 = 1
i Input ri Output xi
Table for generating the discrete variate X
1
1 0.5 2 0.8 1
Chapter 7. Random-Variate Generation 26
3 1.0 2
Computer Science, Informatik 4 Communication and Distributed Systems
Acceptance-Rejection Technique Acceptance Rejection Technique
Chapter 7. Random-Variate Generation 27
Computer Science, Informatik 4 Communication and Distributed Systems
Acceptance-Rejection Technique Acceptance-Rejection Technique
Useful particularly when inverse cdf does not exist in closed form
Procedures: Step 1 Generate R U[0 1]
Generate R
no
Step 1. Generate R ~ U[0,1] Step 2. If R ≥ ¼, accept X=R. Step 3. If R < ¼, reject R, return to Step 1
Condition
yes
Step 3. If R ¼, reject R, return to Step 1
Output R’
R does not have the desired distribution, but R conditioned (R ) on the event {R ≥ ¼} does.
j ti
Chapter 7. Random-Variate Generation 28
rejections.
Computer Science, Informatik 4 Communication and Distributed Systems
Acceptance-Rejection Technique – Poisson Distribution Acceptance-Rejection Technique – Poisson Distribution
y
α
α
−
= = e n n N P
n
! ) (
1 2 1 2 1
+
n n n
W ll k d i d thi t i th b i i f th l
α ) ln(
i i
R A − =
Chapter 7. Random-Variate Generation 29
Computer Science, Informatik 4 Communication and Distributed Systems
Acceptance-Rejection Technique – Poisson Distribution Acceptance-Rejection Technique – Poisson Distribution Substitute the sum by Substitute the sum by
+ = =
1 1 1
n i i n i i
Simplify by
= = 1 1 i i
+
> − ≥
n i n i
R R
1
) ln( ) ln( α
= =
> − ≥
n i n i i i
R R
1 1
ln ln α Simplify by eln(x) = x
+ − >
≥
1 n i n i
R e R
α = = i i 1 1
Chapter 7. Random-Variate Generation 30
= = 1 1 i i i i
e
Computer Science, Informatik 4 Communication and Distributed Systems
Acceptance-Rejection Technique – Poisson Distribution Acceptance-Rejection Technique – Poisson Distribution
Procedure of generating a Poisson random variate N is as follows
Otherwise reject the current n increase n by one and return to
step 2.
Chapter 7. Random-Variate Generation 31
Computer Science, Informatik 4 Communication and Distributed Systems
Acceptance-Rejection Technique – Poisson Distribution Acceptance-Rejection Technique – Poisson Distribution
V i t 3
Step 3: Since P 0 8353 > ( 0 2) reject 0 and return to Step 2 with 1
Chapter 7. Random-Variate Generation 32
Computer Science, Informatik 4 Communication and Distributed Systems
Acceptance-Rejection Technique – Poisson Distribution Acceptance-Rejection Technique – Poisson Distribution It took five random numbers to generate three Poisson It took five random numbers to generate three Poisson variates In long run, the generation of Poisson variates requires some
N Rn+1 P Accept/Reject Result
0.4357 0.4357 P < exp(- α) Accept N=0 0.4146 0.4146 P < exp(- α) Accept N=0 0.8353 0.8353 P ≥ exp(- α) Reject 1 0.9952 0.8313 P ≥ exp(- α) Reject 1 0.9952 0.8313 P ≥ exp( α) Reject 2 0.8004 0.6654 P < exp(- α) Accept N=2
Chapter 7. Random-Variate Generation 33
Computer Science, Informatik 4 Communication and Distributed Systems
Special Properties Special Properties
Chapter 7. Random-Variate Generation 34
Computer Science, Informatik 4 Communication and Distributed Systems
Special Properties Special Properties Based on features of particular family of probability Based on features of particular family of probability distributions For example:
Chapter 7. Random-Variate Generation 35
Computer Science, Informatik 4 Communication and Distributed Systems
Direct Transformation Direct Transformation
2
2
1 ) (
x
e x f
−
=
2
2 ) ( e x f = π
∞ − −
=
x t
dt e x F
2
2
2 1 ) ( π
Chapter 7. Random-Variate Generation 36
Computer Science, Informatik 4 Communication and Distributed Systems
Direct Transformation
Direct Transformation
point in the plane:
Z2 B sin(α)
(Z1,Z2) Z2
B
α Z1
Chapter 7. Random-Variate Generation 37
Z1
Computer Science, Informatik 4 Communication and Distributed Systems
Direct Transformation Direct Transformation Chi-square distribution Chi square distribution
the sum is according chi-square distribution
k i i k
1 2 2
= i 1
2 2 2
1
x k k
k − −
2
2 2 k
Chapter 7. Random-Variate Generation 38
Computer Science, Informatik 4 Communication and Distributed Systems
Direct Transformation Direct Transformation
1 + Z2 2 ~ χ2 distribution with 2 degrees of freedom = exp(λ = 1/2).
) 2 cos( ln 2 R R Z π − = ) 2 sin( ln 2 ) 2 cos( ln 2
2 1 2 2 1 1
R R Z R R Z π π − = − =
Chapter 7. Random-Variate Generation 39
Computer Science, Informatik 4 Communication and Distributed Systems
Direct Transformation Direct Transformation Approach for N(μ,σ2): pp (μ, )
Approach for Lognormal(μ,σ2): pp g (μ, )
Chapter 7. Random-Variate Generation 40
Computer Science, Informatik 4 Communication and Distributed Systems
Direct Transformation – Example Direct Transformation – Example Let R1 = 0.1758 and R2=0.1489 Let R1 0.1758 and R2 0.1489 Two standard normal random variates are generated as follows:
50 . 1 ) 1489 . 2 sin( ) 1758 . ln( 2 11 . 1 ) 1489 . 2 cos( ) 1758 . ln( 2
2 1
= − = = − = π π Z Z
To obtain normal variates Xi with mean μ=10 and variance σ2=4 σ2=4
1
2
Chapter 7. Random-Variate Generation 41
Computer Science, Informatik 4 Communication and Distributed Systems
Convolution Convolution Convolution Convolution
Can be applied to obtain
Chapter 7. Random-Variate Generation 42
Computer Science, Informatik 4 Communication and Distributed Systems
Convolution Convolution Erlang Distribution Erlang Distribution
as the sum of k independent exponential random variables Xi, i = 1 k h h i 1/(k θ) 1, …, k each having mean 1/(k θ)
k
=∑
= k i i
X X
1
1 ⎞ ⎛ − =∑
= k i i
R k
1
1 ) ln( 1 θ ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ − =
= k i i
R k
1
ln 1 θ
Chapter 7. Random-Variate Generation 43
Computer Science, Informatik 4 Communication and Distributed Systems
Summary Summary Principles of random-variate generation via Principles of random variate generation via
I f i i d di di ib i Important for generating continuous and discrete distributions
Chapter 7. Random-Variate Generation 44