Lecture 25 - Tanvir Amin

advertisement
LECTURE 25
SIMULATION AND MODELING
CSE 411
Md. Tanvir Al Amin, Lecturer, Dept. of CSE, BUET
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
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)
Inverse Transform method for Discrete Distributions
Banks Chapter 8.1.7 + Kelton 8.2.1
Things to remember

If R ~ U(0,1), A Random variable X will assume
value x whenever,
F ( x  1)  R  F ( x)
 x  1  F 1 ( R)  x
 x  F 1 ( R)

Also we should know the identities :
x   n  n  x  n  1
x   n  n  1  x  n
x   n  x  1  n  x
x   n  x  n  x  1
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.
Discrete Distributions
F(x) = F(1) = 0.8
R1 = 0.65
F(x-1) = F(0) = 0.4
0
X=1
1
2
3
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
 0,
 0.5,

F ( x)  
0.8,
 1,
x0
0  x 1
1 x  2
x2
Empirical Discrete Distribution
 0, R  0.5

X   1, 0.5  R  0.8
2, 0.8  R  1.0

1.0
R1 = 0.73
0.5
0
1
2
3
Discrete Uniform Distribution

Consider
p ( x) 
x 1
 0,
 1
1 x  2
 ,
k
 2

2 x3
F ( x)   k ,
 

 k 1
, k 1  x  k

k

kx
 1,
1
, x  1, 2, 3 ... k
k
1
k 1
k
3
k
2
k
1
k
1
2
3
…
K-1
k
Discrete Uniform Distribution
Generate R~U(0,1)

1 , output X= 1
k
1
2
 R  output X= 2
k
k
2
3
 R  output X= 3
k
k
3
4 output X= 4
R
k
k
If generated 0  R 
1
k 1
k
3
k
2
k
1
k
1
2
3
…
K-1
k
i 1
i
 R  , output X= i
k
k
Discrete Uniform Distribution
1 , output X=1
If generated
k
1
2
 R  , output X=2
k
k
2
3
 R  , output X=3
k
k
3
4
, output 4
R
k
k
0R
i 1
i
 R  , output X = i
k
k
i 1
i
R
k
k
 i  1  Rk  i
 i  1  Rk and Rk  i
 i  Rk  1 and Rk  i
 Rk  i and i  Rk  1
 Rk  i  Rk  1
 i  Rk   out put X
 X  Rk 
Imp : Expand this method for a general discrete uniform distribution DU(a,b)
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)
Geometric Distribution
p ( x)  p (1  p ) x , where x  0,1, 2, ......
x
F ( x)   p (1  p ) x  1  (1  p ) x 1
j 0
R  1  (1  p ) x 1
 (1  p ) x 1  1  R
 ( x  1) ln(1  P)  ln(1  R)
ln(1  R )
x
1
ln(1  p )
ln(1  R)
1
F ( R) 
1
ln(1  p )
Recall :
X  R  F ( x  1)  R  F ( x)
 ln(1  R) 
X  F ( R)  
 1
 ln(1  p) 
1
Geometric Distribution

Algorithm to generate random variate for
p( x)  p(1  p) x , where x  0,1, 2, ......
 Generate
R~U(0,1) uniform random number
 Return ceil(ln(1-R)/ln(1-p)-1)
Proof of inverse transform method
for Discrete case


Kelton 8.2.1 Page 444
We need to show that P( X  xi )  p( xi ) for all i
for i  1, X  x1 iff U  F ( x1 )  p ( x1 )
(since the xi are in increasingorder)
since,U ~ U (0,1) P( X  x1 )  p ( x1 )
When, i  2, X  xi iff F ( xi 1 )  U  F ( xi ),
since, thealgorithmchoosesi such thatU  F ( xi )
0  F ( xi 1 )  F ( xi )  1
P ( X  xi )  P[ F ( xi 1 )  U  F ( xi )]  F ( xi )  F ( xi 1 )  p ( xi )
Disadvantage of
Inverse Transform Method


Kelton page 445-448
Disadvantage
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
 Need
Advantage of
Inverse Transform Method



Straightforward method, easy to use
Variance reduction techniques has an advantage if
inverse transform method is used
Facilitates generation of order statistics.
Composition Technique
Kelton 8.2.2
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

F ( x)   p j F j ( x)
j 1
Composition Algorithm


To generate random variate for F ( x)   p j F j( x)
 Step
j 1
1 : Generate a positive random integer j such that
P( J  j )  p j
 Step
2 : Return X with distribution function Fj
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
Example
0, x  0


x
,0  x  a

 a(1  a)
 1
f ( x)  
, a  x  1 a
 1 a
 1  x ,1  a  x  1
 a(1  a)

0, x  1

0
a
1-a
1
Example
f ( x) 
x
a(1  a)
x2
F ( x) 
2a(1  a)
a/2
area 
1 a
1
(1  a )
x
F ( x) 
( 1  a)
1  2a
area 
1 a
f ( x) 
1 a
a (1  a )
(1  a ) x
F ( x) 
( 1  a)
a/2
area 
1 a
f ( x) 
Proof of composition technique

Kelton page 449
Download