Past exam of the mathematics course of the University of Cambridge 2019 iii Paper 219 2 c Solution 2026-10-03
For arbitrary nonnegative raw weights , let . The empirical squared coefficient of variation, using variance divisor , isSubstitution into the stated definition gives the usual effective sample size of importance samplingFor normalized weights , this reduces to .
Past exam of the mathematics course of the University of Cambridge 2026 iii Paper 219 2 c Solution Created 2026-09-24 Updated 2026-09-25
If equally informative independent draws have variance , an ordinary mean of draws has variance . The weighted mean has the corresponding variance . Equating them gives the effective sample size of importance samplingwhere the inequality follows from Cauchy-Schwarz inequality.
I would first collapse the duration noises as in part (c), then use self-normalized importance sampling on the two shared parameters. Draw independent , give each the importance weight , and returnThis is likelihood weighting: the observations affect the weights rather than forcing repeated simulation of twenty latent inequalities. Integrating out both the constraints' auxiliary randomness and the future Boolean query is Rao-Blackwellization; at fixed parameters it removes randomness without changing the relevant conditional expectations.
The weights and weighted queries lie in , and the evidence is positive. The strong law of large numbers therefore makes the numerator and denominator averages converge to their corresponding integrals, proving almost sure convergence of their ratio to part (d). The finite- ratio is generally biased; the assertion concerns consistency rather than a finite-sample unbiased estimator. Use logarithms of importance weights to avoid numerical underflow:
def weighted_answer(n, rng):
if n <= 0:
raise ValueError("n must be positive")
samples = []
for _ in range(n):
mu = rng.uniform(0.0, 60.0)
sigma = rng.uniform(1.0, 20.0)
samples.append((journey_loglik(mu, sigma),
math.exp(5.0 * normal_logcdf((mu - 30.0) / sigma))))
offset = max(logw for logw, h in samples)
if not math.isfinite(offset):
raise ArithmeticError("all weights underflowed")
scaled = [(math.exp(logw - offset), h) for logw, h in samples]
den = math.fsum(w for w, h in scaled)
answer = math.fsum(w * h for w, h in scaled) / den
ess = den * den / math.fsum(w * w for w, h in scaled)
return answer, essThe returned effective sample size of importance sampling is a concentration diagnostic, not a proof of accuracy. Repeat runs and inspect the weights. If the prior is much broader than the posterior, improve the proposal with the corresponding importance sampling density correction, or use the Metropolis–Hastings algorithm targeting . Because this particular collapsed problem is only two-dimensional, deterministic numerical integration is also an excellent independent accuracy check; it was used for the figure and numerical illustration. Straight rejection of the original traces is correct but wastes most proposals here.