Computer Science, Informatik 4 Communication and Distributed Systems
Simulation Simulation
Modeling and Performance Analysis with Discrete-Event Simulation g y
- Dr. Mesut Güneş
Simulation Simulation Modeling and Performance Analysis with - - PowerPoint PPT Presentation
Computer Science, Informatik 4 Communication and Distributed Systems Simulation Simulation Modeling and Performance Analysis with Discrete-Event Simulation g y Dr. Mesut Gne Computer Science, Informatik 4 Communication and Distributed
Computer Science, Informatik 4 Communication and Distributed Systems
Modeling and Performance Analysis with Discrete-Event Simulation g y
Computer Science, Informatik 4 Communication and Distributed Systems
Random-Number Generation
Computer Science, Informatik 4 Communication and Distributed Systems
Contents Contents Properties of Random Numbers Properties of Random Numbers Generation of Pseudo-Random Numbers
Tests for Random Numbers
Chapter 6. Random-Number Generation 3
Computer Science, Informatik 4 Communication and Distributed Systems
Purpose & Overview Purpose & Overview Discuss the generation of random numbers. Discuss the generation of random numbers. Introduce the subsequent testing for randomness:
Chapter 6. Random-Number Generation 4
Computer Science, Informatik 4 Communication and Distributed Systems
Properties of Random Numbers Properties of Random Numbers
Two important statistical properties:
distribution with pdf:
1 2 1
pdf for random numbers
1
Chapter 6. Random-Number Generation 5
Computer Science, Informatik 4 Communication and Distributed Systems
Generation of Pseudo-Random Numbers Generation of Pseudo Random Numbers
Chapter 6. Random-Number Generation 6
Computer Science, Informatik 4 Communication and Distributed Systems
Generation of Pseudo-Random Numbers Generation of Pseudo-Random Numbers
Pseudo , because generating numbers using a known method removes the potential for true randomness.
imitates the ideal properties of random numbers (RN) imitates, the ideal properties of random numbers (RN).
Replicable
independence
Chapter 6. Random-Number Generation 7
Computer Science, Informatik 4 Communication and Distributed Systems
Generation of Pseudo-Random Numbers Generation of Pseudo-Random Numbers Problems when generating pseudo-random numbers Problems when generating pseudo random numbers
continuous-valued
low
Several Numbers above the mean followed by several numbers below the mean
Chapter 6. Random-Number Generation 8
Computer Science, Informatik 4 Communication and Distributed Systems
Techniques for Generating Random Numbers Techniques for Generating Random Numbers
Chapter 6. Random-Number Generation 9
Computer Science, Informatik 4 Communication and Distributed Systems
Techniques for Generating Random Numbers Techniques for Generating Random Numbers
g ( )
Chapter 6. Random-Number Generation 10
Computer Science, Informatik 4 Communication and Distributed Systems
Linear Congruential Method Linear Congruential Method
p q g
1 2
by following a recursive relationship:
2 1 mod ) (
1
= + = i m c aX X
i i
,... 2 , 1 , , mod ) (
1
+
+
i m c aX X
i i
The The The modulus
multiplier increment modulus
The selection of the values for a, c, m, and X0 drastically affects the statistical properties and the cycle length.
the integers to random numbers: the integers to random numbers: ,... 2 , 1 , = = i m X R
i i
Chapter 6. Random-Number Generation 11
m
Computer Science, Informatik 4 Communication and Distributed Systems
Linear Congruential Method – Example Linear Congruential Method – Example
, , ,
X1 = (17*27+43) mod 100 = 502 mod 100 = 2, R1 = 0.02; X2 = (17*2 +43) mod 100 = 77, R2 = 0.77; X3 = (17*77+43) mod 100 = 52, R3 = 0.52;
3
( 7 77 3)
5 ,
3
0.5 ; X4= (17*52+43) mod 100 = 27, R3 = 0.27; …
Chapter 6. Random-Number Generation 12
Computer Science, Informatik 4 Communication and Distributed Systems
Linear Congruential Method – Example Linear Congruential Method – Example
i Xi Xi Xi Xi
X0=1 X0=2 X0=3 X0=4 1 1 2 3 4 2 13 26 39 52 3 41 18 59 36
3 41 18 59 36 4 21 42 63 20 5 17 34 51 4 6 29 58 23
7 57 50 43 8 37 10 47 9 33 2 35 10 45 7 10 45 7 11 9 27 12 53 31 13 49 19 13 49 19 14 61 55 15 25 11 16 5 15
Chapter 6. Random-Number Generation
17 1 3
13
Computer Science, Informatik 4 Communication and Distributed Systems
Characteristics of a Good Generator Characteristics of a Good Generator
[0,1]
i
power of 2.
Chapter 6. Random-Number Generation 14
Computer Science, Informatik 4 Communication and Distributed Systems
Random-Numbers in Java Random-Numbers in Java Defined in java.util.Random Defined in java.util.Random
private final static long multiplier = 0x5DEECE66DL; // 25214903917 i t fi l t ti l dd d 0 BL // 11 private final static long addend = 0xBL; // 11 private final static long mask = (1L << 48) - 1; // 281474976710655 protected int next(int bits) { protected int next(int bits) { long oldseed, nextseed; ...
nextseed = (oldseed * multiplier + addend) & mask; ... return (int)(nextseed >>> (48 - bits)); // >>> Unsigned right shift }
Chapter 6. Random-Number Generation 15
Computer Science, Informatik 4 Communication and Distributed Systems
Combined Linear Congruential Generators Combined Linear Congruential Generators
Reason: Longer period generator is needed because of the increasing complexity of simulated systems.
generators.
congruential generators.
g
i,j
pp g [
j
]
Chapter 6. Random-Number Generation 16
Computer Science, Informatik 4 Communication and Distributed Systems
Combined Linear Congruential Generators Combined Linear Congruential Generators
Sugges ed o
1 mod ) 1 (
1 1
− ⎟ ⎟ ⎞ ⎜ ⎜ ⎛ − = ∑
−
m X X
k j i j i
⎪ ⎪ ⎨ ⎧ > = 1 , Hence,
1 i i i
X m X R ) (
1 1 , ⎟
⎠ ⎜ ⎝∑
= j j i i
⎪ ⎪ ⎩ ⎨ = − , 1 ,
1 1 i i
X m m
The coefficient: Performs the subtraction Xi,1-1
) 1 ) ( 1 )( 1 (
1 2 1
2 ) 1 )...( 1 )( 1 (
−
− − − =
k k
m m m P
Chapter 6. Random-Number Generation 17
Computer Science, Informatik 4 Communication and Distributed Systems
Combined Linear Congruential Generators Combined Linear Congruential Generators
a p e
b t co pute s, co b g k ge e ato s t m1 = 2147483563, a1 = 40014, m2 = 2147483399 and a2 = 40692. The algorithm becomes:
Step 1: Select seeds
Step 2: For each individual generator, X1,j+1 = 40014 X1,j mod 2147483563 X2,j+1 = 40692 X2,j mod 2147483399
Step 3:
Xj+1 = (X1,j+1 - X2,j+1 ) mod 2147483562
Step 4: Return Step 4: Return
⎪ ⎪ ⎪ ⎨ ⎧ > =
+ + +
, 2147483563
1 1 1 j j j
X X R
S S b k 2
⎪ ⎪ ⎩ =
+
, 2147483563 2147483562
1 j
X
Chapter 6. Random-Number Generation 18
Step 5: Set j = j+1, go back to step 2.
Computer Science, Informatik 4 Communication and Distributed Systems
Random-Numbers in Excel 2003 Random-Numbers in Excel 2003 In Excel 2003 new Random Number Generator In Excel 2003 new Random Number Generator
It is stated that this method produces more than 10^13 numbers
Chapter 6. Random-Number Generation 19
Computer Science, Informatik 4 Communication and Distributed Systems
Random-Numbers Streams Random-Numbers Streams
g g
P
b i b i
) 1 (
−
virtual random-number generators
the same purpose in each of the simulated systems.
Chapter 6. Random-Number Generation 20
Computer Science, Informatik 4 Communication and Distributed Systems
Tests for Random Numbers Tests for Random Numbers
Chapter 6. Random-Number Generation 21
Computer Science, Informatik 4 Communication and Distributed Systems
Tests for Random Numbers Tests for Random Numbers
Two categories:
H0: Ri ~ U[0,1] H1: Ri ≁ U[0,1]
uniformity has not been detected.
H0: Ri ~ independently H1: Ri ≁ independently
1 i
p y
dependence has not been detected.
α = P( reject H0 | H0 is true)
Chapter 6. Random-Number Generation 22
Computer Science, Informatik 4 Communication and Distributed Systems
Tests for Random Numbers Tests for Random Numbers
When to use these tests:
used, it is probably unnecessary to test
spreadsheet
programs, symbolic/numerical calculators, tests should be applied to many sample numbers.
eo et ca tests e a uate t e c o ces o m, a, a d c t out actua y generating any numbers
Our emphasis.
Chapter 6. Random-Number Generation 23
Computer Science, Informatik 4 Communication and Distributed Systems
Frequency Tests Frequency Tests
Test of uniformity
Chapter 6. Random-Number Generation 24
Computer Science, Informatik 4 Communication and Distributed Systems
Kolmogorov-Smirnov Test Kolmogorov-Smirnov Test
p , ( ), the empirical cdf, SN(x), of the N sample observations.
1 ) ( ≤ ≤ F
1 , ) ( ≤ ≤ = x x x F
is:
i i N
Chapter 6. Random-Number Generation 25
Computer Science, Informatik 4 Communication and Distributed Systems
Kolmogorov-Smirnov Test Kolmogorov-Smirnov Test
Kolmogorov-Smirnov Critical Values
g p
R(1) ≤ R(2) ≤ ... ≤ R(N)
⎬ ⎫ ⎨ ⎧
+
R i D ⎭ ⎬ ⎫ ⎩ ⎨ ⎧ − − = ⎭ ⎬ ⎩ ⎨ − =
≤ ≤ − ≤ ≤ +
N i R D R N D
i N i i N i
1 max max
) ( 1 ) ( 1
St 3 C t D (D+ D ) ⎭ ⎬ ⎩ ⎨
≤ ≤
N
i N i ) ( 1
Chapter 6. Random-Number Generation 26
Computer Science, Informatik 4 Communication and Distributed Systems
Kolmogorov-Smirnov Test Kolmogorov-Smirnov Test
Example: Suppose N 5 numbers: 0.44, 0.81, 0.14, 0.05, 0.93.
Step 1:
Arrange R(i) from smallest to largest i 1 2 3 4 5 R(i) 0.05 0.14 0.44 0.81 0.93
Step 1: Step 2:
D+ = max {i/N – R(i)}
(i)
i/N 0.20 0.40 0.60 0.80 1.00 i/N – R(i) 0.15 0.26 0.16
Step 2: Step 3: D = max(D+, D-) = 0.26
D - = max {R(i) - (i-1)/N} R(i) – (i-1)/N 0.05
0.21 0.13
Step 4: For α = 0.05, Dα = 0.565 > D Hence, H0 is not rejected.
Chapter 6. Random-Number Generation 27
Computer Science, Informatik 4 Communication and Distributed Systems
Chi-square Test Chi-square Test
q p
−
n i i
E O
2 2
) (
n is the # of classes Ei is the expected # in the i-th class
=
= Χ
i i i i
E E O
1 2
) (
Oi is the observed # in the i-th class
F th if di t ib ti E th t d b i h l i
n
# total the is N where , n N Ei =
Chapter 6. Random-Number Generation 28
Computer Science, Informatik 4 Communication and Distributed Systems
Chi-square Test – Example Chi-square Test – Example
Interval Upper Limit Oi Ei Oi-Ei (Oi-Ei)^2 (Oi-Ei)^2/Ei
p numbers from [0,1]
10 i t l
1 0.1 10 10 2 0.2 9 10
1 0.1 3 0.3 5 10
25 2.5
0.05,9 = 16.9
4 0.4 6 10
16 1.6 5 0.5 16 10 6 36 3.6 6 0 6 13 10 3 9 0 9
Accept, since
0=11.2 < X2 0.05,9
6 0.6 13 10 3 9 0.9 7 0.7 10 10 8 0.8 7 10
9 0.9 9 0 9 10 10 9 0.9 10 10 10 1.0 14 10 4 16 1.6 S 100 100 11.2
X2
0=11.2
Chapter 6. Random-Number Generation 29
Computer Science, Informatik 4 Communication and Distributed Systems
Tests for Autocorrelation Tests for Autocorrelation Autocorrelation is concerned with dependence between p numbers in a sequence Example:
0.12 0.01 0.23 0.28 0.89 0.31 0.64 0.28 0.83 0.93 0.99 0.15 0.33 0.35 0.91 0.41 0.60 0.27 0.75 0.88
Numbers at 5-th, 10-th, 15-th, ... are very similar
0.68 0.49 0.05 0.43 0.95 0.58 0.19 0.36 0.69 0.87
Numbers can be
Chapter 6. Random-Number Generation 30
Computer Science, Informatik 4 Communication and Distributed Systems
Tests for Autocorrelation Tests for Autocorrelation
g y ( the lag), starting with the i-th number
N )m (M i ≤ + + 1
N )m (M i ≤ + + 1 yp
dependent are numbers if t independen are numbers if
, : , :
1
≠ =
i im
H H ρ ρ
denoted ρ ˆ dependent are numbers if
, :
1
≠
im
H ρ
is approximately normal.
im
ρ
Chapter 6. Random-Number Generation 31
Computer Science, Informatik 4 Communication and Distributed Systems
Tests for Autocorrelation Tests for Autocorrelation
im
im
ρ
. R R M ρ
M )m (k i km i im
25 1 1 ˆ
1
− ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⋅ + =
+ + +
) (M M σ M
im
ρ k
1 12 7 13 ˆ 1 + + = ⎦ ⎣ +
=
) (M 1 12 +
Chapter 6. Random-Number Generation 32
Computer Science, Informatik 4 Communication and Distributed Systems
Example Example
Test whether the 3 , 8 , 13 , and so on, for the numbers on Slide 24.
25 ) 36 . )( 05 . ( ) 05 . )( 27 . ( ) 27 . )( 33 . ( ) 33 . )( 28 . ( ) 28 . )( 23 . ( 1 4 1 ˆ35 − ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ + + + + + = . ρ 128 7 ) 4 ( 13 1945 . ) )( ( ) )( ( + − = ⎦ ⎣ σ 516 . 1 1280 1945 . 128 . 1 4 12
ˆ35
− = − = = + = Z ) ( σ ρ
1280 .
Chapter 6. Random-Number Generation 33
0.025
.96 e ce, e ypo es s s
Computer Science, Informatik 4 Communication and Distributed Systems
Shortcomings Shortcomings
The test is not very sensitive for small values of M, particularly when the numbers being tested are on the low side.
t t tests:
alone, is 0.9510 = 0.60.
Hence, the probability of detecting significant autocorrelation when it does not exist = 40%
Chapter 6. Random-Number Generation 34
Computer Science, Informatik 4 Communication and Distributed Systems
Summary Summary
In this chapter, we described:
g y , in use, are found to be inadequate.
pattern might have gone undetected.
Chapter 6. Random-Number Generation 35