Generating Random Variates 3 (Chapter 8, Law) • Generating from

B. Maddah
ENMG 622 Simulation
03/14/07
Generating Random Variates 3 (Chapter 8, Law)
• Generating from an empirical distribution with raw data
¾ Suppose that n observations of a random variable X are
available.
¾ Rather than fitting a theoretical distribution to the
distribution of X, an empirical distribution can be assessed
based on actual observations.
¾ Arrange the data such that X1 < X2 < …< Xn. An empirical
distribution can be specified by setting FX(Xi) = (i–1)/n–1
and interpolating.
⎧ 0,
if x < X 1
⎪
x − Xi
⎪ i −1
FX ( x) = ⎨
+
, if X i ≤ x < X i +1 , i = 1, 2,K , n
n
n
X
X
−
1
(
−
1)(
−
)
i +1
i
⎪
⎪⎩1,
if x ≥ X n
U
1
¾ Then, random variates can be generated from X as follows.
1. Generate U ~ U(0,1)
2. Set P = (n−1)U and I = ⎢⎣ P ⎦⎥ + 1
3. Set X = XI + (P − I + 1)(XI+1 − XI)
¾ This algorithm is based on the inverse transform method.
¾ P allows to determine the interval (XI, XI+1), where the
generated value should fall.
¾ Then, inverting the FX(x) on (XI, XI+1) gives X.
• Generating from an empirical distribution with grouped
data
¾ Suppose that instead of the actual observations, the number
of observations that falls in one of k intervals is available.
¾ Suppose the k intervals are [a0,a1), [a1,a2), …, [ak−1,ak).
¾ Let nj be the number of observations in interval [aj, aj+1),
j =0,1, …, k−1, and n the total number of observations.
¾ Then, a distribution function can be defined at aj’s as
⎛ j ⎞
GX(a0) = 0, GX (a j ) = ⎜ ∑ ni ⎟ / n , j =1, …, k .
⎝ i =1 ⎠
¾ The, the completed distribution function can be defined by
linear interpolation between the aj’s as follows.
2
if x < a0
⎧ 0,
⎪
⎪G (a ) + x − a j −1 [G ( a ) − G (a )], if a ≤ x < a ,
⎪ X j −1
X
j
X
j −1
j −1
j
(a j − a j −1 )
GX ( x) = ⎨
⎪ j = 1, 2, K , k
⎪
⎪⎩ 1,
if x ≥ ak
¾ Then, random variates can be generated from X based on the
inverse transform method as follows.
1. Generate U ~ U(0,1)
2. Find an integer J such that G(aJ) ≤ U < G(aJ+1)
3. Set X = aJ + [U − G(aJ)](aJ+1−aJ)/[ G(aJ+1)− G(aJ)] .
• Generating a stationary Poisson arrival process
¾ The objective here is to generate arrival times from a
stationary Poisson process with rate λ.
¾ The key fact used here is that the inter-arrival times are
exponentially distributed with mean 1/λ .
¾ Then, Poisson arrival times can be generated as follows.
1. set t0 = 0, i =1
2. Generate U ~ U(0,1)
3. Set ti = ti−1 − (1/λ)ln(U)
4. Set i=i+1 and go to Step 2.
3
• Generating a nonstationary Poisson arrival process
¾ Suppose that the arrival rate of a Poisson process varies with
time. E.g., in a call center, the arrival rates are high during
lunch and evening rush hours.
¾ This is called a nonstationary Poisson process.
¾ To generated random variates one may be tempted to
proceed in a similar fashion as a stationary process.
1. set t0 = 0, i =1
2. Generate U ~ U(0,1)
3. Set ti = ti−1 − (1/λ(ti−1))ln(U)
4. Set i=i+1 and go to Step 2.
¾ This algorithm is wrong! If λ(ti−1) is small (say around
morning time), then the generated time ti will be long.
¾ This could leading to “skipping” several intervals where λ(t)
is large.
4
¾ A correct algorithm is based on “thinning.” The idea is to
generate a large number of arrival times based on λ* that
majorizes λ(t).
¾ Then, an arrival at time t is accepted as a “true” arrival with
probability λ(t)/ λ* .
¾ The thinning algorithm works as follows.
1. set t0 = 0, i =1
2. Set t =ti−1 .
3. Generate U1, U2 ~ U(0,1)
4. Set t = t − (1/λ*)ln(U1)
5. If U2 ≤ λ(t)/ λ*, set ti = t, i = i+1 and go to Step 2.
Otherwise, go to Step 3.
5