Random Number Generation - Handout #13

Last time we discussed Random Number Generation and we found that random numbers need two properties:

Independence

Uniformity

Random numbers were generated by techniques such as the midsquare method.

Today we're going to generate random numbers by using distributions. Most of this information comes directly from Kobayashi.

Transform Method

One way to do this is by the transform method, page 241 Kobayashi.

Given:

X: random variable

F(x): distribution function, F(x) = P[ X £ x ].

The first thing we do is set:

Y = F( X ).

In this way, Y is defined on the range [0, 1].

If Y is a random variable uniformly distributed between 0 and 1 the variable X defined by:

X = F-1( Y )

Note that this is the inverse function, not 1/F(Y).

Then X has cumulative distribution F(x):

P[ X £ x ] = P [ Y £ F(x) ] = F(x)

Example 4.1, page 242.

Let X be a random variable with exponential distribution:

F(x) = 1 - e-m x, x ³ 0.

Set this equal to a random decimal number Y:

F( X ) = Y

1 - e-m X = Y, or,

Y = 1 - e-m X

Solve for X:

Y = 1 - e-m X

e-m X = 1 - Y

ln (e-m X) = ln (1 - Y)

-m X = ln (1 - Y)

X = - { ln (1 - Y) }/m

So that:

X = F-1(Y) = - { ln (1 - Y) }/m

Because Y is a random decimal number between 0 and 1, then (1 - Y) is also a random decimal number between 0 and 1. Therefore, the equation can be simplified as:

X = F-1(1 - Y) = - { ln Y }/m

What's something we know about the natural log (ln)?

The natural log of decimal numbers less than 1 results in a negative decimal number.

Ex:

ln 0.1 = -2.302585092994

…

ln 0.5 = -0.6931471805599

…

ln 0.99 = -0.0100503358535

{Remember, ln 1 = 0}

So, these random numbers generated will be positive between 0 and 1.

So, we get (assume m = 3)

Y

X = - { ln Y }/m

0.1

0.7675283643313

0.2

0.5364793041447

…

…

0.5

0.2310490601866

…

…

0.8

0.0743811837714

0.9

0.03512017188594

 

Let's do another one!

Let X be a random variable with Weibull distribution:

F(x) = 1 - exp[-{(x-v)/α}^β], for x >= v.

Set this equal to a random decimal number Y:

F( X ) = Y

F(X) = 1 - exp[-{(X-v)/α}^β] = Y

Solve for X:

Not given here!

So that:

X = F-1(Y) = -(a /e^b ) ln(1-Y) + v

Because Y is a random decimal number between 0 and 1, then (1 - Y) is also a random decimal number between 0 and 1. Therefore, the equation can be simplified as:

X = F-1(1 - Y) = -(a /e^b ) ln(Y) + v

 

Rejection Method

The rejection method, Kobayashi page 243, can be used when it is difficult to calculate the inverse function (as in the transform method above). In this method, let:

f(x) be bounded by M, and,

have a finite range a £ x £ b.

Let there be pairs of random decimal numbers (R1, R2) between 0 and 1. Then:

X1 = a + (b - a)R1

is a random number in [a, b]. Whenever we encounter a pair (R1, R2) that satisfies the relationship:

M× R2 £ f(X1)

we accept X1 and reject otherwise.

The probability density function of accepted X1's will be f(x).

The number of trials before a successful pair is found is a random variable n with geometric distribution:

P[n] = r (1 - r )n-1

with

r = 1/[M(b-a)]

and mean value n:

E[n] = 1/r = M(b-a)

So, the method is not appropriate for pdfs with large expected values.

 

Example 4.4.6, page 246.

Consider the following pdf:

See text book.

Use the rejection technique to generate random variates according to this distribution.

So, a = 0, b = 1, and M = 2(1) = 2.

X1 = a + (b - a)R1

X1 = 0 + (1 - 0)R1

X1 = R1

is a random number in [0, 1]. Whenever we encounter a pair (R1, R2) that satisfies the relationship:

M× R2 £ f(X1)

2× R2 £ 2× X1

R2 £ X1

we accept X1 and reject otherwise.

The probability density function of accepted X1's will be f(x).

The number of trials before a successful pair is found is a random variable n with geometric distribution:

P[n] = r (1 - r )n-1

with

r = 1/[M(b-a)] = 1/[2(1-0)] = 1/2

P[n] = (1/2)(1 - (1/2))n-1

P[n] = (1/2)(1/2)n-1

P[n] = (1/2)n

and mean value n:

E[n] = 1/r = 2

 

Composition Method

The composition method, Kobayashi page 244, is another method to generate random numbers from a distribution. Let a distribution F(x) be a mixture of two distributions: F1(x) and F2(x):

F(x) = p× F1(x) + (1 - p)× F2(x)

We obtain a variate X by:

    1. Generating a uniform variate U.
    2. If U < p, then X = F1(x), else X = F2(x)

 

Example 4.4.7. Hyperexponential Distribution. Find a way to generate a sequence of variates that have the two-phase hyperexponential distribution:

See text.

where p + q = 1.

Since p + q = 1, 1 = p + q = p + (1 - p)

... FX(x) = p(1-e-μ1X)+ (p-1)(1-e-μ2X)

Now this is in the correct form.

F1(x) = p(1-e-μ1X)
F2(x) = (p-1)(1-e-μ2X)

So, we generate a random variate U and if U < p, then we set X equal to F1(x), otherwise we use F2(x).

This hyperexponential distribution has parameters (m 1, m 2, p). This distribution means that there are two types of service that may be requested, and are requested in proportions of p and q, respectively.