### Random-Variable Generators Rationale

```Rationale
n
Random-Variable Generators
n
Simulators need generators of random
variable with specific distributions
The actual procedure is:
1.  We generate a sequence X of integer
random numbers
2.  Using X, we generate a sequence Z of
instances of a random variable uniform in
(0,1)
3.  Using Z, we generate instances of the
chosen random variable
Michela Meo
Maurizio M. Munafò
[email protected] – [email protected]
revised by Paolo Giaccone
© TLC Network Group - Politecnico di Torino
© TLC Network Group - Politecnico di Torino
1
Inverse-transform technique
n
n
n
Inverse-transform technique
Proof that u =F(x) is uniform in [0,1] :
n
Let Y=g(X) be function of X invertible
and monotone not decreasing, X=g-1(Y)
FY (y ) = P (Y ≤ y ) = P ( g −1 (Y ) ≤ g −1 (y ))
We want to generate instances of a
random variable X with cumulative
distribution F(x)
The inverse-transform technique is
based on the fact that u =F(x) is a r.v
uniformly distributed in [0,1]
Therefore we can generate an instance
of u uniform and then calculate
x =F-1(u)
© TLC Network Group - Politecnico di Torino
n
= P (X ≤ g −1 (y )) = FX ( g −1 (y ))
Select g(·) such that g(X)=Fx(X), or
also Y=Fx (X), and 0≤y≤1,
FY (y ) = FX ( g −1 (y )) = FX (FX−1 (y )) = y
3
© TLC Network Group - Politecnico di Torino
Inverse-transform technique
n
2
4
Inverse-transform technique
F(x)
1
Moreover, from Fy(y)=y,
Δy2
fY (y ) = dFY /dy = 1
Δy1
hence Y is uniform in [0,1]
0
x
If Δy1=Δy2, the probability of generating an
instance of X in Δx1 or in Δx2 is the same
n For the same dx, the numbers in Δx1 are more
frequent than those in Δx2, because Δx1 is
narrower
Generating Y uniform in [0,1]
and calculating the inverse, F-1(Y),
we obtain X
© TLC Network Group - Politecnico di Torino
Δx1 Δx2
n
5
© TLC Network Group - Politecnico di Torino
6
1
Inverse-transform technique
Negative exponential
Intervals on the x axis are narrower if the
derivative of F(x) is higher, i.e., f(x) is larger
1
n
F(x)
We want to generate instances of a
random variable with negative
exponential distribution and rate a, x≥0,
n
f(x) = a e-ax , F(x) = 1 - e-ax
Δy2
1
a
Δy1
f(x)
0
Δx1
X
Δx2
© TLC Network Group - Politecnico di Torino
f(x)
0
7
© TLC Network Group - Politecnico di Torino
Negative exponential
n
e
−ax
1.
− ax
2.
=1−y
3.
− ax = ln(1 − y )
n
1
x = − ln(1 − y )
a
© TLC Network Group - Politecnico di Torino
9
n
f(x) = 1/(b-a), F(x) =(x-a)/(b-a), a ≤ x ≤ b
F(x)
1
0
1.
2.
a
© TLC Network Group - Politecnico di Torino
10
b
The inverse of F(x) is
(x − a )
y =
(b − a )
(b − a )y = x − a
x = a + (b − a )y
f(x)
1/(b-a)
Since both u and 1-u are uniformly
distributed in (0,1), x can also be
calculated as
x = -1/a ln(u)
Uniform
We want to generate instances of a
uniform random variable with support
[a,b]
n
8
Generate u =U(0,1), uniform in (0,1)
Calculate x = -1/a ln(1-u)
Return x
© TLC Network Group - Politecnico di Torino
Uniform
n
X
Negative exponential
The inverse of F(x) is
y = 1 −e
F(x)
3.
X
11
Generate u =U(0,1), uniform in (0,1)
Calculate x = a + (b-a) u
Return x
© TLC Network Group - Politecnico di Torino
12
2
Discrete uniform distribution
Discrete uniform distribution
We want to generate an instance x of X,
with x in {1,2,…,k} and p(X=x)=1/k
n
1
We have F(x)=x/k with x =1,2,…,k
n
1
F(x)
2/k
2/k
f(x)
1/k
0
1
2
k
0
X
21
k
that is
n
n
x − 1 < ku ≤ x
ku ≤ x < ku + 1
n
n
23
The cumulative distribution is
empirically derived by the measured or
approximated values
x values
Probability
CDF, F(x)
x1
x2
x3
…
p3
…
0
0≤x<x1
p1
x1≤x<x2
p1+p2
x2≤x<x3
…
p1
p2
© TLC Network Group - Politecnico di Torino
X
22
© TLC Network Group - Politecnico di Torino
1.
2.
pk
1
xk≤x
To generate instances of X, we can use
the following procedure:
Generate u=U(0,1), uniform in (0,1)
Return x, according to which condition is
satisfied by u in the following table
x values
Condition
25
24
Empirical discrete distributions
n
xk
Measurements
Approximations (e.g. when the inverse
cannot be expressed in closed form)
X holds the values x1, x2, …, xk with
probability p1, p2, …, pk
We derive the cumulative
We calculate the inverse
n
Empirical discrete distributions
n
k
We want to generate instances of a
random variable whose distribution is
calculated empirically through
n
k
© TLC Network Group - Politecnico di Torino
2
Empirical discrete distributions
The inverse is x =yk
X can be calculated as x = ⎡ku ⎤
Indeed, after generating u uniform in
(0,1), we return x if
x −1
x
<u ≤
n
1
© TLC Network Group - Politecnico di Torino
Discrete uniform distribution
n
f(x)
1/k
© TLC Network Group - Politecnico di Torino
n
F(x)
x1
x2
…
0<u≤F(x1) F(x1)<u≤F(x2) …
© TLC Network Group - Politecnico di Torino
Xk
F(xk-1)<u≤F(xk)
26
3
Other methods
Inverse-transform technique
n
n
n
To apply it we must be able to calculate
the inverse of F(x)
We just need to generate a single
random number U(0,1)
The computational cost depends on the
computational complexity of the inverse
function
n
n
n
n
n
27
convolution method
acceptance rejection method
composition method