110324 Generating random variables with arbitrary distributions

ECE 438 Digital Signal Processing with Applications
Spring 2011
Generating Random Variables
with Arbitrary Distributions
Let U be a random variable that is uniformly distributed on the interval [0,1) . Let X be
the random variable with distribution function FX (x) that we wish to generate by a
suitable transformation φ (⋅) of U , i.e.
X = φ (U ) .
(1)
Assume that there exists x0 < x1 , such that FX (x0 ) = 0, FX (x1 ) = 1 . Further, assume that
FX (a) < FX (b) , for x0 ≤ a < b ≤ x1 . It follows from (1) that the two events below are
equivalent:
{ X ≤ x} = {φ (U ) ≤ x} .
(2)
Assume that x = φ (u) is a monotonically increasing function of u for 0 ≤ u ≤ 1 and
φ (0) = x0 , φ (1) = x1 . Then u = φ −1 (x) exists for x0 ≤ x ≤ x1 , and is a monotonically
increasing function of x . We then have that
{ X ≤ x} = {φ (U ) ≤ x} = {U ≤ φ −1 (x)} .
(3)
Thus
{
}
P { X ≤ x} = P {φ (U ) ≤ x} = P U ≤ φ −1 (x) ,
(4)
or equivalently,
(
)
FX (x) = FU φ −1 (x) = φ −1 (x) .
(5)
The second equality follows from the fact that 0 ≤ φ −1 (x) ≤ 1 ; and over this range for the
argument u = φ −1 (x) , FU ( u ) = u, 0 ≤ u ≤ 1 . From the first and last terms in (5), it then
follows that
φ (u) = FX−1 (u) .
(6)
This is the desired transformation.
As an example, suppose we would like to generate a random variable with the
density function1
f X (x) =
π
cos(π x)rect(x) .
2
1/2
1/2
1
2
1
= . Note that ∫ cos(π x)dx = sin(π x)
π
π
−1/2
−1/2
(7)
2 Since
x
FX (x) =
∫
f X (ξ )dξ
−∞
⎧
⎪
⎪
=⎨
⎪
⎪
⎩
x < −1 / 2,
0,
π
1
1
cos(πξ )dξ = sin(πξ )
= [ sin(π x) + 1], −1 / 2 ≤ x ≤ 1 / 2,
∫
2
2
2
−1/2
−1/2
x
x
, (8)
1 / 2 < x,
1,
we obtain
u = FX (x) =
1
−1
1
[sin(π x) + 1], ≤ x ≤ .
2
2
2
(9)
Inverting this, we obtain
sin(π x) = 2u − 1 ⇒ x =
1 −1
sin (2u − 1), 0 ≤ u ≤ 1 ,
π
(10)
or
φ (u) =
1 −1
sin (2u − 1), 0 ≤ u ≤ 1 .
π
(11)
Thus to generate a random variable X with density function f X (x) given by (7), we
would generate a random U that is uniformly distributed on the interval [0,1) , and then
transform this according to
X = φ (U ) =
1 −1
sin (2U − 1) .
π
(12)
In order to make this example more meaningful, it is suggested that the reader sketch the
functions given by (7), (8), and (12).