Adaptive rejection sampling Created 2026-10-05 Updated 2026-10-06
Adaptive rejection sampling builds a piecewise linear upper envelope for a differentiable log-concave probability density, samples from its piecewise exponential form, and accepts with the target-to-envelope ratio. Adding evaluated points improves the envelope without changing the target distribution. Initial tangent slopes must yield integrable tails. The accepted draws are exact samples, unlike a finite run of Markov chain Monte Carlo.
BUGS 2026-10-06
BUGS specifies a probabilistic model through stochastic nodes, deterministic nodes and observed data, then uses Markov chain Monte Carlo to simulate its Bayesian posterior. Its normal sampling notation uses a precision parameter rather than a variance, and its gamma notation uses shape and rate.
For a positive Harris recurrent Markov chain with invariant probability and , its time average converges almost surely to the invariant expectation:This is the consistency result for Markov chain Monte Carlo averages. Independent-observation variance formulas do not follow from this theorem.
Past exam of the mathematics course of the University of Cambridge 2013 iii Paper 29 3 Solution Created 2026-10-03 Updated 2026-10-07
For the Box-Muller transform, draw independent from the uniform distribution on and setThe radial density is for , with an independent uniform angle. The polar-to-Cartesian Jacobian determinant is , so the joint density of isThis factorization proves that both outputs have the standard normal distribution and are independent. Repeating the Box-Muller transform with fresh independent uniform pairs gives independent normal outputs; discard one extra output if the desired sample size is odd.
For the prescribed binary probabilities, generate independent standard normal values in this way and useThe standard normal distribution function gives , and independence is preserved because each threshold uses a different independent normal value.
For the probit regression posterior, introduce latent variablesGiven , these are independent variables, and normal symmetry gives . Thus this data augmentation has exactly the observed binary likelihood. With the specified normal prior distribution, the augmented joint posterior is proportional toThe latent-normal Gibbs sampler for probit regression alternates two blocks. First, given the current , draw each independently from its truncated normal distribution, namely restricted to the sign fixed by . One exact method is to use the Box-Muller transform for , form , and reject until the sign is correct. The probability of success is positive at every finite parameter value, so the method is valid, although it can be slow for a rare sign.
For direct sign-truncated normal sampling, let , and draw . An inverse transform sampling implementation isUse suitable tail or survival-function evaluations when floating-point probabilities approach zero or one; the rejection construction remains a valid alternative.
Second, completing the square in yields its full conditional distribution:Generate a fresh standard normal value by the Box-Muller transform, multiply by the conditional standard deviation, and add the conditional mean. Start from any finite , alternate these steps, discard an initial transient and use the retained values to approximate its posterior distribution. These are dependent Markov chain Monte Carlo samples, rather than independent posterior draws. Each block is an exact Gibbs sampling update for the augmented posterior, whose marginal in is the requested posterior.
Past exam of the mathematics course of the University of Cambridge 2013 iii Paper 34 1 h Solution Created 2026-10-03 Updated 2026-10-07
Fit two hierarchical Bayesian models to the same observations, one with the bounded uniform distribution sampling density and the other with an exponential distribution density. Specify rate versus mean in the exponential model and assign appropriate, scientifically comparable proper prior distributions; that parameter is no longer a literal maximum size. Obtain posterior distributions, for example by Markov chain Monte Carlo, and check convergence.
At the same observational level in both models use the Bayesian deviance , excluding prior densities. Retain the same likelihood constants and consistently either condition on breed effects or integrate them out. Estimate , evaluate at the posterior mean, and compute the effective parameter count in DIC:Smaller DIC favours the fit–complexity tradeoff. Supplement it with posterior predictive checks; the uniform model's parameter-dependent support and the hierarchical structure make the criterion a diagnostic rather than an automatic definitive decision.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 1 h Solution Created 2026-10-03 Updated 2026-10-06
A uniform prior on makes the posterior density proportional to the Poisson change-point posterior likelihood above. The zeros trick introduces an observed zero with Poisson distribution mean , making its likelihood function equal to . Choose ; since , this mean is strictly positive. Rough BUGS code, with For , omit the array and set
zero=0 supplied as data, ismodel {
theta ~ dunif(0,T)
for (i in 1:n) {
before[i] <- step(theta-time[i])
}
j <- sum(before[])
logL <- theta-2*T+(n-j)*log(2)
zero ~ dpois(K-logL)
}j <- 0. Monitor the sampled theta to obtain its posterior mean, credible interval and interval probabilities.There is also an exact sampling method. On the posterior density is proportional to , so choose the interval with weightsThen draw from a uniform distribution on and set . These weighted interval draws sample the posterior directly, without asking a local Markov chain Monte Carlo update to cross its discontinuities.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 2 d Solution Created 2026-10-03 Updated 2026-10-06
In Markov chain Monte Carlo, retain the derived quantity at every iteration. Rough BUGS code using the actual observations isSupply
model {
pM ~ dbeta(0.5,0.5)
pT ~ dbeta(0.5,0.5)
milkAnswers ~ dbin(pM,4)
teaAnswers ~ dbin(pT,4)
delta <- pM-pT
positive <- step(delta)
}milkAnswers=3 and teaAnswers=1. Summarize delta by its posterior mean, empirical quantiles and credible interval; the average of positive estimates . Here . Check Markov chain Monte Carlo convergence diagnostics before interpreting the simulation. Since both Bayesian posteriors are independent known Beta distributions, direct independent sampling is an equally valid, simpler way to obtain the same summaries. Past exam of the mathematics course of the University of Cambridge 2025 ii Paper 4 28L c Solution Created 2026-09-24 Updated 2026-09-25
Sincethe first full conditional isHolding fixed and comparing powers and exponential rates givesThe assumed parity of makes a positive integer.
Initialize arbitrarily. At iteration , putDraw independent uniform variables and setBy sampling an integer-shape gamma distribution, this has the required law. Next draw independently and setThese are exactly the two full-conditional updates of the normal mean-precision Gibbs sampler. After discarding burn-in, the pairs are approximate samples from the posterior by Markov chain Monte Carlo.