Chapter 7 Random-Number Generaton Banks, Carson, Nelson & Ncol Dscrete-Event System Smulaton Purpose & Overvew Dscuss the generaton of random numbers. Introduce the subsequent testng for randomness: Frequency test Autocorrelaton test.
Propertes of Random Numbers Two mportant statstcal propertes: Unformty Independence. Random Number, R, must be ndependently drawn from a unform dstrbuton wth pdf:, f ( x) 0, E( R) xdx 0 0 x otherwse x 0 Fgure: pdf for random numbers 3 Generaton of Pseudo-Random Numbers Pseudo, because generatng numbers usng a known method removes the potental for true randomness. Goal: To produce a sequence of numbers n [0,] that smulates, or mtates, the deal propertes of random numbers (RN). Important consderatons n RN routnes: Fast Portable to dfferent computers Have suffcently long cycle Replcable Closely approxmate the deal statstcal propertes of unformty and ndependence. 4
Technques for Generatng Random Numbers Lnear Congruental Method (LCM). Combned Lnear Congruental Generators (CLCG). Random-Number Streams. 5 Lnear Congruental Method [Technques] To produce a sequence of ntegers, X, X, between 0 and m- by followng a recursve relatonshp: X ( ax + c) mod m, 0,,,... + The multpler The ncrement The modulus The selecton of the values for a, c, m, and X 0 drastcally affects the statstcal propertes and the cycle length. The random ntegers are beng generated [0,m-], and to convert the ntegers to random numbers: X R,,,... m 6 3
Example [LCM] Use X 0 7, a 7, c 43, and m 00. The X and R values are: X (7*7+43) mod 00 50 mod 00, R 0.0; X (7*+3) mod 00 77, R 0.77; X 3 (7*77+3) mod 00 5, R 3 0.5; 7 Characterstcs of a Good Generator [LCM] Maxmum Densty Such that he values assumed by R,,,, leave no large gaps on [0,] Problem: Instead of contnuous, each R s dscrete Soluton: a very large nteger for modulus m Approxmaton appears to be of lttle consequence Maxmum Perod To acheve maxmum densty and avod cyclng. Acheve by: proper choce of a, c, m, and X 0. Most dgtal computers use a bnary representaton of numbers Speed and effcency are aded by a modulus, m, to be (or close to) a power of. 8 4
Combned Lnear Congruental Generators [Technques] Reason: Longer perod generator s needed because of the ncreasng complexty of stmulated systems. Approach: Combne two or more multplcatve congruental generators. Let X,, X,,, X,k, be the th output from k dfferent multplcatve congruental generators. The j th generator: Has prme modulus m j and multpler a j and perod s m j- Produces ntegers X,j s approx ~ Unform on ntegers n [, m-] W,j X,j - s approx ~ Unform on ntegers n [, m-] 9 Combned Lnear Congruental Generators [Technques] Suggested form: X k j ( ) X, j mod m j The coeffcent: Performs the subtracton X,- Hence, X, m R m, m X f 0 X 0 The maxmum possble perod s: P ( m )( m )...( k m k ) 0 5
Combned Lnear Congruental Generators [Technques] Example: For 3-bt computers, L Ecuyer [988] suggests combnng k generators wth m,47,483,563, a 40,04, m,47,483,399 and a 0,69. The algorthm becomes: Step : Select seeds X,0 n the range [,,47,483,56] for the st generator X,0 n the range [,,47,483,398] for the nd generator. Step : For each ndvdual generator, X,j+ 40,04 X,j mod,47,483,563 X,j+ 40,69 X,j mod,47,483,399. Step 3: X j+ (X,j+ - X,j+ ) mod,47,483,56. Step 4: Return X j+, X j+ > 0 R,47,483,563 j+,47,483,56, X j+ 0,47,483,563 Step 5: Set j j+, go back to step. Combned generator has perod: (m )(m )/ ~ x 0 8 Random-Numbers Streams [Technques] The seed for a lnear congruental random-number generator: Is the nteger value X 0 that ntalzes the random-number sequence. Any value n the sequence can be used to seed the generator. A random-number stream: Refers to a startng seed taken from the sequence X 0, X,, X P. If the streams are b values apart, then stream could defned by startng seed: S X b ( ) Older generators: b 0 5 ; Newer generators: b 0 37. A sngle random-number generator wth k streams can act lke k dstnct vrtual random-number generators To compare two or more alternatve systems. Advantageous to dedcate portons of the pseudo-random number sequence to the same purpose n each of the smulated systems. 6
Tests for Random Numbers Two categores: Testng for unformty: H 0 : R ~ U[0,] H : R ~ / U[0,] Falure to reject the null hypothess, H 0, means that evdence of non-unformty has not been detected. Testng for ndependence: H 0 : R ~ ndependently H : R ~ / ndependently Falure to reject the null hypothess, H 0, means that evdence of dependence has not been detected. Level of sgnfcance α, the probablty of rejectng H 0 when t s true: α P(reject H 0 H 0 s true) 3 Tests for Random Numbers When to use these tests: If a well-known smulaton languages or random-number generators s used, t s probably unnecessary to test If the generator s not explctly known or documented, e.g., spreadsheet programs, symbolc/numercal calculators, tests should be appled to many sample numbers. Types of tests: Theoretcal tests: evaluate the choces of m, a, and c wthout actually generatng any numbers Emprcal tests: appled to actual sequences of numbers produced. Our emphass. 4 7
Frequency Tests [Tests for RN] Test of unformty Two dfferent methods: Kolmogorov-Smrnov test Ch-square test 5 Kolmogorov-Smrnov Test [Frequency Test] Compares the contnuous cdf, F(x), of the unform dstrbuton wth the emprcal cdf, S N (x), of the N sample observatons. We know: F( x) x, 0 x If the sample from the RN generator s R, R,, R N, then the emprcal cdf, S N (x) s: number of R, R,..., R x) N Based on the statstc: D max F(x) - S N (x) S N ( whch are x Samplng dstrbuton of D s known (a functon of N, tabulated n Table A.8.) A more powerful test, recommended. n 6 8
Kolmogorov-Smrnov Test [Frequency Test] Example: Suppose 5 generated numbers are 0.44, 0.8, 0.4, 0.05, 0.93. Step : Step : R () /N 0.0 0.40 0.60 0.80.00 /N R () 0.5 0.6 0.6-0.07 R () (-)/N 0.05 0.05 Step 3: D max(d +, D - ) 0.6 Step 4: For α 0.05, D α 0.565 > D 0.4-0.44 0.04 0.8 0. 0.93 0.3 Arrange R () from smallest to largest D + max {/N R () } D - max {R () -(-)/N} Hence, H 0 s not rejected. 7 Ch-square test [Frequency Test] Ch-square test uses the sample statstc: n s the # of classes Χ 0 n ( O E ) E E s the expected # n the th class O s the observed # n the th class Approxmately the ch-square dstrbuton wth n- degrees of freedom (where the crtcal values are tabulated n Table A.6) For the unform dstrbuton, E, the expected number n the each class s: N E, where N s the total # of observaton n Vald only for large samples, e.g. N > 50 8 9
Tests for Autocorrelaton [Tests for RN] Testng the autocorrelaton between every m numbers (m s a.k.a. the lag), startng wth the th number The autocorrelaton ρ m between numbers: R, R +m, R +m, R +(M+)m M s the largest nteger such that + (M + )m N Hypothess: H : H 0 : If the values are uncorrelated: For large values of M, the dstrbuton of the estmator of ρ m, denoted s approxmately normal. ρˆm ρ 0, m ρ 0, m f numbers are ndependent f numbers are dependent 9 Tests for Autocorrelaton [Tests for RN] Test statstcs s: Z 0 ˆ ρm ˆ σ ˆ ρ m Z 0 s dstrbuted normally wth mean 0 and varance, and: M ρˆ m R kmr (k )m 0. 5 M + + + + k 0 σˆ ρ m 3M + 7 (M + ) If ρ m > 0, the subsequence has postve autocorrelaton Hgh random numbers tend to be followed by hgh ones, and vce versa. If ρ m < 0, the subsequence has negatve autocorrelaton Low random numbers tend to be followed by hgh ones, and vce versa. 0 0
Example [Test for Autocorrelaton] Test whether the 3 rd, 8 th, 3 th, and so on, for the followng output on P. 65. Hence, α 0.05, 3, m 5, N 30, and M 4 ρˆ σˆ 35 ρ35 Z 0 (0.3)(0.8) + (0.5)(0.33) + (0.33)(0.7) 0 5 4 (0.8)(0.05) (0.05)(0.36). + + + 0.945 3(4) + 7 0.8 ( 4 + ) 0.945.56 0.80 From Table A.3, z 0.05.96. Hence, the hypothess s not rejected. Shortcomngs [Test for Autocorrelaton] The test s not very senstve for small values of M, partcularly when the numbers beng tests are on the low sde. Problem when fshng for autocorrelaton by performng numerous tests: If α 0.05, there s a probablty of 0.05 of rejectng a true hypothess. If 0 ndependence sequences are examned, The probablty of fndng no sgnfcant autocorrelaton, by chance alone, s 0.95 0 0.60. Hence, the probablty of detectng sgnfcant autocorrelaton when t does not exst 40%
Summary In ths chapter, we descrbed: Generaton of random numbers Testng for unformty and ndependence Cauton: Even wth generators that have been used for years, some of whch stll n used, are found to be nadequate. Ths chapter provdes only the basc Also, even f generated numbers pass all the tests, some underlyng pattern mght have gone undetected. 3