j.-a. goulet 90
ample of a random walk generated with MCMC that follows the
density described by the underlying contour plot.
Several MCMC methods exist: Metropolis-Hastings, Gibbs sam-
pling, slice sampling, Hamiltonian Monte Carlo, and more. This
chap t er covers only the Metropolis and Metropolis-Hastings meth-
ods b e cau se t h ey ar e t h e most acc e ss ib l e. The r e ade r i nterested in
advanced methods should refer to dedicated textbooks such as the
one by Brooks et al.
1
1
Brooks, S., A. Gelman, G. Jones, and
X.-L. Meng (2011). Handbook of Markov
Chain Monte Carlo.CRCPress
7.1 Metropolis
The Metropolis algorithm
2
was de veloped during the Second World
2
Metropol is, N ., A. W. Rosenbluth, M. N.
Rosenbluth, A. H. Teller, and E. Teller
(1953). Equation of state calculations by
fast computing machines. The J o u r na l of
Chemical Physics 21 (6), 1087–1092
War while working on the Manhattan project (i.e., the atomic
bomb) at Los Alamos, Ne w Me x ic o. M et r opolis i s not th e mos t
efficient sampling algorithm, yet it is a simple one allowing for an
easy introduction to MCMC methods. Notation
Initial state: ✓
0
Target distribution:
˜
f(✓)
Proposal distribution: q(✓
0
|✓)
The Metropolis algorithm requires defining an initial state f or
a set of
P
parameters
✓
0
=[
✓
1
✓
2
··· ✓
P
]
|
0
, a target distribution
˜
f
(
✓
)=
f
(
D|✓
)
· f
(
✓
) corresponding to the unnormalized posterior
we want to sample f r om, an d a proposal distribut ion,
q
(
✓
0
|✓
), which
describes where to move next given the current parameter values.
The proposal must have a nonz ero probability to transit from the
current state to any state supported by the target distribution and
must be symmetric, th at is,
q(✓
0
|✓)=q(✓|✓
0
).
The Normal distribution (see
§
4.1) is a common general-purpose
proposal distribution,
q(✓
0
|✓)=N(✓
0
; ✓, ⌃
q
),
where the mean is defined by the current position and the proba-
bility to move in a region around the current position is controlled
by the covariance matrix
⌃
q
. Figure 7.2 presents an example of 1-D
and 2-D Normal proposal distributions.
(a) N(✓
0
; ✓,
2
q
)
(b)
N
✓
0
;[✓
1
✓
2
]
|
, diag(
⇥
2
q
1
2
q
2
⇤
)
Figure 7.2: Examples of 1-D and 2-D
proposal distributions, q(✓
0
|✓).
The Metropolis algorithm is recursive so at the
s
th
step, given a
current position in the parameter space
✓
=
✓
s
,weemploy
q
(
✓
0
|✓
)
to propose mov i ng to a new positi on
✓
0
. If the target distribution
evaluated at the proposed location is greater than or equal to the
current one, that is,
˜
f
(
✓
0
)
˜
f
(
✓
)—we accept the proposed location.
If the proposed location has a target value that is lower than the
current one, we accept moving to the proposed location with a
probability equal to the acceptance ratio
˜
f(✓
0
)
˜
f(✓)
. In the case where
Note:
In order to accept a proposed
location with a probability equal to
r
=
˜
f(✓
0
)/
˜
f(✓)
,wecompareitwithasample
u
taken from
U
(0
,
1). If
u r
,weacceptthe
move; otherwise, we reject it.