Solution (source code)

= Solution

In <Bayesian inference>, a finite parameter space has posterior probabilities $\pi(\theta)=w(\theta)/Z$, with $w(\theta)$ the product of the prior probability and likelihood and $Z=\sum_\theta w(\theta)$ the evidence. Although each weight may be easy to evaluate, summing a large parameter space can be impractical. The <Metropolis–Hastings algorithm> constructs a <Markov chain> with posterior <stationary distribution>, allowing posterior expectations, probabilities and credible regions to be estimated from its trajectory. Its acceptance ratios cancel $Z$, so direct enumeration of the normalizing constant is unnecessary. Posterior sampling alone does not automatically provide the evidence for comparing models.