ISyE 6644 — Fall 2014

Transcription

ISyE 6644 — Fall 2014
1
ISyE 6644 — Fall 2014
Homework #4 Solutions
1. Do some of the following random number generation problems from Law, pp. 419–
421: #7.1, 7.2(a), 7.3(d), 7.11, 7.12, 7.13.
Problem 7.1: If Xi = (5Xi−1 + 3)mod(16) find X500 .
Solution: X0 = 7. Then X1 = 38 mod(16) = 6, X2 = 1, X3 = 8, . . . , X16 = 7. So
the cycle repeats itself every 16 iterations (see Table 7.2, p. 407 of the text). This
implies that X32 = 7 = X48 = · · · = X496 , and so X500 = X496+4 = X4 = 11. 2
Problem 7.2(a): Starting with X0 = 1, write out the entire cycle for Xi =
11Xi−1 mod(16).
Solution: Then X1 = 11, X2 = 9, X3 = 3, X4 = 1. So the period is only m/4 = 4.
2
Problem 7.3(d): Does Xi = (Xi−1 + 12)mod(13) have full period?
Solution: Yes, this is a full-period generator. (You can verify this either by plugand-chug or via Theorem 7.1 of the text.) 2
Problem 7.11: For the LCG from Problem 7.3(d) above, plot the pairs
(U1 , U2 ), (U2 , U3 ), . . ..
Solution: Basically, the points form a straight line. 2
Problem 7.12: Consider the Fibonacci generator Xi = (Xi−1 + Xi−2 )mod(m).
(a) Show that it’s not possible to obtain the following arrangement of PRN’s:
Ui−2 < Ui < Ui−1 .
Solution: Equivalently, we’ll show that it’s not possible to obtain Xi−2 <
Xi < Xi−1 . Let’s consider what happens when we have the following two
cases: Xi−1 + Xi−2 < m and Xi−1 + Xi−2 ≥ m.
2
(i) Suppose Xi−1 + Xi−2 < m. Then Xi = (Xi−1 + Xi−2 )mod(m) = Xi−1 +
Xi−2 > Xi−1 , so we can’t have Xi−2 < Xi < Xi−1 for this case.
(ii) Suppose Xi−1 + Xi−2 ≥ m. Then Xi = (Xi−1 + Xi−2 )mod(m) = Xi−1 +
Xi−2 − m < Xi−2 (since Xi−1 − m < 0). So, again, so we can’t have
Xi−2 < Xi < Xi−1 for this case.
Since neither of the above cases work, we’re done. (By the way, there may be
an easy geometric argument for this problem, but I’m too lazy to figure one
out.) 2
(b) Show that the arrangement in (a) should occur 1/6 of the time for a “perfect”
PRN generator.
Solution: This follows because Ui−2 < Ui < Ui−1 is one of 6 random permutations of three consecutive PRN’s. 2
Problem 7.13: Suppose that U1 , U2 , . . . , Uk are i.i.d. Unif(0,1). Let hxi denote the
decimal part of x, e.g., h3.73i = 0.73. Show that hU1 + U2 + · · · + Uk i ∼ Unif(0, 1).
Solution: We’ll solve this problem by induction. The induction is actually the
easy part. The tricky part is the base case — i.e., we’ll first need to show that
hU1 + U2 i ∼ Unif(0, 1). To do so, let’s define Y ∼ U1 + U2 . From class notes, we
know that Y ∼ triangular(0, 1, 2), i.e., the p.d.f. of Y is
(
fy (y) ≡
y
if 0 ≤ y ≤ 1
,
2 − y if 1 ≤ y ≤ 2
and the c.d.f. of Y is
(
Fy (y) ≡
y 2 /2
−1 + 2y −
y2
2
if 0 ≤ y ≤ 1
.
if 1 ≤ y ≤ 2
So the c.d.f. of X ≡ hU1 + U2 i is
Pr(X ≤ x) =
=
=
=
=
=
=
Pr(X ≤ x, Y ≤ 1) + Pr(X ≤ x, Y > 1)
Pr(hU1 + U2 i ≤ x, U1 + U2 ≤ 1) + Pr(hU1 + U2 i ≤ x, U1 + U2 > 1)
Pr(U1 + U2 ≤ x, U1 + U2 ≤ 1) + Pr(U1 + U2 − 1 ≤ x, U1 + U2 > 1)
Pr(U1 + U2 ≤ x) + Pr(1 < U1 + U2 ≤ x + 1)
Pr(Y ≤ x) + Pr(1 < Y ≤ x + 1)
FY (x) + FY (x + 1) − FY (1)
x (after some algebra).
3
This is the c.d.f. of the Unif(0,1), so we have just proven that X = hU1 + U2 i ∼
Unif(0, 1).
Actually, now that I think about it, you can probably use a very easy geometric
argument to flip over the two pieces of the triangle to get a Unif(0,1) — maybe
saving all of the above work!
In any case, the inductive step is to assume that hU1 + U2 + · · · + Uk i ∼ Unif(0, 1)
and to use this to prove that hU1 + U2 + · · · + Uk+1 i ∼ Unif(0, 1). To this end, note
that
hU1 + U2 + · · · + Uk+1 i =
D
hU1 + U2 + · · · + Uk i + Uk+1
E
∼ hUnif(0, 1) + Uk+1 i (by the inductive step)
∼ Unif(0, 1) (by the base case). 2
2. Runs distributions.
(a) Suppose that U1 , U2 , U3 are i.i.d. Unif(0,1). Find the distribution of the number of runs up-and-down.
Solution: We write out every possible permutation of the order of the three
Ui ’s, each of which will have equal probability of occurring.
U1
U1
U2
U2
U3
U3
event
< U2 < U3
< U3 < U2
< U1 < U3
< U3 < U1
< U1 < U2
< U2 < U1
+/−
++
+−
−+
+−
−+
−−
number of runs
1
2
2
2
2
1
Hence, in the case of three observations, there is 1 run with probability 1/3
and two runs w.p. 2/3. 2
(b) Now suppose that U1 , U2 , U3 , U4 are i.i.d. Unif(0,1). Find the distribution of
the number of runs up-and-down. You can do this either analytically (which
is tedious) or by running a lot of simulations and estimating the distribution.
4
Solution: Now let’s look at the number of runs from U1 , U2 , U3 , U4 . Again,
we’ll write out every possible permutation of the order of the Ui ’s, each of
which will have equal probability of occurring.
U1
U1
U1
U1
U1
U1
U2
U2
U2
U2
U2
U2
U3
U3
U3
U3
U3
U3
U4
U4
U4
U4
U4
U4
event
< U2 < U3
< U2 < U4
< U3 < U2
< U3 < U4
< U4 < U2
< U4 < U3
< U1 < U3
< U1 < U4
< U3 < U1
< U3 < U4
< U4 < U1
< U4 < U3
< U1 < U2
< U1 < U4
< U2 < U1
< U2 < U4
< U4 < U1
< U4 < U2
< U1 < U2
< U1 < U3
< U2 < U1
< U2 < U3
< U3 < U1
< U3 < U2
< U4
< U3
< U4
< U2
< U3
< U2
< U4
< U3
< U4
< U1
< U3
< U1
< U4
< U2
< U4
< U1
< U2
< U1
< U3
< U2
< U3
< U1
< U2
< U1
+/−
+++
++−
+−+
+−+
++−
+−−
−++
−+−
−++
−++
−+−
−+−
+−+
+−+
−−+
−−+
+−+
−−+
++−
+−−
−+−
−+−
+−−
−−−
number of runs
1
2
3
3
2
2
2
3
2
2
3
3
3
3
2
2
3
2
2
2
3
3
2
1
Hence, in the case of four observations, there is 1 run with probability 1/12,
two runs w.p. 1/2, and three runs w.p. 5/12. 2
(c) Now use simulation to do the same for U1 , U2 , . . . , U10 . How close is your result
to the asymptotic distribution we did in class?
3. Implement the pseudo-random number generator
Xi = 16807Xi−1 mod(231 − 1)
in your favorite computer language. Using the seed X0 = 1234567, run the generator for 100,000 observations.
5
(a) Perform a χ2 goodness-of-fit test on the resulting PRN’s. Use 20 equalprobability intervals and level α = 0.05.
Solution: When I performed the χ2 test, I obtained χ2 = 14.4552. The critical value is χ20.05,19 = 30.144. So we fail to reject the hypothesis that these
numbers are from a Unif(0,1) distribution at the 0.05 level of significance. 2
(b) Perform a runs up-and-down test with α = 0.05 on the observations to see if
they are independent.
Solution: When I performed the runs up-and-down test, I obtained A = 66735
runs. Since E[A] = 66666.33 and Var(A) = 17777.46, I find the standardized
√
= 0.515 < 1.96. So we fail to reject the hystatistic to be Z0 = 66735−66666.33
17777.46
pothesis that these numbers are independent at the 0.05 level of significance.
2
(c) Do a runs above-and-below-the-mean test for independence.
4. A bad generator. Consider the RANDU generator,
Xi = 65539Xi−1 mod(231 ).
(Note that m is a power of 2.) This generator is known to have problems. Generate
10000 observations and graph Xi−1 vs. Xi . Comments?
Solution: Starting with the seed X0 = 123,456,789 and drawing (Xi−2 , Xi−1 , Xi ),
you should obtain something similar to Figure 7.4 in Law. If you are drawing just
(Xi−1 , Xi ) they will look scattered, so the problem is not obvious from that graph.
Don’t try to draw all of the points if you want to see a clear graph. 2
5. Implement the Tausworthe generator for q = 32 and your choice of r and base-2
word size `. Generate 10000 observations and make a histogram. Also graph Xi−1
vs. Xi . Comments?
Solution: Choosing r = 12 and ` = 5, it I found that the data were not quite
uniform. To make the histogram, I divided the random numbers into 20 equal intervals. For example, in the intervals (0,0.05), (0.05,0.1), and (0.2,0.25) there were
6
more than 650 numbers, whereas in the intervals (0.1,0.15) and (0.25,0.3) there
were only around 300 numbers. If this was truly uniform, we would expect approximately 500 numbers in each interval. 2
6. Pick any three Arena problems from Chapter 5 of the Kelton, Sadowski, and Swets
text.