Approximation of the normalization constant
Background
Let $\pi(x)$ denote a probability density called the target. In many problems, e.g. in Bayesian statistics, the density $\pi$ is typically known only up to a normalization constant,
\[\pi(x) = \frac{\gamma(x)}{Z},\]
where $\gamma$ can be evaluated pointwise, but $Z$ is unknown.
In many applications, it is useful to approximate the constant $Z$. For example, in Bayesian statistics, this corresponds to the marginal likelihood, and it is used for model selection.
Normalization constant approximation in Pigeons
As a side-product of parallel tempering, we automatically obtain an approximation of the logarithm of the normalization constant $\log Z$. This is done automatically using the stepping stone estimator computed in stepping_stone()
.
It is shown in the standard output report produced at each round:
using DynamicPPL
using Pigeons
# example target: Binomial likelihood with parameter p = p1 * p2
an_unidentifiable_model = Pigeons.toy_turing_unid_target(100, 50)
pt = pigeons(target = an_unidentifiable_model)
┌ Info: Neither traces, disk, nor online recorders included.
│ You may not have access to your samples (unless you are using a custom recorder, or maybe you just want log(Z)).
└ To add recorders, use e.g. pigeons(target = ..., record = [traces; record_default()])
──────────────────────────────────────────────────────────────────────────────────────────────────
scans Λ time(s) allc(B) log(Z₁/Z₀) min(α) mean(α) min(αₑ) mean(αₑ)
────────── ────────── ────────── ────────── ────────── ────────── ────────── ────────── ──────────
2 3.24 0.000999 1.07e+06 -8.14 0.00178 0.64 1 1
4 1.64 0.00198 2.1e+06 -5.04 0.0352 0.818 1 1
8 1.17 0.00371 4.1e+06 -4.42 0.708 0.871 1 1
16 1.2 0.00764 8.65e+06 -4.03 0.549 0.867 1 1
32 1.11 0.0151 1.69e+07 -4.77 0.754 0.877 1 1
64 1.35 0.0304 3.39e+07 -4.79 0.698 0.85 1 1
128 1.6 0.0965 6.72e+07 -4.97 0.725 0.823 1 1
256 1.51 0.157 1.33e+08 -4.92 0.758 0.832 1 1
512 1.48 0.27 2.69e+08 -4.94 0.806 0.836 1 1
1.02e+03 1.53 0.525 5.37e+08 -5.08 0.808 0.83 1 1
──────────────────────────────────────────────────────────────────────────────────────────────────
and can also be accessed using:
stepping_stone(pt)
-5.082685915340117
From ratios to normalization constants
To be more precise, the steppping stone estimator computes the log of the ratio, $\log (Z_1/ Z_0)$ where $Z_1$ and $Z_0$ are the normalization constants of the target and reference respectively.
Hence to estimate $\log Z_1$ the reference distribution $\pi_1$ should have a known normalization constant. In cases where the reference is a proper prior distribution, for example in Turing.jl models, this is typically the case.
In scenarios where the reference is specified manually, e.g. for black-box functions or Stan models, more care is needed. In such cases, one alternative is to use variational PT in which case the built-in variational distribution is constructed so that its normalization constant is one.