i
i
i
i
i
i
i
i
334 14. Sampling
i.e., x
i+1
= x
i
. We phrase this as generating a potential candidate y ∼ t(x
i
→ y)
and “accepting” this candidate (i.e., x
i+1
= y) with probability a(x
i
→ y) and re-
jecting it (i.e., x
i+1
= x
i
) with probability 1−a(x
i
→ y). Note that the sequence
x
0
,x
1
,x
2
,...will be a random set, but there will be some correlationamong sam-
ples. They will still be suitable for Monte Carlo integration or density estimation,
but analyzing the variance of those estimates is much more challenging.
Now, suppose we are given a transition function t(x → y) and a function f(x)
of which we want to mimic the distribution, can we use a(y → x) such that the
points are distributed in the shape of f? Or more precisely,
{x
0
,x
1
,x
2
,...}∼
f
#
s
f
.
It turns out this can be forced by making sure the x
i
are stationary in some strong
sense. If you visualize a huge collection of sample points x, you want the “flow”
between two points to be the same in each direction. If we assume the density of
points near x and y are proportional to f(x) and f(y), respectively, then the flow
in the two directions should be the same:
flow(x → y)=kf(x)t(x → y)a(x → y),
flow(y → x)=kf(y)t(y → x)a(y → x),
where k is some positive constant. Setting these two flows constant gives a con-
straint on a:
a(y → x)
a(x → y)
=
f(x)t(x → y)
f(y)t(y → x)
.
Thus, if either a(y → x) or a(x → y) is known, so is the other. Making them
larger improves the chance of acceptance, so the usual technique is to set the
larger of the two to 1.
Adifficulty in using the Metropolis sample generation technique is that it is
hard to estimate how many points are needed before the set of points is “good.”
Things are accelerated if the first n points are discarded, although choosing n
wisely is non-trivial.
14.4.4 Example: Choosing Random Lines in the Square
As an example of the full process of designing a sampling strategy, consider the
problem of finding random lines that intersect the unit square [0, 1]
2
.Wewant
this process to be fair; that is, we would like the lines to be uniformly distributed
within the square. Intuitively, we can see that there is some subtlety to this prob-
lem; there are “more” lines at an oblique angle than in horizontal or vertical di-
rections. This is because the cross section of the square is not uniform.