Computer Science, Informatik 4 Communication and Distributed Systems Simulation Simulation Modeling and Performance Analysis with Discrete-Event Simulation g y Dr. Mesut Güneş
Computer Science, Informatik 4 Communication and Distributed Systems Chapter 7 Random-Variate Generation
Computer Science, Informatik 4 Communication and Distributed Systems Contents Contents � Inverse-transform Technique Inverse transform Technique � Acceptance-Rejection Technique � Special Properties p p Dr. Mesut Güneş Chapter 7. Random-Variate Generation 3
Computer Science, Informatik 4 Communication and Distributed Systems Purpose & Overview Purpose & Overview � Develop understanding of generating samples from a Develop understanding of generating samples from a specified distribution as input to a simulation model. � Illustrate some widely-used techniques for generating random variates. • Inverse-transform technique I t f t h i • Acceptance-rejection technique • Special properties Special properties Dr. Mesut Güneş Chapter 7. Random-Variate Generation 4
Computer Science, Informatik 4 Communication and Distributed Systems Preparation Preparation � It is assumed that a source of uniform [0,1] random numbers It is assumed that a source of uniform [0,1] random numbers exists. • Linear Congruential Method (LCM) � Random numbers R , R 1 , R 2 , … with • PDF PDF ≤ ≤ ⎧ 1 0 1 x = ( ( ) ) ⎨ ⎨ f R f R x 0 0 otherwise th i ⎩ ⎩ • CDF < ⎧ 0 0 x ⎪ = ≤ ≤ ( ) 0 1 ⎨ F R x x x ⎪ ⎪ > 1 1 ⎩ x Dr. Mesut Güneş Chapter 7. Random-Variate Generation 5
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique Inverse transform Technique Dr. Mesut Güneş Chapter 7. Random-Variate Generation 6
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique Inverse-transform Technique � The concept: The concept: • For CDF function: r = F(x) • Generate r from uniform (0,1) , a.k.a U (0,1) • Find x , x = F -1 ( r ) F ( x ) F ( x ) 1 1 1 1 r = F ( x ) r = F(x) r 1 r 1 x x x 1 x 1 Dr. Mesut Güneş Chapter 7. Random-Variate Generation 7
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique Inverse-transform Technique The inverse-transform technique can be used in principle for The inverse transform technique can be used in principle for � any distribution. Most useful when the CDF F ( x ) has an inverse F -1 ( x ) which � is easy to compute. Required steps R i d t � 1. Compute the CDF of the desired random variable X . 2 2. Set F(X) R on the range of X . Set F(X) = R on the range of X 3. Solve the equation F(X) = R for X in terms of R . 4. Generate uniform random numbers R 1 , R 2 , R 3 , … and compute the desired random variate by X i = F -1 ( R i ) Dr. Mesut Güneş Chapter 7. Random-Variate Generation 8
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Example Inverse-transform Technique – Example Exponential Distribution p To generate X 1 , X 2 , X 3 … g � � 1 , 2 , 3 • PDF − λ − = 1 X e R − λ = λ ( ) x f x e − λ = − 1 X e R • CDF − λ λ = − ln( ln( 1 1 ) ) = 1 = 1 − − λ ( ( ) ) X X R R x F F x x e e − ln( 1 ) R = X − λ λ Simplification � − ln( 1 ) R = − X ln( R ln( R ) ) λ λ = − X λ 1 R − = ( ) X F • • Since R and (1 R ) are Since R and (1- R ) are uniformly distributed on [0,1] Dr. Mesut Güneş Chapter 7. Random-Variate Generation 9
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Example Inverse-transform Technique – Example Inverse-transform technique for exp( λ = 1) q p( ) Dr. Mesut Güneş Chapter 7. Random-Variate Generation 10
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Example Inverse-transform Technique – Example Example: Generate 200 variates X i with distribution exp( λ = 1) Example: Generate 200 variates X i with distribution exp( λ 1) � • Generate 200 R s with U (0,1) , the histogram of X s becomes: 0,7 0,6 0,5 0,4 0 3 0,3 0,2 0,1 0,1 0 0,5 1 1,5 2 2,5 3 3,5 4 4,5 5 5,5 6 6,5 7 Empirical Histogram Empirical Histogram Theor PDF Theor. PDF Dr. Mesut Güneş Chapter 7. Random-Variate Generation 11
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique Inverse-transform Technique Check: Does the random variable X 1 have the desired distribution? � 1 ≤ = ≤ = ( ) ( ( )) ( ) P X x P R F x F x 1 0 1 0 0 Dr. Mesut Güneş Chapter 7. Random-Variate Generation 12
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Other Distributions Inverse-transform Technique – Other Distributions � Examples of other distributions for which inverse CDF works Examples of other distributions for which inverse CDF works are: • Uniform distribution • Weibull distribution • Triangular distribution Dr. Mesut Güneş Chapter 7. Random-Variate Generation 13
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Uniform Distribution Inverse-transform Technique – Uniform Distribution � Random variable X uniformly distributed over [ a , b ] Random variable X uniformly distributed over [ a , b ] = ( ( ) ) F F X X R R − X a = R − b b a − = − ( ) X a R b a = + − ( ) X a R b a Dr. Mesut Güneş Chapter 7. Random-Variate Generation 14
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Weibull Distribution Inverse-transform Technique – Weibull Distribution The Weibull Distribution is The variate is � � described by = ( ) F X R ( ) ( ) β − • PDF PDF − X X = 1 α e R β ( ) β − β − ( ) = x 1 ( ) β α f x x e − X = − 1 β α α α e R ( ) β − = − ln( 1 ) X R α β β • • CDF CDF X X = − − ln( 1 ) ( ) R β − = 1 − x β α ( ) α F X e β β = − α α β β ⋅ − ln( ln( 1 1 ) ) X X R R β = β − α ⋅ − ln( 1 ) x R = α ⋅ − − β ln( 1 ) X R Dr. Mesut Güneş Chapter 7. Random-Variate Generation 15
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Triangular Distribution Inverse-transform Technique – Triangular Distribution The CDF of a Triangular g � Distribution with endpoints (0, 2) is given by ≤ 0 ⎧ 0 x ⎧ 2 X ⎪ ⎪ 2 ≤ ≤ ≤ ≤ 0 0 1 1 x x ⎪ ⎪ X X < ≤ ⎪ ⎪ 0 1 ⎪ x 2 = ⎪ ( ) ⎨ 2 R X = ( ) − ⎨ 2 ( 2 ) F x X ⎪ − 2 ( 2 ) − ≤ ≤ 1 1 2 x ⎪ ⎪ X − < < ≤ ≤ ⎪ ⎪ 1 1 1 1 2 2 x x ⎩ ⎩ 2 2 ⎪ ⎪ 2 ⎪ > 1 2 ⎩ x X is generated by X is generated by � � ⎧ ≤ ≤ ⎪ 2 0 1 R R = 2 ⎨ ⎨ X X ⎪ − − < ≤ 2 2 ( 1 ) 1 1 ⎩ R R 2 Dr. Mesut Güneş Chapter 7. Random-Variate Generation 16
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Empirical Continuous Distributions Inverse-transform Technique – Empirical Continuous Distributions When theoretical distributions are not applicable e eo e ca d s bu o s a e o app cab e � To collect empirical data: � • Resample the observed data • • Interpolate between observed data points to fill in the gaps Interpolate between observed data points to fill in the gaps Dr. Mesut Güneş Chapter 7. Random-Variate Generation 17
Computer Science, Informatik 4 Communication and Distributed Systems Inverse-transform Technique – Empirical Continuous Distributions Inverse-transform Technique – Empirical Continuous Distributions For a small sample set (size n ): p ( ) � • Arrange the data from smallest to largest ≤ ≤ … ≤ x x x (1) (2) (n) • Set x (0) =0 ≤ ≤ = x x x 1 , 2 , , K • Assign the probability 1/ n to each interval i n (i - 1) (i) • The slope of each line segment is defined as The slope of each line segment is defined as − − x x x x − − = ( ) ( 1 ) = ( ) ( 1 ) i i i i a − ( 1 ) 1 i i i − n n n • The inverse CDF is given by − ⎛ ⎛ ⎞ ⎞ − ) ( ( 1 1 ) ) ( ( 1 1 ) i i i i i i ˆ = − = + − 1 ⎜ ⎟ < ≤ ( ) X F R x a R when R − ( 1 ) i i ⎝ ⎠ n n n Dr. Mesut Güneş Chapter 7. Random-Variate Generation 18
Recommend
More recommend