Sunteți pe pagina 1din 22

Section 6.

3: Discrete Random Variable Applications


Discrete-Event Simulation: A First Course
c 2006 Pearson Ed., Inc. 0-13-142917-5

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

1/ 22

Section 6.3: Discrete Random Variable Applications

Example 6.3.1: The inventory demand model in program sis2 The demand per time interval is an Equilikely(10,50) random variate = 30, = 140 = 11.8, and the demand pdf is at
0.10 f (d) 0.05 0 d

10

20

30

40

50

This model is not very realistic (see Chapter 9)

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

2/ 22

Alternative Inventory Demand Model


Consider a Binomial(100,0.3) model
100 instances per time interval when demand for 1 unit may occur The probability of demand is 0.3 per instance (independently) The function GetDemand in sis2 becomes:

Modied GetDemand Method


long GetDemand(void) { return (Binomial(100,0.3)); }

= 30, =
0.10 f (d) 0.05 0

21 = 4.6 and the pdf is:

10

20

30

40

50

d
3/ 22

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

Example 6.3.2: A Poisson(30) Model


Recall that Binomial (n, p ) Poisson(np ) for large n If Binomial(100, 0.3) is realistic, should also consider Poisson(30) The function GetDemand in program sis2 would be Modied GetDemand Method
long GetDemand(void) { return (Poisson(30.0)); }

= 30, =

30 = 5.5 and the pdf has slightly heavier tails


0.10

f (d) 0.05 0 d

10

20

30

40

50

Poisson() is the inventory demand model used in sis3 with = 30


Discrete-Event Simulation: A First Course Section 6.3: Discrete Random Variable Applications 4/ 22

Example 6.3.3: A Pascal(50,0.375) Model


50 instances per time interval The demand per instance is Geometric(p) with p = 0.375 The function GetDemand in program sis2 would be Modied GetDemand Method
long GetDemand(void) { return return (Pascal(50,0.375)); }

= 30, = 48 = 6.9 and the pdf has heavier tails than the Poisson(30) pdf
0.10 f (d) 0.05 0 d
5/ 22

10

20

30

40

50

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

Example 6.3.4
The number of demand instances per time interval is Poisson(50) The demand per instance is Geometric(p) with p = 0.375 Modied GetDemand Method
long GetDemand(void) { long instances = Poisson(50.0); /* avoid 0 */ return (Pascal(instances, 0.375)); }

= 30, =
0.10 f (d) 0.05 0

66 = 8.1 and the pdf has heavier tails

10

20

30

40

50

d
6/ 22

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

The pdf in Example 6.3.4


Dene random variables
D : the demand amount I : the number of demand instances per time interval

f (d ) = Pr(D = d ) =
i =0

Pr(I = i ) Pr(D = d |I = i ) d = 0, 1, 2, ...

To compute f (d ), truncate innite sum: 0 < a i b Computing f (d )


/* use the library rvms */ double sum = 0.0; for (i = a; i <= b; i++) sum += pdfPoisson(50.0,i) * pdfPascal(i,0.375,d); return sum; /* sum is f(d) */

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

7/ 22

Program sis4

Based on sis3 but with a more realistic inventory demand model The inter-demand time is an Exponential(1/) random variate Whether or not a demand occurs at demand instances is random with probability p To allow for the possibility of more than 1 unit of demand, the demand amount is a Geometric(p) random variate Expected demand per time interval is p (1 p )

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

8/ 22

Example 6.3.5: The Auto Dealership


The inventory demand model for sis4 corresponds to customers per week on average Each customer will buy
0 autos with probability 1 p 1 auto with probability (1 p )p 2 autos with probability (1 p )p 2 , etc.

With = 120.0 and p = 0.2, average demand is 30.0


30.0 =
X p x (1p )p x = (1 p )p + 2(1 p )p 2 + 3(1 p )p 3 + = 1p | {z } | {z } | {z } x =0 19.2000 7.680 2.304

(1 p ) = 96.0 customers buy 0 autos

(1 p )p = 19.200 customers buy 1 auto

(1 p )p 2 = 3.840 customers buy 2 autos


Discrete-Event Simulation: A First Course

(1 p )p 3 = 0.768 customers buy 3 autos, etc.


Section 6.3: Discrete Random Variable Applications 9/ 22

Truncation

In the previous example, no bound on number of autos purchased Can be made more realistic by truncating possible values Start with random variable X with possible values X = {0, 1, 2, . . . } and cdf F (x ) = Pr (X x ) If a > 0,

Want to restrict X to the nite range 0 a x b < = Pr(X > b ) = 1 Pr(X b ) = 1 F (b )

= Pr(X < a) = Pr(X a 1) = F (a 1)

Pr(a X b ) = Pr(X b ) Pr(X < a) = F (b ) F (a 1) Essentially, always true i F (b ) = 1.0 and F (a 1) = 0.0

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

10/ 22

Specifying truncation points

If a and b are specied


Left-tail, right-tail probabilities and obtained using cdf = Pr (X < a) = F (a1) Transformation is exact and = Pr (X > b ) = 1F (b )

If and are specied


Idf can be used to obtain a and b a = F () and b = F (1 )

Transformation is not exact because X is discrete Pr(X < a) and Pr(X > b ) <

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

11/ 22

Example 6.3.6
For the Poisson(50) random variable I , determine a, b so that Pr(a I b ) = 1.0 Use = = 106 Use rvms to compute Determining a, b
a = idfPoisson(50.0,); /* = 106 */ b = idfPoisson(50.0,1.0 - ); /* = 106 */

Results: a = 20 and b = 87 Consistent with the bounds produced by the conversion: Pr(I < 20) = cdfPoisson(50.0, 19) = 0.48 106 <
Section 6.3: Discrete Random Variable Applications

Pr(I > 87) = 1.0 cdfPoisson(50.0, 87) = 0.75 106 <


Discrete-Event Simulation: A First Course 12/ 22

Eects of Truncation

Truncating Poisson(50) to the range {20, . . . , 87} is insignicant: truncated and un-truncated random variables have (essentially) the same distribution Truncation is useful for eciency:
When idf is complex, inversion requires cdf search cdf values are typically stored in an array Small range gives improved space/time eciency

Truncation is useful for realism:


Prevents arbitrarily large values possible from some variates

In some applications, truncation is signicant


Produces a new random variable Must be done correctly

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

13/ 22

Incorrect Truncation
Use a Poisson(30) demand model in program sis2 Truncate the demand to the range 20 d 40 Incorrect Truncation
d = Poisson(30.0); if (d < 20) d = 20; if (d > 40) d = 40; return d;

Original left and right tails grouped together at 20 and 40


0.10 f (d) 0.05 0 d

10

20

30

40

50

This is incorrect for most applications


Discrete-Event Simulation: A First Course Section 6.3: Discrete Random Variable Applications 14/ 22

Truncation by cdf Modication (1)


Example 6.3.8: Truncate Poisson(30) demands to range 20 d 40 The Poisson(30) pdf is (before truncation) f (d ) = exp (30) 30d d!

d = 0, 1, 2, ...
40

Pr(20 D 40) = F (40) F (19) =

d =20

f (d ) = 0.945817

Compute a new truncated random variable Dt with pdf ft (d ) ft (d ) = f (d ) F (40) F (19) d = 20, 21, ..., 40

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

15/ 22

Truncation by cdf Modication (2)

The corresponding truncated cdf is


d

Ft (d ) =
t =20

ft (t ) =

F (d ) F (19) F (40) F (19)

d = 20, 21, ..., 40

Mean and standard deviation of Dt


t =
40 X

dft (d ) = 29.841

and

d =20

v u 40 uX (d t )2 ft (d ) t = t = 4.720
d =20

Mean and standard deviation of Poisson(30) = 30.0 and = 30 = 5.477

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

16/ 22

Truncation by cdf Modication (3)


A random variate truncated to 20 d 40 can be generated by inversion, using the truncated cdf Ft () and Alg.6.2.2 Truncation by cdf Modication
u = Random(); d = 30; if (Ft (d) <= u) while (Ft (d) <= u) d++; else if (Ft (20) <= u) while (Ft (d-1) > u) d--; else d = 20; return d;

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

17/ 22

Illustration of pdfs
0.10 f (d) 0.05 0 0.10 f (d) 0.05 0 0.10 f (d) 0.05 0 Poisson(30) correctly truncated d

10 Poisson(30) incorrectly truncated

20

30

40

50

10 Poisson(30) not truncated

20

30

40

50

10

20

30

40

50

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

18/ 22

Truncation By cdf Modication In General

To truncate (integer-valued, discrete) X to possible values Xt = {a, a + 1, , b } X ft (x ) = Ft (x ) = f (x ) F (b ) F (a 1) F (x ) F (a 1) F (b ) F (a 1) x Xt x Xt

Above equations assume a 1 X

Random values of Xt can be generated using inversion and Alg.6.2.2 with cdf Ft ()

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

19/ 22

Truncation by Constrained Inversion


Use the idf of X to generate Xt truncated to a x b Truncation by Constrained Inversion
/* assumes a - 1 is a possible value of X */ = F (a-1); = 1.0 - F (b ); u = Uniform(, 1.0 - ); x = F (u ); /* F () is the idf of X */ return x ;

The key is that u is constrained to a subrange (, 1 ) (0, 1)

Truncation is automatically enforced prior to inversion

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

20/ 22

Example 6.3.9

Generate a Poisson(30) random demand truncated to 20 d 40 Example 6.3.9


= cdfPoisson(30.0, 19); /*set-up*/ = 1.0 - cdfPoisson(30.0, 40); /*set-up*/ u = Uniform(, 1.0 - ); d = idfPoisson(30.0, u ); return d ;

Uses library rvms and are static variables that are computed once only

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

21/ 22

Truncation By Acceptance-Rejection

Truncate Poisson(30) by using acceptance-rejection Truncation By Acceptance-Rejection


d = Poisson(30.0); while ((d < 20) or ( d > 40)) d = Poisson(30.0); return d ;

Acceptance-rejection is not synchronized or monotone even if the un-truncated generator has these properties Truncation by cdf modication or constrained inversion is preferable

Discrete-Event Simulation: A First Course

Section 6.3: Discrete Random Variable Applications

22/ 22

S-ar putea să vă placă și