simulation simulation
play

Simulation Simulation Modeling and Performance Analysis with - PowerPoint PPT Presentation

Computer Science, Informatik 4 Communication and Distributed Systems Simulation Simulation Modeling and Performance Analysis with Discrete-Event Simulation g y Dr. Mesut Gne Computer Science, Informatik 4 Communication and Distributed


  1. Computer Science, Informatik 4 Communication and Distributed Systems Simulation Simulation Modeling and Performance Analysis with Discrete-Event Simulation g y Dr. Mesut Güneş

  2. Computer Science, Informatik 4 Communication and Distributed Systems Chapter 6 Random-Number Generation

  3. Computer Science, Informatik 4 Communication and Distributed Systems Contents Contents � Properties of Random Numbers Properties of Random Numbers � Generation of Pseudo-Random Numbers • Linear Congruential Method � Tests for Random Numbers Dr. Mesut Güneş Chapter 6. Random-Number Generation 3

  4. Computer Science, Informatik 4 Communication and Distributed Systems Purpose & Overview Purpose & Overview � Discuss the generation of random numbers. Discuss the generation of random numbers. � Introduce the subsequent testing for randomness: • Frequency test • Autocorrelation test. Dr. Mesut Güneş Chapter 6. Random-Number Generation 4

  5. Computer Science, Informatik 4 Communication and Distributed Systems Properties of Random Numbers Properties of Random Numbers Two important statistical properties: Two important statistical properties: � • Uniformity • Independence. Random Number, R i , must be independently drawn from a uniform � distribution with pdf: ≤ ≤ ⎧ 1 , 0 x 1 = f f ( ( x ) ) ⎨ ⎨ 0 , otherwise ⎩ 1 2 x x 1 1 1 1 = ∫ ∫ = = E ( R ) xdx 2 2 0 0 pdf for random numbers Dr. Mesut Güneş Chapter 6. Random-Number Generation 5

  6. Computer Science, Informatik 4 Communication and Distributed Systems Generation of Pseudo-Random Numbers Generation of Pseudo Random Numbers Dr. Mesut Güneş Chapter 6. Random-Number Generation 6

  7. Computer Science, Informatik 4 Communication and Distributed Systems Generation of Pseudo-Random Numbers Generation of Pseudo-Random Numbers “Pseudo”, because generating numbers using a known method Pseudo , because generating numbers using a known method � removes the potential for true randomness. Goal: To produce a sequence of numbers in [0,1] that simulates, or � imitates the ideal properties of random numbers (RN) imitates, the ideal properties of random numbers (RN). Important considerations in RN routines: � • Fast • Portable to different computers • Have sufficiently long cycle • Replicable Replicable • Closely approximate the ideal statistical properties of uniformity and independence Dr. Mesut Güneş Chapter 6. Random-Number Generation 7

  8. Computer Science, Informatik 4 Communication and Distributed Systems Generation of Pseudo-Random Numbers Generation of Pseudo-Random Numbers � Problems when generating pseudo-random numbers Problems when generating pseudo random numbers • The generated numbers might not be uniformly distributed • The generated numbers might be discrete-valued instead of continuous-valued • The mean of the generated numbers might be too high or too low • The variance of the generated numbers might be too high or too • The variance of the generated numbers might be too high or too low • There might be dependence: - Autocorrelation between numbers - Numbers successively higher or lower than adjacent numbers - Several Numbers above the mean followed by several numbers Several Numbers above the mean followed by several numbers below the mean Dr. Mesut Güneş Chapter 6. Random-Number Generation 8

  9. Computer Science, Informatik 4 Communication and Distributed Systems Techniques for Generating Random Numbers Techniques for Generating Random Numbers Dr. Mesut Güneş Chapter 6. Random-Number Generation 9

  10. Computer Science, Informatik 4 Communication and Distributed Systems Techniques for Generating Random Numbers Techniques for Generating Random Numbers Linear Congruential Method (LCM) g ( ) � Combined Linear Congruential Generators (CLCG) � Random-Number Streams � Dr. Mesut Güneş Chapter 6. Random-Number Generation 10

  11. Computer Science, Informatik 4 Communication and Distributed Systems Linear Congruential Method Linear Congruential Method To produce a sequence of integers X 1 , X 2 , … between 0 and m -1 p q g � 1 2 by following a recursive relationship: = + + = X X ( ( aX aX c c ) ) mod mod m m , i i 0 0 , 1 1 , 2 2 ,... + i i 1 1 i i The The The modulus modulus multiplier increment The selection of the values for a , c , m , and X 0 drastically affects The selection of the values for a , c , m , and X 0 drastically affects � the statistical properties and the cycle length. The random integers are being generated [ 0,m- 1 ], and to convert � the integers to random numbers: the integers to random numbers: X = = i R , i 1 , 2 ,... i m m Dr. Mesut Güneş Chapter 6. Random-Number Generation 11

  12. Computer Science, Informatik 4 Communication and Distributed Systems Linear Congruential Method – Example Linear Congruential Method – Example Use X 0 = 27, a = 17, c = 43 , and m = 100 . , � , , 0 The X i and R i values are: � X 1 = (17*27+43) mod 100 = 502 mod 100 = 2, R 1 = 0.02; X 2 = (17*2 +43) mod 100 = 77, R 2 = 0.77; X 3 = (17*77+43) mod 100 = 52, ( 7 77 3) od 00 5 , R 3 = 0.52; 0.5 ; 3 3 X 4 = (17*52+43) mod 100 = 27, R 3 = 0.27; … Dr. Mesut Güneş Chapter 6. Random-Number Generation 12

  13. Computer Science, Informatik 4 Communication and Distributed Systems Linear Congruential Method – Example Linear Congruential Method – Example i X i X i X i X i � Use a = 13 c = 0 and � Use a = 13, c = 0 , and X 0 =1 X 0 =2 X 0 =3 X 0 =4 1 1 2 3 4 m = 64 2 13 26 39 52 � The period of the � The period of the 3 3 41 41 18 18 59 59 36 36 4 21 42 63 20 generator is very low 5 17 34 51 4 6 29 58 23 7 57 50 43 8 37 10 47 9 33 2 35 10 10 45 45 7 7 11 9 27 12 53 31 13 13 49 49 19 19 14 61 55 15 25 11 16 5 15 17 1 3 Dr. Mesut Güneş Chapter 6. Random-Number Generation 13

  14. Computer Science, Informatik 4 Communication and Distributed Systems Characteristics of a Good Generator Characteristics of a Good Generator Maximum Density � • Such that the values assumed by R i , i= 1,2,… leave no large gaps on [0,1] • Problem: Instead of continuous, each R i is discrete i • Solution: a very large integer for modulus m - Approximation appears to be of little consequence Maximum Period � • To achieve maximum density and avoid cycling. • • Achieved by proper choice of a c m and X Achieved by proper choice of a , c , m , and X 0 . Most digital computers use a binary representation of numbers � • Speed and efficiency are aided by a modulus, m , to be (or close to) a power of 2. Dr. Mesut Güneş Chapter 6. Random-Number Generation 14

  15. Computer Science, Informatik 4 Communication and Distributed Systems Random-Numbers in Java Random-Numbers in Java � Defined in java.util.Random Defined in java.util.Random private final static long multiplier = 0x5DEECE66DL; // 25214903917 private final static long addend = 0xBL; // 11 i t fi l t ti l dd d 0 BL // 11 private final static long mask = (1L << 48) - 1; // 281474976710655 protected int next(int bits) { protected int next(int bits) { long oldseed, nextseed; ... oldseed = seed.get(); nextseed = (oldseed * multiplier + addend) & mask; ... return (int)(nextseed >>> (48 - bits)); // >>> Unsigned right shift } Dr. Mesut Güneş Chapter 6. Random-Number Generation 15

  16. Computer Science, Informatik 4 Communication and Distributed Systems Combined Linear Congruential Generators Combined Linear Congruential Generators Reason: Longer period generator is needed because of the Reason: Longer period generator is needed because of the � increasing complexity of simulated systems. Approach: Combine two or more multiplicative congruential � generators. Let X i,1 , X i,2 , …, X i,k , be the i -th output from k different multiplicative � congruential generators. • The j -th generator: - Has prime modulus m j and multiplier a j and period is m j - 1 - Produces integers X i,j is approx ~ Uniform on integers in [ 1 , m j – 1 ] g pp g [ ] i,j j - W i,j = X i,j - 1 is approx ~ Uniform on integers in [ 0 , m j - 2 ] Dr. Mesut Güneş Chapter 6. Random-Number Generation 16

  17. Computer Science, Informatik 4 Communication and Distributed Systems Combined Linear Congruential Generators Combined Linear Congruential Generators • Suggested form: Sugges ed o ⎧ X > i , X 0 ⎪ ⎛ ⎞ = ∑ k i ⎪ m ⎝ ∑ ⎜ ⎟ − − − j 1 X ( ( 1 ) ) X mod m 1 = , ⎟ Hence, , R 1 ⎨ ⎨ ⎜ ⎜ ⎟ − i i i i j j 1 1 m 1 1 i i ⎠ ⎪ = = 1 j 1 , X 0 ⎪ i m ⎩ 1 The coefficient: Performs the subtraction X i, 1 -1 − − − ( ( m 1 1 )( )( m 1 1 ) ( )...( m 1 1 ) ) • The maximum possible period is: = P 1 2 k − k 1 2 Dr. Mesut Güneş Chapter 6. Random-Number Generation 17

Recommend


More recommend