Академический Документы
Профессиональный Документы
Культура Документы
1
Manuel D. Rossetti, All Rights Reserved
Objectives
To be able to describe and use the basic
pseudo-random number generation methods
To be able to describe and use the common
random variate generation methods
2
Manuel D. Rossetti, All Rights Reserved
3
Manuel D. Rossetti, All Rights Reserved
4
Manuel D. Rossetti, All Rights Reserved
LCG Example
Consider an LCG with parameters m 8, a 5, c 1, R0 5 and compute the first nine Ri
and U i from the defined sequence.
y
z y mod m z y m where x is the floor operator, i.e. the greatest integer x
m
e.g. z 6 mod 9 z 6 9 6 9 0 6
6
9
5
Manuel D. Rossetti, All Rights Reserved
Solution
Notice that the random R1 (5 R0 1) mod 8
numbers are fractions of 8 R2 (5 R1 1) mod 8
Notice that if one of the R3 (5 R2 1) mod 8
numbers is repeated, then
the sequence cycles
R4 (5 R3 1) mod 8
R5 6 U 5 0.75
Want to pick a, m, and c
to have long cycles and R6 7 U 6 0.875
dense coverage of (0,1) R7 4 U 7 0.5
R8 5 U 8 0.625
R9 2 U 9 0.25
6
Manuel D. Rossetti, All Rights Reserved
Desirable Properties
Fast
Close to true U(0,1)
Long period before repeating
Does not degenerate to constant or zero
Ability to reproduce identical sequences of random
numbers
Ability to select subsequences
7
Manuel D. Rossetti, All Rights Reserved
different tasks
R4 1
8
Manuel D. Rossetti, All Rights Reserved
Arenas Generator
Combines two separate generators in order to
achieve a very large period
Combined multiple recursive generator, see
reference LEcuyer et al. (2002) in the text
Would take approximately 219 years into the
future before average desktop computers will
have the capability to exhaust the cycle of the
(generator) in a year of continuous computing
Cycle length of 3.1 1057 with approximately 1.8 1019 streams with stream lengths of
1.7 10 38 and sub-streams of length 7.6 10 22 numbering at 2.3 1015 per stream
9
Manuel D. Rossetti, All Rights Reserved
11
Manuel D. Rossetti, All Rights Reserved
Proof: U
xi F 1 (ui )
PY y PF X y 1
PF 1 F X F 1 y
PX F 1 y ui
F F 1
y
y
13
Manuel D. Rossetti, All Rights Reserved
Discrete Example
R
xi 1 2 3 4 1.0
0 if x 1 .6
X=2 (0.4 < R 0.7)
0.4 if 1 x 2
.4
F ( x) 0.7 if 2 x 3
0.9 if 3 x 4 X=1 (0 R 0.4)
.2
1 if 4 x
0
0 1 2 3 4
14
Manuel D. Rossetti, All Rights Reserved
Loop
15
Manuel D. Rossetti, All Rights Reserved
Convolution
The distribution of the sum of two or more random variables is called the convolution.
n
Convolution Example
Convolution Generation Algorithm
Step 1: Generate Yi ~ G( y) i 1,2, , n
n
Step 2: Return X Yi
i 1
Suppose X is Erlang with mean E[ X ] k . Then, X can be defined as the sum of k IID
exponential random variables each with mean .
Yi ~ exp, E[Yi ]
n n n n
X Yi ln(1 U i ) ln(1 U i ) ln
(1 U i )
i 1 i 1 i 1 i 1
17
Manuel D. Rossetti, All Rights Reserved
Acceptance-Rejection
In the acceptance-rejection method, the PDF f (x) from which we desire to obtain a
sample is replaced by a proxy PDF h(x) that can be sampled from more easily. h(x) is
defined such that the selected samples from h(x) can be used directly to represent random
variates from f (x) . The PDF h(x) is based on the development of a majorizing function
for f (x) . A majorizing function, g (x) , for f (x) , is a function such that
g ( x ) f ( x) x .
g(x)
Let c g ( x)dx
Define h( x) g ( x) c
f(x)
x
18
Manuel D. Rossetti, All Rights Reserved
Acceptance Rejection
Algorithm
Acceptance-Rejection Algorithm
Step 1: Generate W ~ h( x)
Step 2: Generate U ~ U (0,1)
Step 3: if U g (Y ) f (W ) accept X W and return, else reject W and return to step 1
19
Manuel D. Rossetti, All Rights Reserved
Example
A simple method to choose a majorizing function is to
3
1 x 2
f ( x) 4
1 x 1
set g ( x) max f ( x) . As can be seen from the figure of
0 otherwise f (x) the maximum ( 3 4 ) occurs at 0 so that g ( x) 3 4 .
We need to find h( x) g ( x) c using g ( x) 3 4 .
1
0.75
1 1
3 3
0.8 c g ( x)dx dx
1 1 4 2
0.6
f ( x) Thus,
0.4
1
0.2 1 x 1
h( x ) 2
0 0 otherwise
0
1 0.6 0.2 0.2 0.6 1
1 x 1
Therefore, h(x) is a uniform distribution over the
range [-1,1], i.e. Uniform(-1,1).
20
Manuel D. Rossetti, All Rights Reserved
Example
A simple method to choose a majorizing function is to
3
1 x 2
f ( x) 4
1 x 1
set g ( x) max f ( x) . As can be seen from the figure of
f (x) the maximum ( 3 4 ) occurs at 0 so that g ( x) 3 4 .
0 otherwise
We need to find h( x) g ( x) c using g ( x) 3 4 .
1
0.75
1 1
3 3
0.8 c g ( x)dx dx
1 1 4 2
0.6
f ( x) Thus,
0.4
1
0.2 1 x 1
h( x ) 2
0 0 otherwise
0
1 0.6 0.2 0.2 0.6 1
1 x 1
Therefore, h(x) is a uniform distribution over the
range [-1,1], i.e. Uniform(-1,1).
21
Manuel D. Rossetti, All Rights Reserved
Algorithm
Steps 1 and 2 generate a random variate, W , from
Step 1: Generate U1 ~ U (0,1) h(x) . Notice that W is in the range [-1,1] (the same as
the range of X ) so that step 4 is simply finding the
Step 2: Set W 1 2U 1
height associated with W in terms of f . In step 3,
Step 3: Generate U 2 ~ U (0,1) 3
we generate U 2 . What is the range of U 2 ? The
Step 4: Set f
3
1W 2 4
4
range is 0, . Notice that this range corresponds to
3
3 4
Step 5: if U 2 f accept X W
4 the range of possible values for f . Thus, in step 5,
and return, else reject W and return
we are comparing a point between 0, to the
3
to step 1 4
candidate point, W s height, along the vertical axis. If
we are under f we accept the W , otherwise we reject
W and generate another candidate point. In other
words, if we generate a point under the curve we
accept it.
22
Manuel D. Rossetti, All Rights Reserved
Cont. Example
Step 1: U1 = 0.25
Step 2: W = a + (b-a)U1(inverse transform for uniform distribution)
= -1 +2(2.5)
= -0.5
Step 3: f = 0.75(1-(-0.5^2))
= 9/16
Step 4: U2= some random number say 0.4
Step 5: Use that number and multiply by majorizing function
= u2*0.75 <= f
= 0.4*0.75 <= 9/16
= 0.3 <= 9/16 Therefore accept 23
Manuel D. Rossetti, All Rights Reserved
Algorithm
Steps 1 and 2 generate a random variate, W , from
Step 1: Generate U1 ~ U (0,1) h(x) . Notice that W is in the range [-1,1] (the same as
the range of X ) so that step 4 is simply finding the
Step 2: Set W 1 2U 1
height associated with W in terms of f . In step 3,
Step 3: Generate U 2 ~ U (0,1) 3
we generate U 2 . What is the range of U 2 ? The
Step 4: Set f
3
1W 2 4
4
range is 0, . Notice that this range corresponds to
3
3 4
Step 5: if U 2 f accept X W
4 the range of possible values for f . Thus, in step 5,
and return, else reject W and return
we are comparing a point between 0, to the
3
to step 1 4
candidate point, W s height, along the vertical axis. If
we are under f we accept the W , otherwise we reject
W and generate another candidate point. In other
words, if we generate a point under the curve we
accept it.
24
Manuel D. Rossetti, All Rights Reserved
Composition
n n
f x p f x
i i
i 1
The idea is to first randomly select the appropriate distribution using p i and
then generate an X from f (x) .
25
Manuel D. Rossetti, All Rights Reserved
350
300
250
200 distributions to
150
100
50
each part
0
Use composition
4. 031 4
5. 433 8
8 92
7. 923 6
10 204 8 4
11 844 4 8
14 765 1 4
12 846 2
13 512 76
52 4
8
3. 629 5
9. 639 2
40 0
26
7
8
6
2
method to generate
03 2
85 7
20 5
36 6
52 6
6. 357
8
.1 19
.6 48
.3 40
.8 02
2. 872
6
0.
4
0
from overall
Bin
distribution.
26
Manuel D. Rossetti, All Rights Reserved
Algorithm
Based on input data analysis:
Algorithm
Step 1: Generate U ~ U (0,1)
Step 2: if U p1 , set X 0.45 ERLA(0.305 , 8)
Else set X 5.0 GAMM(1.07, 1.79)
where ERLA() and GAMM() are functions that generate Erlang and
Gamma random variates.
27