Escolar Documentos
Profissional Documentos
Cultura Documentos
OUTLINE:
Why do we need random numbers;
Basic steps in generation;
Uniformly distributed random numbers;
Statistical tests for uniform random numbers;
Random numbers with arbitrary distributions;
Statistical tests for random numbers with arbitrary distribution;
Multidimensional distributions.
2. General notes
General approach nowadays:
transforming one random variable to another one;
as a reference distribution a uniform distribution is often used.
i = 0, 1, . . . ,
(1)
1, 0 x 1
.
f (x) =
0, otherwise
(2)
2 [X] =
1
x
1
xdx = = ,
2
2
2
1
.
12
(3)
(4)
What we get:
something like: 0.12, 0.67, 0.94, 0.04, 0.65, 0.20, . . . ;
sequence that appears to be random...
10
11
user choice s0
u0=g(s0)
u4
u1=g(s1)
s0
s1=f(s0)
s1
u1
s4
s3
s2=f(s1)
u0
u4=g(s4)
s4=f(s3)
u3
u3=g(s3)
u2
s2 s3=f(s2)
u2=g(s2)
12
13
mod m,
(5)
(6)
14
(7)
(8)
Characteristics:
divide by m to get U (0, 1);
maximum period is mk ;
note: rarely used.
Shortcomings: consider k = 2:
consider three consecutive numbers ui2 , ui1 , ui ;
we will never get: ui2 < ui < ui1 and ui1 < ui < ui2 (must be 1/6 of all sequences).
15
mod m.
(9)
Characteristics:
divide by m to get U (0, 1);
theoretical maximum period is m;
note: rarely used.
Shortcomings:
can never produce 0.
Choice of a, m is very important:
recommended m = (2p 1) with p = 2, 3, 5, 7, 13, 17, 19, 31, 61 (Fermat numbers);
if m = 2q , q 4 simplifies the calculation of modulo;
practical maximum period is at best no longer than m/4.
16
mod m,
(10)
17
Examples:
x0 = 7, a = 7, c = 7, m = 10 we get: 7,6,9,0,7,6,9,0,... (period = 4);
x0 = 1, a = 1, c = 5, m = 13 we get: 1,6,11,3,8,0,5,10,2,7,12,4,9,1... (period = 13);
x0 = 8, a = 2, c = 5, m = 13 we get: 8,8,8,8,8,8,8,8,... (period = 1!).
Recommended values: a = 314, 159, 269, c = 453, 806, 245, m = 231 for 32 bit machine.
18
19
20
(11)
j=1
Advantages:
independent of the system (computer architecture);
independent of the word size;
very large periods;
can be used in composite generators (we consider in what follows).
21
l1
X
znl+j 2(j+1) .
(12)
j=0
In practice, only two ai are used and set to 1 at places h and k. We get:
zn = (zih + zik ) mod 2.
(13)
Example:
h = 3, k = 4, initial values 1,1,1,1;
we get: 110101111000100110101111...;
period is 2k 1 = 15;
if l = 4: 13/16, 7/16, 8/16, 9/16, 10/16, 15/16, 1/16, 3/16...
22
23
24
1/3
1/3
1/3
1/3
1/3
1/3
25
Do the following:
consider a sequence of pseudo random numbers: {ui , i = 0, 1, . . . , n};
consider unbroken subsequences of numbers where numbers are monotonically increasing;
such subsequence is called run-up;
example: 0.78,081,0.89,0.81 is a run-up of length 3.
compute all run-ups of length i:
ri , i = 1, 2, 3, 4, 5;
all run-ups of length i 6 are grouped into r6 .
calculate:
1 X
(ri nbi )(rj nbj )aij ,
R=
n 1i,j6
1 i, j 6,
(14)
where
(b1 , b2 , . . . , b6 ) =
1 5 11 19 29
1
, ,
,
,
,
6 24 120 720 5040 840
(15)
26
27
(16)
j=1
28
k X
n 2
=
fi
.
n i=1
k
2
(17)
29
Hypotheses:
H0 observations are uniformly distributed;
H1 observations are not uniformly distributed.
H0 is rejected if:
computed value of 2 is greater than one obtained from the tables;
you should check the entry with k 1 degrees of freedom and 1-a level of significance.
30
(18)
if R > R : H0 is rejected;
if R R : H0 is accepted.
Note: use tables for N , (significance level), to find R .
31
R(j)
0.05
0.14
0.44
0.81
0.93
j/N
0.20
0.40
0.60
0.80
1.00
j/N R(j)
0.15
0.26
0.16
0.07
R(j) (j-1)/N
0.05
0.04
0.21
0.13
32
33
(19)
34
General notes:
some common generators are found to be inadequate;
even if generator passed tests, some underlying pattern might still be undetected;
if the task is important use composite generator.
35
Continuous distributions:
inverse transform;
rejection method;
composition method;
methods for specific distributions.
36
j = 0, 1, . . .,
pj = 1.
(20)
j=0
37
38
39
40
i = 0, 1, . . . .
(21)
pi ,
i+1
i = 1, 2, . . . .
(22)
The algorithm:
1. generate u = U (0, 1);
2. i = 0, p = e , F = p;
3. if u < F , set X = i;
4. p = p/(i + 1), F = F + p, i = i + 1;
5. go to step 3.
41
n!
pi (1 p)ni ,
i!(n i)!
i = 0, 1, . . . .
(23)
ni p
pi ,
i+11p
i = 0, 1, . . . .
(24)
The algorithm:
1. generate u = U (0, 1);
2. c = p/(1 p), i = 0, d = (1 p)n, F = d;
3. if u < F , set X = i
4. d = [c(n i)/(i + 1)]d, F = F + d, i = i + 1;
5. go to step 3.
42
Assume:
we would like to generate numbers with pdf f (x) and cdf F (x);
recall, F (x) is defined on [0, 1].
43
Example:
we want to generate numbers from the following pdf f (x) = 2x, 0 x 1;
calculate the cdf as follows:
Z
F (x) =
2tdt = x2 ,
0 x 1.
(25)
x;
44
1 , a<x<b
(xa) , a < x < b
f (x) = (ba)
,
F (x) = (ba)
.
0,
otherwise
0,
otherwise
(26)
The algorithm:
generate u = U (0, 1);
set u = F (x) = (x a)/(b a);
solve to get x = a + (b a)u.
45
F (x) = 1 ex ,
> 0,
x 0.
(27)
The algorithm:
generate u = U (0, 1);
set u = F (x) = ex ;
solve to get x = (1/) log u.
46
The algorithm:
generate u = U (0, 1);
sum of exponential variables x1 , . . . , xk with mean 1/;
solve to get:
x=
k
X
i=1
X
1X
1
xi =
log ui = log
ui .
i=1
i=1
(28)
47
< x < ,
(29)
< z < ,
where
= 0, = 1.
(30)
48
ui N
,
,
or
N (0, 1).
2 12
k/ 12
(31)
,
or
=
k/ 12
r
x=
(32)
12
k
X
k
ui
2
+ .
(33)
49
50
f (xk ),
(34)
51
The algorithm:
generate u = U (0, 1);
assume that u {F (xi1 ), F (xi )};
use the following linear interpolation to get:
x = xi1 + (xi xi1 )
u F (xi1 )
.
F (xi ) F (xi1 )
(35)
Note: this approach can also be used for analytical continuous distribution.
get (xi , f (xi )), i = 1, 2, . . . , k and follow the procedure.
52
53
54
55
pj Fj (x),
(36)
j=1
pj 0, j = 1, 2, . . . ,
j=1
pj = 1.
Works when:
it is easy to to generate RVs with distribution Fj (x) than F (x);
hyperexponential RV;
Erlang RV.
The algorithm:
1. generate discrete RV J, P r{J = j} = pj ;
2. given J = j generate RV with Fj (x);
P
3. compute
j=1 pj Fj (x).
56
(37)
i x < i + 1.
(38)
57
58
7. Multi-dimensional distributions
Task: generate samples from RV (X1 , X2 , . . . , Xn ).
Write the joint density function as:
f (x1 , x2 , . . . , xn ) = f1 (x1 )f2 (x2 |x1 ) . . . f (xn |x1 . . . xn1 ).
(39)
F2 (X2 |X1 ) = u2 ,
...
(40)
59
Z
F (x) =
0
1
f (x0 )dx0 = (x2 + x).
2
(41)
1 2
xy
+
y
2
f (y 0 |x)dy 0 =
.
x + 12
(42)
Z
F (y|x) =
0
by inversion we get:
1
x = ( 8u1 + 1 1),
2
p
y = x2 + u2 (1 + 2x) x.
(43)
60