Professional Documents
Culture Documents
2 Random Variables
2 Random Variables
Random Variables
1. Random-number generation
2. Random-variable generation
© Kleber Barcia V.
Chapter 2
2
© Kleber Barcia V.
Chapter 2
1, 0 x 1 E r
a b
f ( x) 2
0, otherwise b a
2
V r
12
The expected value and the
Figure: pdf for random numbers
variance of each random number is:
2 1 3 1 2
x 1 1 1 1 1
V (r ) x 2 dx E r
1 x
E (r ) xdx
1
2
0 2 0
2 0 3 0 2 3 4 12
3
© Kleber Barcia V.
Chapter 2
4
© Kleber Barcia V.
Chapter 2
Middle-square algorithm
Middle-product algorithm
Constant multiplier algorithm
Linear algorithm
Multiplicative congruential algorithm
Additive congruential algorithm
Congruential non-linear algorithms
Quadratic
Blumy Shub
5
© Kleber Barcia V.
Chapter 2
Middle-square algorithm
Middle-square algorithm
If x0 = 5735
Then,
Y0 = (5735)2 = 32890225 x1 = 8902 r1 = 0.8902
Y1 = (8902)2 = 79245604 x2 = 2456 r2 = 0.2456
Y2 = (2456)2 = 06031936 x3 = 0319 r3 = 0.0319
Y3 = (0319)2 = 101760 x4 = 0176 r4 = 0.0176
Y4 = (0176)2 = 030976 x5 = 3097 r5 = 0.3097
1. Small cycles
2. May lose the series (e.g.: X0 = 0012)
7
© Kleber Barcia V.
Chapter 2
Middle-product algorithm
8
© Kleber Barcia V.
Chapter 2
Middle-product algorithm
Example:
9
© Kleber Barcia V.
Chapter 2
10
© Kleber Barcia V.
Chapter 2
Example:
11
© Kleber Barcia V.
Chapter 2
Linear algorithm
Linear algorithm
Example:
13
© Kleber Barcia V.
Chapter 2
Xi
ri
m 1
16
© Kleber Barcia V.
Chapter 2
Example:
17
© Kleber Barcia V.
Chapter 2
Quadratic:
xi 1 ax 2 bx c mod m i 0,1,2,3,..., N
Example:
xi 1 ax 2 bx c mod m i 0,1,2,3,..., N
a=1
b=0
c=0
20
© Kleber Barcia V.
Chapter 2
Maximum Density
Such that the values assumed by Ri, i = 1,2,…, leave no large
gaps on [0,1]
Solution: a very large integer for modulus m
Maximum Period
To achieve maximum density and avoid cycling.
Achieve by: proper choice of a, c, m, and X0.
Most digital computers use a binary representation of
numbers
Speed and efficiency depend on the modulus, m. It can be
consider as a big number (2b)
21
© Kleber Barcia V. Rev. 1
Chapter 2
Two categories:
Testing for uniformity:
H0: Ri ~ U[0,1]
H1: Ri ~/ U[0,1]
Test for independence:
H0: Ri ~ independently
H1: Ri ~/ independently
Mean test
H0: µri = 0.5
H1: µri =/ 0.5
We can use the normal distribution with σ2 = 1/12
or σ = 0.2887 with a significance level α = 0.05
22
© Kleber Barcia V.
Chapter 2
23
© Kleber Barcia V. Rev. 1
Chapter 2
Procedure:
1. Arrange the ri from lowest to highest
2. Determine D+, D-
3. Determine D
4. Determine the critical value of Dα, n
5. If D> Dα, n then ri are not uniform
24
© Kleber Barcia V.
Chapter 2
25
© Kleber Barcia V.
Chapter 2
Example: Use Chi-square with a = 0.05 to test that the data shown
are uniformly distributed
0.34 0.90 0.25 0.89 0.87 0.44 0.12 0.21 0.46 0.67
0.83 0.76 0.79 0.64 0.70 0.81 0.94 0.74 0.22 0.74
0.96 0.99 0.77 0.67 0.56 0.41 0.52 0.73 0.99 0.02
0.47 0.30 0.17 0.82 0.56 0.05 0.45 0.31 0.78 0.05
0.79 0.71 0.23 0.19 0.82 0.93 0.65 0.37 0.39 0.42
0.99 0.17 0.99 0.46 0.05 0.66 0.10 0.42 0.18 0.49
0.37 0.51 0.54 0.01 0.81 0.28 0.69 0.34 0.75 0.49
0.72 0.43 0.56 0.97 0.30 0.94 0.96 0.58 0.73 0.05
0.06 0.39 0.84 0.24 0.40 0.64 0.40 0.19 0.79 0.62
0.18 0.26 0.97 0.88 0.64 0.47 0.60 0.11 0.29 0.78
(Oi-Ei)2
Interval Oi Ei Oi-Ei (Oi-Ei)2
Ei
1 8 10 -2 4 0.4
2 8 10 -2 4 0.4
3 10 10 0 0 0.0
4 9 10 -1 1 0.1
5 12 10 2 4 0.4
6 8 10 -2 4 0.4
7 10 10 0 0 0.0
8 14 10 4 16 1.6
9 10 10 0 0 0.0
10 11 10 1 1 0.1
100 100 0 3.4
29
© Kleber Barcia V.
Chapter 2
1 M
ρˆ im
M 1 k 0
Ri km i (k 1 )m 0.25
R
13M 7
σˆ ρim
12(M 1 )
Then i = 3, m = 5, N = 30
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
0.68 0.49 0.05 0.43 0.95 0.58 0.19 0.36 0.69 0.87
i (M 1 )m N
3 4 15 30
28 30
Then M = 4
31
© Kleber Barcia V.
Chapter 2
13(4) 7
σˆ ρ35 0.128
12( 4 1 )
0.1945
Z0 1.516
0.1280
32
© Kleber Barcia V.
Chapter 2
34
© Kleber Barcia V.
Chapter 2
Inverse-transform technique
x = F-1(r)
x1
35
© Kleber Barcia V.
Chapter 2
e lX 1 r
lX ln(1 r )
1
X ln(1 r )
l
To generate X1, X2, X3 …
Xi = F-1(ri)
= -(1/l ln(1-ri) Figure: Inverse-transform
technique for exp (l = 1)
= -(1/l) ln(ri)
36
© Kleber Barcia V.
Chapter 2
F x x
2
0 x 1 x 2r 0 r 1
2 2
Triangular
F x 1 2 x 2
1 x 2 x 2 21 r
1 r 1
2
2
Normal x z
37
© Kleber Barcia V.
Chapter 2
38
© Kleber Barcia V.
Chapter 2
Measurements ri Temperature oC
1 0.48 95+5*0.48=97.40
2 0.82 99.10
3 0.69 98.45
4 0.67 98.35
5 0.00 95.00
39
© Kleber Barcia V.
Chapter 2
Convolution Method
Y = x1+x2+…+xk
Y = (-1/kλ)ln(1-r1)+ (-1/kλ)ln(1-r2)+…+ (-1/kλ)ln(1-rk)
Where:
Y = Eri= (-1/kλ)lnπ(1-ri) The factor production
42
© Kleber Barcia V.
Chapter 2
Convolution Method
ˆ 1 (i 1)
X F ( R ) x( i 1) ai R
n
Example: Suppose that the observed data of 100 repair times of a machine
are:
Consider r1 = 0.83:
45
© Kleber Barcia V.
Chapter 2
Acceptance-Rejection technique