Académique Documents
Professionnel Documents
Culture Documents
1 / 45
Random number generation Generating random numbers Generating random vectors
Table of Contents
2 / 45
Random number generation Generating random numbers Generating random vectors
3 / 45
Random number generation Generating random numbers Generating random vectors
4 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
5 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
The ”true” random numbers are not practical to use since they
require physical phenomena to derive. For statistical applications
pseudo-random numbers are most often used. These are derived
from a computer algorithm and as such it is possible to predict a
sequence of these numbers.
Pseudo-random numbers
are fast to calculate
have bias-properties which are easy to control
are reproducible
6 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Congruential generators
7 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
8 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
9 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
10 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
11 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
12 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Inverse-transform method
F −1 (y ) = inf{x : F (x) ≥ y }, 0 ≤ y ≤ 1.
The operator inf A means the greatest lower bound of the set A.
Similarly, sup A means the least upper bound of the set A.
Proposition (Probability integral transform)
If U ∼ U(0, 1), then the random variable F −1 (U) has cdf F .
13 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Inverse-transform method
Inverse-transform algorithm:
1 Generate u from ∼ U(0, 1)
2 Return x = F −1 (u).
Thus we may generate random numbers from F by generating a
random number u from the standard uniform distribution and then
calculating the inverse of F and evaluate it with u as argument.
14 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
F −1 (u) = (b − a)u + a.
15 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
16 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Transform method
17 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
18 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
19 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Pseudo-random numbers
21 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Acceptance-rejection method
22 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Acceptance-rejection method
Rb
As an example, assume that a fX (x)dx = 1 and that fX is
bounded by c. We can then simulate the random pair
(Y , U) ∼ U(0 < u < c) by simulating Y ∼ U(a, b) and
U|Y = y ∼ U(0, c) and then only accept the pair as an
instantiation from X if 0 < u < fX (y ) is satisfied.
23 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
24 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
We proceed as follows:
1 Generate U from U(0, 1)
α−1
2 Generate V from U 0, fX α+β−2
3 If V ≤ fX (U), return X = U. Else, return to 1.
25 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
26 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Things to note:
The probability of acceptance is
1
P(accept) = ,
c(b − a)
that is, the percentage of the area covered by the pdf of the
desired R.V. Hence, on average we need to repeat the
procedure c(b − a) times to retrieve one such number.
The domain of the desired density must be a fixed interval
otherwise we can’t produce the corresponding uniformly
distributed random variable.
27 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Acceptance-rejection method
The efficiency of the method can be improved by making an
adjustment to the algorithm. Again, we want to generate random
numbers from a density f . Let X and Y be random variables with
density functions f and g . Assume that we can readily generate
random numbers from g . Assume also that there is a constant c
such that
f (t)
c = sup < ∞,
g (t)
for all t such that f (t) > 0. Then the following algorithm (A-R
algorithm) can be applied to generate the random variable X :
1 Generate y from g
2 Generate v from U(0, 1)
f (y )
3 If v < c(g (y )) , return x = y . Otherwise go back to 1.
28 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
29 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
q
2 −X 2 /2
πe X 2 +2X +1 (X −1)2
U≤p ⇐⇒ U ≤ e − 2 ⇐⇒ U ≤ e − 2
2e/πe −X
(X − 1)2 (X − 1)2
⇐⇒ ln(U) ≤ − ⇐⇒ − ln(U) ≥
2 2
Note that − ln U and X are independent and both Exp(1)
distributed.
30 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
31 / 45
Random number generation Generating random numbers Generating random vectors
Pseudo-random numbers
Sums or Convolutions
Table of Contents
33 / 45
Random number generation Generating random numbers Generating random vectors
Continuous distributions
Exponential distribution
So F −1 (u) = − ln(1−u)
λ and we have the algorithm:
1 Generate u from U(0, 1)
2 Return x = − ln(1−u)
λ
34 / 45
Random number generation Generating random numbers Generating random vectors
Continuous distributions
Normal distribution
35 / 45
Random number generation Generating random numbers Generating random vectors
Continuous distributions
Gamma distribution
36 / 45
Random number generation Generating random numbers Generating random vectors
Continuous distributions
Beta distribution
We have, for X ∼ Beta(α, β),
γ(α + β) α−1
f (x) = x (1 − x)β−1 , 0 ≤ x ≤ 1.
γ(α)γ(β)
f (x; β = 1) = αx α−1 , 0 ≤ x ≤ 1
or
f (x; β = 1) = β(1 − x)β−1 , 0 ≤ x ≤ 1
and the inverse-transform method can be used.
37 / 45
Random number generation Generating random numbers Generating random vectors
Continuous distributions
Beta distribution
Y1
X = ∼ Beta(α, β).
Y1 + Y2
38 / 45
Random number generation Generating random numbers Generating random vectors
Discrete distributions
Bernoulli distribution
p(x) = p x (1 − p)1−x , x = 0, 1.
39 / 45
Random number generation Generating random numbers Generating random vectors
Discrete distributions
Binomial distribution
40 / 45
Random number generation Generating random numbers Generating random vectors
Discrete distributions
Geometric distribution
For a R.V. X ∼ Ge(p) the pmf is:
Note that:
e −λ = 1 − p ⇐⇒ −λ = ln(1 − p) ⇐⇒ λ = − ln(1 − p)
Discrete distributions
Poisson distribution
For X ∼ Po(λ), the pmf is
e −λ λx
p(x) = , x = 0, 1, . . . ; 0 ≤ λ < ∞.
x!
We can interpret a Po(λ) R.V. as the maximum number of
independent Exp(λ) R.V.s whose sum does not exceed 1.
Proposition
Let Yj , j ∈ {1, . . . , n} be independent R.V.s such that
∀j, Yj ∼ Exp(λ). Then
n
X
X = max{n : Yj ≤ 1}
j=1
Discrete distributions
Poisson distribution
43 / 45
Random number generation Generating random numbers Generating random vectors
Table of Contents
44 / 45
Random number generation Generating random numbers Generating random vectors
45 / 45