simulation
play

Simulation Discrete-Event System Simulation Dr. Mesut Gne Computer - PowerPoint PPT Presentation

Computer Science, Informatik 4 Communication and Distributed Systems Simulation Discrete-Event System Simulation Dr. Mesut Gne Computer Science, Informatik 4 Communication and Distributed Systems Chapter 5 Random-Number Generation


  1. Computer Science, Informatik 4 Communication and Distributed Systems Simulation “Discrete-Event System Simulation” Dr. Mesut Güneş

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

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

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

  5. Computer Science, Informatik 4 Communication and Distributed Systems Generation of Pseudo-Random Numbers “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). Important considerations in RN routines: � • Fast • Portable to different computers • Have sufficiently long cycle • Replicable • Closely approximate the ideal statistical properties of uniformity and independence. Dr. Mesut Güneş Chapter 5. Random-Number Generation 5

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

  7. Computer Science, Informatik 4 Communication and Distributed Systems Linear Congruential Method To produce a sequence of integers, X 1 , X 2 , … between 0 and m-1 � by following a recursive relationship: = + = X aX c m i ( ) mod , 0 , 1 , 2 ,... + i i 1 The The The modulus multiplier increment 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: X = = i R i , 1 , 2 ,... i m Dr. Mesut Güneş Chapter 5. Random-Number Generation 7

  8. Computer Science, Informatik 4 Communication and Distributed Systems Linear Congruential Method – Example Use X 0 = 27 , a = 17 , c = 43 , and m = 100 . � 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, R 3 = 0.52; X 4 =(17*52+43) mod 100 = 27, R 3 = 0.27; … Dr. Mesut Güneş Chapter 5. Random-Number Generation 8

  9. Computer Science, Informatik 4 Communication and Distributed Systems Characteristics of a Good Generator Maximum Density � • Such that he values assumed by R i , i = 1,2,… , leave no large gaps on [0,1] • Problem: Instead of continuous, each R i is discrete • Solution: a very large integer for modulus m - Approximation appears to be of little consequence Maximum Period � • To achieve maximum density and avoid cycling. • Achieve 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 5. Random-Number Generation 9

  10. Computer Science, Informatik 4 Communication and Distributed Systems Random-Numbers in Java � Defined in java.util.Random private final static long multiplier = 0x5DEECE66DL; private final static long addend = 0xBL; private final static long mask = (1L << 48) - 1; protected int next(int bits) { long oldseed, nextseed; ... oldseed = seed.get(); nextseed = (oldseed * multiplier + addend) & mask; ... return (int)(nextseed >>> (48 - bits)); } Dr. Mesut Güneş Chapter 5. Random-Number Generation 10

  11. Computer Science, Informatik 4 Communication and Distributed Systems Combined Linear Congruential Generators 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] - W i,j = X i,j - 1 is approx ~ Uniform on integers in [0 , m j -2 ] Dr. Mesut Güneş Chapter 5. Random-Number Generation 11

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

  13. Computer Science, Informatik 4 Communication and Distributed Systems Combined Linear Congruential Generators Example: For 32-bit computers, combining k = 2 generators with � m 1 = 2,147,483,563 , a 1 = 40,014 , m 2 = 2,147,483,399 and a 2 = 20,692 . The algorithm becomes: Step 1: Select seeds X 1,0 in the range [ 1, 2,147,483,562] for the 1 st generator - X 2,0 in the range [ 1, 2,147,483,398] for the 2 nd generator. - Step 2: For each individual generator, X 1,j+1 = 40,014 X 1,j mod 2,147,483,563 X 2,j+1 = 40,692 X 1,j mod 2,147,483,399 . Step 3: X j+1 = ( X 1,j+1 - X 2,j+1 ) mod 2,147,483,562 . Step 4: Return ⎧ X + j > 1 X ⎪ , 0 + j 1 2,147,483, 563 ⎪ = R ⎨ + j 1 ⎪ 2,147,483, 562 = X ⎪ , 0 + j 1 ⎩ 2,147,483, 563 Step 5: Set j = j+1 , go back to step 2. • Combined generator has period: (m 1 – 1)(m 2 – 1)/2 ~ 2 x 10 18 Dr. Mesut Güneş Chapter 5. Random-Number Generation 13

  14. Computer Science, Informatik 4 Communication and Distributed Systems Random-Numbers in Excel 2003 � In Excel 2003 new Random Number Generator ∈ X, Y, Z {1,...,300 00} = ⋅ X X 171 mod 30269 = ⋅ Y Y 172 mod 30307 = ⋅ Z Z 170 mod 30323 ⎛ ⎞ Z X Y = + + ⎜ ⎟ R mod 1.0 ⎝ ⎠ 30269 30307 30323 � It is stated that this method produces more than 10^13 numbers Dr. Mesut Güneş Chapter 5. Random-Number Generation 14

  15. Computer Science, Informatik 4 Communication and Distributed Systems Random-Numbers Streams The seed for a linear congruential random-number generator: � • Is the integer value X 0 that initializes the random-number sequence. • Any value in the sequence can be used to “seed” the generator. A random-number stream: � • Refers to a starting seed taken from the sequence X 0 , X 1 , …, X P. • If the streams are b values apart, then stream i could defined by starting seed: ⎣ ⎦ = = S X i P K 1 , 2 , , − i b i b ( 1 ) • Older generators: b = 10 5 ; Newer generators: b = 10 37 . A single random-number generator with k streams can act like k distinct � virtual random-number generators To compare two or more alternative systems. � • Advantageous to dedicate portions of the pseudo-random number sequence to the same purpose in each of the simulated systems. Dr. Mesut Güneş Chapter 5. Random-Number Generation 15

  16. Computer Science, Informatik 4 Communication and Distributed Systems Tests for Random Numbers Two categories: � • Testing for uniformity: H 0 : R i ~ U[0,1] H 1 : R i ~ U[0,1] / - Failure to reject the null hypothesis, H 0 , means that evidence of non- uniformity has not been detected. • Testing for independence: H 0 : R i ~ independently H 1 : R i ~ independently / - Failure to reject the null hypothesis, H 0 , means that evidence of dependence has not been detected. Level of significance α, the probability of rejecting H 0 when it is true: � α = P( reject H 0 | H 0 is true) Dr. Mesut Güneş Chapter 5. Random-Number Generation 16

  17. Computer Science, Informatik 4 Communication and Distributed Systems Tests for Random Numbers When to use these tests: � • If a well-known simulation languages or random-number generators is used, it is probably unnecessary to test • If the generator is not explicitly known or documented, e.g., spreadsheet programs, symbolic/numerical calculators, tests should be applied to many sample numbers. Types of tests: � • Theoretical tests: evaluate the choices of m , a , and c without actually generating any numbers • Empirical tests: applied to actual sequences of numbers produced. - Our emphasis. Dr. Mesut Güneş Chapter 5. Random-Number Generation 17

  18. Computer Science, Informatik 4 Communication and Distributed Systems Frequency Tests Test of uniformity � Two different methods: � • Kolmogorov-Smirnov test • Chi-square test Dr. Mesut Güneş Chapter 5. Random-Number Generation 18

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend