CPSC 531: System Modeling and Simulation Carey Williamson - - PowerPoint PPT Presentation

cpsc 531
SMART_READER_LITE
LIVE PREVIEW

CPSC 531: System Modeling and Simulation Carey Williamson - - PowerPoint PPT Presentation

CPSC 531: System Modeling and Simulation Carey Williamson Department of Computer Science University of Calgary Fall 2017 Recap and Terminology (Pseudo-) Random Number Random Variate Generation Generation (RNG) (RVG) A fundamental


slide-1
SLIDE 1

CPSC 531: System Modeling and Simulation

Carey Williamson Department of Computer Science University of Calgary Fall 2017

slide-2
SLIDE 2

Recap and Terminology

▪ (Pseudo-) Random Number Generation (RNG) ▪ A fundamental primitive required for simulations ▪ Goal: Uniform(0,1) ▪ Uniformity ▪ Independence ▪ Computational efficiency ▪ Long period ▪ Multiple streams ▪ Common approach: LCG ▪ Careful design and seeding ▪ Never generates 0.0 or 1.0 ▪ Covered in guest lecture (JH) ▪ Readings: 2.1, 2.2 ▪ Random Variate Generation (RVG) ▪ Builds upon Uniform(0,1) ▪ Goal: any distribution ▪ Discrete distributions ▪ Continuous distributions ▪ Independence (usually) ▪ Correlation (if desired) ▪ Computational efficiency ▪ Common approach: the inverse transform method ▪ Straightforward math (usually) ▪ Might generate 0.0 or 1.0 ▪ Covered in today’s lecture ▪ Readings: 6.1, 6.2

2

slide-3
SLIDE 3

▪ Random variate generation

—Inverse transform method —Convolution method —Empirical distribution —Other techniques

Outline

3

slide-4
SLIDE 4

▪ Input parameters such as inter-arrival times and service times are often modeled by random variables with some given distributions ▪ A mechanism is needed to generate variates for a wide class of distributions Discrete-Event Simulation

This can be done using a sequence of random numbers that are independent of each other and are uniformly distributed between 0 and 1

4

slide-5
SLIDE 5

▪ Uniformly distributed between 0 and 1

—Consider a sequence of random numbers u1,u2,…,uN —Uniformity: expected number of random numbers in each

sub-interval is N/n

—Independence: value of each random number is not

affected by any other numbers

Uniform Random Numbers

  • • •

1 n equal sub-intervals

5

slide-6
SLIDE 6

A Bernoulli variate is useful for generating a binary outcome (0 or 1) to represent “success” (1) or “failure” (0) Example: wireless network packet transmission Example: coin flipping to produce “heads” or “tails” Bernoulli trial (with parameter p) p(1) = p, p(0) = 1 – p ▪ Random variate generation

— Generate 𝑣 — If 0 < 𝑣 ≤ 𝑞, 𝑦 = 1; — Otherwise 𝑦 = 0

Bernoulli Variate

6

slide-7
SLIDE 7

▪ Consider a tri-modal discrete distribution

—Example: size of an email message (in paragraphs, or KB) —Example: p(1) = 0.5, p(2) = 0.3, p(3) = 0.2

▪ Cumulative distribution function, F(x)

Inverse Transformation Method: Discrete Distributions

1.0 0.8

F(x)

0.5 1 2 3

x

7

slide-8
SLIDE 8

▪ Algorithm

—Generate random number 𝑣 —Random variate 𝑦 = 𝑗 if 𝐺 𝑗 − 1 < 𝑣 ≤ 𝐺(𝑗)

▪ Example: F(0) = 0, F(1) = 0.5, F(2) = 0.8, F(3) = 1.0

—0 < u ≤ 0.5

variate 𝑦 = 1

—0.5 < u ≤ 0.8

variate 𝑦 = 2

—0.8 < u ≤ 1.0

variate 𝑦 = 3

Inverse Transformation Method: Discrete Distributions

8

slide-9
SLIDE 9

▪ Discrete uniform (with parameters a and b) p(n) = 1/(b – a + 1) for n = a, a + 1, …, b F(n) = (n – a + 1)/(b – a + 1) ▪ Random variate generation

—Generate 𝑣 —𝑦 = 𝑏 + 𝑔𝑚𝑝𝑝𝑠(𝑣 ∗ 𝑐 − 𝑏 + 1 )

OR

—𝑦 = 𝑏 − 1 + 𝑑𝑓𝑗𝑚𝑗𝑜𝑕(𝑣 ∗ 𝑐 − 𝑏 + 1 )

Discrete Uniform Variate

9

slide-10
SLIDE 10

▪ Geometric (with parameter p) 𝑞 𝑜 = 𝑞 1 − 𝑞 𝑜−1, n = 1,2,3, … ▪ Gives the number of Bernoulli trials until achieving the first success ▪ Random variate generation

—Generate 𝑣 —Geometric variate 𝑦 =

ln 𝑣 ln 1−𝑞

Geometric Variate

10

slide-11
SLIDE 11

▪ Algorithm

—Generate uniform random number 𝑣 —Solve 𝐺 𝑦 = 𝑣 for random variate 𝑦

Inverse Transformation Method: Continuous Distributions

F(x) 1 u

Variate 𝑦

x F(x): Cumulative Distribution Function of X = ℙ(𝑌 ≤ 𝑦)

11

slide-12
SLIDE 12

▪ Define the random variable 𝑍 as: 𝑍 = 𝐺(𝑌) ℙ 𝑍 ≤ 𝑧 = ℙ 𝑌 ≤ 𝑦 = 𝑧 Therefore, 𝑍~𝑉(0, 1)

Proof

1 y x

𝐺(𝑦)

12

slide-13
SLIDE 13

▪ Uniform (with parameters a and b) F(x) = (x – a)/(b – a), 𝑏 ≤ 𝑦 ≤ 𝑐 ▪ Random variate generation

—Generate 𝑣 —𝑦 = 𝑏 + 𝑐 − 𝑏 𝑣

Continuous Uniform Variate

1/( ) , ( )

  • therwise.

b a a x b f x       

13

slide-14
SLIDE 14

▪ Exponential (with parameter 𝜇) f (x) = 𝜇 e-𝜇 x F(x) = 1 – e-𝜇 x ▪ Random variate generation

—Generate 𝑣 —𝑦 = −

1 𝜇 ⋅ ln(𝑣)

▪ Can also use 𝑦 = −

1 𝜇 ⋅ ln(1 − 𝑣)

Exponential Variate

Note: If 𝑣 is Uniform(0,1), then 1 − 𝑣 is Uniform(0,1) too!

14

slide-15
SLIDE 15

▪ Sum of n variables: 𝑦 = 𝑧1 + 𝑧2 + ⋯ + 𝑧𝑜

  • 1. Generate n random variate 𝑧𝑗's
  • 2. The random variate 𝑦 is given by the sum of 𝑧𝑗’s

Example: the sum of two fair dice that are rolled P(x=2) = 1/36; P(x=3) = 2/36; P(x=4) = 3/36; P(x=5) = 4/36; P(x=6) = 5/36; P(x=7) = 6/36; P(x=8) = 5/36; P(x=9) = 4/36; P(x=10) = 3/36; P(x=11) = 2/36; P(x=12) = 1/36 Convolution Method

15

slide-16
SLIDE 16

▪ Geometric (with parameter p) 𝑞 𝑜 = 𝑞 1 − 𝑞 𝑜−1, n = 1,2,3, … ▪ Gives the number of Bernoulli trials until achieving the first success

—let 𝑐 = 0, 𝑜 = 0 —while (𝑐 == 0) ▪ Generate Bernoulli variate 𝑐 with parameter 𝑞 ▪ Geometric variate 𝑜 = 𝑜 + 1

Geometric Variate

Inefficient!!

16

slide-17
SLIDE 17

▪ Binomial (with parameters p and 𝑜) 𝑞 𝑙 = ℙ(𝑌 = 𝑙) = 𝑜 𝑙 𝑞𝑙 1 − 𝑞 𝑜−𝑙 , 𝑙 = 0,1, … , 𝑜 Random variate generation

—Generate 𝑜 Bernoulli variates, 𝑧1, 𝑧2, … , 𝑧𝑜 —Binomial variate 𝑦 = 𝑧1 + 𝑧2 + ⋯ + 𝑧𝑜

Binomial Variate

17

slide-18
SLIDE 18

▪ Poisson (with parameter 𝜇) 𝑞 𝑙 = ℙ 𝑌 = 𝑙 =

𝜇𝑙 𝑙! 𝑓−𝜇, 𝑙 = 0,1,2, …

▪ Random variate generation (based on the relationship with exponential distribution)

— let 𝑡 = 0, 𝑜 = 0 — while (𝑡 ≤ 1) ▪ Generate exponential variate y with parameter 𝜇 ▪ 𝑡 = 𝑡 + 𝑧 ▪ 𝑜 = 𝑜 + 1 — Poisson variate 𝑦 = 𝑜 − 1

Poisson Variate

18

slide-19
SLIDE 19

▪ Normal (with parameters 𝜈 and 𝜏2) ▪ Random variate generation using approximation method

— Generate two random numbers u1 and u2 — Random variates 𝑦1and 𝑦2 are given by:

𝑦1 = 𝜈 + 𝜏 −2 ln(𝑣1) ⋅ cos(2𝜌𝑣2) 𝑦2 = 𝜈 + 𝜏 −2 ln(𝑣1) ⋅ sin(2𝜌𝑣2)

Other Techniques: Normal Variate

𝑔 𝑦 =

1 𝜏 2𝜌 𝑓−1

2 𝑦−𝜈 𝜏 2

, for −∞ ≤ 𝑦 ≤ +∞

19

slide-20
SLIDE 20

Could be used if no theoretical distributions fit the data adequately ▪ Example: Piecewise Linear empirical distribution

—Used for continuous data —Appropriate when a large

sample data is available

—Empirical CDF is approximated

by a piecewise linear function:

▪ the ‘jump points’ connected by linear functions

Empirical Distribution

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Piecewise Linear Empirical CDF

20

slide-21
SLIDE 21

▪ Piecewise Linear empirical distribution

— Organize 𝑌-axis into 𝐿 intervals — Interval 𝑗 is from 𝑏𝑗−1 to 𝑏𝑗 for 𝑗 = 1,2, … , 𝐿 — 𝑞𝑗: relative frequency of interval 𝑗 — 𝑑𝑗: relative cumulative frequency of interval 𝑗, i.e., 𝑑𝑗 = 𝑞1 + ⋯ + 𝑞𝑗 — Empirical CDF:

▪ If 𝑦 is in interval 𝑗, i.e., 𝑏𝑗−1 < 𝑦 ≤ 𝑏𝑗, then: 𝐺 𝑦 = 𝑑𝑗−1 + 𝛽𝑗 𝑦 − 𝑏𝑗−1 where, slope 𝛽𝑗 is given by 𝛽𝑗 = 𝑑𝑗 − 𝑑𝑗−1 𝑏𝑗 − 𝑏𝑗−1

Empirical Distribution

  • • •

𝑏0 𝑏𝐿 𝑏𝑗−1 𝑏𝑗 𝐿 intervals interval 𝑗

21

slide-22
SLIDE 22

▪ Suppose the data collected for 100 broken machine repair times are:

Example Empirical Distribution

i Interval (Hours) Frequency Relative Frequency Cumulative Frequency Slope 1 0.0 < x ≤ 0.5 31 0.31 0.31 0.62 2 0.5 < x ≤ 1.0 10 0.10 0.41 0.2 3 1.0 < x ≤ 1.5 25 0.25 0.66 0.5 4 1.5 < x ≤ 2.0 34 0.34 1.00 0.68

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0.5 1 1.5 2

Piecewise Linear Empirical CDF

Slope 𝛽3 =

𝑑3−𝑑2 𝑏3−𝑏2 = 0.5

𝑏0 𝑏2 𝑏3 𝑏4 𝑏1 22

slide-23
SLIDE 23

▪ Random variate generation:

—Generate random number 𝑣 —Select the appropriate interval 𝑗 such that

𝑑𝑗−1 < 𝑣 ≤ 𝑑𝑗

—Use the inverse transformation method to compute the

random variate 𝑦 as follows 𝑦 = 𝑏𝑗−1 +

1 𝛽𝑗 (𝑣 − 𝑑𝑗−1)

Empirical Distribution

23

slide-24
SLIDE 24

▪ Suppose the data collected for 100 broken machine repair times are: ▪ Suppose: 𝑣 = 0.83 𝑑3 = 0.66 < 𝑣 ≤ 𝑑4 = 1.00 ⇒ 𝑗 = 4 𝑦 = 𝑏3 + 1 𝛽4 𝑣 − 𝑑3 = 1.5 + 1 0.68 0.83 − 0.66 = 1.75

Example Empirical Distribution

i Interval (Hours) Frequency Relative Frequency Cumulative Frequency Slope 1 0.25 < x ≤ 0.5 31 0.31 0.31 1.24 2 0.5 < x ≤ 1.0 10 0.10 0.41 0.2 3 1.0 < x ≤ 1.5 25 0.25 0.66 0.5 4 1.5 < x ≤ 2.0 34 0.34 1.00 0.68

24