Skip to content
BIASED

Sampling unnormalized densities: MALA and HMC

Block 1 of 8~3 min

Densities known up to a constant

The topic The change of variables bought an exact likelihood with a strict architecture: every layer invertible, in the same dimension, with a cheap log-determinant. Now drop normalization altogether. Take any network U:RD→RU: \mathbb R^D \to \mathbb R and declare

p(x)=p~(x)Z,p~(x)=e−U(x),Z=∫e−U(x) dx.p(x) = \frac{\tilde p(x)}{Z}, \qquad \tilde p(x) = e^{-U(x)}, \qquad Z = \int e^{-U(x)}\, dx .

UU is the energy: low energy means high density. Any architecture will do, but ZZ is an integral over all of RD\mathbb R^D, and nobody can compute it. So p(x)p(x) itself cannot be evaluated. Two other quantities can:

p(y)p(x)=eU(x)−U(y),∇xlog⁡p(x)=−∇xU(x).\frac{p(y)}{p(x)} = e^{U(x) - U(y)}, \qquad \nabla_x \log p(x) = -\nabla_x U(x).

In the ratio ZZ cancels. The gradient in xx never sees it, because log⁡Z\log Z does not depend on xx. The gradient of the log-density is called the score, and it costs one backward pass through UU. How do we draw samples of pp with nothing but these two?

Half of the answer exists already. The course Bayesian Methods in Machine Learning builds Markov chains for exactly such targets, posteriors with an unknown evidence (see its topics Monte Carlo and Markov chains and Gibbs sampling and Metropolis–Hastings). Recall Metropolis–Hastings: from the state xx, propose y∼r(y∣x)y \sim r(y \mid x) and move there with probability

A(x,y)=min⁡(1, p~(y) r(x∣y)p~(x) r(y∣x)),A(x, y) = \min\left(1,\ \frac{\tilde p(y)\, r(x \mid y)}{\tilde p(x)\, r(y \mid x)}\right),

otherwise stay at xx. Only a ratio of p~\tilde p enters, and detailed balance makes pp the stationary distribution.

The usual proposal is a random walk, y=x+szy = x + s z with z∼N(0,I)z \sim \mathcal N(0, I). It knows nothing about the target. Its step ss must be about the width of the narrowest direction, or proposals land in low density and get rejected. Independent steps add in variance, so nn steps travel about sns\sqrt n, and crossing the widest direction takes about (σmax⁡/σmin⁡)2(\sigma_{\max}/\sigma_{\min})^2 steps. For a bivariate normal with unit variances and correlation ρ=0.95\rho = 0.95, the axes of the ellipse have variances 1+ρ=1.951 + \rho = 1.95 and 1−ρ=0.051 - \rho = 0.05, so σmax⁡≈1.40\sigma_{\max} \approx 1.40 and σmin⁡≈0.22\sigma_{\min} \approx 0.22: about 3939 steps for one crossing, even if every proposal were accepted.

Answers are saved on the server and tied to this browser until you sign in.