Pseudo-Random Numbers: Linear Congruential Generators As digital computers are deterministic machines, they are incapable of generating random numbers.

Presentation on theme: "Pseudo-Random Numbers: Linear Congruential Generators As digital computers are deterministic machines, they are incapable of generating random numbers."— Presentation transcript:

Pseudo-Random Numbers: Linear Congruential Generators As digital computers are deterministic machines, they are incapable of generating random numbers. Instead they generate large cycles of pseudo-random numbers (i.e.) numbers which will pass most of the statistical tests for randomness. However, if the program is rerun on a subsequent day the exact same stream of numbers will be produced. To overcome this problem, since the chain of numbers is very large, a starting seed which uses the current date and I.D. number of the user can be used to enter the chain at different points every time the program is run. a pseudo-random number generator is said to be full cycle if it leaves no gaps in the range of numbers it generates. Form:X 0 a given “seed” X i+1 = ( a X i + c ) mod m Example X i+1 = 7 X i mod 11 ->1, 7, 5, 2, 3, 10, 4, 6, 9, 8, (1) X i+1 = 6 X i mod 11 ->1, 6, 3, 7, 9, 10, 5, 8, 4, 2, (1) Example [IMSL]X i+1 = 16807 X i mod (2 31 - 1) a prime modulus [SIMSCRIPT] X i+1 = 6303600167 X i mod (2 31 - 1) [RANDU] X i+1 = 65539 X i mod (2 31 ) Lemma. X i+1 = a X i mod m, with m prime, is full cycle if m divides a i - 1 for i = m-1, but for no smaller i X i+1 = ( a X i + c ) mod m is full cycle if c and m are relatively prime and if p divides m then p divides a - 1, if 4 divides m then 4 divides a - 1

Tests for Randomness In addition to various “Run Tests” and non-parametric tests, the following are useful. Chi-Square Test We partition the M random numbers generated into n classes and calculate the test statistic  O j - E j ) 2 / E j ~  2 M-n-1 distribution for M large, min {E j } > 4 and E j ~ 4 M 0.4. Kolmogorov Smirniv Test. Order the observations so that  X 1  X 2  …  X n and calculate over i = { 1, 2, …, n} K + n =  n Max { i / n - F ( X i ) } K - n =  n Max { F ( X i ) - (i - 1) / n} If K + n or K - n are either too big or too small, reject H 0 : Distribution is F at the relevant confidence interval. k-Dimensional Spectral Tests 1. Regard the numbers as points on [0, 1] ~ uniformly distributed 2. Regard the pairs ( X i, X i+1 ) as points in [0, 1] 2 ~ uniformly distributed 3. Regard the triplets ( X i, X i+1, X i+2 ) as points on [0, 1] 3 ….. Lemma.The sequences of size n from the generator X i+1 = a X i mod m fall on at most (n! m) 1/n parallel hyperplanes. The Spectral Value of a generator is the maximum distance between the hyperplanes. A generator with a small spectral value is desirable.

Example. The diagrams show that X i+1 = 7 X i mod 11 has a spectral value of 3.479, while that of X i+1 = 6 X i mod 11 is 4.919. Newspaper Boy Problem This is a seminal example, which shows how a (Historical Data) forecasting filter can use historical data to Index Demand Freq. optimise parameter settings in nonlinear models. i X i f i  f i F ( X i ) The newspaper boy buys papers at 40p, sells 1 10 10 10 0.10 them at 50p and gets 20p back on unsold copies 2 30 25 35 0.35 at the end of the day. His “corporate strategy” is 3 70 45 80 0.80 to buy 90% of the demand that occurred on the 4 100 15 95 0.95 previous day. 5 130 5 100 1.00 Day0 1 2 3 4 5 6 Random #- 0.25 0.60 0.80 0.55 0.90 0.45 Buy- 63 20 47 63 43 81 Demand70 22 52 70 48 90 39 Sell - 22 20 47 48 43 39 Return- 41 0 0 15 0 42 Profit (p) - -600 200 470 180 430 -450 Cumulative (p)- -600 -400 70 250 680 230 3.479 4.919

Nonuniform Random Numbers - Search In simulation models we typically disregard the first 10,000 iterations to allow the system reach an equilibrium and then monitor the simulation over the next 100,000 iterations. Binary search is quite an efficient algorithm for finding the simulation value relative to a look-up key. In simulation models as this look-up facility will be used a large number of times, it is important that the most efficient algorithm is used. Bucket search is the most efficient algorithm known for searching tables. Suppose X 1 (i - 1) / m} q i = Min { j: F (X j )  i / m } Algorithm:Generate the uniform [0, 1] random number U Search p k p k +1, …, q k for j with F (X j - 1 ) < U  F (X j ) Return j - 1 Interpolate for the exact value X = [F(X j ) - U]X j-1 + [U - F(X j-1 )]X j F(X j ) - F(X j-1 ) Example [Newspaper Boy] Suppose U = 0.96 and m = 8, so we search {4, …, 5} for j : F( X 4 ) < 0.96  F (X 5 ) Return 4 and so X = 106, by interpolation.

Generating Nonuniform Random Numbers Lemma.U uniform [0, 1] Prob { U  } =  Lemma. F(X) increasing => F(X) uniform [0, 1] Prob { F(X)  } = Prob { X  F -1 (  )] = F F -1 (  ) = . Lemma. F -1 (U) has the distribution function F. Prob { F -1 (U)  t} = Prob { U  F( t) } = F( t). Exponential.F( x) = 1 - exp ( -  x), for x  0, so F -1 (U) = - ln ( 1 - U ) / has an exponential distribution with rate. For convenience, tables of - ln ( 1 - U ) have been published. This distribution is the kernel of simulation systems for modelling queues. Cauchy This is the Student t 1 distribution has median , scale  and has no mean or higher moments. Using this distribution will result in the simulation model crashing. The sequence in which it crashes can be used to debug the simulation model. Later a proper random number generator can be substituted. F(x) = 1 /  Tan -1 [(x -   F -1 ( U) =  Tan [  ( U - 1/2 )] +  NormalThe Box-Muller formulae generate approximate n (0, 1) pairs: Y i = Cos ( 2  U i+1 )  -2 ln (U i ) Z i = Sin ( 2  U i+1 )  -2 ln (U i ) U 1 1 F (x)   F -1 (  ) 1 X 1

Illustration of M | M | 1 The diagram illustrates the dual nature of queuing statistics. T is the length of the simulation run. Expected number in the system = Shaded Area / T. This corresponds to numerical integration (accumulation) and requires careful computer coding. Expected waiting time in the system = {  Service Time Ends i -  Arrival Time i } Number of Customers n This is a tally operation, requiring the use of three registers and is easy to implement. Computer simulation languages, such as SIMSCRIPT, are a direct implementation of these ideas. The one caveat that needs to be added at this time, is that writing good simulation models requires considerable skill. In particular, unless the variance terms are controlled, each simulation run will result in wildly differing results. No. in the System State 3 Stage 3 012 T 456 E1E1 E2E2 E3E3 E4E4 E5E5 E6E6

Similar presentations