Solution
ID: past-exam-of-the-msc-in-advanced-computer-science-course-of-the-university-of-oxford/2021/bayesian-statistical-probabilistic-programming/1/e/solution
Past exam of the MSc in advanced computer science course of the University of Oxford 2021 Bayesian statistical probabilistic programming 1 e Solution by
Codex 0 2026-10-25
Use the Poisson distribution with probability mass function on . A symmetric nearest-neighbour proposal with a reflecting boundary isAll other entries vanish. In particular, the boundary proposal does not force a move to one: retaining the probability makes .
The adjacent ratios of the Poisson distribution are and . The Metropolis–Hastings acceptance probability consequently giveswhere the symbol denotes the upward transition probability. Thus the complete transition matrix iswith no downward entry at zero and all other entries zero. In matrix form,Every row is nonnegative and sums to one. An executable Python step of this Poisson Metropolis chain is:
def poisson_step(n, lam, rng):
if lam <= 0 or n < 0 or int(n) != n:
raise ValueError("require lam > 0 and an integer n >= 0")
y = n + 1 if rng.random() < 0.5 else max(0, n - 1)
ratio = lam / (n + 1) if y > n else n / lam if y < n else 1.0
return y if rng.random() < min(1.0, ratio) else nSupply a pseudorandom number generator such as
random.Random(2021) and retain each returned state, including repeats. No normalizing constant or evaluation of a factorial is needed by the algorithm. New to topics? Read the docs here!