( Var iat e) A cak

( Var iat e) A cak

Now t hat we have lear ned how t o generat e a uniformly dist ribut ed random variable, we will st udy how t o produce random variables of ot her dist ribut ion using t he uniformly dist ribut ed random variable.

Thet echniques discussed include inverse t ransform and convolut ion. Also discussed is t he accept ance-reject ion t echnique. All work here assume t he exist ence of a source of uniform ( 0,1) random numbers,

8.1 Tekn ik Tr ansfor masi B alik

² The inverse t ransform t echnique can be used t o sample from exponen- t ial, t he uniform, t he Weibull and t he t riangle dist ribut ions.

² The basic principle is t o …nd t he inverse funct ion of F , F ¡1 such t hat

FF ¡1 =F F=1

²F ¡1 denot es t he solut ion of t he equat ion r = F (x) in t erms of r , not 1=F . For example, t heinverseof y = x is x = y, t heinverseof y = 2x+ 1 is x = (y ¡ 1)=2.

8.1.1 D i st r i busi Eksp onensi al

² pdf

¸e ¡¸x ;x¸0

1¡¸e ¡¸x ;x¸0

F (x) =

f ( t)dt =

The idea is t o solve y = 1 ¡ e ¡¸x for x where y is uniformly dist ribut ed on (0; 1) because it is a cdf. T hen x is exponent ially dist ribut ed. This met hod can be used for any dist ribut ion in t heory. But it is par- t icularly useful for random var iat es t hat t heir inverse funct ion can be easily solved.

St eps involved are as follows: St ep 1.

Comput e t he cdf of t he desired random variable X . For t he exponent ial dist ribut ion, t he cdf is F ( x) = 1 ¡ e ¡¸x .

St ep 2. Set R = F (X ) on t he r ange of X . For t he exponent ial dist ribut ion, R = 1 ¡ e ¸x on t he r ange of

x ¸ 0. . St ep 3. Solve t he equat ion F ( X ) = R for X in t erms of R. For t he

exponent ial dist ribut ion, t he solut ion proceeds as follows.

1¡e ¡¸X = R

e ¡¸X = 1¡R ¡¸X = ln(1 ¡ R)

ln(1 ¡ R)

Generat e (as needed) uniform random numbers R 1 ;R 2 ; : : : and comput e t he desir ed random variat es by

X i =F ¡1 (R i )

I n t he case of exponent ial dist ribut ion

ln(1 ¡ R i )

¸ for i = 1; 2; 3; :::where R i is a uniformly dist ribut ed random num-

ber on (0; 1).

I n pract ice, since bot h R i AND 1 ¡ R i are uniformly dist ribut ed random number, so t he calculat ion can be simpli…ed as

ln R i

To see why t his is correct , recall

Because X i ·x 0 is equivelant t o F ¡1 (R i )·x 0 , and F is a non-decr easing funct ion (so t hat if x · y t hen F (x) · F (y) ) we get X i ·x 0 is equivelant toF ¡1 (R i )·x 0 , which implies t hat F (F ¡1 (R i )) · F (x 0 )which is equivelant toR i · F (x 0 ). This means

P(X i ·x 0 ) = P(R i · F (x 0 )) Since R i is uniformly dist ribut ed on (0; 1) and F (x 0 ) is t he cdf of exponent ial

funct ion which is between 0 and 1, so

P(R i · F (x 0 )) = F (x 0 )

which means

P(X i ·x 0 ) = F (x 0 )

This says t he F ( x 0 ) is t he cdf for X and X has t he desired dist ribut ion. Once we have t his procedure est ablished, we can proceed t o solve ot her

8.1.2 D i st r i busi U ni for m

² I f we want a random variat e X uniformly dist ribut ed on t he int erval [a; b]; a reasonable guess for generat ing X is given by

X = a + (b¡ a)R

where R is uniformly dist r ibut ed on (0; 1) . ² I f we follow t he st eps out lined in previous sect ion, we get t he same

result . ² pdf for X

1=(b ¡ a) a · x · b

f (x) =

0 other wise

² St eps: St ep 1.

a·x·b

> : b¡ a

1 x¸b

St ep 2. Set F (X ) = (X ¡ a)=(b¡ a) = R St ep 3. Solve for X is t erms of R yields

X = a + (b ¡ a)R

which is t he same as t he earlier guess. St ep 4. Generat e R i as needed, calcualt e X i using t he funct ion obt ained.

8.1.3 D i st r i busi W ei bul l

² pdf

® ¯ x ¯¡1 e ¡ (x =®) ¯ ;x¸0

² St eps: St ep 1.

cdf

¡ ( x=®) F (x) = 1 ¡ e ¯ ; for x ¸ 0

St ep 2. let

F(X)=1¡e ¡ (X =®) ¯ =R

St ep 3. Solve for X in t erms of R yields

X = ®[¡ ln(1 ¡ R)] 1=¯

St ep 4. Generat e uniformly dist ribut ed from (0; 1) feeding t hem t o t he

funct ion in St ep 3 t o get X .

8.1.4 D i st r i busi Tri angul ar

2¡x1<x·2

0 other wise

I t s curve is shown on page 328 ² St eps

St ep 1. cdf

8 > 0 > x·0

< > x 2 =2

0<x·1

F (x) =

(2 ¡ x) 2

1<x·2

1 x>2

St ep 2.

St ep 3. Solve X in t erms of R

8.1.5 D i st r i busi K ont i ny u Em pi ri s

² I f t he modeler has been unable t o …nd a t heoret ical dist ribut ion t hat provides a good model for t he input dat a, it may be necessary t o use t he empirical dist ribut ion of t he dat a.

² A t ypical way of resolving t his di¢ cult is t hrough “ curve …tt ing” . ² St eps involved: (see Exmaple 9.2 on page 328)

– Collect empirical dat a and group t hem accor dingly. – Tabulat e t he frequency and cumulat ive frequency. – Now assume t he value of cumulat ive frequency as a funct ion of

t he empirical dat a, i.e.F (x) = r – Est ablish a relat ion between x and r using linear int er polat ion

for each of t he int ervals. ² Example 9.3 on page 332: not e t hat in t his example, … ve response t ime

are used which are all dist inct . If t here are values are t he same, or if t he number of samples are large, we can cert ainly gr oup t hem in t he di¤erent ways.

8.1.6 D i st r i busi K ont i nyu t anpa i nver s bent uk t er t ut up

² Many cont inuous dist ribut ions don’t have a closed-form inverse func- t ion. St rict ly speaking, t he inverse t ransform met hod discussed ear lier cannot be applied.

² I f we are willing t o accept numeric solut ion, inverse funct ions can be found. Here we have an example for normal dist ribut ion.

² One of t he inverse cdf of t hest andard normal dist ribut ion was proposed by Schmeiser:

for 0:0013499 · R · 0:9986501 which mat ches t he t rue normal dis- t ribut ion wit h one digit aft er decimal point . See Table 9.6 on page 335.

8.1.7 D i st r i busi D i sk r i t

² A ll discret e dist ribut ions can be gener at ed using t he inverse t ransform t echnique.

² This sect ion discusses t he case of empir ical dist ribut ion, ( discret e) uni- form dist ribut ion, and geomet ric dist ribut ion.

² Empirical discret e dist r ibut ion. The idea is t o collect and group t he dat a, t hen develop t he pdf and cdf. Use t his informat ion t o obt ain

F ¡1 so t hat X = F ¡1 (R) will be t he random number funct ion t hat we look for. Example 9.4 on page 336.

² Discret e Uniform Dist ribut ion (Example 9.5 on page 338) – pdf

p(x) = 1=k; x = 1; 2; : : : k

– cdf

< 0 x<1

F (x) =

i=k i · x · k; for 1 · i < k

1 k·x

– Let F (X ) = R

– Solve X in t erms of R. Since x is discret e,

i¡1

r i¡1 =

<R·r i =

t hus,

i¡1< Rk · i

Rk ·

i · Rk + 1

Consider t he fact t hat i and k are int egers and R is bet ween (0; 1). For t he above relat ion t o hold, we need

X = dRke

– For example, t o generat e a r andom variat e X , uniformly dist rib- ut ed on f 1; 2; :::; 10g (t hus k= 10)

R 1 = 0:78 X 1 = d7; 8e = 8 R 2 = 0:03 X 2 = d0:3e = 1 R 3 = 0:23 X 3 = d2:3e = 3 R 4 = 0:97 X 4 = d9:7e = 10

² Example 9.6 on page 339 gives us anot her ‡avor. When an inverse funct ion has more t han one solut ion, one has t o choose which one t o use. I n t he example, one result s in posit ive value and t he ot her result s in negat ive value. T he choice is obvious.

² Example 9.7 on page 340: Geomet ric dist ribut ion. – pmf

p(x) = p(1 ¡ p) x ; x = 0; 1; 2; : : : where 0 < p < 1

– cdf

F (x) =

p(1 ¡ p) j

j=0

p(1 ¡ (1 ¡ p) x+1 )

– Let R = F (x) , solve for x in t erm of R. Because t his is a discret e

random variat e, use t he inequality (9.12) on page 337,

F (x i¡1 )=r i¡1 <R·r i = F (x i ) t hat is

(x + 1) ln(1 ¡ p) · ln(1 ¡ R) · x ln( 1 ¡ p) Not ice t hat ln(1 ¡ p) < 0

ln(1 ¡ R)

ln(1 ¡ R)

¡1·x<

ln(1 ¡ p) Consider t hat x must be an int eger, so

ln(1 ¡ p)

ln(1 ¡ R)

X=

ln(1 ¡ p)

– Let ¯ = ¡ 1= ln(1 ¡ p) t he equat ion above becomes

X = d¡ ¯ ln(1 ¡ R) ¡ 1e

The it em in t he ceiling funct ion before subt ract ing one is t he func- t ion t o generat e exponent ially dist ribut ed variat e.

– Thus one way t o generat e geomet ric dist ribut ion is t o ¤ let ¸ = ¯ ¡1 = ¡ ln( 1¡ p) as t he paramet er t o t he exponent ial

dist ribut ion, ¤ generat e an exponent ially dist ribut ed variat e by

1 ¡ ln(1 ¡ R) ¸

¤ subt ract one and t ake t he ceiling – Example 9.8 on page 341

8.2 Tr ansfor masi L angsu ng D ist r i busi N or m al

I n t he previous sect ion, a simple, but less accurat e met hod of generat ing a normal dist ribut ion was present ed. Here we consider a direct t ransormat ion.

² Let Z 1 Z 2 be two st andard normal random variat es.

² Plot t he two as a point in t he plane and represent t hem in a polar coordinat e syst em as

B cosµ

B sin µ ² I t is known t hat B 2 =Z 2 1 +Z 2 2 has t he chi-squar e dist ribut ion wit h 2

degrees of freedom, which is equivalent t o an exponent ial dist ribut ion wit h mean2

Y ¡¸t = ¸e ;t¸0

E [Y ] = 2=¸

t hus t he raidus B can be generat ed using (9.3)

p B= ¡ 2 ln R

² So a normal dist ribut ion can be generat ed by any one of t he following.

¡ 2ln R 1 cos(2¼R 2 )

¡ 2ln R 1 sin(2¼R 2 )

where R 1 and R 2 are unifor mly dist ribut ed over (0,1). ² To obt ain normail variat es X i wit h mean ¹ and variance ¾ 2 , t ransform

X i = ¹ + ¾Z i

8.3 M et ode K onvolu si

² The probability dist ribut ion of a sum of two or mor e independent r an- dom variables is called a convolution of t he dist ribut ions of t he original

– an Er lang random variable X wit h paramet ers (K ; µ) can be shown t o be t he sum of K independent exponent ial random variables X i (i = 1; 2; : : : :K ), each having a mean 1=K µ

X=

i=1

– Using equat ion (9.3) t hat can gener at e exponent ial variable, an Erlang variat e can be generat ed by

² Example 9.9 on page 343

8.4 Tekn ik Pener i maan Penolakan ( A ccept ance- R ej ect ion )

² Example: use following st eps t o generat e uniformly dist ribut ed random

numbers bet ween 1/ 4 and 1. St ep 1.

Generat e a random number R St ep 2a.

I f R ¸ 1=4, accept X = R, got o St ep 3 St ep 2b.

I f R < 1=4, reject R, ret urn t o St ep 1 St ep 3.

I f anot her uniform random variat e on [1=4; 1] is needed, repeat t he procedure begining at St ep 1. Ot herwise st op.

– Do we know if t he r andom variat e generat ed using above met hods is indeed uniformly dist ribut ed over [1/ 4, 1]? The answer is Yes. To prove t his, use t he de… nit ion. Take any 1=4 · a < b · 1, – Do we know if t he r andom variat e generat ed using above met hods is indeed uniformly dist ribut ed over [1/ 4, 1]? The answer is Yes. To prove t his, use t he de… nit ion. Take any 1=4 · a < b · 1,

– The e¢ ciency: use t his met hod in t his part icular example, t he reject ion pr obabilit y is 1/ 4 on t he average for each number gener- at ed. The number of reject ions is a geomet rically dist r ibut ed r an- dom variable wit h probabilit y of “ success” being p = 3=4, mean number of reject ions is (1=p¡ 1) = 4=3¡ 1 = 1=3 (i.e. 1=3 wast e).

– For t his reason, t he inverse t ransform (X = 1=4+ (3=4)R) is more e¢ cient met hod.

² Poisson D ist r ibut ion – pmf

e ¡® ® n

p(n) = P(N = n) =

; n = 0; 1; 2; : : :

n!

where N can be int erpret ed as t he number of arr ivals in one unit t ime.

– From t he original Poisson pr ocess de… nit ion, we know t he int er- arrival t ime A 1 ;A 2 ; : : : are exponent ially dist ribut ed wit h a mean of ®, i.e. ® arrivals in one unit t ime.

– Relat ion bet ween t he t wo dist ribut ion:

N=n

if and only if

A 1 +A 2 +:::+A n ·1·A 1 +A 2 +:::+A n +A n+ 1 essent ially t his means if t here are n arrivals in one unit t ime, t he

sum of int erarrival t ime of t he past n observat ions has t o be less t han or equal t o one, but if one more int erarrival t ime is added, it is great er t hen one (unit t ime).

– The A i s in t he relat ion can be generat ed from unifor mly dist rib- ut ed random number A i = (¡ 1=®) ln R i , t hus

bot h sides are mult iplied by ¡ ®

– Now we can use t he Accept ance-Reject met hod t o generat e Pois- son dist ribut ion.

St ep 1. Set n = 0; P = 1.

St ep 2. Generat e a random number R n+ 1 and replace P by PR n+ 1 . St ep 3. IfP<e ¡® , t hen accept N = n, meaning at t his t ime unit , t here

are n ar rivals. Ot herwise, reject t he current n, incr ease nby one, ret urn t o St ep 2.

– E¢ ciency: How many random numbers will be requir ed, on t he average, t o generat e one Poisson variat e, N ? I f N = n, t hen n + 1 random numbers ar e required (because of t he (n + 1) random numbers product ).

E( N + 1) = ®+ 1

– Example 9.10 on page 346, Example 9.11 on page 347 – When is large, say ® ·

15, t he accept ance-reject ion t echnique described here becomes t oo expensive. Use nor mal dist ribut ion t o approximat e Poisson dist ribut ion. When ® is large

N¡® Z= p ®

is approximat ely normally dist ribut ed wit h mean 0 and var iance

1, t hus

N= ®+ ®Z ¡ 0:5

can be used t o generat e Poisson random variat e.