160 likes | 438 Views
Simulation Modeling and Analysis. Pseudo-Random Numbers. 1. Outline. Properties of Random Numbers Generating Random Numbers Testing Random Numbers. 2. Properties of Random Numbers. Key Properties Uniformity Independence Density function (continuous!)
E N D
Simulation Modeling and Analysis Pseudo-Random Numbers 1
Outline • Properties of Random Numbers • Generating Random Numbers • Testing Random Numbers 2
Properties of Random Numbers • Key Properties • Uniformity • Independence • Density function (continuous!) f(x) = {1 for 0 < x < 1, 0 otherwise • Moments E(R) = 1/2 V(R) = 1/12 3
Generating Random Numbers • Random Numbers vs Pseudo-random Numbers • Requirements of a RNG routine • Speed • Portable • Long Cycle • Replicable RN • Uniform and Independent RN’s 4
Random Number Generation • Linear Congruential Method X i+1 = (a Xi + c) mod m Ri = Xi/m • Note: Only values from the set I = {0,1/m,2/m,…,(m-1)/m} are obtained 5
Random Number Generation -contd • Longest Possible Period (P) • If m = 2b and |c| > 0 , P = m • If m = 2b and c = 0 , P = m/4 • If m = prime and c = 0 , P = m-1 • Example: X i+1 = (75 Xi ) mod (231-1) 6
Random Number Generation -contd • Combined Congruential Generators. Two distinct congruential generators can be combined to obtain PRN’s with longer periods. X i+1 = ((-1)j-1 Xi,j ) mod (m1 - 1) Ri = Xi/m1, Xi > 0 ; Ri = (m1-1)/m1, Xi > 0 7
Testing Random Numbers • Null Hypotheses H0 : Ri ~ U[0,1] ; H0 : Ri ~ independent • Tests • Frequency test • Runs test • Autocorrelation test • Gap test • Poker test 8
Kolmogorov-Smirnov Frequency Test 1.- Arrange data in increasing value 2.- Compute D+, D- and D 3.- Find critical Dc (Handout) for given a 4.- Accept or reject the null hypothesis. 5.- Example: Stat::Fit 9
Chi-Square Frequency Test • The Chi static compares observed frequencies of occurrence of PRN’s in selected subdomains against expected frequencies derived from the U distribution function. See Stat::Fit X02 = n (Oi - Ei)2/Ei 10
Runs Testing • Run: sequence of similar events • Runs up and runs down (independence) • Maximum number of runs (N numbers) = N-1 • mean = (2N-1)/3; variance = (16N-29)/90 • Test hypothesis against normal distribution. 11
Runs Testing -contd • Runs above and below the mean • Maximum number of runs (N numbers, n1 above and n2 below the mean) = n1+n2 • mean = 2 n1 n2/N + 1/2 • variance = 2 n1 n2 (2 n1 n2 - N)/N2 (N-1) • Test hypothesis against normal distribution. 12
Runs Testing -contd • Runs length • Test hypothesis against Chi square distribution 13
Autocorrelation Testing • Seek the autocorrelation between every m numbers (I.e. dependence) • Null Hypothesis H0 : im = 0 • Note: If values are uncorrelated, im has normal distribution. So, test hypothesis against normal distribution. 14
Gap Testing • Gap: Interval of recurrence of same digit. • Monitor Frequency of gaps and test 1.- Specify the cdf F(x) = 1-0.9 x+1 2.- Arrange the observed gaps into S(x) 3.- Find D and Dc 4.- Accept or reject the null hypothesis. 15
Poker Test • Frequency of repetition of certain digits in a series • Null hypothesis is tested againts the Chi-square distribution. 16