Particle MCMC

Fitting parameters of stochastic models

Where we got to

p̂(y∣θ)=∏t1J∑j=1Jwt,j\hat{p}(y \mid \theta) = \prod_{t} \frac{1}{J}\sum_{j=1}^{J} w_{t,j}

An estimate of the marginal likelihood at one θ\theta. We want the posterior over θ\theta.

Substituting the estimate

We already have an algorithm that explores a posterior using nothing but likelihood evaluations: Metropolis-Hastings.

So: propose θ*\theta^*, run a particle filter to get p̂(y∣θ*)\hat{p}(y \mid \theta^*), and accept or reject as usual.

r=min⁡(1,p̂(y∣θ*)p(θ*)p̂(y∣θ)p(θ))r = \min\left(1, \frac{\hat{p}(y \mid \theta^*)\, p(\theta^*)}{\hat{p}(y \mid \theta)\, p(\theta)}\right)

This is particle marginal Metropolis-Hastings (PMMH).

Why should that work at all?

Same θ\theta, same data, 400 runs of the filter — fed into an algorithm derived assuming the exact likelihood.

The reason it works

The estimate is unbiased:

𝔼[p̂(y∣θ)]=p(y∣θ)\mathbb{E}\big[\hat{p}(y \mid \theta)\big] = p(y \mid \theta)

The chain still targets the correct posterior — exactly, not approximately. The noise costs us efficiency, never correctness.

Andrieu et al. (2010) — derived in the appendix

The practical problem

Noise makes the chain sticky

A lucky high estimate sits in the denominator of every later acceptance ratio, so the chain rejects good proposals until something beats it.

Choosing the number of particles

Tune JJ so the standard deviation of the log likelihood estimate is roughly 1 to 3 at a representative θ\theta.

Measured here at the posterior mean. The estimator is noisier out in the tails of the posterior, which is why the practical uses 256 rather than the 128 this curve appears to license.

Pitt et al. (2012); Doucet et al. (2015)

Why RAM rather than NUTS

  • Resampling and discrete events make the likelihood non-differentiable: no gradient to follow.
  • The filter returns a different number every run, so there is no fixed surface for HMC to integrate along.

Metropolis-Hastings survives the second because the estimate is unbiased. HMC does not.

So we use robust adaptive Metropolis, which learns the proposal covariance for us (Vihola 2012).

The pay-off

Everything from the deterministic part of the course now carries over to stochastic models:

  • posterior distributions over parameters
  • credible intervals
  • posterior predictive checks

And we get the latent trajectories for free: each accepted θ\theta comes with a sampled state path, which is state estimation alongside parameter estimation.

Comparing models

Is temporary immunity better described by one compartment or four? No amount of sampling SEITL answers that: you have to fit both.

  • Posterior predictive checks: which reproduces the features you care about?
  • DIC: the fit at the posterior mean, penalised by how much worse the fit is on average across the posterior

Both ask only for the likelihood of the whole series, which is what the filter returns. DIC is the criterion we can compute here, and a rough one: it approximates predictive accuracy less well than the criteria usually recommended, which need a likelihood term for each observation on its own.

The criterion that is appropriate for model comparison is determined by the structure of the model.

DIC

Deviance, so that smaller is a better fit: D(θ)=−2log⁡p(y∣θ)D(\theta) = -2 \log p(y \mid \theta).

DIC=D(θ‾)+2pD,pD=D¯−D(θ‾)\mathrm{DIC} = D(\bar{\theta}) + 2 p_D, \qquad p_D = \overline{D} - D(\bar{\theta})

  • D(θ‾)D(\bar{\theta}): the fit at the posterior mean θ‾\bar{\theta}
  • D¯\overline{D}: the fit averaged over the posterior
  • pDp_D: how much worse the average is than the fit at the mean, the effective number of parameters

Lower is better, and only the difference between two models means anything.

Your Turn

In the practical you will

  • assemble the particle filter and Metropolis-Hastings into PMMH
  • run a short chain and see the poor mixing for yourself
  • vary the particle count and watch the trade-off appear
  • work with a pre-computed long chain, and compare against the deterministic fit
  • compare SEITL against SEIT4L, from the pre-computed chains, with DIC and a posterior predictive check

Appendix: why PMMH is exact

Making the randomness explicit

The filter is random only because it consumes random numbers. Collect all of them into one vector uu:

  • the draws that initialise the particles
  • the noise that propagates each particle at each step
  • the uniforms that drive resampling

Write m(u)m(u) for their density. Because the propagation is a deterministic map applied to standard draws, mm does not depend on θ\theta.

Given uu, the filter is a deterministic function:

p̂(y∣θ)=p̂(y∣θ,u)\hat{p}(y \mid \theta) = \hat{p}(y \mid \theta, u)

A distribution on the enlarged space

Define a joint density over the pair (θ,u)(\theta, u):

π̃(θ,u)=p(θ)p̂(y∣θ,u)m(u)p(y)\tilde{\pi}(\theta, u) = \frac{p(\theta)\, \hat{p}(y \mid \theta, u)\, m(u)}{p(y)}

Integrating uu out at fixed θ\theta averages the estimator over its own randomness, which is exactly what unbiasedness controls:

∫p̂(y∣θ,u)m(u)du=𝔼[p̂(y∣θ)]=p(y∣θ)\int \hat{p}(y \mid \theta, u)\, m(u)\, \mathrm{d}u = \mathbb{E}\big[\hat{p}(y \mid \theta)\big] = p(y \mid \theta)

This is the only place unbiasedness is used.

The marginal is the posterior

It follows that π̃\tilde{\pi} integrates to one, and that

∫π̃(θ,u)du=p(θ)p(y∣θ)p(y)=p(θ∣y)\int \tilde{\pi}(\theta, u)\, \mathrm{d}u = \frac{p(\theta)\, p(y \mid \theta)}{p(y)} = p(\theta \mid y)

The θ\theta-marginal of the enlarged target is the posterior we wanted.

PMMH is Metropolis-Hastings on that target

Propose θ*\theta^* from q(⋅∣θ)q(\cdot \mid \theta), then fresh random numbers u*∼m(⋅)u^* \sim m(\cdot). The Metropolis-Hastings ratio for π̃\tilde{\pi} under that proposal is

p(θ*)p(θ)⋅p̂(y∣θ*,u*)p̂(y∣θ,u)⋅m(u*)m(u)⏟target⋅q(θ∣θ*)q(θ*∣θ)⋅m(u)m(u*)⏟proposal\underbrace{\frac{p(\theta^*)}{p(\theta)} \cdot \frac{\hat{p}(y \mid \theta^*, u^*)}{\hat{p}(y \mid \theta, u)} \cdot \frac{m(u^*)}{m(u)}}_{\text{target}} \;\cdot\; \underbrace{\frac{q(\theta \mid \theta^*)}{q(\theta^* \mid \theta)} \cdot \frac{m(u)}{m(u^*)}}_{\text{proposal}}

The two mm factors are reciprocals, so they cancel, leaving

p(θ*)p̂(y∣θ*,u*)q(θ∣θ*)p(θ)p̂(y∣θ,u)q(θ*∣θ)\frac{p(\theta^*)\, \hat{p}(y \mid \theta^*, u^*)\, q(\theta \mid \theta^*)}{p(\theta)\, \hat{p}(y \mid \theta, u)\, q(\theta^* \mid \theta)}

This is the acceptance ratio we started from. The random numbers never appear in the implementation because their proposal density cancels against their target density.

What the argument gives

  • It holds for any number of particles, J=1J = 1 included. Correctness never required JJ to be large.
  • The variance of p̂\hat{p} never entered, which is why noise costs efficiency alone.
  • uu is part of the chain’s state and changes only when a move is accepted. A lucky uu is carried until something beats it: the plateaus we saw earlier, seen from the enlarged space.

The condition worth naming is that π̃\tilde{\pi} must be a proper density, so the estimator has to be non-negative and strictly positive wherever the posterior is. Particle filter estimates satisfy this.

Andrieu and Roberts (2009); Andrieu et al. (2010)

Return to the session