We will try to simulate from the ABC posterior more efficiently.
We will do this sequentially, starting from the prior, and building a sequence of distributions that get closer and closer to the posterior.
In Lecture 2, we discussed how to specify a joint distribution for \(Y_1, Y_2\) by first specifying a distribution for \(Y_1\) and then specifying a distribution for \(Y_2 \mid Y_1\).
We calculated joint probabilities for discrete random variables using \[ P(Y_1=y_1,Y_2=y_2) = P(Y_1=y_1)\,P(Y_2=y_2\mid Y_1=y_1). \]
The same multiplication rule holds for densities.
If we construct a joint distribution as:
Then:
This is how we specify \(\Theta\) and \(X\) in a Bayesian model.
Recall that when we talked about conditional distributions for discrete random variables in Lecture 10, we had
\[ \begin{aligned} P(X = x \mid X \in E) &= \frac{P(X = x \text{ and }X \in E) }{ P(X \in E)}\\ &= \begin{cases} \frac{P(X = x)}{P(X \in E)} & x \in E \\ 0 & x \not\in E \end{cases}\\ &= \frac{P(X = x)}{ P(X \in E)} \mathbf 1(x \in E) \\ &\propto P(X = x) \mathbf 1(x \in E) \end{aligned} \]
(first two lines from Lecture 10, last two lines new here).
The analogous statement for a continuous random variable involves the pdf:
Given a prior \(\pi\), probability model \(P_\theta\) that you can simulate from, summary statistics \(s\), and tolerance \(\epsilon\):
The retained parameters are draws from the conditional distribution
\[ \Theta\mid d(s(X),s(x^{obs}))<\epsilon. \]
Smaller tolerances usually mean fewer acceptances.
Usually you will be dealing with summary statistics and/or parameter vectors that are more than 1-dimensional, but the same picture holds: you simulate from the prior and retain draws in a small window around the observed summary.
After \(N\) samples from the prior, you might not have retained very many draws that matched the summary statistics well enough, but you could still have an idea about values of \(\theta\) that are more or less plausible.
The ABC-SMC idea is that we bias our proposal distribution away from the prior and toward regions we think have higher posterior mass.
Then we can use our importance sampling weights to correct for our biased proposal.
Suppose our proposal distribution for \((\Theta, X)\) is \(\Theta \sim \pi\), \(X \mid \Theta \sim P_\Theta\).
Suppose our target distribution is \((\Theta, X) \mid d(s(X), s(x^{obs})) < \epsilon\).
Importance sampling:
Importance sampling works well for describing a distribution if the target and proposal distributions are similar.
If the data are informative, the prior and posterior will be far from each other.
ABC-SMC idea: sequentially modify the proposal/target distributions so that you gradually get to the desired posterior.
Choose a sequence of tolerances \(\epsilon_1 > \epsilon_2 > \cdots > \epsilon_T\).
At round \(t\), our target posterior is \(\Theta \mid d(s(X), s(x^{obs})) < \epsilon_t\).
Round 1: Run rejection ABC with tolerance \(\epsilon_1\). Give the retained draws equal weight.
Rounds 2 to \(T\):
Repeat until we get to the final tolerance \(\epsilon_T\).
Each round produces a weighted collection of parameter draws, called particles.
Suppose the previous round produced particles \(\theta_1,\ldots, \theta_N\) with weights \(w_1,\ldots, w_N\).
For round \(t\), choose a noise distribution that you can simulate from and which has a pdf that you can compute.
Let \(k_{t, \mu}\) denote the pdf of that noise distribution shifted so that it is centered at \(\mu\).
To propose a parameter for this round, we:
The resulting proposal density is \[ q_t(\theta)=\sum_{j=1}^N w_j\,k_{t,\theta_j}(\theta). \]
We can compute this because we have chosen \(k\) to have a pdf we can compute.
The previous roundโs weighted particles \((\theta_1, w_1), \ldots, (\theta_N, w_N)\) are supposed to approximate the ABC posterior with tolerance \(\epsilon_{t-1}\).
The proposal selects particles according to their weights and then adds noise.
The noise both smooths out the approximating distribution (we can get proposals that are not exactly the same as the particles), and widens it.
If \(\epsilon_t\) is only a bit smaller than \(\epsilon_{t-1}\), we expect that the proposals from this distribution will match the target posterior with \(\epsilon_t\) reasonably well.
At round \(t\), our target is the ABC posterior with tolerance \(\epsilon_t\).
Our proposal distribution is \(\Theta \sim q_t\), \(X \mid \Theta \sim P_\Theta\). Write \(f_\theta(x)\) to denote the density of \(X \mid \Theta\). This is going to cancel out so we wonโt need to ever compute it.
Importance sampling:
We can compute \(\pi(\theta) / q_t(\theta)\)!
Same model as the rejection ABC picture:
\[ \Theta\sim\operatorname{Uniform}(-3,3), \qquad X\mid\Theta=\theta\sim N(\theta,0.35^2), \qquad x^{obs}=0.8, \]
with \(s(x)=x\) and \(d(a,b)=|a-b|\), so the ABC check is \(|X-0.8|<\epsilon\).
To make the proposal easy to see, in round 1 we will keep only three particles.
In practice we would keep many more particles in every round. Here three are enough to build a usable proposal.
R
Python
import numpy as np
rng = np.random.default_rng(686)
x_obs, N1 = 0.8, 3
def prior_d(theta):
inside = (theta >= -3) & (theta <= 3)
return np.where(inside, 1/6, 0.0)
theta1 = []
while len(theta1) < N1:
th = rng.uniform(-3, 3)
X = rng.normal(th, 0.35)
if abs(X - x_obs) < 0.5:
theta1.append(th)
theta1 = np.array(theta1)
w1 = np.full(N1, 1 / N1)Each particle gets weight 1/3. Three points are a crude approximation to the ABC posterior at \(\epsilon_1=0.5\), but they show where to look.
Select a parent with probability \(w_j=1/3\), add \(N(0,0.3^2)\) noise, and keep the proposal if its simulated \(X\) lands in the narrower band \(|X-0.8|<0.1\).
R
A proposal outside \([-3,3]\) has prior density 0 and would get weight 0, so we skip it without simulating.
Each attempt has three steps. Letโs watch three attempts.
Select a particle: each has probability 1/3. We get \(\theta_2=0.27\).
Perturb it: draw \(\Theta^*\) from \(N(0.27,0.3^2)\). We get \(\theta^*=0.36\).
Simulate \(X\sim N(0.36,0.35^2)\). We get \(X=0.73\), inside the band: keep \(\theta^*=0.36\).
Select a particle. This time we get \(\theta_3=1.22\).
Perturb it. We get \(\theta^*=0.65\), moved toward the center.
Simulate. We get \(X=0.81\): keep \(\theta^*=0.65\).
Select a particle. We get \(\theta_1=-0.46\).
Perturb it. We get \(\theta^*=-0.97\), further from the center.
Simulate. We get \(X=-1.23\), far outside the band: reject. From \(\theta^*=-0.97\), landing in the band was very unlikely.
Repeat until enough proposals are kept.
Every proposal is a perturbed copy of one of the three particles.
Left: orange points are exact draws from \((\Theta, X) \mid d(s(X), s(x^{obs})) < .1\).
Right: orange points need to be reweighted by \(\pi(\theta) / q_t(\theta)\) to represent \((\Theta, X) \mid d(s(X), s(x^{obs})) < .1\).
Left: Histogram of samples from \(\Theta \mid d(s(X), s(x^{obs})) < .1\) when \(\Theta \sim \pi\) (rejection ABC).
Middle: Histogram of unweighted samples from \(\Theta \mid d(s(X), s(x^{obs})) < .1\) when \(\Theta\) is drawn from the ABC-SMC proposal distribution.
Right: Histogram of weighted samples from \(\Theta \mid d(s(X), s(x^{obs})) < .1\) when \(\Theta\) is drawn from the ABC-SMC proposal distribution.