Approximate Bayesian Computation
When the likelihood has no formula you can evaluate, keep the simulated parameters whose fake data land close to the real data.
Why Does This Exist?
Many science simulators (epidemics, galaxy formation, agent economies) generate data freely but offer no evaluable likelihood: you can run the model forward, never score . Standard Bayes needs that score, so it stalls. Approximate Bayesian Computation replaces evaluation with comparison: simulate from a proposed , reduce both real and fake data to summaries, and keep when the distance falls under a tolerance .
The price is approximation in three places: the summaries discard information, admits near-misses, and tiny acceptance rates demand many simulations. This page gives the rejection loop, the tolerance trade-off with numbers, and the two standard upgrades. Likelihood-based posterior sampling is under Bayesian inference; plain Monte Carlo covers sample averages without any likelihood.
The one idea you need first
A summary statistic compresses data to a few numbers (mean, variance, a count). ABC compares summaries, not raw datasets, because raw high-dimensional distances are always large. Good summaries are near-sufficient: they keep almost everything the data says about .
Think of It Like This
Finding a jam recipe by taste tests
You lost the recipe card but remember the jam's taste. You cannot analyze its chemistry (no likelihood), but you can cook trial batches. Each attempt varies sugar and pectin, a friend tastes blind, and you keep the recipes rated within a point of your memory, discarding the rest.
The friend's score is the distance between summaries; your tolerance is how close counts as a match. Demand an exact match and you cook forever. Accept anything and the kept pile includes chutney. The kept recipes cluster around the lost original exactly when the tasting notes capture what matters (sweetness, set) and the tolerance is tight but reachable.
How It Actually Works
The rejection loop:
- Draw from the prior.
- Simulate fake data from the model at .
- Compute summaries and distance .
- Keep when .
Kept draws approximate the posterior conditioned on . As with sufficient summaries, this tends to the true posterior; as , it degrades to the prior.
Worked example
Infer a coin bias with prior uniform on , observing heads in flips. Summary: head count. Tolerance keeps simulations with to heads. Draw : , usually kept. Draw : that probability is about , almost never kept. Over draws, roughly survive, and their mean sits near with standard deviation about : close to the exact posterior mean (Beta(8,4)) while slightly wider from the slack. Tighten to (exactly ): about survive with mean , tighter but three times the simulation cost.
Upgrades
ABC-MCMC proposes local moves instead of fresh prior draws, raising acceptance. ABC-SMC runs a chain of shrinking tolerances, resampling survivors as the next round's proposals. Both keep the same accept rule; they just waste fewer simulations reaching it.
Code
import random
def simulate(theta: float, n: int = 10) -> int: return sum(1 for _ in range(n) if random.random() < theta) # head count
def abc_reject(obs: int, eps: int, draws: int) -> list[float]: kept = [] for _ in range(draws): theta = random.random() # uniform prior on [0, 1] if abs(simulate(theta) - obs) <= eps: kept.append(theta) return kept
random.seed(7)kept = abc_reject(7, 1, 10000)print(len(kept), round(sum(kept) / len(kept), 2)) # -> about 1200 kept, mean about 0.65About twelve percent survive at with mean near the exact ; exact matching keeps roughly four percent.
Watch Out For
Summaries that silently drop the signal
ABC conditions on summaries, so a summary blind to some parameter returns the prior for it no matter how many simulations run. Symptoms: one marginal never moves from the prior while others sharpen. Test summaries on fake data with known first: if the distance cannot tell from on simulations, it cannot do it on real data either.
Setting tolerance by impatience
Pushing up to raise acceptance trades compute for bias directly: at on the coin example the kept mean drifts toward (the prior mean) and the interval covers the truth by luck, not information. Fix a simulation budget first, then pick the smallest that yields a few hundred survivors, never the reverse.
The Quick Version
- ABC keeps prior draws whose simulated summaries land within of observed summaries.
- It needs only a simulator, never a likelihood formula.
- Three approximations stack: summary choice, tolerance slack, and Monte Carlo error.
- On heads with , about of draws survive with mean near against truth .
- ABC-MCMC and ABC-SMC cut simulation waste with local moves and shrinking tolerances.
- Validate summaries on fake data with known parameters before trusting real-data results.