Nothing Special   »   [go: up one dir, main page]

Tutorial 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

NETW 707: Modeling & Simulation

Assoc. Prof. Tallal El-Shabrawy


Tutorial 3

Tests for Random Number Generators


1. A random number generator gave the following numbers
U= {0.615, 0.79, 0.92, 0.74, 0.18}
Use the Kolmogorov Smirnov- test with a level of significance  of 0.01 to determine if the
hypothesis that the number in U are uniformly distributed on [0, 1) can be rejected or not.
2. Suppose that five numbers: 0.44, 0.81, 0.14, 0.05 and 0.93 were generated and it is desired to
perform a test on uniformity using the Kolmogorov Smirnov- test with a level of significance
 of 0.05.
3. Can the following five numbers be regarded as a random choice from the interval 0 to 1: 0.52,
0.65, 0.13, 0.71, and 0.58? Use Kolmogorov Smirnov- test with a level of significance  of
0.05.
4. A sample of size 10 is obtained with: 0.503, 0.621, 0.447, 0.203, 0.701, 0.480, 0.320, 0.581,
0.55, and 0.381 for a level of significance   5 % . Test the null hypothesis that the numbers
in a sample are uniformly distributed on [0, 1) can be rejected or not, using Kolmogorov
Smirnov- test.
5. The sequence of numbers: 0.54, 0.73, 0.98, 0.11, and 0.68 has been generated. Use the
Kolmogorov Smirnov- test with a level of significance   0.05 to determine if the hypothesis
that the numbers are uniformly distributed on the interval [0, 1) can be rejected or not.
6. Use the Chi-square test with α=0.05 to test whether the data shown next is uniformly
distributed
NETW 707: Modeling & Simulation
Assoc. Prof. Tallal El-Shabrawy
Tutorial 3
Testing Random – Number Generators

Since RNGs are completely deterministic, we need to test them to see if they appear to be
random and IID uniform on [0, 1]. Most computers will have built-in RNGs but unless software
is designed for simulation the RNGs can be extremely poor and may not be adequate to be used to
generate random variates in a stochastic model. It is recommended to test such generators before
usage (or any generator in general) with one of the following tests. There two types of tests:
 empirical tests
 theoretical tests
In the empirical test the Ui’s produced by the generator themselves are used to check how
good is the generator using any of the statistical tests available.
The theoretical test on the other hand uses the parameters of the generator to assess it
globally without actually generating any random numbers. So this test is not actually a test in the
statistical sense.

The Kolmogrov-smirnov test


This test compares the continuous CDF, F(x) of the uniform distribution to the empirical
distribution SN(x) from the data sample.
- BY definition the uniform distribution have CDF F(x) as follows : F  x   x, 0  x 1
- If the sample from the random generator is [R1, R2, …, RN] then the empirical CDF SN(x) is
Number of Rs  x
given by : S N x  
N
- The test is simply based on the largest absolute deviation between F(x) and SN(x) over the
range of the random variable
- Quantitatively this means it is based on : D  max | F ( x)  S N ( x) |
- Now D in itself is a random variable with a known distribution as a function of N and given as
follows
For testing we follow the following simple steps :
1. Rank the data from smallest to largest.

2. Compute D+, D- given by : D  max  i
1i  N N

 R(i) ,
1i  N

D   max R(i)  iN1 
3. Compute D=max (D+, D- )
i. Determine the critical value D from the table. For significant level  and sample size N.
ii. If D  D . Then no difference has been detected between the sample distribution and the
uniform distribution.
The Chi-square Test

1- Rank the data from smallest to largest


R1≤R2≤…..≤RN

2- Divide the range RN- R1 in n equidistant intervals such that each interval has at least 5
observations

3- Calculate
where:
Oi = the number of observations in the ith class
Ei = the expected number in the ith class
n = the number of classes

4- For significant level α, utilize the table of percentage points of the Chi square distribution
with v degrees of freedom to determine

5- If ≤
Accept: “No difference between and F(x)
If >
Reject

You might also like