Simulation Modeling and Analysis Pseudo-Random Numbers 1

advertisement

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 X i

+ c) mod m

R i

= X i

/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 = 2 b and |c| > 0 , P = m

– If m = 2 b and c = 0 , P = m/4

– If m = prime and c = 0 , P = m-1

• Example:

X i+1

= (7 5 X i

) mod (2 31 -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 X i,j

) mod (m

1

- 1)

R i

= X i

/m

1

, X i

> 0 ; R i

= (m

1

-1)/m

1

, X i

> 0

7

Testing Random Numbers

• Null Hypotheses

H

0

: R

• Tests i

~ U[0,1] ; H

0

: R i

~ independent

– 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 D c

(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

X

0

2 =

 n

(O i

- E i

) 2 /E i

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)/N 2 (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 H

0

:

 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 Chisquare distribution.

16

Download