A posterior is useful only if we can extract a prediction from it. Even after specifying a law , an integral such as may be inaccessible analytically. Could repeated draws replace a high-dimensional integration grid?
Imagine estimating the probability of an event by counting its frequency. Monte Carlo applies exactly that idea to a general integrand. We first distinguish three promises (correct average, eventual convergence and finite-sample accuracy), then ask what survives when independent draws are unavailable.
Week 4: Monte Carlo methods
Monte Carlo methods
We now focus very much on estimating integrals of the form
where is an -valued r.v. and (or at least defined on the range of ); is the law of , and we usually assume that has PDF with
We often call the target distribution and the target density.
Key assumption: the integral defining actually converges, i.e.
"Vanilla" Monte Carlo
Key enabling assumption: We can draw as many independent samples as we like from the target distr. .
In this situation, we approximate by the Monte Carlo estimator
Unbiasedness and LLN
(since have the same law)
We also have convergence as the number of samples tends to infinity by the law of large numbers (LLN): so long as exists (i.e. ), converges to almost surely as , i.e.
When , MC estimators converge in root mean square at a that is independent of the dimension ; the rate is the inverse square root of the no. of samples taken, i.e. like .
Let's examine the random quadrature error
which has mean zero and variance
i.e. the root mean square error is
(For bounded , one can often do much better using tools from concentration of measure.)
Watch a single running estimate accumulate evidence. The reference line is the exact integral; the shrinking envelope is the theoretical RMSE scale, so crossing it is not a failure of the estimator.
Sample the integrand
Running estimate
J=1, estimate=0.075, exact integral=1/3
New samples change one running average. The amber envelope is a scale for random error, not a promise that every running estimate stays inside it.
Play once, pause, or scrub to inspect an intermediate state.
We can also obtain a probabilistic error bound using Chebyshev's inequality: for any ,
The part highlights the basic inverse sq. root cost-accuracy tradeoff in MC methods: if you want instead of (i.e. to double the accuracy), then you must quadruple since
The exponent is independent of dimension. The variance of and the cost of producing a draw can nevertheless grow with dimension; this is not a dimension-free computational guarantee.
But how can we apply the MC method if we cannot easily draw samples from / . This spurs the Markov chain Monte Carlo (MCMC) methods we consider next.
Note that because
uses only the values and does not care about the spacing of the nodes , the performance of is robust to poor features of (roughness, high-dim domain, ...), but it is also unable to leverage any nice features of (e.g. smoothness).
quasi-Monte Carlo methods try to have the best of both worlds.
Before replacing independent samples by a chain, compare the cost of precision with the cost of correlation.
Four times as many iid draws halve RMSE. A slowly decaying lag correlation can undo much of that gain: many recorded states need not mean many independent pieces of information.
Markov chain Monte Carlo
Setup: We have a formula for evaluating the target dens. but drawing samples from is hard/impossible. Our idea is to construct a random walk (more precisely, a Markov chain) of states in such that
-
as , the distribution of should approach/converge to the target dist. / its PDF ;
-
correlations of relevant observables should decay with increasing lag. In stationarity, is independent of and need not vanish;
-
we want to approximate integrals:
(space average time average)
Stationarity alone cannot ensure convergence of a time average: a chain that never moves preserves any starting law. For a stationary chain, write . Expanding the variance of the sum gives
Positive serial correlation inflates uncertainty. Under absolute summability the bracket tends to the asymptotic variance; it is not generally . Ergodicity and suitable moment assumptions, rather than invariance alone, justify the limiting time-average identity.
How do we construct such sequences ? We use a transition kernel / Markov kernel
telling us the prob. dist. of the next state given the current one.
One minimal requirement (necessary but not sufficient for (i)–(iii)) is that the target be invariant under , i.e. that if , then should be -distributed as well:
In practice, to construct a that has as an invariant/equilibrium distn., we often construct a that satisfies detailed balance / reversibility w.r.t. :
Proof that reversibility invariance. Suppose that is -reversible, and let .
The Metropolis–Hastings (MH) scheme
The Metropolis–Hastings (MH) scheme offers a simple implementation of a -reversible (and hence -invariant) transition kernel , in two steps.
We need one further prob. distn., called the proposal distribution with PDF .
-
Given that , draw a proposed new state with PDF . (here we need the proposal to be quick and easy to sample)
-
Calculate the acceptance probability , where
In practice compute and accept when . Initialise in the positive-density support; proposals with zero reverse probability are rejected. This avoids underflow and requires no normalising constant for .
- Draw .
- if , then we accept the proposal and set ;
- if , then we reject the proposal and set .
FACT: The MH scheme always yields a kernel , i.e. a rule for sampling given , that is reversible w.r.t. and hence has the target as an invariant distn.
Trace the algorithm one proposal at a time. When a proposal is rejected, watch both the point on the target density and the next entry in the time series. A rejected proposal still consumes an iteration.
Target and current proposal
Chain including rejected steps
Step 1: proposed -2.446; accepted
Amber hollow proposals were rejected. Their iterations remain in the chain as repeated states; deleting them would change the sampling law.
Play once, pause, or scrub to inspect an intermediate state.
Why rejection is part of the algorithm
For distinct states the accepted probability flow is
which is symmetric in . Rejected proposals supply a self-transition; the diagonal flow is automatically symmetric. This proves detailed balance, and the earlier proof then gives invariance. Deleting rejected states changes the chain and generally changes its invariant law.
Thought experiment. A reversible chain alternates deterministically between two states. Is it mixing? Its invariant law is uniform, but a point initial distribution oscillates forever. In Week 5, the Markov operator lets us recognise this obstruction as an eigenvalue .