Module 06 Lecture Slides
Module 06 Lecture Slides
Introduction
M6-001
Module Overview
Last Module: We covered basic
(and advanced) Arena concepts.
To Serve Man:
www.youtube.com/watch?v=dk01eeKMD_I
M6-002
Module Overview
1. Introduction • This lesson
2. Some Lousy Generators
3. Linear Congruential
Generators
4. Tausworthe Generators
5. Generalizations of LCGs
6. Choosing a Good Generator
— Some Theory
7. Choosing a Good Generator
— Statistical Tests
M6-003
Introduction
niform(O 1 random number are the ke to random ariate
generation in imulation - ou tran form uniform to et other RV .
M6-006
Computer Simulation
Module 6: Generating Uniform
Random Numbers
M6-007
Lesson Overview
Last Lesson: We introduced the
topic of Unif(0,1) generation. It’s
the key to all knowledge!
M6-008
Some Lousy Generators
a. Random Device
ice randomne propertie . Howe er Unif O 1 equence torage
difficult o it tough to repeat exp riment.
Example ·
■ flip a oin
■ particle count b Geiger counter
■ lea t ignificant diait of atomic clock
M6-009
More Lousy Generators
b. Random umber Table
Li t of digit upplied in table .
M6-010
Even More!
c. id-Square ethod J. on eu1nann
Idea: Take the middle part of the quar of the pre iou random
number. on eumann wa a fun-lo in gu but method i terrible!
Example: Take R - == ·/ 10000 v· where are integer < 10000.
t d o == 632· then 6 22 ➔ 98342 ·
So 1 == 3 · then 9 2 ➔ 9 7075 ·
So 2 == 707 etc ...
U nfortunatel po 1t1 e erial orrelation in Ri
Al o oc a ionall degenerate · e.g. con ider
M6-011
· == 0003.
Still More Bad Boys
d. Fibonacci and Additi e Congruential Generator
1, ·- 1 + i- 2 dm . == 1 2 ....
)
M6-013
Computer Simulation
Module 6: Generating Uniform
Random Numbers
Linear Congruential
Generators
M6-014
Lesson Overview
Last Time: Discussed some awful
Unif(0,1) generators.
M6-015
LCGs
LCG are the 1no t widel u ed generator . The e are pretty good
when implemented properly.
R · == ·/ '
. == 1. 2
J
i - ( ·-1 +3 m
If 0 == 0 we ha e 1 == ( o+ 1n d -- · continuing
0 1 2 3 4 s 6 7 9
0 3 2 s 4 7 6 1 0 3
3 2 4 7 6 1 3
R· 0 - - - - - - 0 -
-
~
(4,7)
j
?_
,,,,
/ (7,6) /
(2,5),..,, / / ~
/ (5,4) I/
(0,3) I / / ~
I
/ (3,2) ,L_
,,,,
(-2,1) / / (6,1)
,====,
/ ~ (1,0) V ·~,I
....
~
-,e·
/ "'
The random
numbers fall
mainly on the
planes
M6-018
Easy Exercise
Consider the generator
Xi = (5 Xi -1 + 2) mod 8
i == 1 07 i -1 m 231 - 1 .
M6-020
Example: If O == 12 7 then K == and
1 +- 1 07 [12 7 - 12777 ] - 2 == 1 00
o that R1 == 0. 21 3 . D
M6-021
Fir t of all what can go wron with LCG .
■ Somethin like · == ( ·- 1 + 2 m d i not full-period
ince it onl produce e en integer .
■ Something like · == ( i -1 + 1) m d i full-period but it
produce ery non-random output: 1 == 1 2 == 2
'
etc.
■ In an a if m i mall ou 11 get quick c clino whether or not
the oenerator i full period. Small ould mean an thing le
than 2 billion or o !
■ And ju t becau e i big ou till ha e to be careful. Some
ubtle problem an ari e. Take a look at RA U....
M6-022
Example: The infa1nou RA D oenerator
·- 1
..
."
.
·"
.,
"
"0
M6-023
Exercises:
D Implement RA DU and ee how it doe . That i plot R ·-1
R,i for · == 1 2, ... 1000 and ee what happen . Tr a few
different . eed and ma be ou 11 ee ome h perplane . You 11
e11ainl ee them if ou plot (Ri-2 , R ·- 1 R · in 3-D.
FJ ow do the a1ne thing with the 16 07 enerator. You probabl
won t be able to ee an h perplane here.
M6-024
Summary
This Time: Discussed the linear
congruential generator.
M6-025
Computer Simulation
Module 6: Generating Uniform
Random Numbers
Tausworthe Generators
M6-026
Lesson Overview
Last Time: Discussed LCG PRNs,
OMG! QED, BTW! LOL! •
M6-027
Tausworthe Generator
Defin a equence of binar digit B 1 B , . . . b
M6-028
Obtain
M6-030
Summary
This Time: Discussed Tausworthe
generators, which are alternatives to
LCGs.
M6-031
Computer Simulation
Module 6: Generating Uniform
Random Numbers
Generalizations of LCGs
M6-032
Lesson Overview
Last Time: We studied the
Tausworthe PRN generator, which
actually looked a bit like an LCG.
M6-033
A Simple Generalization:
i == ( I:]=l · i- J)m where the ai are con tant .
Extreme! large period po ible up to m q - 1 if parameter are
ho en properl . But watch out! - Fibonacci i a pecial ca e.
Combinations of Generators:
Can combine two generator 1, 2 ... nd 1, 2 ... to con truct
Z1 Z .... Some ugge tion :
■ Set Z i == i + · mod m
Danger Will Robinson!
■ Shufflino- Properties are difficult
■ Set Zi == · or Zi == i to prove!
M6-034
A Really Good Combined Generator due to L Ecu er 1999
and di cu ed in Law 2015 .
M6-035
Some Remarks
It is of interest to note that Matsumoto
and Nishimura have developed the
“Mersenne Twister” generator, which
has period of 219937 – 1 (yes, that's a
prime number) and works great!!
M6-037
Computer Simulation
Module 6: Generating Uniform
Random Numbers
X X1 X2 X3 X4
1 1. 1 ~1 17 1
..... 1 4 ... 2
1 3
4 2 36 2 4 Really short periods! •
M6-040
Lot of th e t_pe of c_cle length re ult .
Theorem: , , - . ·_1 + · d > 0 ha full c 1 if i
and m are relati el prime· ii - 1 i a multiple of e er prin1e
which di ide · and 111 - 1 i a multiple of 4 if 4 di ide
(- )2) + - +6
Thi upper bound i ery mall for m in the ran e of 2 billion and
a == 1 7.
M6-043
Summary
This Time: We saw a mishmash of
PRN generator theoretical properties
– just to give you a flavor (not to
hold you responsible, necessarily).
M6-044
Computer Simulation
Module 6: Generating Uniform
Random Numbers
M6-046
Statistical Tests Intro
We’ll look at two classes of tests:
Goodness-of-fit tests — are the
PRNs approximately Unif(0,1)?
Independence tests — are the
PRNs approximately independent?
If a generator passes both types of
tests (in addition to others I won’t
tell you about), we’ll be happy to
use the PRNs it generates.
M6-047
Intro (cont’d)
All tests are of the form H0 (our
null hypothesis) vs. H1 (the
alternative hypothesis).
M6-050
Computer Simulation
Module 6: Generating Uniform
Random Numbers
k 2
2
0 L--
i =l
M6-054
2 Goodness-of-Fit Test
M6-055
Unlike what ou learned in bab tat la when we te t PR
oen rator we u uall ha a hu number of ob r ation at lea t
million with a large nu1nber of cell k. When k i large we can u e
th approximation
2
k- 1 ~ (7 - 1 1- 2 +
9 k- 1 " - 1
where i the appropriate tandard normal quantile.
Remarks: 1 16 07 PR enerator u uall pa e the -o-f te t ju t
fine. 2 We 11 how how to do g-o-f te t for other di tribution later
on - ju t doing uniform PR for now. 3 Other -o-f te t :
Kohnooorov- mimo te t Ander on-Darlin te t etc.
M6-056
Illustrative Example: == 1000 b rvation k == int r al .
2 2
0 .27. k- 1 0.0 9.
Since 6
< 2 k-l we fail to reject Ho and owe 11 la u1ne that the
ob er ation are appro imatel uniform. □
M6-057
Summary
This Time: Showed how to do a chi-
squared g-o-f test for uniformity of
PRNs. It’s fun! It’s nutritious!
M6-058
Computer Simulation
Module 6: Generating Uniform
Random Numbers
A. H T H T H T H T H T. . . negati e cotTelation
B. H H H H H T T T T T. . . po iti e correlation
C. H H H T T H T T H T. . . ju t right
M6-061
Definition: A r ,n i a erie of imilar ob er ation .
M6-062
Runs Test "Up and Down". Con ider the following PR .
++ -- + - + --- ...
Here are the a ociated run :
++ -- + - + - - -
So do we ha e too man or two few run .
M6-063
Let d note the total nu1nber of run up and down out of
ob ervation . in the abov example.
Then A is approximately
Nor(66.33, 17.46).
So Z0 = -2.71.
+ + + + + + + ---
M6-066
Fact: If i lar and the Rj are actuall independen~ then
B~
where 1 i th numb r of ob ervation > . and ·2 == - 1·
M6-067
Illustrat ive Example from BC uppo e that with the
followino +/ - equence.
- + + + + + + + --- + +-+-----
-- + + ---- + + -- + - + -- +-
Then 1 == 1 == 22 and B == 17. Thi implie that [B ] . 20. ·
and r B · . . And thi ield Z 0 == - 1.07.
M6-069
Computer Simulation
Module 6: Generating Uniform
Random Numbers
12 n -1
p"' - - ~ R-kR 1+ ..
-1~
k=l
p"' ~ or (o 1 7
-
1 )
- 1)2
under Ho .
- 19
""
p .9 0 and .r p ""
0. 1.
So Zo == o_gr.:o; Jo. 1 == 1. .
Sine IZo l < / == 1. w fail tor ject th t t meanin° that w
can treat the PR a independent. Of cour e == 0 i ort of
1nall and perhap thi deci ion will chanoe if we increa e . D
M6-073
Summary
This Time: Autocorrelation tests for
independence of PRNs.
M6-074