Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tests for Random Numbers Dr. Akram Ibrahim Aly Lecture (9)

Similar presentations


Presentation on theme: "Tests for Random Numbers Dr. Akram Ibrahim Aly Lecture (9)"— Presentation transcript:

1 Tests for Random Numbers Dr. Akram Ibrahim Aly Lecture (9)

2 Tests for Random Numbers Frequency Tests: compare the distribution of the set of numbers to a uniform distribution – Kolmogorov-Smirnov (KS) – Chi-Square Test. Autocorrelation Test: Test the correlation between numbers and compares the sample correlation to the expected correlation of zero.

3 The Kolmogorov-Smirnov Test The KS test compares a continuous CDF F(x) to an empirical CDF S N (x), of the sample of N observations. If the sample from the random number generator is R 1, R 2, …, R N, then the empirical CDF S N (x) is given by:

4 The Kolmogorov-Smirnov Test Step 1: – Rank the data from smallest to largest: Step 2: – Compute:

5 The Kolmogorov-Smirnov Test Step 3: – Compute D=max(D +,D - ) Step 4: – locate the critical value D α in the “Kolmogorov Smirnov Critical Values table” for the specified significance level α and the given sample size (N) Step 5: – If D ≤ D α → Accept: “No difference between S N (x) and F(x)” – If D > D α → Reject: “No difference between S N (x) and F(x)”

6 The K-S Test, Kolmogorov Smirnov Critical Values Table

7 Example: The K-S Test The five numbers: 0.44, 0.81, 0.14, 0.05, 0.93 were generated and it is required to test for uniformity using the Kolmogorov-Smirnov Test with the level of significance α = 0.05.

8 Solution 0.050.140.440.810.93 0.20.40.60.81 0.150.260.16--0.07 0.05--0.040.210.13 D=max(D +,D - ) = max(0.26,0.21) = 0.26 In KS critical values table, For α = 0.05 and N = 5, the critical value D α = 0.565 Since D < D α, no difference has been detected between the true distribution of {R 1, R 2, …, R N } and the uniform distribution

9 Solution: The K-S Test

10 The Chi-square Test The chi-square test uses the sample statistic: Where: – O i = the number of observations in the i-th class – E i = the expected number in the i-th class – n = the number of classes.

11 The Chi-square Test Step 1: – Rank the data from smallest to largest: Step 2: – Divide the Range R N -R 1 in n equidistant intervals such that each interval has at least 5 observations. Step 3: – Calculate:

12 The Chi-square Test Step 4: – For significant level α, utilize the table of (Percentage points of the chi square distribution with ν degrees of freedom) to determine χ α,n-1. Step 5: – If χ 0 2 ≤ χ 2 α,n-1 → Accept: “No difference between S N (x) and F(x)” – If χ 0 2 > χ 2 α,n-1 → Reject: “No difference between S N (x) and F(x)”

13 Example Use the chi-square test with α=0.05 to test whether the data shown next are uniformly distributed. 0.340.900.250.890.870.440.120.210.460.67 0.830.760.790.640.700.810.940.740.220.74 0.960.990.770.670.560.410.520.730.990.02 0.470.300.170.820.560.050.450.310.780.05 0.790.710.230.190.820.930.650.370.390.42 0.990.170.990.460.050.660.100.420.180.49 0.370.510.540.010.810.280.690.340.750.49 0.720.430.560.970.300.940.960.580.730.05 0.060.390.840.240.400.640.400.190.790.62 0.180.260.970.880.640.470.600.110.290.78

14 Solution Interval 1810-240.4 2810-240.4 310 000 49 10.1 51210240.4 6810-240.4 710 000 814104161.6 910 000 1110110.1 100 03.4

15 Solution The test uses n=10 intervals of equal length, namely [0,0.1[, [0.1,0.2[, …, [0.9,1] The value of χ 0 2 =3.4 From table (Percentage points of the CHI SQUARE distribution with ν degrees of freedom), the critical value of χ 0.05,9 =16.9 Since χ 0 2 < χ 0.05,9, the hypothesis of uniform distribution is not rejected.

16 Percentage points of the CHI SQUARE distribution with ν degrees of freedom

17 Notes on Uniformity tests Both the Kolmogorov-Smirnov test and the chi- square test are acceptable for testing the uniformity of sample data provided that the sample size is large. The KS test can be applied to small sample sizes, whereas the chi-square test is valid only for large samples, e.g.: N ≥ 50. The KS test is more powerful and is recommended

18 Test for Auto-correlation The tests for auto-correlation are concerned with the dependence between numbers in a sequence. Example: – Examination of the 5 th, 10 th, 15 th, …,etc. indicates a large number in that position. 0.120.010.230.280.890.310.640.280.830.93 0.990.150.330.350.910.410.600.270.750.88 0.680.490.050.430.950.580.190.360.690.87

19 Test for Auto-correlation The test requires the computation of the autocorrelation between every m numbers (m is known as the lag), starting with the i th number: – The autocorrelation ρ im of interest shall be between numbers: R i, R i+m, R i+2m, R i+(M+1)m – M is the largest integer such that i+(M+1)m ≤ N If the values are uncorrelated: – For large values of M, the distribution of the estimator of ρ im, denoted is approximately normal.

20 Test for Auto-correlation Test statistics is: Where: Z 0 is distributed normally with mean = 0 and variance = 1.

21 Test for Auto-correlation Compute Z 0 The hypothesis of independence is not rejected if: Where α is the level of significance and z α/2 is obtained from the standard normal distribution table.

22 Test for Auto-correlation Figure illustrates the test

23 Test for Auto-correlation If ρ im > 0, the subsequence has positive autocorrelation – High random numbers tend to be followed by high ones, and vice versa. If ρ im < 0, the subsequence has negative autocorrelation – Low random numbers tend to be followed by high ones, and vice versa.

24 Example Test whether the 3 rd, 8 th, 13 th, and so on, for the following output using α = 0.05. 0.120.010.230.280.890.310.640.280.830.93 0.990.150.330.350.910.410.600.270.750.88 0.680.490.050.430.950.580.190.360.690.87

25 Solution i = 3, m = 5, N = 30, 3+(M+1)5 ≤ 30→ M = 4

26 Solution The test statistic is given by: From the standard normal distribution table, the critical value is: Since The hypothesis of independence cannot be rejected

27 The standard normal distribution table


Download ppt "Tests for Random Numbers Dr. Akram Ibrahim Aly Lecture (9)"

Similar presentations


Ads by Google