Vous êtes sur la page 1sur 23

Test for Random Numbers

Pablo Hinojosa Nava Selected topics of computational science

Index
1. Tests (Hypothesis testing)
a. b. c. d. Kolmogorov-Smirnof test Chi-square test Runs up and runs down Runs above and below mean

2. Simulating Coin Tossing Experiment

Tests properties
Uniformity -Frequency test a)Kolmogorov-Smirnov b)Chi-Square test Independence -Runs c)Runs up and runs down d)Runs above and below mean -Autocorrelation -Gap -Poker

Begining of the Tests


1. Formulate H0 (null hypothesis) in confrontation with H1 (alternative hypothesis) H0 -> the numbers are distributed uniformly or independent on the interval [0,1] 2. Level of significance must be stated (confidence interval) is frequently set to 0,01 or 0,05 3. Measure the quantity of interest Q 4. Check Qt from the distribution table based on and: v= n-1 (n=number of intervals) (Chi-Square test) N (total number of numbers) (the rest of the tests) 5. If Q < Qt then H0 is true else false

a) Kolmogorov-Smirnov test
1. Arrange the numbers in ascending order 2. Compute Q+ = max 1 i N {i/N - ri} Q- = max 1 i N { ri - i/N } 3. Choose Q (maximum between Q+ and Q-) 4. Determine the critical value Qt from the next table for the specified and N 5. If Q < Qt then numbers are uniformly distributed else not

a) Kolmogorov-Smirnov test table

a) Kolmogorov-Smirnov test example


Example 2.9 Suppose that the five numbers 0.44, 0.81, 0.14, 0.05, 0.93 are generated. So, N = 5. Let = 0.05. The calculations can be facilitated by use of Table 2.2.

b)Chi-Square test
1. Fix the number of intervals n of equal length in [0, 1]. 2. Compute E = N/n 3. Compute the observed number Oi in ith interval for i = 1, 2, . . . , n. 4. Compute 5. Determine the critical value, Qt , from the next table for the specified and n. 6. If Q < Qt then numbers are uniformly distributed else not

b)Chi-Square test

table

b)Chi-Square test

example

b)Chi-Square test

result
The value of Q is 7. This is compared with the critical value Qt = 16.9 for = 0.05 and = n 1 = 9 in the Table. Since Q < Qt, H0 is accepted. That is, the numbers are uniformly distributed.

Independence tests
Some definitions 1. Run. A run is defined as a succession of similar events preceded and followed by a different event 2. Length of run. The length of a run is the number of events that occur in the run 3. Up run. An up run is a sequence of numbers each of which is succeeded by a larger number 4. Down run. A down run is a sequence of numbers each of which is succeeded by a smaller number For the random number to be tested we give + or a - depending on whether they are followed by a larger number or a smaller number.

Example
Consider this numbers: 0.87, 0.15, 0.23, 0.45, 0.69, 0.32, 0.30, 0.19, 0.24, 0.18, 0.65, 0.82, 0.93, 0.22, 0.81. The sequence of + and is as follows: + + + + + + + + So, the number of runs is 8, the number of up runs is 4 and the number of down runs is 4.

c)Runs up and runs down test I 1. Find X, the total number of runs in the given sequence of random numbers to be tested. 2. Compute 3. Let N denote the total number of random numbers in the sequence. 4. If N 20, proceed further. Else, nothing can be said about the independency of the numbers.

c)Runs up and runs down test II 5. Compute X number of runs 6. Determine the critical value, Qt , from the next tables for the specified 7. If Q < Qt , the numbers are independent, else, they are not.

c)Runs up and runs down table I

c)Runs up and runs down table II

c)Runs up and runs down example

d)Runs above and below mean The following steps will be carried out for the runs above and below mean procedure: 1. Find X, the total number of runs in the given sequence of random numbers to be tested. 2. Find the number n1 of random numbers above the mean (total number of + signs) 3. Find the number n2 of random numbers below the mean (total number signs). The cross check is N = n1 + n2 .

d)Runs above and below mean II

6. If n1 > 20 or n2 > 20, proceed further. Else, nothing can be said about the independency of the given random numbers

d)Runs above and below mean III

8. Determine the critical value, Qt , from the last tables for the specified . 9. If Q < Qt , the numbers are independent, else, they are not.

d)Runs above and below mean example

Simulating Coin Tossing Experiment http://nlvm.usu. edu/en/nav/frames_asid_305_g_4_t_5.html http://pbskids. org/cyberchase/games/probability/

Vous aimerez peut-être aussi