Simulation Discrete-Event System Simulation Dr. Mesut Gne Computer - - PowerPoint PPT Presentation

simulation
SMART_READER_LITE
LIVE PREVIEW

Simulation Discrete-Event System Simulation Dr. Mesut Gne Computer - - PowerPoint PPT Presentation

Computer Science, Informatik 4 Communication and Distributed Systems Simulation Discrete-Event System Simulation Dr. Mesut Gne Computer Science, Informatik 4 Communication and Distributed Systems Chapter 6 Random-Variate Generation


slide-1
SLIDE 1

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation

“Discrete-Event System Simulation”

  • Dr. Mesut Güneş
slide-2
SLIDE 2

Computer Science, Informatik 4 Communication and Distributed Systems

Chapter 6

Random-Variate Generation

slide-3
SLIDE 3
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 3 Chapter 6. Random-Variate Generation

Purpose & Overview 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
  • Acceptance-rejection technique
  • Special properties
slide-4
SLIDE 4
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 4 Chapter 6. Random-Variate Generation

Preparation It is assumed that a source of uniform [0,1] random numbers exists.

  • Linear Congruential Method

Random numbers R, R1, R2, … with

  • PDF
  • CDF

⎩ ⎨ ⎧ ≤ ≤ =

  • therwise

1 1 ) ( x x fR

⎪ ⎩ ⎪ ⎨ ⎧ > ≤ ≤ < = 1 1 1 ) ( x x x x x FR

slide-5
SLIDE 5
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 5 Chapter 6. Random-Variate Generation

Inverse-transform Technique The concept:

  • For CDF function: r = F(x)
  • Generate r from uniform (0,1), a.k.a U(0,1)
  • Find x,

x = F-1(r)

r1 x1

r = F(x)

x F(x) 1 r1 x1

r = F(x)

x F(x) 1

slide-6
SLIDE 6
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 6 Chapter 6. Random-Variate Generation

Inverse-transform Technique

  • The inverse-transform technique can be used in principle for

any distribution.

  • Most useful when the CDF F(x) has an inverse F -1(x) which

is easy to compute.

  • Required steps
  • 1. Compute the CDF of the desired random variable X.
  • 2. Set F(X)=R on the range of X.
  • 3. Solve the equation F(X)=R for X in terms of R.
  • 4. Generate uniform random numbers R1, R2, R3, … and compute

the desired random variate by Xi = F-1(Ri)

slide-7
SLIDE 7
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 7 Chapter 6. Random-Variate Generation

Exponential Distribution

  • Exponential Distribution
  • PDF
  • CDF
  • To generate X1, X2, X3 …

x

e x f

λ

λ

= ) (

x

e x F

λ −

− =1 ) (

) ( ) 1 ln( ) 1 ln( ) 1 ln( 1 1

1 R

F X R X R X R X R e R e

X X − − −

= − − = − − = − = − − = = − λ λ λ

λ λ

  • Simplification
  • Since R and (1-R) are

uniformly distributed on [0,1]

λ ) ln(R X − =

slide-8
SLIDE 8
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 8 Chapter 6. Random-Variate Generation

Exponential Distribution

Figure: Inverse-transform technique for exp(λ = 1)

slide-9
SLIDE 9
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 9 Chapter 6. Random-Variate Generation

  • Example: Generate 200 variates Xi with distribution exp(λ= 1)
  • Generate 200 Rs with U(0,1), the histogram of Xs become:
  • Check: Does the random variable X1 have the desired distribution?

Exponential Distribution

) ( )) ( ( ) (

1 1

x F x F R P x X P = ≤ = ≤

0,1 0,2 0,3 0,4 0,5 0,6 0,7 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
slide-10
SLIDE 10
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 10 Chapter 6. Random-Variate Generation

Other Distributions Examples of other distributions for which inverse CDF works are:

  • Uniform distribution
  • Weibull distribution
  • Triangular distribution
slide-11
SLIDE 11
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 11 Chapter 6. Random-Variate Generation

Uniform Distribution Random variable X uniformly distributed over [a, b]

) ( ) ( ) ( a b R a X a b R a X R a b a X R X F − + = − = − = − − =

slide-12
SLIDE 12
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 12 Chapter 6. Random-Variate Generation

Weibull Distribution

  • The Weibull Distribution is

described by

  • PDF
  • CDF
  • The variate is

( )

β α x

e X F

− =1 ) (

( ) ( )

( )

β β β β β β β β α

α α α α

β α β α

) 1 ln( ) 1 ln( ) 1 ln( ) 1 ln( ) 1 ln( 1 1 ) ( R X R x R X R X R R e R e R X F

X

X X

− − ⋅ = − ⋅ − = − ⋅ − = − − = − = − − = = − =

− −

( )

β α

β β

α β

x

e x x f

− −

=

1

) (

slide-13
SLIDE 13
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 13 Chapter 6. Random-Variate Generation

Triangular Distribution

  • The CDF of a Triangular

Distribution with endpoints (0, 2) is given by

  • X is generated by

2 ) 2 ( 1 2 1 for and 2 1 For

2 2

X R X X R X − − = ≤ ≤ = ≤ ≤ ⎪ ⎪ ⎪ ⎩ ⎪ ⎪ ⎪ ⎨ ⎧ > ≤ < − − ≤ < ≤ = 2 1 2 1 2 ) 2 ( 1 1 2 ) (

2 2

x x x x x x x F ⎪ ⎩ ⎪ ⎨ ⎧ ≤ < − − ≤ ≤ = 1 ) 1 ( 2 2 2

2 1 2 1

R R R R X

slide-14
SLIDE 14
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 14 Chapter 6. Random-Variate Generation

Empirical Continuous Distributions

  • When theoretical distribution is not applicable
  • To collect empirical data:
  • Resample the observed data
  • Interpolate between observed data points to fill in the gaps
  • For a small sample set (size n):
  • Arrange the data from smallest to largest
  • Set x(0)=0
  • Assign the probability 1/n to each interval
  • The slope of each line segment is defined as
  • The inverse CDf is given by

(n) (2) (1)

x x x ≤ … ≤ ≤

(i) 1)

  • (i

x x x ≤ ≤

⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − − + = =

− −

n i R a x R F X

i i

) 1 ( ) ( ˆ

) 1 ( 1

n x x n i n x x a

i i i i i

/ 1 / ) 1 ( / 1

) 1 ( ) ( ) 1 ( ) ( − −

− = − − − =

slide-15
SLIDE 15
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 15 Chapter 6. Random-Variate Generation

Empirical Continuous Distributions

4.65 1.0 0.2 1.83 < x ≤2.76 5 1.90 0.8 0.2 1.45 < x ≤ 1.83 4 1.05 0.6 0.2 1.24 < x ≤ 1.45 3 2.20 0.4 0.2 0.8 < x ≤ 1.24 2 4.00 0.2 0.2 0.0 < x ≤ 0.8 1 Slope ai Cumulative Probability Probability Interval i

66 . 1 ) 6 . 71 . ( 90 . 1 45 . 1 ) / ) 1 4 ( ( 71 .

1 4 ) 1 4 ( 1 1

= − + = − − + = =

n R a x X R

slide-16
SLIDE 16
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 16 Chapter 6. Random-Variate Generation

Empirical Continuous Distributions What happens for large samples of data

  • Several hundreds or tens of thousand

First summarize the data into a frequency distribution with smaller number of intervals Afterwards, fit continuous empirical CDF to the frequency distribution Slight modifications

  • Slope
  • The inverse CDf is given by

1 ) 1 ( ) ( − −

− − =

i i i i i

c c x x a

( )

1 ) 1 ( 1

) ( ˆ

− − −

− + = =

i i i

c R a x R F X

ci cumulative probability of the first i intervals

slide-17
SLIDE 17
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 17 Chapter 6. Random-Variate Generation

Empirical Continuous Distributions

  • Example: Suppose the data collected for 100 broken-widget repair

times are:

i Interval (Hours) Frequency Relative Frequency Cumulative Frequency, c i Slope, a i 1 0.25 ≤ x ≤ 0.5 31 0.31 0.31 0.81 2 0.5 ≤ x ≤ 1.0 10 0.10 0.41 5.0 3 1.0 ≤ x ≤ 1.5 25 0.25 0.66 2.0 4 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

slide-18
SLIDE 18
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 18 Chapter 6. Random-Variate Generation

Empirical Continuous Distributions Problems with empirical distributions

  • The data in the previous example is restricted in the range

0.25 ≤ X ≤ 2.0

  • The underlying distribution might have a wider range
  • Thus, try to find a theoretical distribution

Hints for building empirical distribution based on frequency tables

  • It is recommended to use relatively short intervals
  • Number of bin increase
  • This will result in a more accurate estimate
slide-19
SLIDE 19
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 19 Chapter 6. Random-Variate Generation

Discrete Distribution All discrete distributions can be generated via inverse-transform technique Method: numerically, table-lookup procedure, algebraically, or a formula Examples of application:

  • Empirical
  • Discrete uniform
  • Gamma
slide-20
SLIDE 20
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 20 Chapter 6. Random-Variate Generation

Discrete Distribution Example: Suppose the number of shipments, x, on the loading dock of a company is either 0, 1, or 2

  • Data - Probability distribution:

The inverse-transform technique as table-lookup procedure

  • Set X1 = xi

x p(x) F(x)

0.50 0.50 1 0.30 0.80 2 0.20 1.00

) ( ) (

1 1 i i i i

x F r R r x F = ≤ < =

− −

slide-21
SLIDE 21
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 21 Chapter 6. Random-Variate Generation

Discrete Distribution

Consider R1 = 0.73: F(xi-1) < R <= F(xi) F(x0) < 0.73 <= F(x1) Hence, x1 = 1

. 1 8 . 8 . 5 . 5 . , 2 , 1 , ≤ < ≤ < ≤ ⎪ ⎩ ⎪ ⎨ ⎧ = R R R x

Method - Given R, the generation scheme becomes:

2 1.0 3 1 0.8 2 0.5 1 Output xi Input ri i

Table for generating the discrete variate X

slide-22
SLIDE 22
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 22 Chapter 6. Random-Variate Generation

Acceptance-Rejection technique

  • Useful particularly when inverse cdf does not exist in closed form, a.k.a.

thinning

  • Illustration: To generate random variates, X ~ U(1/4, 1)
  • R does not have the desired distribution, but R conditioned (R’) on the

event {R ≥ ¼} does.

  • Efficiency: Depends heavily on the ability to minimize the number of

rejections.

Procedures: Step 1. Generate R ~ U[0,1] Step 2a. If R >= ¼, accept X=R. Step 2b. If R < ¼, reject R, return to Step 1

Generate R Condition Output R’

yes no

slide-23
SLIDE 23
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 23 Chapter 6. Random-Variate Generation

Poisson Distribution

  • PMF of a Poisson Distribution
  • Exactly n arrivals during one time unit
  • Since interarrival times are exponentially distributed we can set
  • Well known, we derived this generator in the beginning of the class

α

α

= = e n n N P

n

! ) (

1 2 1 2 1

1

+

+ + + + < ≤ + + +

n n n

A A A A A A A L L

α ) ln(

i i

R A − =

slide-24
SLIDE 24
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 24 Chapter 6. Random-Variate Generation

Poisson Distribution Substitute the sum by Simplify by

  • multiply by -α, which reverses the inequality sign
  • sum of logs is the log of a product

Simplify by eln(x) = x

∏ ∏

+ = − =

> ≥

1 1 1 n i i n i i

R e R

α

∑ ∑

+ = =

− < ≤ −

1 1 1

) ln( 1 ) ln(

n i i n i i

R R α α

∏ ∑ ∑ ∏

= + = = =

= > − ≥ =

n i i n i i n i i n i i

R R R R

1 1 1 1 1

ln ) ln( ) ln( ln α

slide-25
SLIDE 25
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 25 Chapter 6. Random-Variate Generation

Poisson Distribution

  • Procedure of generating a Poisson random variate N is as

follows

  • 1. Set n=0, P=1
  • 2. Generate a random number Rn+1, and replace P by P x Rn+1
  • 3. If P < exp(-α), then accept N=n
  • Otherwise, reject the current n, increase n by one, and return to

step 2.

slide-26
SLIDE 26
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 26 Chapter 6. Random-Variate Generation

Poisson Distribution

  • Example: Generate three Poisson variates with mean α=0.2
  • exp(-0.2) = 0.8187
  • Variate 1
  • Step 1: Set n=0, P=1
  • Step 2: R1 = 0.4357, P = 1 x 0.4357
  • Step 3: Since P = 0.4357 < exp(- 0.2), accept N = 0
  • Variate 2
  • Step 1: Set n=0, P=1
  • Step 2: R1 = 0.4146, P = 1 x 0.4146
  • Step 3: Since P = 0.4146 < exp(-0.2), accept N = 0
  • Variate 3
  • Step 1: Set n=0, P=1
  • Step 2: R1 = 0.8353, P = 1 x 0.8353
  • Step 3: Since P= 0.8353 > exp(-0.2), reject n=0 and return to Step 2 with n=1
  • Step 2: R2 = 0.9952, P = 0.8353 x 0.9952 = 0.8313
  • Step 3: Since P= 0.8313 > exp(-0.2), reject n=1 and return to Step 2 with n=2
  • Step 2: R3 = 0.8004, P = 0.8313 x 0.8004 = 0.6654
  • Step 3: Since P = 0.6654 < exp(-0.2), accept N = 2
slide-27
SLIDE 27
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 27 Chapter 6. Random-Variate Generation

Poisson Distribution It took five random numbers to generate three Poisson variates In long run, the generation of Poisson variates requires some

  • verhead!

N=2 Accept P < exp(- α) 0.6654 0.8004 2 Reject P ≥ exp(- α) 0.8313 0.9952 1 Reject P ≥ exp(- α) 0.8353 0.8353 N=0 Accept P < exp(- α) 0.4146 0.4146 N=0 Accept P < exp(- α) 0.4357 0.4357

Result Accept/Reject P Rn+1 N

slide-28
SLIDE 28
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 28 Chapter 6. Random-Variate Generation

Special Properties Based on features of particular family of probability distributions For example:

  • Direct Transformation for normal and lognormal distributions
  • Convolution
  • Beta distribution (from gamma distribution)
slide-29
SLIDE 29
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 29 Chapter 6. Random-Variate Generation

Approach for N(0,1):

  • Consider two standard normal random variables, Z1 and Z2, plotted as a

point in the plane:

  • B2 = Z2

1 + Z2 2 ~ χ2 distribution with 2 degrees of freedom = Exp(λ = 2).

Hence,

  • The radius B and angle φ are mutually independent.

Direct Transformation

2 / 1

) ln 2 ( R B − =

In polar coordinates: Z1 = B cos(φ) Z2 = B sin(φ) ) 2 sin( ) ln 2 ( ) 2 cos( ) ln 2 (

2 2 / 1 2 2 2 / 1 1

R R Z R R Z π π − = − =

slide-30
SLIDE 30
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 30 Chapter 6. Random-Variate Generation

Direct Transformation Approach for N(μ,σ2):

  • Generate Zi ~ N(0,1)

Approach for Lognormal(μ,σ2):

  • Generate X ~ N((μ,σ2)

Yi = eXi Xi = μ + σ Zi

slide-31
SLIDE 31
  • Dr. Mesut Güneş

Computer Science, Informatik 4 Communication and Distributed Systems 31 Chapter 6. Random-Variate Generation

Summary Principles of random-variate generation via

  • Inverse-transform technique
  • Acceptance-rejection technique
  • Special properties

Important for generating continuous and discrete distributions