← All notes

Computing Log Density Ratios Given Unnormalized Score Functions

Let $p$ be a density of interest and let $p(x) = \tilde{p}(x)/Z$. Then $\log p(x) = \log \tilde{p}(x) - \log Z$.

Suppose we have access to $\nabla \log p(x) = \nabla \log \tilde{p}(x)$. We'd like to compute density ratios at a pair of points. By the fundamental theorem for line integrals, if we set a path $\gamma$ from $y$ to $z$ via $x(0)=y$ and $x(1)=z$, with $x(t)= (1-t)y + tz$, then

$$ \begin{aligned} \log \frac{p(z)}{p(y)} &= \log p(z) - \log p(y) \\ &= \log \tilde{p}(z) - \log Z - \log \tilde{p}(y) + \log Z \\ &= \log \tilde{p}(z) - \log \tilde{p}(y) \\ &= \int_\gamma \nabla \log \tilde{p}(x)^\top dx \\ &= \int_0^1 \nabla \log \tilde{p}(x(t))^\top \dot{x}(t)\, dt\\ &= \int_0^1 \nabla \log \tilde{p}(x(t))^\top (z-y)\, dt. \end{aligned} $$

Thus, we can compute log density ratios given only the score $\nabla \log \tilde{p}$, up to a numerical line integral.

Remarks