lecture 25 simulation and modeling md. tanvir al amin, lecturer, dept. of cse, buet cse 411

24
LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Upload: julianna-baldwin

Post on 03-Jan-2016

229 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

LECTURE 25

SIMULATION AND MODELINGMd. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET

CSE 411

Page 2: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Recap : Inverse Transform Method Find cumulative distribution function Let it be F Find F-1

X = F-1(R) is the desired variate where R ~ U(0,1)

Other methods are Accept Reject technique Composition method Convolution technique Special observations

Page 3: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Random variate for Continuous Distribution We already covered for continuous case :

Proof of inverse transform method(Kelton 8.2.1 pg440)

Exponential distribution (Banks 8.1.1) Uniform distribution (Banks 8.1.2) Weibull distibution (Banks 8.1.3) Triangular distribution (Banks 8.1.4) Empirical continuous distribution (Banks 8.1.5) Continuous distributions without a closed form

inverse (Self study – Banks 8.1.6)

Page 4: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Banks Chapter 8.1.7 + Kelton 8.2.1

Inverse Transform method for Discrete Distributions

Page 5: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Things to remember

If R ~ U(0,1), A Random variable X will assume value x whenever,

Also we should know the identities :

)(

)(1

)()1(

1

1

RFx

xRFx

xFRxF

1

1

1

1

xnxnx

xnxnx

nxnnx

nxnnx

We could use this identity also, It results in F-1(R) = floor(x) which is not useful because x is already an integer for discrete distribution.

Page 6: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Discrete Distributions

0 1 2 3

R1 = 0.65

F(x) = F(1) = 0.8

F(x-1) = F(0) = 0.4

X = 1

Page 7: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Empirical Discrete Distribution Say we want to find random variate for

the following discrete distribution.

At first find the F

x p(x)

0 0.50

1 0.30

2 0.20

x p(x) F(x)

0 0.50 0.50

1 0.30 0.80

2 0.20 1.00

2 ,1

21 ,8.0

10 ,5.0

0 ,0

)(

x

x

x

x

xF

Page 8: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Empirical Discrete Distribution

0 1 2 3

0.5

1.0

R1 = 0.73

0.1.80 ,2

8.05.0 ,1

5.0 ,0

R

R

R

X

Page 9: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Discrete Uniform Distribution

Consider kxk

xp ... 3 ,2 ,1 ,1

)(

xk

kxkk

k

xk

xk

x

xF

,1

1,1

32,2

21,1

1,0

)(

k

1

k

2

k

3

k

k 1

1

1 2 3 … K-1 k

Page 10: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Discrete Uniform Distribution Generate R~U(0,1)

k

1

k

2

k

3

k

k 1

1

1 2 3 … K-1 k

, output X= 1k

R1

0

output X= 2k

Rk

21

output X= 3k

Rk

32

, output X= ik

iR

k

i

1

output X= 4k

Rk

43

If generated

Page 11: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Discrete Uniform Distribution

, output X=1k

R1

0

, output X = i

, output 4

, output X=2k

Rk

21

, output X=3k

Rk

32

k

iR

k

i

1

kR

k

43

If generated

RkX

XRki

RkiRk

RkiiRk

iRkRki

iRkRki

iRkik

iR

k

i

output

1

1 and

and 1

and 1

1

1

Imp : Expand this method for a general discrete uniform distribution DU(a,b)

Page 12: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Discrete Uniform Distribution Algorithm to generate random variate

for p(x)=1/k where x = 1, 2, 3, … k

Generate R~U(0,1) uniform random number

Return ceil(R*k)

Page 13: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Geometric Distribution

1)1ln(

)1ln()(

1)1ln(

)1ln(

)1ln()1ln()1(

1)1(

)1(1

)1(1)1()(

...... 2, 1, 0, x where,)1()(

1

1

1

1

0

p

RRF

p

Rx

RPx

Rp

pR

pppxF

ppxp

x

x

xx

j

x

x

)()1( xFRxFRX

Recall :

1)1ln(

)1ln()(1

p

RRFX

Page 14: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Geometric Distribution

Algorithm to generate random variate for

Generate R~U(0,1) uniform random number

Return ceil(ln(1-R)/ln(1-p)-1)

...... 2, 1, 0, x where,)1()( xppxp

Page 15: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Proof of inverse transform method for Discrete case Kelton 8.2.1 Page 444 We need to show that ixpxXP ii allfor )()(

)()()()]()([)(

1)()(0

)(such that i chooses algorithm thesince,

),()( iff ,2 When,

)()( )1,0(~ since,

order) increasingin are the(since

)()( iff ,1for

11

1

1

11

111

iiiiii

ii

i

iii

i

xpxFxFxFUxFPxXP

xFxF

xFU

xFUxFxXi

xpxXPUU

x

xpxFUxXi

Page 16: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Disadvantage of Inverse Transform Method Kelton page 445-448 Disadvantage

Need to evaluate F-1. We may not have a closed form. In that case numerical methods necessary. Might be hard to find stopping conditions.

For a given distribution, Inverse transform method may not be the fastest way

Page 17: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Advantage ofInverse Transform Method Straightforward method, easy to use Variance reduction techniques has an

advantage if inverse transform method is used

Facilitates generation of order statistics.

Page 18: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Kelton 8.2.2

Composition Technique

Page 19: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Composition Technique

Applies when the distribution function F from which we wish to generate can be expressed as a convex combination of other distributions F1, F2, F3, …

i.e., for all x, F(x) can be written as

1

)()(j

jj xFpxF

Page 20: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Composition Algorithm

To generate random variate for Step 1 : Generate a positive random integer

j such that

Step 2 : Return X with distribution function Fj

1

)()(j

jj xFpxF

jpjJP )(

Page 21: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Geometric Interpretation

For a continuous random variable X with density f, we might be able to divide the area under f into regions of areas p1,p2,…(corresponding to the decomposition of f into its convex combination representation)

Then we can think of step 1 as choosing a region Step 2 as generating from the distribution

corresponding to the chosen region

Page 22: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Example

1 ,0

11,1

1

1 ,1

1

0,1

0 ,0

)(

x

xaa)a(

x

axaa

axa)a(

xx

xf

0 a 1-a 1

Page 23: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Example

a

aarea

a)a(

xxF

aa

xxf

1

2/

12)(

)1()(

2

a

aarea

a)(

xxF

axf

1

21

1)(

)1(

1)(

a

aarea

a)(

xaxF

aa

axf

1

2/

1

)1()(

)1(

1)(

Page 24: LECTURE 25 SIMULATION AND MODELING Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET CSE 411

Proof of composition technique Kelton page 449