Importance Sampling over Discrete Structures
March 13th 2020
Importance sampling is a general inference method for estimating posterior expectations. While its validity in Rn is straightforward, when considering discrete structural choices that change the set and number of continuous parameters, we may wonder if importance weights still yield a valid estimate of the posterior given the varying dimensionality.
Define a probabilistic model under which a discrete structure k∼p(⋅) is chosen. Conditioned on this branch, a corresponding set of continuous parameters θ∼p(⋅∣k) of length Nk are sampled, so that θ∈Θk=RNk. Finally an observation is generated D∼p(⋅∣k,θ). The full joint distribution is
p(k,θ,D)=p(k)p(θ∣k)p(D∣k,θ)
Computing expectations of test functions here is generally intractable, as we must sum over all discrete choices and integrate over the corresponding continuous parameters. Even the normalizing constant, the marginal likelihood of the data, has this form:
p(D)=k∑p(k)∫Θkp(θ∣k)p(D∣k,θ) dθ
Note that each inner integral lives entirely within one branch, over a space of fixed dimension Nk. We give it a name, the branch marginal likelihood:
Zk=p(D∣k)=∫Θkp(θ∣k)p(D∣k,θ) dθ
so that p(D)=∑kp(k)Zk. The strategy is to show that importance sampling estimates each Zk in the ordinary fixed-dimensional way, and that the overall estimate is simply a weighted sum of these. At no point will we need to compare densities across spaces of different dimension.
Importance sampling introduces a proposal q, which we factor in the same way as the model, q(k,θ)=q(k)q(θ∣k), and takes a set of N latent variables {(ki,θi)}i=1N∼q(⋅,⋅), assigning corresponding importance weights
w(k,θ)=q(k)q(θ∣k)p(k)p(θ∣k)p(D∣k,θ)=q(k)p(k)⋅wk(θ),wk(θ)=q(θ∣k)p(θ∣k)p(D∣k,θ)
The weight factors into a ratio of probabilities over the discrete choice and a ratio of densities within a single branch, both taken over the same space. We require the usual support conditions: q(k)>0 whenever p(k)Zk>0, and within each such branch q(θ∣k)>0 whenever p(θ∣k)p(D∣k,θ)>0.
Theorem 1. The expected value of the importance weights under a chosen branch is the marginal likelihood of its continuous distribution.
Proof. Fix a branch k. Then
Eq(θ∣k)[wk(θ)]=∫Θkq(θ∣k)p(θ∣k)p(D∣k,θ)q(θ∣k) dθ=∫Θkp(θ∣k)p(D∣k,θ) dθ=Zk
where the support condition ensures that dividing by q(θ∣k) loses no mass. This is ordinary importance sampling in RNk.
□
Theorem 2. The expected value of the importance weights is a finite sum of continuous marginal likelihoods.
Proof. Conditioning on the sampled branch,
Eq[w(k,θ)]=k∑q(k) Eq(θ∣k)[q(k)p(k)wk(θ)]=k∑p(k) Eq(θ∣k)[wk(θ)]=k∑p(k)Zk=p(D)
using Theorem 1 in the third line. The sum is finite when there are finitely many structures. With countably many, it is a series of nonnegative terms, so exchanging the sum and expectation is still justified (Tonelli's theorem) and the series converges to p(D).
□
Theorem 2 says the estimator p^(D)=N1∑i=1Nw(ki,θi) is unbiased. Since the weights are i.i.d. with finite mean, the strong law of large numbers makes it consistent as well: p^(D)→p(D) almost surely. Sampling a branch and then its parameters is therefore equivalent, in expectation, to enumerating every branch and estimating each Zk separately.
To estimate posterior expectations, we use the weights to form the self-normalized importance sampling estimator of a test function f:
μ^f=∑i=1Nw(ki,θi)∑i=1Nw(ki,θi)f(ki,θi)
Theorem 3. The self-normalized importance sampling estimator is a consistent estimator of the expected value of the test function under the posterior, provided that expectation exists.
Proof. Divide the numerator and denominator by N. By the strong law of large numbers, the denominator converges almost surely to Eq[w(k,θ)]=p(D)>0 by Theorem 2, and the numerator converges almost surely to Eq[w(k,θ)f(k,θ)], which is finite when Ep(⋅,⋅∣D)[∣f∣]<∞. The ratio of two almost surely convergent sequences converges to the ratio of their limits, so it suffices to show
Eq[w(k,θ)f(k,θ)]=p(D)⋅E(k,θ)∼p(⋅,⋅∣D)[f(k,θ)]
Following the same steps as Theorem 2,
Eq[w(k,θ)f(k,θ)]=k∑∫Θkq(k)q(θ∣k)p(k)p(θ∣k)p(D∣k,θ)f(k,θ) q(k)q(θ∣k) dθ=k∑∫Θkp(k,θ,D)f(k,θ) dθ=p(D)k∑∫Θkp(k,θ∣D)f(k,θ) dθ=p(D)⋅E(k,θ)∼p(⋅,⋅∣D)[f(k,θ)]
Dividing by the limit of the denominator, μ^f→Ep(⋅,⋅∣D)[f(k,θ)] almost surely. Note that μ^f is biased for finite N; only its limit is exact.
□
The question we started with is now a special case. Choosing the indicator f(k,θ)=I[k=k∗] gives an estimate of the posterior probability of a single structure:
Corollary. The estimator
p^(k∗∣D)=∑i=1Nw(ki,θi)∑i:ki=k∗w(ki,θi)
converges almost surely to the posterior marginal over structures,
p(k∗∣D)=∑kp(k)Zkp(k∗)Zk∗
Proof. The indicator is bounded, so Theorem 3 applies. Its posterior expectation is ∑k∫Θkp(k,θ∣D)I[k=k∗] dθ=p(k∗∣D), and by Bayes' rule p(k∗∣D)=p(k∗)p(D∣k∗)/p(D)=p(k∗)Zk∗/∑kp(k)Zk.
□
For every N, these estimates are nonnegative and sum to exactly one across structures, so they always form a proper distribution over branches, and that distribution converges to the true posterior marginal.
We were able to avoid a measure-theoretic analysis by exploiting the factorization of the distribution. Because the importance weight splits into a ratio over the discrete choice and a ratio of densities within a single branch, every density ratio we ever form compares two densities over the same space Θk. Each branch is ordinary importance sampling in RNk, and the discrete choice only reweights branches against one another. Consistency is an asymptotic guarantee, though. When the proposal over branches or parameters is poorly matched to the posterior, the variance of the weights can make the number of samples needed impractically large.