Interactive demo · Bayesian and Probabilistic Machine Learning · Chapter 11

From uniform numbers to any distribution

Every sampler starts from uniform random numbers. The transformation method pushes them through an inverse distribution function; rejection sampling throws points uniformly under an envelope kq(z) and keeps those under p̃(z); importance sampling keeps every draw from q but weights it by p̃/q. Watch the acceptance rates and the effective sample size: they tell you how much each method wastes.

Method

λ
a
b ×
D
σq/σp
mean q
sd q

Draw

Try these

Densities: the exponential λe−λy; the Cauchy (1/π)/(1+y2); the gamma Gam(z|a, 1) of (11.15) with the Cauchy envelope of (11.16) centred at c = a − 1 with scale b = √(2a − 1) (times the factor b×) and the smallest k; the two-bump p̃(z) = 0.55 e−(z+2)2/(2·0.752) + 0.45 e−(z−2)2/(2·0.952) of Figures 11.8 and 11.13, with f(z) = tanh(0.6(z+1)). One press of 1 is one proposal (or one uniform), so acceptance rates can be read off directly.

In the lecture notes