SlideShare a Scribd company logo
1 of 91
SCC430
Modeling and Simulation
Chapter 05 Random-Number Generation
Part 02
Dr. Ahmed Hagag
Faculty of Computers and Artificial Intelligence
Benha University
Fall 2020
• Properties of Random Numbers.
• Generation of Pseudo-Random Numbers.
• Techniques for Generating Pseudo-Random Numbers.
• Tests for Random Numbers.
©Ahmed Hagag SCC430 Modeling and Simulation 2
Chapter 5: Ran. Num. Gen.
Tests for PRNs (1/7)
©Ahmed Hagag SCC430 Modeling and Simulation 3
Introduction (1/5)
The properties of random numbers: Uniformity and
Independence. Number of tests can be performed to check
these properties been achieved or not.
• Frequency Test: Uses the Kolmogorov-Smirnov or the
Chi-square test to compare the distribution of the set of
numbers generated to a uniform distribution.
• Autocorrelation Test: Tests the correlation between
numbers and compares the sample correlation to the
expected correlation, zero.
Tests for PRNs (1/7)
Introduction (2/5)
©Ahmed Hagag SCC430 Modeling and Simulation 4
Tests for PRNs (1/7)
Introduction (3/5)
In testing for uniformity, the hypotheses are as follows:
The null hypothesis, 𝐻0, reads that the numbers are
distributed uniformly on the interval [0, 1]. Failure to reject
the null hypothesis means that evidence of nonuniformity
has not been detected by this test. This does not imply that
further testing of the generator for uniformity is
unnecessary.
©Ahmed Hagag SCC430 Modeling and Simulation 5
Tests for PRNs (1/7)
Introduction (4/5)
In testing for independence, the hypotheses are as follows:
This null hypothesis, 𝐻0, reads that the numbers are
independent. Failure to reject the null hypothesis means
that evidence of dependence has not been detected by this
test. This does not imply that further testing of the
generator for independence is unnecessary.
©Ahmed Hagag SCC430 Modeling and Simulation 6
Tests for PRNs (1/7)
Introduction (5/5)
For each test, a level of significance 𝛼 must be stated. The
level 𝛼 is the probability of rejecting the null hypothesis
when the null hypothesis is true:
The decision maker sets the value of 𝛼 for any test.
©Ahmed Hagag SCC430 Modeling and Simulation 7
Tests for PRNs (2/7)
Kolmogorov-Smirnov (K-S) Test (1/5)
Compares the continuous cumulative distribution function
(cdf), F(x), of the uniform distribution with the empirical
distribution fun. 𝑆𝑁(𝑥) of the sample of N observations.
Uniformity
𝐹 𝑥 =
0, 𝑥 ≤ 𝑎
𝑥 − 𝑎
,
©Ahmed Hagag SCC430 Modeling and Simulation 8
𝑏 − 𝑎
1,
𝑎 < 𝑥 < 𝑏
𝑥 ≥ 𝑏
Tests for PRNs (2/7)
Kolmogorov-Smirnov (K-S) Test (1/5)
Compares the continuous cumulative distribution function
(cdf), F(x), of the uniform distribution with the empirical
distribution fun. 𝑆𝑁(𝑥) of the sample of N observations.
𝐷 = max 𝐹 𝑥 − 𝑆𝑁 𝑥
The sampling distribution of 𝐷 is known; it is tabulated as
a function of 𝑁 in the following Table.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 9
Tests for PRNs (2/7)
©Ahmed Hagag SCC430 Modeling and Simulation 10
Tests for PRNs (2/7)
𝒊𝒇 𝑵 = 𝟖 and 𝑎 = 𝟎. 𝟎𝟓
𝑫𝟎.𝟎𝟓 = 𝟎. 𝟒𝟓𝟕
©Ahmed Hagag SCC430 Modeling and Simulation 11
Tests for PRNs (2/3)
Kolmogorov-Smirnov (K-S) Test (1/7)
©Ahmed Hagag SCC430 Modeling and Simulation 12
𝑁
𝟏. 𝟔𝟑
𝑵
𝟏. 𝟑𝟔
𝑵
𝟏. 𝟐𝟐
𝑵
𝟏. 𝟏𝟒
𝑵
𝟏. 𝟎𝟕
𝑵
Tests for PRNs (2/7)
Kolmogorov-Smirnov (K-S) Test (2/5)
For testing against a uniform cdf, the test procedure
follows these steps:
Step1: Rank the data from smallest to largest. Let 𝑅𝑖
denote 𝑖th smallest observation, so that 𝑅1 ≤ 𝑅2 ≤ ⋯ 𝑅𝑁
𝑖
Step2: Null hypothesis 𝐻0: 𝑅′s~U 0,1
Uniformity
Distributed as uniform distribution
©Ahmed Hagag SCC430 Modeling and Simulation 13
Tests for PRNs (2/7)
Kolmogorov-Smirnov (K-S) Test (3/5)
Step3: Compute 𝐷+ and 𝐷−, where
𝐷+ = max
𝑁 𝑖 𝑖
𝑖 𝑖 − 1
− 𝑅 , 𝐷− = max 𝑅 −
𝑁
Step4: Compute 𝐷 = max 𝐷+, 𝐷−
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 14
Tests for PRNs (2/7)
Kolmogorov-Smirnov (K-S) Test (3/5)
Step3: Compute 𝐷+ and 𝐷−, where
𝑁 𝑖
𝐷+ = max
𝑖
− 𝑅 , 𝑖
𝐷− = max 𝑅 −
𝑖 − 1
𝑁
Step4: Compute 𝐷 = max 𝐷+, 𝐷−
Uniformity
𝒊 = 𝟏, 𝟐, … , 𝑵
©Ahmed Hagag SCC430 Modeling and Simulation 15
Tests for PRNs (2/7)
Kolmogorov-Smirnov (K-S) Test (4/5)
Step5: Locate the critical value 𝐷𝛼 in the K-S Table for the
specified significance level 𝛼 and the sample size 𝑁.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 16
Tests for PRNs (2/7)
Kolmogorov-Smirnov (K-S) Test (5/5)
Step6: If the sample statistic 𝐷 is greater than the critical
value 𝐷𝛼, the null hypothesis is rejected. If 𝐷 ≤ 𝐷𝛼,
conclude that we fail to reject the null hypothesis and these
PRNs can be accepted according to K-S test.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 17
Tests for PRNs (3/7)
Example – (K-S) Test (1/5)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
For the specified significance level 𝛼 = 0.05.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 18
Tests for PRNs (3/7)
Example – (K-S) Test (1/5)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
For the specified significance level 𝛼 = 0.05.
Uniformity
𝑵 = 𝟓 and 𝑎 = 𝟎. 𝟎𝟓
©Ahmed Hagag SCC430 Modeling and Simulation 19
Tests for PRNs (3/7)
Example – (K-S) Test (2/5)
𝑵
Uniformity
𝑵 = 𝟓 and 𝑎 = 𝟎. 𝟎𝟓
𝑫𝟎.𝟎𝟓 = 𝟎. 𝟓𝟔𝟓
©Ahmed Hagag SCC430 Modeling and Simulation 20
Tests for PRNs (3/7)
Example – (K-S) Test (3/5)
The 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
First, the numbers must be sorted from smallest to largest.
𝑹𝒊 0.05 0.14 0.44 0.81 0.93
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 21
Tests for PRNs (3/7)
Example – (K-S) Test (3/5) Uniformity
𝑹𝒊 0.05 0.14 0.44 0.81 0.93
𝒊 = 𝟏, 𝟐, … , 𝑵
𝑁=5
©Ahmed Hagag SCC430 Modeling and Simulation 22
Tests for PRNs (3/7)
Example – (K-S) Test (3/5) Uniformity
𝑹𝒊 0.05 0.14 0.44 0.81 0.93
𝒊 = 𝟏, 𝟐, … , 𝟓
𝑁=5
©Ahmed Hagag SCC430 Modeling and Simulation 23
Tests for PRNs (3/7)
Example – (K-S) Test (3/5)
𝑹𝒊 0.05 0.14 0.44 0.81 0.93
𝒊/𝑵 0.20 0.40 0.60 0.80 1.00
Uniformity
𝑁=5
©Ahmed Hagag SCC430 Modeling and Simulation 24
Tests for PRNs (3/7)
Example – (K-S) Test (3/5)
𝑹𝒊 0.05 0.14 0.44 0.81 0.93
𝒊/𝑵 0.20 0.40 0.60 0.80 1.00
𝒊/𝑵 – 𝑹𝒊 0.15 0.26 0.16 − 0.07 𝑫+ = 𝟎. 𝟐𝟔
Uniformity
𝑁=5
©Ahmed Hagag SCC430 Modeling and Simulation 25
Tests for PRNs (3/7)
Example – (K-S) Test (3/5)
𝑹𝒊 0.05 0.14 0.44 0.81 0.93
𝒊/𝑵 0.20 0.40 0.60 0.80 1.00
𝒊/𝑵 – 𝑹𝒊 0.15 0.26 0.16 − 0.07
(𝒊 − 𝟏)/𝑵 0.00 0.20 0.40 0.60 0.80
𝑫+ = 𝟎. 𝟐𝟔
Uniformity
𝑁=5
©Ahmed Hagag SCC430 Modeling and Simulation 26
Tests for PRNs (3/7)
Example – (K-S) Test (3/5)
𝑹𝒊 0.05 0.14 0.44 0.81 0.93
𝒊/𝑵 0.20 0.40 0.60 0.80 1.00
𝒊/𝑵 – 𝑹𝒊 0.15 0.26 0.16 − 0.07
(𝒊 − 𝟏)/𝑵 0.00 0.20 0.40 0.60 0.80
𝑹𝒊 – (𝒊 − 𝟏)/𝑵 0.05 − 0.04 0.21 0.13
𝑁=5
𝑫+ = 𝟎. 𝟐𝟔
𝑫− = 𝟎. 𝟐𝟏
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 27
Tests for PRNs (3/7)
Example – (K-S) Test (4/5)
𝐷 = max 𝐷+, 𝐷− = 0.26
Uniformity
𝑫+ = 𝟎. 𝟐𝟔
𝑫− = 𝟎. 𝟐𝟏
©Ahmed Hagag SCC430 Modeling and Simulation 28
Tests for PRNs (3/7)
Example – (K-S) Test (5/5)
Since the computed value, 0.26, is less than the critical value,
0.565, the hypothesis that the distribution of the generated
numbers is the uniform distribution is “failed to reject".
𝐷 = max 𝐷+, 𝐷− = 0.26 < 𝐷𝛼 𝐷𝛼 = 0.565
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 29
Tests for PRNs (4/7)
Chi-Square ( 𝝌𝟐 ) Test (1/4)
We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁.
Step1: We divide [0, 1) into 𝑘 subintervals of equal length
(i.e., Classes). (As a general rule, 𝑘 should be at least 100)
𝑖
Step2: Null hypothesis 𝐻0: 𝑅′s~U 0,1
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 30
Tests for PRNs (4/7)
Chi-Square ( 𝝌𝟐 ) Test (2/4)
We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁.
Step3: Chi-square test uses the sample statistic:
𝑖
=1
𝑘
𝑂 − 𝐸
𝜒2 = ෍ 𝑖 𝑖
2
𝐸𝑖
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 31
Tests for PRNs (4/7)
Chi-Square ( 𝝌𝟐 ) Test (2/4)
We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁.
Step3: Chi-square test uses the sample statistic:
𝑖
=1
𝑘
𝑂 − 𝐸
𝜒2 = ෍ 𝑖 𝑖
2
𝐸𝑖
Uniformity
𝒌 is the#
of classes
©Ahmed Hagag SCC430 Modeling and Simulation 32
Tests for PRNs (4/7)
Chi-Square ( 𝝌𝟐 ) Test (2/4)
We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁.
Step3: Chi-square test uses the sample statistic:
𝑘
𝜒2 = ෍
𝑖=1
𝑂𝑖 − 𝐸𝑖
2
𝐸𝑖
Uniformity
is theobserved #
in the 𝒊𝒕𝒉 class
How many 𝑹′𝒔
in the 𝒊𝒕𝒉 class 𝒌 is the#
of classes
©Ahmed Hagag SCC430 Modeling and Simulation 33
Tests for PRNs (4/7)
Chi-Square ( 𝝌𝟐 ) Test (2/4)
We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁.
Step3: Chi-square test uses the sample statistic:
𝑘
𝜒2 = ෍
𝑖=1
𝑂𝑖 − 𝐸𝑖
2
𝐸𝑖
Uniformity
is theobserved #
in the 𝒊𝒕𝒉 class
is theexpected #
in the 𝒊𝒕𝒉 class
How many 𝑹′𝒔
in the 𝒊𝒕𝒉 class
𝑵
𝑬𝒊 =
𝒌
Uniform
Distribution
𝒌 is the#
of classes
©Ahmed Hagag SCC430 Modeling and Simulation 34
Tests for PRNs (4/7)
Chi-Square ( 𝝌𝟐 ) Test (3/4)
We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁.
Step4: 𝜒2 will have an approximate chi-square distribution
with 𝑘 − 1 degrees of freedom (df) at significance level 𝛼.
𝛼, 𝑘−1
𝜒2
= critical value, where the critical values are
tabulated in the following Table.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 35
©Ahmed Hagag SCC430 Modeling and Simulation 36
©Ahmed Hagag SCC430 Modeling and Simulation 37
𝜒
2
𝛼, 𝑘−1
©Ahmed Hagag SCC430 Modeling and Simulation 38
0.025, 9
𝜒2
= 19
𝛼 = 0.025,
𝑘 = 10
©Ahmed Hagag SCC430 Modeling and Simulation 39
Tests for PRNs (4/7)
Chi-Square ( 𝝌𝟐 ) Test (4/4)
We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁.
Step5:
If 𝜒2 > 𝜒2 , we reject 𝐻0, else we fail to reject 𝐻0.
𝛼, 𝑘−1
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 40
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (1/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 41
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (2/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Step1: We divide [0, 1) into 𝟏𝟎 subintervals of equal length.
[0, 0.1), [0.1, 0.2), [0.2, 0.3), …, [0.9,1.0)
Or we divide (0, 1] into 𝟏𝟎 subintervals of equal length.
(0, 0.1], (0.1, 0.2], (0.2, 0.3], …, (0.9,1.0]
𝑖
Step2: Null hypothesis 𝐻0: 𝑅′s~U 0,1
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 42
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (3/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Step3: Chi-square test uses the sample statistic:
𝑘
𝜒2 = ෍
𝑖=1
𝑂𝑖 − 𝐸𝑖
2
𝐸𝑖
Uniformity
is theobserved #
in the 𝒊𝒕𝒉 class
is theexpected #
in the 𝒊𝒕𝒉 class
How many 𝑹′𝒔
in the 𝒊𝒕𝒉 class
𝑵
𝑬𝒊 =
𝒌
𝒌 is the#
of classes
©Ahmed Hagag SCC430 Modeling and Simulation 43
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (3/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Step3: Chi-square test uses the sample statistic:
𝑘
𝜒2 = ෍
𝑖=1
𝑂𝑖 − 𝐸𝑖
2
𝐸𝑖
Uniformity
is theobserved #
in the 𝒊𝒕𝒉 class
is theexpected #
in the 𝒊𝒕𝒉 class
How many 𝑹′𝒔
in the 𝒊𝒕𝒉 class
𝟏𝟎𝟎
𝑬𝒊 =
𝟏𝟎
= 𝟏𝟎
𝒌 is the#
of classes
=10
©Ahmed Hagag SCC430 Modeling and Simulation 44
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (3/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Step3: Chi-square test uses the sample statistic:
𝑖
=1
10
𝜒2 = ෍ 𝑖
𝑂 − 10 2
10
Uniformity
is theobserved #
in the 𝒊𝒕𝒉 class
is theexpected #
in the 𝒊𝒕𝒉 class
How many 𝑹′𝒔
in the 𝒊𝒕𝒉 class
𝟏𝟎𝟎
𝑬𝒊 =
𝟏𝟎
= 𝟏𝟎
©Ahmed Hagag SCC430 Modeling and Simulation 45
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (4/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 46
(0.0, 0.1]
(0.1, 0.2]
(0.2, 0.3]
(0.9, 1.0]
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (4/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 47
(0.0, 0.1]
(0.1, 0.2]
(0.2, 0.3]
(0.9, 1.0]
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (4/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 48
(0.0, 0.1]
(0.1, 0.2]
(0.2, 0.3]
(0.9, 1.0]
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (4/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 49
(0.0, 0.1]
(0.1, 0.2]
(0.2, 0.3]
(0.9, 1.0]
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (4/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 50
(0.0, 0.1]
(0.1, 0.2]
(0.2, 0.3]
(0.9, 1.0]
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (5/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Uniformity
𝑘
𝜒2 = ෍
𝑖=1
𝑂𝑖 − 𝐸 2
𝐸𝑖
𝑖
= 3.4
(0.0, 0.1]
(0.1, 0.2]
(0.2, 0.3]
©Ahmed Hagag SCC430 Modeling and Simulation 51
(0.9, 1.0]
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (6/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Step4: Calculate 𝜒2 = 𝜒2
𝛼, 𝑘−1 0.05, 9
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 52
©Ahmed Hagag SCC430 Modeling and Simulation 53
0.05, 9
𝜒2
= 16.9
Tests for PRNs (5/7)
Example – ( 𝝌𝟐) Test (7/7)
We have 100 generated PRNs 𝑅′s are shown below. Use
𝑖
Chi-square test with 𝛼 = 0.05 and 𝑘 = 10.
Step5:
𝜒2 = 3.4
0.05, 9
𝜒2
= 16.9
0.05, 9
∵ 𝜒2 < 𝜒2 , then we fail to reject 𝐻0, and these PRNs are
accepted according to chi-square test.
Uniformity
©Ahmed Hagag SCC430 Modeling and Simulation 54
Tests for PRNs (6/7)
Autocorrelation (1/3)
Correlation between a signal and itself signals for detecting
dependency. Efficient calculation of correlation coefficient
between two sequences (listed in time order of collection)
𝑥(𝑖), 𝑦(𝑖), where 𝑖 = 1, 2, … , 𝑛.
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 55
Tests for PRNs (6/7)
Autocorrelation (1/3)
Correlation between a signal and itself signals for detecting
dependency. Efficient calculation of correlation coefficient
between two sequences (listed in time order of collection)
𝑥(𝑖), 𝑦(𝑖), where 𝑖 = 1, 2, … , 𝑛.
Independence
𝑖
=1
expected value (sample mean) = σ𝑛 𝑥𝑖 /𝑛
©Ahmed Hagag SCC430 Modeling and Simulation 56
Tests for PRNs (6/7)
Autocorrelation (1/3)
Correlation between a signal and itself signals for detecting
dependency. Efficient calculation of correlation coefficient
between two sequences (listed in time order of collection)
𝑥(𝑖), 𝑦(𝑖), where 𝑖 = 1, 2, … , 𝑛.
Independence
𝑟𝑥𝑦 =
1
𝑛 − 1
𝑖
=1
σ𝑛
𝑥𝑖 − 𝑥ҧ𝑦𝑖 − 𝑦
ത
𝑠𝑥𝑠𝑦
standard deviation 𝑠𝑥
©Ahmed Hagag SCC430 Modeling and Simulation 57
Tests for PRNs (6/7)
Autocorrelation (2/3)
Efficient calculation of correlation
sequence 𝑥(𝑖), where 𝑖 = 1, 2, … , 𝑛.
coefficient for a
𝑥
𝑥
𝑟 𝑘 =
1
𝑛 − 𝑘
𝑖
=1
σ𝑛−𝑘
𝑥𝑖 − 𝑥ҧ𝑥 𝑖+𝑘 − 𝑥
ҧ
𝑠𝑥𝑠𝑥
𝑟𝑥𝑥 𝑘 is calculated for 𝑘 = 1, 2, … , 𝑛 − 1 for 𝑛 PRNs.
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 58
Tests for PRNs (6/7)
Autocorrelation (3/3)
𝑟𝑥𝑥 𝑘 is calculated for 𝑘 = 1,2, … , 𝑛 − 1 for 𝑛 PRNs.
If the samples are independent, then all the values should be
theoretically zero. But in practice we can say:
• Small values (close to zero) indicate independence.
• Large values (close to 1) indicate dependence.
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 59
Tests for PRNs (6/7)
Example (1/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 60
Tests for PRNs (6/7)
Example (2/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
Independence
1 2 3 4 5
𝒏 = 𝟓
©Ahmed Hagag SCC430 Modeling and Simulation 61
Tests for PRNs (6/7)
Example (2/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
Independence
1 2 3 4 5
𝒏 = 𝟓
©Ahmed Hagag SCC430 Modeling and Simulation 62
Tests for PRNs (6/7)
Example (3/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
Independence
1 2 3 4 5
𝒏 = 𝟓
𝑥ҧ
=
𝑖
=1
σ𝑛
𝑥𝑖
𝑛
=
0.44 + 0.81 + 0.14 + 0.05 + 0.93
5
= 0.474
𝑠𝑥
©Ahmed Hagag SCC430 Modeling and Simulation 63
Tests for PRNs (6/7)
Example (4/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
𝒙𝒊 − 𝒙
ഥ -0.034 0.336 -0.334 -0.424 0.456
Independence
1 2 3 4 5
𝑥ҧ = 0.474
𝑠𝑥
𝑠𝑥 = 0.15333
©Ahmed Hagag SCC430 Modeling and Simulation 64
Tests for PRNs (6/7)
Example (4/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
𝒙𝒊 − 𝒙
ഥ -0.034 0.336 -0.334 -0.424 0.456
Independence
1 2 3 4 5
𝑥ҧ = 0.474
𝑠𝑥
𝑠𝑥 = 0.15333
©Ahmed Hagag SCC430 Modeling and Simulation 65
Tests for PRNs (6/7)
Example (5/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
Independence
1 2 3 4 5
𝑥ҧ = 0.474
𝑠𝑥 = 0.15333
𝑟𝑥𝑥 𝑘 =
1
5 − 𝑘
𝑖
=1
σ5−𝑘
𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474
0.15333
𝑘 = 1,2,3,4
©Ahmed Hagag SCC430 Modeling and Simulation 66
Tests for PRNs (6/7)
Example (6/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
Independence
1 2 3 4 5
𝑥ҧ = 0.474
𝑠𝑥 = 0.15333
𝑟𝑥𝑥 𝑘 =
1
5 − 𝑘
𝑖
=1
σ5−𝑘
𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474
0.15333
𝑘 = 1,2,3,4
𝑟𝑥𝑥
1 −0.17538
1 =
4 0.15333
©Ahmed Hagag SCC430 Modeling and Simulation 67
= −0.28595
Tests for PRNs (6/7)
Example (7/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
Independence
1 2 3 4 5
𝑥ҧ = 0.474
𝑠𝑥 = 0.15333
𝑟𝑥𝑥 𝑘 =
1
5 − 𝑘
𝑖
=1
σ5−𝑘
𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474
0.15333
𝑘 = 1,2,3,4
𝑟𝑥𝑥
1 −0.28341
2 =
3 0.15333
©Ahmed Hagag SCC430 Modeling and Simulation 68
= −0.61613
Tests for PRNs (6/7)
Example (8/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
Independence
1 2 3 4 5
𝑥ҧ = 0.474
𝑠𝑥 = 0.15333
𝑟𝑥𝑥 𝑘 =
1
5 − 𝑘
𝑖
=1
σ5−𝑘
𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474
0.15333
𝑘 = 1,2,3,4
𝑟𝑥𝑥
1 0.167632
3 =
2 0.15333
©Ahmed Hagag SCC430 Modeling and Simulation 69
= 0.546638
Tests for PRNs (6/7)
Example (9/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒙𝒊 0.44 0.81 0.14 0.05 0.93
Independence
1 2 3 4 5
𝑥ҧ = 0.474
𝑠𝑥 = 0.15333
𝑟𝑥𝑥 𝑘 =
1
5 − 𝑘
𝑖
=1
σ5−𝑘
𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474
0.15333
𝑘 = 1,2,3,4
𝑟𝑥𝑥
1 −0.0155
4 =
1 0.15333
©Ahmed Hagag SCC430 Modeling and Simulation 70
= −0.10112
Tests for PRNs (6/7)
Example (10/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
𝒓𝒙𝒙(𝒌) −0.28595 −0.61613 0.546638 −0.10112
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 71
1 2 3 4
𝑘
Tests for PRNs (6/7)
Example (10/10)
Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93.
Independence
You can
indicate independence
𝒓𝒙𝒙(𝒌) −0.28595 −0.61613 0.546638 −0.10112
1 2 3 4
𝑘
𝐴𝑣𝑔 𝐴𝑏𝑠 𝑟𝑥𝑥 𝑘 = 0.387456
©Ahmed Hagag SCC430 Modeling and Simulation 72
Tests for PRNs (7/7)
Another forAutocorrelation (1/6)
As an example, consider the following sequence of numbers,
read from left to right:
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 73
Tests for PRNs (7/7)
Another forAutocorrelation (1/6)
As an example, consider the following sequence of numbers,
read from left to right:
From a visual inspection, these numbers appear random, and
they would probably pass all the tests presented to this point.
However, an examination of the 5th, 10th, 15th (every five
numbers beginning with the fifth), and so on, indicates a very
large number in that position.
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 74
Tests for PRNs (7/7)
Another forAutocorrelation (2/6)
The test to be described shortly requires the computation of the
autocorrelation between every 𝑃 numbers (𝑃 is also known as
the lag), starting with the 𝑖th number. Thus, the autocorrelation
𝜌𝑖𝑃 between the following numbers would be of interest:
𝑅𝑖 , 𝑅𝑖+𝑃, 𝑅𝑖+2𝑃, … , 𝑅𝑖+(𝑀+1)𝑃.
The value 𝑀 is the largest integer such that 𝑖 + (𝑀 + 1)𝑃 ≤ 𝑁,
where 𝑁 is the total number of values in the sequence.
Independence
𝑵 − 𝒊 − 𝒍
𝑴 =
𝒍
©Ahmed Hagag SCC430 Modeling and Simulation 75
Tests for PRNs (7/7)
Another forAutocorrelation (3/6)
A nonzero autocorrelation implies a lack of independence, so
the following two-tailed test is appropriate:
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 76
Tests for PRNs (7/7)
Another forAutocorrelation (4/6)
For large values of 𝑀, the distribution of the estimator of 𝜌𝑖𝑃,
denoted 𝜌
ො 𝑖𝑃, is approximately normal if the values
𝑅𝑖 , 𝑅𝑖+𝑃, 𝑅𝑖+2𝑃, … , 𝑅𝑖+(𝑀+1)𝑃 are uncorrelated. Then the test
statistic can be formed as follows:
which is distributed normally with a mean of zero and a
variance of 1, under the assumption of independence, for large
𝑀.
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 77
Tests for PRNs (7/7)
Another forAutocorrelation (5/6) Independence
©Ahmed Hagag SCC430 Modeling and Simulation 78
Tests for PRNs (7/7)
Another forAutocorrelation (6/6)
After computing 𝑍0, do not reject the null hypothesis of
−𝑧𝛼/2 ≤ 𝑍0 ≤ 𝑧𝛼/2
independence if where 𝛼 is the level of
significance and 𝑧𝛼/2 is obtained from the following Table.
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 79
Tests for PRNs (7/7)
Another forAutocorrelation (6/3)
After computing 𝑍0, do not reject the null hypothesis of
−𝑧𝛼/2 ≤ 𝑍0 ≤ 𝑧𝛼/2
independence if where 𝛼 is the level of
significance and 𝑧𝛼/2 is obtained from the following Table.
Independence
©Ahmed Hagag SCC430 Modeling and Simulation 80
Another for Autocorrelation (6/3)
After computing 𝑍0, do not reject the null hypothesis of
−𝑧𝛼/2 ≤ 𝑍0 ≤ 𝑧𝛼/2
independence if where 𝛼 is the level of
significance and 𝑧𝛼/2 is obtained from the following Table.
Independence
Hagag S Modeling and tion 81
Tests for PRNs (7/7)
Example (1/7) Independence
©Ahmed Hagag SCC430 Modeling and Simulation 82
Tests for PRNs (7/7)
Example (2/7) Independence
𝑴 =
𝑵 − 𝒊 − 𝒍
𝒍
=
𝟑𝟎 − 𝟑 − 𝟓
𝟓
©Ahmed Hagag SCC430 Modeling and Simulation 83
= 𝟒
Tests for PRNs (7/7)
Example (3/7) Independence
©Ahmed Hagag SCC430 Modeling and Simulation 84
Tests for PRNs (7/7)
Example (4/7) Independence
©Ahmed Hagag SCC430 Modeling and Simulation 85
Tests for PRNs (7/7)
Example (5/7) Independence
©Ahmed Hagag SCC430 Modeling and Simulation 86
Tests for PRNs (7/7)
Example (6/7) Independence
©Ahmed Hagag SCC430 Modeling and Simulation 87
Tests for PRNs (7/7)
Example (7/7) Independence
Therefore, the hypothesis of independence
cannot be rejected on the basis of this test.
©Ahmed Hagag SCC430 Modeling and Simulation 88
Discussion Question
Draw the bar chart for the following data:
©Ahmed Hagag SCC430 Modeling and Simulation 89
Object Speed (km/hr.)
Ant 0.36
Car 200
Rocket 5,760
Light 1,079,252,848
Discussion Question
Draw the bar chart for the following data:
©Ahmed Hagag SCC430 Modeling and Simulation 90
Dr. AhmedHagag
ahagag@
f
c
i
.bu.edu.eg

More Related Content

Similar to BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx

WCSMO-ModelSelection-2013
WCSMO-ModelSelection-2013WCSMO-ModelSelection-2013
WCSMO-ModelSelection-2013
OptiModel
 
ModelSelection1_WCSMO_2013_Ali
ModelSelection1_WCSMO_2013_AliModelSelection1_WCSMO_2013_Ali
ModelSelection1_WCSMO_2013_Ali
MDO_Lab
 
EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171
Yaxin Liu
 
Parameter Optimisation for Automated Feature Point Detection
Parameter Optimisation for Automated Feature Point DetectionParameter Optimisation for Automated Feature Point Detection
Parameter Optimisation for Automated Feature Point Detection
Dario Panada
 

Similar to BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx (20)

Six Sigma Methods and Formulas for Successful Quality Management
Six Sigma Methods and Formulas for Successful Quality ManagementSix Sigma Methods and Formulas for Successful Quality Management
Six Sigma Methods and Formulas for Successful Quality Management
 
WCSMO-ModelSelection-2013
WCSMO-ModelSelection-2013WCSMO-ModelSelection-2013
WCSMO-ModelSelection-2013
 
ModelSelection1_WCSMO_2013_Ali
ModelSelection1_WCSMO_2013_AliModelSelection1_WCSMO_2013_Ali
ModelSelection1_WCSMO_2013_Ali
 
LOGNORMAL ORDINARY KRIGING METAMODEL IN SIMULATION OPTIMIZATION
LOGNORMAL ORDINARY KRIGING METAMODEL IN SIMULATION OPTIMIZATIONLOGNORMAL ORDINARY KRIGING METAMODEL IN SIMULATION OPTIMIZATION
LOGNORMAL ORDINARY KRIGING METAMODEL IN SIMULATION OPTIMIZATION
 
Software Quality Testing
Software Quality TestingSoftware Quality Testing
Software Quality Testing
 
EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171EE660_Report_YaxinLiu_8448347171
EE660_Report_YaxinLiu_8448347171
 
Six Sigma Methods and Formulas for Successful Quality Management
Six Sigma Methods and Formulas for Successful Quality ManagementSix Sigma Methods and Formulas for Successful Quality Management
Six Sigma Methods and Formulas for Successful Quality Management
 
Grid search.pptx
Grid search.pptxGrid search.pptx
Grid search.pptx
 
Distributional RL via Moment Matching
Distributional RL via Moment MatchingDistributional RL via Moment Matching
Distributional RL via Moment Matching
 
Da35573574
Da35573574Da35573574
Da35573574
 
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...
 
Implementation of K-Nearest Neighbor Algorithm
Implementation of K-Nearest Neighbor AlgorithmImplementation of K-Nearest Neighbor Algorithm
Implementation of K-Nearest Neighbor Algorithm
 
Differential evolution
Differential evolutionDifferential evolution
Differential evolution
 
Comparing the methods of Estimation of Three-Parameter Weibull distribution
Comparing the methods of Estimation of Three-Parameter Weibull distributionComparing the methods of Estimation of Three-Parameter Weibull distribution
Comparing the methods of Estimation of Three-Parameter Weibull distribution
 
Week8 Live Lecture for Final Exam
Week8 Live Lecture for Final ExamWeek8 Live Lecture for Final Exam
Week8 Live Lecture for Final Exam
 
Differential Evolution Algorithm with Triangular Adaptive Control Parameter f...
Differential Evolution Algorithm with Triangular Adaptive Control Parameter f...Differential Evolution Algorithm with Triangular Adaptive Control Parameter f...
Differential Evolution Algorithm with Triangular Adaptive Control Parameter f...
 
Efficient anomaly detection via matrix sketching
Efficient anomaly detection via matrix sketchingEfficient anomaly detection via matrix sketching
Efficient anomaly detection via matrix sketching
 
Parameter Optimisation for Automated Feature Point Detection
Parameter Optimisation for Automated Feature Point DetectionParameter Optimisation for Automated Feature Point Detection
Parameter Optimisation for Automated Feature Point Detection
 
Flavours of Physics Challenge: Transfer Learning approach
Flavours of Physics Challenge: Transfer Learning approachFlavours of Physics Challenge: Transfer Learning approach
Flavours of Physics Challenge: Transfer Learning approach
 
MM - KBAC: Using mixed models to adjust for population structure in a rare-va...
MM - KBAC: Using mixed models to adjust for population structure in a rare-va...MM - KBAC: Using mixed models to adjust for population structure in a rare-va...
MM - KBAC: Using mixed models to adjust for population structure in a rare-va...
 

More from MaiGaafar

Modeling&Simulation_Ch01_lecture 2.pptx
Modeling&Simulation_Ch01_lecture 2.pptxModeling&Simulation_Ch01_lecture 2.pptx
Modeling&Simulation_Ch01_lecture 2.pptx
MaiGaafar
 
Introduction to Time Series Analysis.pptx
Introduction to Time Series Analysis.pptxIntroduction to Time Series Analysis.pptx
Introduction to Time Series Analysis.pptx
MaiGaafar
 
Modeling_Simulation_ch3_lecture_1.pptx
Modeling_Simulation_ch3_lecture_1.pptxModeling_Simulation_ch3_lecture_1.pptx
Modeling_Simulation_ch3_lecture_1.pptx
MaiGaafar
 
strategic-planning_chp (1).pptx
strategic-planning_chp (1).pptxstrategic-planning_chp (1).pptx
strategic-planning_chp (1).pptx
MaiGaafar
 
HU200-Introduction-2020-2021.pptx
HU200-Introduction-2020-2021.pptxHU200-Introduction-2020-2021.pptx
HU200-Introduction-2020-2021.pptx
MaiGaafar
 
Modeling&Simulation_Ch01_part 3.pptx
Modeling&Simulation_Ch01_part 3.pptxModeling&Simulation_Ch01_part 3.pptx
Modeling&Simulation_Ch01_part 3.pptx
MaiGaafar
 
HU200-Supply-modified2020.pptx
HU200-Supply-modified2020.pptxHU200-Supply-modified2020.pptx
HU200-Supply-modified2020.pptx
MaiGaafar
 
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdfBU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
MaiGaafar
 
Modeling&Simulation_Ch04 (1). part 2pptx.pptx
Modeling&Simulation_Ch04 (1). part 2pptx.pptxModeling&Simulation_Ch04 (1). part 2pptx.pptx
Modeling&Simulation_Ch04 (1). part 2pptx.pptx
MaiGaafar
 

More from MaiGaafar (11)

Modeling&Simulation_Ch01_lecture 2.pptx
Modeling&Simulation_Ch01_lecture 2.pptxModeling&Simulation_Ch01_lecture 2.pptx
Modeling&Simulation_Ch01_lecture 2.pptx
 
Lecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptLecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.ppt
 
Introduction to Time Series Analysis.pptx
Introduction to Time Series Analysis.pptxIntroduction to Time Series Analysis.pptx
Introduction to Time Series Analysis.pptx
 
Modeling_Simulation_ch3_lecture_1.pptx
Modeling_Simulation_ch3_lecture_1.pptxModeling_Simulation_ch3_lecture_1.pptx
Modeling_Simulation_ch3_lecture_1.pptx
 
strategic-planning_chp (1).pptx
strategic-planning_chp (1).pptxstrategic-planning_chp (1).pptx
strategic-planning_chp (1).pptx
 
HU200-Introduction-2020-2021.pptx
HU200-Introduction-2020-2021.pptxHU200-Introduction-2020-2021.pptx
HU200-Introduction-2020-2021.pptx
 
sm-161216124538.pptx
sm-161216124538.pptxsm-161216124538.pptx
sm-161216124538.pptx
 
Modeling&Simulation_Ch01_part 3.pptx
Modeling&Simulation_Ch01_part 3.pptxModeling&Simulation_Ch01_part 3.pptx
Modeling&Simulation_Ch01_part 3.pptx
 
HU200-Supply-modified2020.pptx
HU200-Supply-modified2020.pptxHU200-Supply-modified2020.pptx
HU200-Supply-modified2020.pptx
 
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdfBU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
 
Modeling&Simulation_Ch04 (1). part 2pptx.pptx
Modeling&Simulation_Ch04 (1). part 2pptx.pptxModeling&Simulation_Ch04 (1). part 2pptx.pptx
Modeling&Simulation_Ch04 (1). part 2pptx.pptx
 

Recently uploaded

obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
yulianti213969
 

Recently uploaded (20)

Call 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All TimeCall 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
 
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service AvailableNashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Buy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail AccountsBuy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail Accounts
 
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
 
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableBerhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
KOTA 💋 Call Girl 9827461493 Call Girls in Escort service book now
KOTA 💋 Call Girl 9827461493 Call Girls in  Escort service book nowKOTA 💋 Call Girl 9827461493 Call Girls in  Escort service book now
KOTA 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Cuttack Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Cuttack Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableCuttack Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Cuttack Call Girl Just Call 8084732287 Top Class Call Girl Service Available
 
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSDurg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
 
Puri CALL GIRL ❤️8084732287❤️ CALL GIRLS IN ESCORT SERVICE WE ARW PROVIDING
Puri CALL GIRL ❤️8084732287❤️ CALL GIRLS IN ESCORT SERVICE WE ARW PROVIDINGPuri CALL GIRL ❤️8084732287❤️ CALL GIRLS IN ESCORT SERVICE WE ARW PROVIDING
Puri CALL GIRL ❤️8084732287❤️ CALL GIRLS IN ESCORT SERVICE WE ARW PROVIDING
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
 
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdf
 
Cannabis Legalization World Map: 2024 Updated
Cannabis Legalization World Map: 2024 UpdatedCannabis Legalization World Map: 2024 Updated
Cannabis Legalization World Map: 2024 Updated
 

BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx

  • 1. SCC430 Modeling and Simulation Chapter 05 Random-Number Generation Part 02 Dr. Ahmed Hagag Faculty of Computers and Artificial Intelligence Benha University Fall 2020
  • 2. • Properties of Random Numbers. • Generation of Pseudo-Random Numbers. • Techniques for Generating Pseudo-Random Numbers. • Tests for Random Numbers. ©Ahmed Hagag SCC430 Modeling and Simulation 2 Chapter 5: Ran. Num. Gen.
  • 3. Tests for PRNs (1/7) ©Ahmed Hagag SCC430 Modeling and Simulation 3 Introduction (1/5) The properties of random numbers: Uniformity and Independence. Number of tests can be performed to check these properties been achieved or not. • Frequency Test: Uses the Kolmogorov-Smirnov or the Chi-square test to compare the distribution of the set of numbers generated to a uniform distribution. • Autocorrelation Test: Tests the correlation between numbers and compares the sample correlation to the expected correlation, zero.
  • 4. Tests for PRNs (1/7) Introduction (2/5) ©Ahmed Hagag SCC430 Modeling and Simulation 4
  • 5. Tests for PRNs (1/7) Introduction (3/5) In testing for uniformity, the hypotheses are as follows: The null hypothesis, 𝐻0, reads that the numbers are distributed uniformly on the interval [0, 1]. Failure to reject the null hypothesis means that evidence of nonuniformity has not been detected by this test. This does not imply that further testing of the generator for uniformity is unnecessary. ©Ahmed Hagag SCC430 Modeling and Simulation 5
  • 6. Tests for PRNs (1/7) Introduction (4/5) In testing for independence, the hypotheses are as follows: This null hypothesis, 𝐻0, reads that the numbers are independent. Failure to reject the null hypothesis means that evidence of dependence has not been detected by this test. This does not imply that further testing of the generator for independence is unnecessary. ©Ahmed Hagag SCC430 Modeling and Simulation 6
  • 7. Tests for PRNs (1/7) Introduction (5/5) For each test, a level of significance 𝛼 must be stated. The level 𝛼 is the probability of rejecting the null hypothesis when the null hypothesis is true: The decision maker sets the value of 𝛼 for any test. ©Ahmed Hagag SCC430 Modeling and Simulation 7
  • 8. Tests for PRNs (2/7) Kolmogorov-Smirnov (K-S) Test (1/5) Compares the continuous cumulative distribution function (cdf), F(x), of the uniform distribution with the empirical distribution fun. 𝑆𝑁(𝑥) of the sample of N observations. Uniformity 𝐹 𝑥 = 0, 𝑥 ≤ 𝑎 𝑥 − 𝑎 , ©Ahmed Hagag SCC430 Modeling and Simulation 8 𝑏 − 𝑎 1, 𝑎 < 𝑥 < 𝑏 𝑥 ≥ 𝑏
  • 9. Tests for PRNs (2/7) Kolmogorov-Smirnov (K-S) Test (1/5) Compares the continuous cumulative distribution function (cdf), F(x), of the uniform distribution with the empirical distribution fun. 𝑆𝑁(𝑥) of the sample of N observations. 𝐷 = max 𝐹 𝑥 − 𝑆𝑁 𝑥 The sampling distribution of 𝐷 is known; it is tabulated as a function of 𝑁 in the following Table. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 9
  • 10. Tests for PRNs (2/7) ©Ahmed Hagag SCC430 Modeling and Simulation 10
  • 11. Tests for PRNs (2/7) 𝒊𝒇 𝑵 = 𝟖 and 𝑎 = 𝟎. 𝟎𝟓 𝑫𝟎.𝟎𝟓 = 𝟎. 𝟒𝟓𝟕 ©Ahmed Hagag SCC430 Modeling and Simulation 11
  • 12. Tests for PRNs (2/3) Kolmogorov-Smirnov (K-S) Test (1/7) ©Ahmed Hagag SCC430 Modeling and Simulation 12 𝑁 𝟏. 𝟔𝟑 𝑵 𝟏. 𝟑𝟔 𝑵 𝟏. 𝟐𝟐 𝑵 𝟏. 𝟏𝟒 𝑵 𝟏. 𝟎𝟕 𝑵
  • 13. Tests for PRNs (2/7) Kolmogorov-Smirnov (K-S) Test (2/5) For testing against a uniform cdf, the test procedure follows these steps: Step1: Rank the data from smallest to largest. Let 𝑅𝑖 denote 𝑖th smallest observation, so that 𝑅1 ≤ 𝑅2 ≤ ⋯ 𝑅𝑁 𝑖 Step2: Null hypothesis 𝐻0: 𝑅′s~U 0,1 Uniformity Distributed as uniform distribution ©Ahmed Hagag SCC430 Modeling and Simulation 13
  • 14. Tests for PRNs (2/7) Kolmogorov-Smirnov (K-S) Test (3/5) Step3: Compute 𝐷+ and 𝐷−, where 𝐷+ = max 𝑁 𝑖 𝑖 𝑖 𝑖 − 1 − 𝑅 , 𝐷− = max 𝑅 − 𝑁 Step4: Compute 𝐷 = max 𝐷+, 𝐷− Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 14
  • 15. Tests for PRNs (2/7) Kolmogorov-Smirnov (K-S) Test (3/5) Step3: Compute 𝐷+ and 𝐷−, where 𝑁 𝑖 𝐷+ = max 𝑖 − 𝑅 , 𝑖 𝐷− = max 𝑅 − 𝑖 − 1 𝑁 Step4: Compute 𝐷 = max 𝐷+, 𝐷− Uniformity 𝒊 = 𝟏, 𝟐, … , 𝑵 ©Ahmed Hagag SCC430 Modeling and Simulation 15
  • 16. Tests for PRNs (2/7) Kolmogorov-Smirnov (K-S) Test (4/5) Step5: Locate the critical value 𝐷𝛼 in the K-S Table for the specified significance level 𝛼 and the sample size 𝑁. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 16
  • 17. Tests for PRNs (2/7) Kolmogorov-Smirnov (K-S) Test (5/5) Step6: If the sample statistic 𝐷 is greater than the critical value 𝐷𝛼, the null hypothesis is rejected. If 𝐷 ≤ 𝐷𝛼, conclude that we fail to reject the null hypothesis and these PRNs can be accepted according to K-S test. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 17
  • 18. Tests for PRNs (3/7) Example – (K-S) Test (1/5) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. For the specified significance level 𝛼 = 0.05. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 18
  • 19. Tests for PRNs (3/7) Example – (K-S) Test (1/5) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. For the specified significance level 𝛼 = 0.05. Uniformity 𝑵 = 𝟓 and 𝑎 = 𝟎. 𝟎𝟓 ©Ahmed Hagag SCC430 Modeling and Simulation 19
  • 20. Tests for PRNs (3/7) Example – (K-S) Test (2/5) 𝑵 Uniformity 𝑵 = 𝟓 and 𝑎 = 𝟎. 𝟎𝟓 𝑫𝟎.𝟎𝟓 = 𝟎. 𝟓𝟔𝟓 ©Ahmed Hagag SCC430 Modeling and Simulation 20
  • 21. Tests for PRNs (3/7) Example – (K-S) Test (3/5) The 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. First, the numbers must be sorted from smallest to largest. 𝑹𝒊 0.05 0.14 0.44 0.81 0.93 Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 21
  • 22. Tests for PRNs (3/7) Example – (K-S) Test (3/5) Uniformity 𝑹𝒊 0.05 0.14 0.44 0.81 0.93 𝒊 = 𝟏, 𝟐, … , 𝑵 𝑁=5 ©Ahmed Hagag SCC430 Modeling and Simulation 22
  • 23. Tests for PRNs (3/7) Example – (K-S) Test (3/5) Uniformity 𝑹𝒊 0.05 0.14 0.44 0.81 0.93 𝒊 = 𝟏, 𝟐, … , 𝟓 𝑁=5 ©Ahmed Hagag SCC430 Modeling and Simulation 23
  • 24. Tests for PRNs (3/7) Example – (K-S) Test (3/5) 𝑹𝒊 0.05 0.14 0.44 0.81 0.93 𝒊/𝑵 0.20 0.40 0.60 0.80 1.00 Uniformity 𝑁=5 ©Ahmed Hagag SCC430 Modeling and Simulation 24
  • 25. Tests for PRNs (3/7) Example – (K-S) Test (3/5) 𝑹𝒊 0.05 0.14 0.44 0.81 0.93 𝒊/𝑵 0.20 0.40 0.60 0.80 1.00 𝒊/𝑵 – 𝑹𝒊 0.15 0.26 0.16 − 0.07 𝑫+ = 𝟎. 𝟐𝟔 Uniformity 𝑁=5 ©Ahmed Hagag SCC430 Modeling and Simulation 25
  • 26. Tests for PRNs (3/7) Example – (K-S) Test (3/5) 𝑹𝒊 0.05 0.14 0.44 0.81 0.93 𝒊/𝑵 0.20 0.40 0.60 0.80 1.00 𝒊/𝑵 – 𝑹𝒊 0.15 0.26 0.16 − 0.07 (𝒊 − 𝟏)/𝑵 0.00 0.20 0.40 0.60 0.80 𝑫+ = 𝟎. 𝟐𝟔 Uniformity 𝑁=5 ©Ahmed Hagag SCC430 Modeling and Simulation 26
  • 27. Tests for PRNs (3/7) Example – (K-S) Test (3/5) 𝑹𝒊 0.05 0.14 0.44 0.81 0.93 𝒊/𝑵 0.20 0.40 0.60 0.80 1.00 𝒊/𝑵 – 𝑹𝒊 0.15 0.26 0.16 − 0.07 (𝒊 − 𝟏)/𝑵 0.00 0.20 0.40 0.60 0.80 𝑹𝒊 – (𝒊 − 𝟏)/𝑵 0.05 − 0.04 0.21 0.13 𝑁=5 𝑫+ = 𝟎. 𝟐𝟔 𝑫− = 𝟎. 𝟐𝟏 Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 27
  • 28. Tests for PRNs (3/7) Example – (K-S) Test (4/5) 𝐷 = max 𝐷+, 𝐷− = 0.26 Uniformity 𝑫+ = 𝟎. 𝟐𝟔 𝑫− = 𝟎. 𝟐𝟏 ©Ahmed Hagag SCC430 Modeling and Simulation 28
  • 29. Tests for PRNs (3/7) Example – (K-S) Test (5/5) Since the computed value, 0.26, is less than the critical value, 0.565, the hypothesis that the distribution of the generated numbers is the uniform distribution is “failed to reject". 𝐷 = max 𝐷+, 𝐷− = 0.26 < 𝐷𝛼 𝐷𝛼 = 0.565 Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 29
  • 30. Tests for PRNs (4/7) Chi-Square ( 𝝌𝟐 ) Test (1/4) We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁. Step1: We divide [0, 1) into 𝑘 subintervals of equal length (i.e., Classes). (As a general rule, 𝑘 should be at least 100) 𝑖 Step2: Null hypothesis 𝐻0: 𝑅′s~U 0,1 Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 30
  • 31. Tests for PRNs (4/7) Chi-Square ( 𝝌𝟐 ) Test (2/4) We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁. Step3: Chi-square test uses the sample statistic: 𝑖 =1 𝑘 𝑂 − 𝐸 𝜒2 = ෍ 𝑖 𝑖 2 𝐸𝑖 Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 31
  • 32. Tests for PRNs (4/7) Chi-Square ( 𝝌𝟐 ) Test (2/4) We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁. Step3: Chi-square test uses the sample statistic: 𝑖 =1 𝑘 𝑂 − 𝐸 𝜒2 = ෍ 𝑖 𝑖 2 𝐸𝑖 Uniformity 𝒌 is the# of classes ©Ahmed Hagag SCC430 Modeling and Simulation 32
  • 33. Tests for PRNs (4/7) Chi-Square ( 𝝌𝟐 ) Test (2/4) We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁. Step3: Chi-square test uses the sample statistic: 𝑘 𝜒2 = ෍ 𝑖=1 𝑂𝑖 − 𝐸𝑖 2 𝐸𝑖 Uniformity is theobserved # in the 𝒊𝒕𝒉 class How many 𝑹′𝒔 in the 𝒊𝒕𝒉 class 𝒌 is the# of classes ©Ahmed Hagag SCC430 Modeling and Simulation 33
  • 34. Tests for PRNs (4/7) Chi-Square ( 𝝌𝟐 ) Test (2/4) We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁. Step3: Chi-square test uses the sample statistic: 𝑘 𝜒2 = ෍ 𝑖=1 𝑂𝑖 − 𝐸𝑖 2 𝐸𝑖 Uniformity is theobserved # in the 𝒊𝒕𝒉 class is theexpected # in the 𝒊𝒕𝒉 class How many 𝑹′𝒔 in the 𝒊𝒕𝒉 class 𝑵 𝑬𝒊 = 𝒌 Uniform Distribution 𝒌 is the# of classes ©Ahmed Hagag SCC430 Modeling and Simulation 34
  • 35. Tests for PRNs (4/7) Chi-Square ( 𝝌𝟐 ) Test (3/4) We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁. Step4: 𝜒2 will have an approximate chi-square distribution with 𝑘 − 1 degrees of freedom (df) at significance level 𝛼. 𝛼, 𝑘−1 𝜒2 = critical value, where the critical values are tabulated in the following Table. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 35
  • 36. ©Ahmed Hagag SCC430 Modeling and Simulation 36
  • 37. ©Ahmed Hagag SCC430 Modeling and Simulation 37 𝜒 2 𝛼, 𝑘−1
  • 38. ©Ahmed Hagag SCC430 Modeling and Simulation 38 0.025, 9 𝜒2 = 19 𝛼 = 0.025, 𝑘 = 10
  • 39. ©Ahmed Hagag SCC430 Modeling and Simulation 39
  • 40. Tests for PRNs (4/7) Chi-Square ( 𝝌𝟐 ) Test (4/4) We have 𝑁 generated PRNs are 𝑅1, 𝑅2, … , 𝑅𝑁. Step5: If 𝜒2 > 𝜒2 , we reject 𝐻0, else we fail to reject 𝐻0. 𝛼, 𝑘−1 Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 40
  • 41. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (1/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 41
  • 42. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (2/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Step1: We divide [0, 1) into 𝟏𝟎 subintervals of equal length. [0, 0.1), [0.1, 0.2), [0.2, 0.3), …, [0.9,1.0) Or we divide (0, 1] into 𝟏𝟎 subintervals of equal length. (0, 0.1], (0.1, 0.2], (0.2, 0.3], …, (0.9,1.0] 𝑖 Step2: Null hypothesis 𝐻0: 𝑅′s~U 0,1 Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 42
  • 43. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (3/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Step3: Chi-square test uses the sample statistic: 𝑘 𝜒2 = ෍ 𝑖=1 𝑂𝑖 − 𝐸𝑖 2 𝐸𝑖 Uniformity is theobserved # in the 𝒊𝒕𝒉 class is theexpected # in the 𝒊𝒕𝒉 class How many 𝑹′𝒔 in the 𝒊𝒕𝒉 class 𝑵 𝑬𝒊 = 𝒌 𝒌 is the# of classes ©Ahmed Hagag SCC430 Modeling and Simulation 43
  • 44. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (3/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Step3: Chi-square test uses the sample statistic: 𝑘 𝜒2 = ෍ 𝑖=1 𝑂𝑖 − 𝐸𝑖 2 𝐸𝑖 Uniformity is theobserved # in the 𝒊𝒕𝒉 class is theexpected # in the 𝒊𝒕𝒉 class How many 𝑹′𝒔 in the 𝒊𝒕𝒉 class 𝟏𝟎𝟎 𝑬𝒊 = 𝟏𝟎 = 𝟏𝟎 𝒌 is the# of classes =10 ©Ahmed Hagag SCC430 Modeling and Simulation 44
  • 45. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (3/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Step3: Chi-square test uses the sample statistic: 𝑖 =1 10 𝜒2 = ෍ 𝑖 𝑂 − 10 2 10 Uniformity is theobserved # in the 𝒊𝒕𝒉 class is theexpected # in the 𝒊𝒕𝒉 class How many 𝑹′𝒔 in the 𝒊𝒕𝒉 class 𝟏𝟎𝟎 𝑬𝒊 = 𝟏𝟎 = 𝟏𝟎 ©Ahmed Hagag SCC430 Modeling and Simulation 45
  • 46. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (4/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 46 (0.0, 0.1] (0.1, 0.2] (0.2, 0.3] (0.9, 1.0]
  • 47. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (4/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 47 (0.0, 0.1] (0.1, 0.2] (0.2, 0.3] (0.9, 1.0]
  • 48. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (4/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 48 (0.0, 0.1] (0.1, 0.2] (0.2, 0.3] (0.9, 1.0]
  • 49. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (4/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 49 (0.0, 0.1] (0.1, 0.2] (0.2, 0.3] (0.9, 1.0]
  • 50. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (4/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 50 (0.0, 0.1] (0.1, 0.2] (0.2, 0.3] (0.9, 1.0]
  • 51. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (5/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Uniformity 𝑘 𝜒2 = ෍ 𝑖=1 𝑂𝑖 − 𝐸 2 𝐸𝑖 𝑖 = 3.4 (0.0, 0.1] (0.1, 0.2] (0.2, 0.3] ©Ahmed Hagag SCC430 Modeling and Simulation 51 (0.9, 1.0]
  • 52. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (6/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Step4: Calculate 𝜒2 = 𝜒2 𝛼, 𝑘−1 0.05, 9 Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 52
  • 53. ©Ahmed Hagag SCC430 Modeling and Simulation 53 0.05, 9 𝜒2 = 16.9
  • 54. Tests for PRNs (5/7) Example – ( 𝝌𝟐) Test (7/7) We have 100 generated PRNs 𝑅′s are shown below. Use 𝑖 Chi-square test with 𝛼 = 0.05 and 𝑘 = 10. Step5: 𝜒2 = 3.4 0.05, 9 𝜒2 = 16.9 0.05, 9 ∵ 𝜒2 < 𝜒2 , then we fail to reject 𝐻0, and these PRNs are accepted according to chi-square test. Uniformity ©Ahmed Hagag SCC430 Modeling and Simulation 54
  • 55. Tests for PRNs (6/7) Autocorrelation (1/3) Correlation between a signal and itself signals for detecting dependency. Efficient calculation of correlation coefficient between two sequences (listed in time order of collection) 𝑥(𝑖), 𝑦(𝑖), where 𝑖 = 1, 2, … , 𝑛. Independence ©Ahmed Hagag SCC430 Modeling and Simulation 55
  • 56. Tests for PRNs (6/7) Autocorrelation (1/3) Correlation between a signal and itself signals for detecting dependency. Efficient calculation of correlation coefficient between two sequences (listed in time order of collection) 𝑥(𝑖), 𝑦(𝑖), where 𝑖 = 1, 2, … , 𝑛. Independence 𝑖 =1 expected value (sample mean) = σ𝑛 𝑥𝑖 /𝑛 ©Ahmed Hagag SCC430 Modeling and Simulation 56
  • 57. Tests for PRNs (6/7) Autocorrelation (1/3) Correlation between a signal and itself signals for detecting dependency. Efficient calculation of correlation coefficient between two sequences (listed in time order of collection) 𝑥(𝑖), 𝑦(𝑖), where 𝑖 = 1, 2, … , 𝑛. Independence 𝑟𝑥𝑦 = 1 𝑛 − 1 𝑖 =1 σ𝑛 𝑥𝑖 − 𝑥ҧ𝑦𝑖 − 𝑦 ത 𝑠𝑥𝑠𝑦 standard deviation 𝑠𝑥 ©Ahmed Hagag SCC430 Modeling and Simulation 57
  • 58. Tests for PRNs (6/7) Autocorrelation (2/3) Efficient calculation of correlation sequence 𝑥(𝑖), where 𝑖 = 1, 2, … , 𝑛. coefficient for a 𝑥 𝑥 𝑟 𝑘 = 1 𝑛 − 𝑘 𝑖 =1 σ𝑛−𝑘 𝑥𝑖 − 𝑥ҧ𝑥 𝑖+𝑘 − 𝑥 ҧ 𝑠𝑥𝑠𝑥 𝑟𝑥𝑥 𝑘 is calculated for 𝑘 = 1, 2, … , 𝑛 − 1 for 𝑛 PRNs. Independence ©Ahmed Hagag SCC430 Modeling and Simulation 58
  • 59. Tests for PRNs (6/7) Autocorrelation (3/3) 𝑟𝑥𝑥 𝑘 is calculated for 𝑘 = 1,2, … , 𝑛 − 1 for 𝑛 PRNs. If the samples are independent, then all the values should be theoretically zero. But in practice we can say: • Small values (close to zero) indicate independence. • Large values (close to 1) indicate dependence. Independence ©Ahmed Hagag SCC430 Modeling and Simulation 59
  • 60. Tests for PRNs (6/7) Example (1/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. Independence ©Ahmed Hagag SCC430 Modeling and Simulation 60
  • 61. Tests for PRNs (6/7) Example (2/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 Independence 1 2 3 4 5 𝒏 = 𝟓 ©Ahmed Hagag SCC430 Modeling and Simulation 61
  • 62. Tests for PRNs (6/7) Example (2/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 Independence 1 2 3 4 5 𝒏 = 𝟓 ©Ahmed Hagag SCC430 Modeling and Simulation 62
  • 63. Tests for PRNs (6/7) Example (3/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 Independence 1 2 3 4 5 𝒏 = 𝟓 𝑥ҧ = 𝑖 =1 σ𝑛 𝑥𝑖 𝑛 = 0.44 + 0.81 + 0.14 + 0.05 + 0.93 5 = 0.474 𝑠𝑥 ©Ahmed Hagag SCC430 Modeling and Simulation 63
  • 64. Tests for PRNs (6/7) Example (4/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 𝒙𝒊 − 𝒙 ഥ -0.034 0.336 -0.334 -0.424 0.456 Independence 1 2 3 4 5 𝑥ҧ = 0.474 𝑠𝑥 𝑠𝑥 = 0.15333 ©Ahmed Hagag SCC430 Modeling and Simulation 64
  • 65. Tests for PRNs (6/7) Example (4/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 𝒙𝒊 − 𝒙 ഥ -0.034 0.336 -0.334 -0.424 0.456 Independence 1 2 3 4 5 𝑥ҧ = 0.474 𝑠𝑥 𝑠𝑥 = 0.15333 ©Ahmed Hagag SCC430 Modeling and Simulation 65
  • 66. Tests for PRNs (6/7) Example (5/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 Independence 1 2 3 4 5 𝑥ҧ = 0.474 𝑠𝑥 = 0.15333 𝑟𝑥𝑥 𝑘 = 1 5 − 𝑘 𝑖 =1 σ5−𝑘 𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474 0.15333 𝑘 = 1,2,3,4 ©Ahmed Hagag SCC430 Modeling and Simulation 66
  • 67. Tests for PRNs (6/7) Example (6/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 Independence 1 2 3 4 5 𝑥ҧ = 0.474 𝑠𝑥 = 0.15333 𝑟𝑥𝑥 𝑘 = 1 5 − 𝑘 𝑖 =1 σ5−𝑘 𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474 0.15333 𝑘 = 1,2,3,4 𝑟𝑥𝑥 1 −0.17538 1 = 4 0.15333 ©Ahmed Hagag SCC430 Modeling and Simulation 67 = −0.28595
  • 68. Tests for PRNs (6/7) Example (7/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 Independence 1 2 3 4 5 𝑥ҧ = 0.474 𝑠𝑥 = 0.15333 𝑟𝑥𝑥 𝑘 = 1 5 − 𝑘 𝑖 =1 σ5−𝑘 𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474 0.15333 𝑘 = 1,2,3,4 𝑟𝑥𝑥 1 −0.28341 2 = 3 0.15333 ©Ahmed Hagag SCC430 Modeling and Simulation 68 = −0.61613
  • 69. Tests for PRNs (6/7) Example (8/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 Independence 1 2 3 4 5 𝑥ҧ = 0.474 𝑠𝑥 = 0.15333 𝑟𝑥𝑥 𝑘 = 1 5 − 𝑘 𝑖 =1 σ5−𝑘 𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474 0.15333 𝑘 = 1,2,3,4 𝑟𝑥𝑥 1 0.167632 3 = 2 0.15333 ©Ahmed Hagag SCC430 Modeling and Simulation 69 = 0.546638
  • 70. Tests for PRNs (6/7) Example (9/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒙𝒊 0.44 0.81 0.14 0.05 0.93 Independence 1 2 3 4 5 𝑥ҧ = 0.474 𝑠𝑥 = 0.15333 𝑟𝑥𝑥 𝑘 = 1 5 − 𝑘 𝑖 =1 σ5−𝑘 𝑥𝑖 − 0.474 𝑥 𝑖+𝑘 − 0.474 0.15333 𝑘 = 1,2,3,4 𝑟𝑥𝑥 1 −0.0155 4 = 1 0.15333 ©Ahmed Hagag SCC430 Modeling and Simulation 70 = −0.10112
  • 71. Tests for PRNs (6/7) Example (10/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. 𝒓𝒙𝒙(𝒌) −0.28595 −0.61613 0.546638 −0.10112 Independence ©Ahmed Hagag SCC430 Modeling and Simulation 71 1 2 3 4 𝑘
  • 72. Tests for PRNs (6/7) Example (10/10) Suppose 5 generated numbers are 0.44, 0.81, 0.14, 0.05, 0.93. Independence You can indicate independence 𝒓𝒙𝒙(𝒌) −0.28595 −0.61613 0.546638 −0.10112 1 2 3 4 𝑘 𝐴𝑣𝑔 𝐴𝑏𝑠 𝑟𝑥𝑥 𝑘 = 0.387456 ©Ahmed Hagag SCC430 Modeling and Simulation 72
  • 73. Tests for PRNs (7/7) Another forAutocorrelation (1/6) As an example, consider the following sequence of numbers, read from left to right: Independence ©Ahmed Hagag SCC430 Modeling and Simulation 73
  • 74. Tests for PRNs (7/7) Another forAutocorrelation (1/6) As an example, consider the following sequence of numbers, read from left to right: From a visual inspection, these numbers appear random, and they would probably pass all the tests presented to this point. However, an examination of the 5th, 10th, 15th (every five numbers beginning with the fifth), and so on, indicates a very large number in that position. Independence ©Ahmed Hagag SCC430 Modeling and Simulation 74
  • 75. Tests for PRNs (7/7) Another forAutocorrelation (2/6) The test to be described shortly requires the computation of the autocorrelation between every 𝑃 numbers (𝑃 is also known as the lag), starting with the 𝑖th number. Thus, the autocorrelation 𝜌𝑖𝑃 between the following numbers would be of interest: 𝑅𝑖 , 𝑅𝑖+𝑃, 𝑅𝑖+2𝑃, … , 𝑅𝑖+(𝑀+1)𝑃. The value 𝑀 is the largest integer such that 𝑖 + (𝑀 + 1)𝑃 ≤ 𝑁, where 𝑁 is the total number of values in the sequence. Independence 𝑵 − 𝒊 − 𝒍 𝑴 = 𝒍 ©Ahmed Hagag SCC430 Modeling and Simulation 75
  • 76. Tests for PRNs (7/7) Another forAutocorrelation (3/6) A nonzero autocorrelation implies a lack of independence, so the following two-tailed test is appropriate: Independence ©Ahmed Hagag SCC430 Modeling and Simulation 76
  • 77. Tests for PRNs (7/7) Another forAutocorrelation (4/6) For large values of 𝑀, the distribution of the estimator of 𝜌𝑖𝑃, denoted 𝜌 ො 𝑖𝑃, is approximately normal if the values 𝑅𝑖 , 𝑅𝑖+𝑃, 𝑅𝑖+2𝑃, … , 𝑅𝑖+(𝑀+1)𝑃 are uncorrelated. Then the test statistic can be formed as follows: which is distributed normally with a mean of zero and a variance of 1, under the assumption of independence, for large 𝑀. Independence ©Ahmed Hagag SCC430 Modeling and Simulation 77
  • 78. Tests for PRNs (7/7) Another forAutocorrelation (5/6) Independence ©Ahmed Hagag SCC430 Modeling and Simulation 78
  • 79. Tests for PRNs (7/7) Another forAutocorrelation (6/6) After computing 𝑍0, do not reject the null hypothesis of −𝑧𝛼/2 ≤ 𝑍0 ≤ 𝑧𝛼/2 independence if where 𝛼 is the level of significance and 𝑧𝛼/2 is obtained from the following Table. Independence ©Ahmed Hagag SCC430 Modeling and Simulation 79
  • 80. Tests for PRNs (7/7) Another forAutocorrelation (6/3) After computing 𝑍0, do not reject the null hypothesis of −𝑧𝛼/2 ≤ 𝑍0 ≤ 𝑧𝛼/2 independence if where 𝛼 is the level of significance and 𝑧𝛼/2 is obtained from the following Table. Independence ©Ahmed Hagag SCC430 Modeling and Simulation 80
  • 81. Another for Autocorrelation (6/3) After computing 𝑍0, do not reject the null hypothesis of −𝑧𝛼/2 ≤ 𝑍0 ≤ 𝑧𝛼/2 independence if where 𝛼 is the level of significance and 𝑧𝛼/2 is obtained from the following Table. Independence Hagag S Modeling and tion 81
  • 82. Tests for PRNs (7/7) Example (1/7) Independence ©Ahmed Hagag SCC430 Modeling and Simulation 82
  • 83. Tests for PRNs (7/7) Example (2/7) Independence 𝑴 = 𝑵 − 𝒊 − 𝒍 𝒍 = 𝟑𝟎 − 𝟑 − 𝟓 𝟓 ©Ahmed Hagag SCC430 Modeling and Simulation 83 = 𝟒
  • 84. Tests for PRNs (7/7) Example (3/7) Independence ©Ahmed Hagag SCC430 Modeling and Simulation 84
  • 85. Tests for PRNs (7/7) Example (4/7) Independence ©Ahmed Hagag SCC430 Modeling and Simulation 85
  • 86. Tests for PRNs (7/7) Example (5/7) Independence ©Ahmed Hagag SCC430 Modeling and Simulation 86
  • 87. Tests for PRNs (7/7) Example (6/7) Independence ©Ahmed Hagag SCC430 Modeling and Simulation 87
  • 88. Tests for PRNs (7/7) Example (7/7) Independence Therefore, the hypothesis of independence cannot be rejected on the basis of this test. ©Ahmed Hagag SCC430 Modeling and Simulation 88
  • 89. Discussion Question Draw the bar chart for the following data: ©Ahmed Hagag SCC430 Modeling and Simulation 89 Object Speed (km/hr.) Ant 0.36 Car 200 Rocket 5,760 Light 1,079,252,848
  • 90. Discussion Question Draw the bar chart for the following data: ©Ahmed Hagag SCC430 Modeling and Simulation 90