Graphics Reference
In-Depth Information
Exercise 30.2: Continuing the preceding problem, suppose that instead of
having a three-sided coin, you have a slightly broken random number generator,
xrand , which returns a random number between 0 and 3. Seventy percent of the
time it's in [ 0, 1 ] , uniformly distributed; 20% of the time it's in [ 1, 2 ] , uniformly
distributed; and 10% of the time it's in [ 2, 3 ] , uniformly distributed. You're given
a single sample t generated by xrand , and you ask your friend to tell you y = f ( t ) .
(a) Show how to use the value y to estimate the integral as before. Hint: Use impor-
tance sampling.
(b) Compute the variance of your estimate.
(c) When, qualitatively, would you expect the variance to be larger than that of the
preceding problem's estimator? When would you expect it to be lower?
(d) Write a short program to confirm that the expected value and variance really
are what you predicted.
Exercise 30.3: Now imagine that instead of a function with three values, you
had a function that took on infinitely many, such as h ( x )= 1 +( 2 ) 2 .
(a) Compute the integral of h over [ 1, 3 ] using calculus.
(b) Estimate the integral of h over [ 1, 3 ] by writing a small program that picks a
random number x uniformly in the interval, evaluates h there, and multiplies by
3
1. Run the program 100 times and average the results, and compare with your
answer to part (a).
Exercise 30.4: In Equation 30.29, we showed that the pdf p W for the random
variable W satisfied b
a
p W ( r ) dr = b 2
a 2 for every a and b in the interval [ 0, 1 ] .
(a) Write f ( b )= b
a p W ( r ) dr , and compute f ( b ) in terms of p W using the Funda-
mental Theorem of Calculus.
(b) Since f ( b )= b 2
a 2 as well, compute f ( b ) inadifferentway.
(c) Conclude that p W ( r )= 2 r for any r
[ 0, 1 ] .
Exercise 30.5: Importance sampling. (a) Compute the integral of f ( x )= x 2
on the interval [ 0, 1 ] using calculus.
(b) Use stochastic integration (with uniformly distributed samples) to estimate the
integral, using n = 10, 100, 1,000, and 10,000 samples.
(c) Plot the error as a function of the number of samples. Repeat three times.
(d) Do the same computation, but for f ( x )=cos 2 ( x ) e 20 x .
(e) Use nonuniformly distributed samples to estimate the integral again, where the
probability density of generating the sample x is proportional to s ( x )= e 20 x .
To do this, you'll need to determine the constant of proportionality; fortunately,
that's easy because s is easy to integrate on the interval [ 0, 1 ] . You'll also need
to generate samples with density proportional to s ; the simplest approach is to
generate a uniform sample, u
[ 0, 1 ] , and compute x =
ln( u )
/
20. If x is larger
than 1, ignore it and repeat the process.
(f) Does this produce better estimates of the integral? Try to give an intuitive
explanation of your conclusion.
Exercise 30.6: Consistency and bias. Consider a random variable X
U ( 0, 1 ) . We saw in the chapter that we can estimate its mean by averaging n sam-
ples; this estimator will be unbiased. But consider the estimator
1 +
,
n
Y n = 1
n
X n
(30.71)
i = 1
where the X i are iid
U ( 0, 1 ) .
(a) Show that each Y n is a biased estimator of the mean X .
 
Search WWH ::




Custom Search