Unbiased estimation of log normalizing constants with applications to Bayesian cross-validation

Maxime Rischard, Pierre E. Jacob, Natesh Pillai

Setting

In this article we propose a new estimator of ZZ, which combines unbiased Markov chain Monte Carlo (Jacob et al., 2017) with the path sampling identity (Gelman and Meng, 1998; see also Chapter 5 of Chen et al., 2000), also known as thermodynamic integration (Kirkwood, 1935; Neal, 2005; Calderhead and Girolami, 2009). The specificity of the proposed estimator is its unbiasedness for the logarithm of ZZ, i.e. the expectation of the proposed estimator is exactly log⁡Z\log Z. Existing estimators based on Markov chain Monte Carlo (Chen et al., 1997) are only asymptotically unbiased, while existing estimators based on annealed importance samplers (Neal, 2001) and sequential Monte Carlo samplers (Del Moral et al., 2006) are unbiased for ZZ and not for log⁡Z\log Z.

Leveraging unbiasedness for log⁡Z\log Z, we consider a Bayesian cross-validation (CV) criterion based on the logarithmic scoring rule (Alqallaf and Gustafson, 2001; Bornn et al., 2010; Vehtari et al., 2017, e.g). In cross-validation, one randomly splits the available data into training and validation, then the posterior distribution given the training data is numerically approximated, and finally the predictive performance on the validation data is assessed e.g. with the logarithmic scoring rule (Parry et al., 2012). We propose an estimator that is directly unbiased for these Bayesian cross-validation objectives, which can be averaged over independent copies to obtain consistent estimators and asymptotically exact confidence intervals from the central limit theorem for i. i. d. variables.

The rest of the document is structured as follows. Section 2 introduces the proposed estimators, and their tuning parameters are discussed. Numerical experiments in simple examples can be found in Section 3. Section 4 discusses our findings and future directions. The code to reproduce the experiments of the article is available at https://github.com/pierrejacob/unbiasedpathsampling.

Proposed estimators

We propose an unbiased estimator of log⁡Z\log Z in Section 2.1, and obtain an unbiased estimator of a Bayesian cross-validation criterion in Section 2.2. Our implementation relies on the unbiased MCMC estimators of Jacob et al., 2017, which are briefly reviewed in Section 2.3, while Section 2.4 discusses tuning choices.

The thermodynamic integration or path sampling identity relies on the following interchange between differentiation and integration (Kirkwood, 1935),

By introducing an arbitrary density λ↦q(λ)\lambda\mapsto q(\lambda), strictly positive on (0,1)(0,1), we obtain the path sampling identity:

This is useful if we can approximate integrals with respect to λ\lambda by Monte Carlo or numerical integration, and if we can approximate the inside expectation \Eλ[∇λUλ(X)]\E_{\lambda}[\nabla_{\lambda}U_{\lambda}(X)] by Markov chain Monte Carlo (MCMC, Robert and Casella, 2004), for instance.

Here we denote by E(λ)=−\Eλ[∇λUλ(X)]E(\lambda)=-\E_{\lambda}[\nabla_{\lambda}U_{\lambda}(X)] the inner expectation in (3), and we introduce E^(λ)\hat{E}(\lambda), an unbiased estimator of E(λ)E(\lambda) that we can generate for any λ∈\lambda\in; we defer the construction of such estimators to Section 2.3. We can then define an estimator of r01=log⁡(Z1/Z0)r_{01}=\log(Z_{1}/Z_{0}) with the following procedure.

Draw λ∼q(dλ)\lambda\sim q(\mathop{d\lambda}), a distribution supported on $$.

Given λ\lambda, generate a variable E^(λ)\hat{E}(\lambda) with expectation E(λ)=−\Eλ[∇λUλ(X)]E(\lambda)=-\E_{\lambda}[\nabla_{\lambda}U_{\lambda}(X)].

Return r^01=E^(λ)/q(λ)\hat{r}_{01}=\hat{E}(\lambda)/q(\lambda).

The random variable r^01\hat{r}_{01} has expectation r01r_{01} by the law of iterated expectations, and we refer to it as an unbiased path sampling estimator (UPS). Note that sequential Monte Carlo samplers and related methods (Del Moral et al., 2006) would provide unbiased estimators of ZZ and not of log⁡Z\log Z. Thus these estimators will not be unbiased for r01r_{01}. We will now see that the lack of bias on the logarithmic scale can be exploited to propose new estimators of Bayesian cross-validation criteria.

2 Unbiased Bayesian cross-validation

A number of articles discuss the computational difficulties associated with Bayesian cross-validation, e.g. Alqallaf and Gustafson, 2001; Bhattacharya and Haslett, 2007; Bornn et al., 2010; Lamnisos et al., 2012; McVinish et al., 2013; Vehtari et al., 2017. We first define the object of interest, before presenting our estimator. Let xx denote an unknown parameter with prior density \prob(x)\prob(x), and let y1:n={y1,…,yn}y_{1:n}=\{y_{1},\dotsc,y_{n}\} denote the data composed of nn units. The likelihood function is denoted by x↦\prob(y1:n∣x)x\mapsto\prob(y_{1:n}\mid x). Cross-validation consists in randomly splitting y1:ny_{1:n} into TT and VV, where TT stands for training and VV for validation. The sets T,VT,V form a partition of y1:ny_{1:n}, T∩V=∅T\cap V=\emptyset and T∪V=y1:nT\cup V=y_{1:n}. Denote by nTn_{T} and nVn_{V} the numbers of elements in TT and VV; for instance, if nT=n−1n_{T}=n-1, the procedure is termed “leave-one-out” cross-validation. Given a split of the data y1:n=(T,V)y_{1:n}=(T,V), we introduce a measure of accuracy in predicting VV using the training data TT. A typical choice is the logarithmic score −log⁡\prob(V∣T)-\log\prob(V\mid T) (see Parry et al., 2012, for a discussion on the choice of scoring rule) where \prob(V∣T)=∫\prob(V∣T,x)\prob(x∣T)dx\prob(V\mid T)=\int\prob(V\mid T,x)\prob(x\mid T)\mathop{dx} is the posterior predictive density given TT and evaluated on VV. Note that \prob(V∣T,x)\prob(V\mid T,x) simplifies to \prob(V∣x)\prob(V\mid x) if the data are modeled as conditionally independent given xx. The cross-validation objective, “CV” below, is defined as an average over all splits (T,V)(T,V) of size (nT,nV)(n_{T},n_{V}),

Given a split T,VT,V, we can estimate log⁡\prob(V∣T)\log\prob(V\mid T) using the path sampling identity and the unbiased estimators of the previous section. Indeed, that quantity is a log-ratio of the normalizing constants \prob(T)\prob(T) and \prob(T,V)\prob(T,V). By introducing the path

This motivates the following strategy: sample a split T,VT,V uniformly from S\mathcal{S}, and then obtain an unbiased estimator of −log⁡\prob(V∣T)-\log\prob(V\mid T) given T,VT,V. The resulting estimator is directly unbiased for CV in (4), by the law of iterated expectations. We summarize the procedure below.

Sample index sets T,VT,V uniformly at random over S\mathcal{S}, the set of partitions of {1,…,n}\{1,\dotsc,n\} into a set of size nTn_{T} and a set of size nV=n−nTn_{V}=n-n_{T}.

Note how the lack of bias on the logarithmic scale is important for the above procedure to produce an unbiased estimator of CV. We could also extend the above procedure to allow for non-uniform sampling of the partitions from S\mathcal{S}.

3 Reminders on unbiased MCMC

4 Tuning choices

A number of choices have to be made for the proposed estimators to be operational. The first choice is that of a path of distributions. There are generic choices such as the geometric path, and choices motivated by algorithmic considerations on a case-by-case basis. We will discuss the choice of paths through examples, in Section 3.

Given a path of distributions (πλ)(\pi_{\lambda}), algorithms approximating expectations \Eλ\E_{\lambda} with respect to πλ\pi_{\lambda} typically involve tuning parameters. We describe the tuning of unbiased MCMC in Section 2.4.1. Then we discuss choices of distribution q(dλ)q(\mathop{d\lambda}) in Section 2.4.2.

The unbiased MCMC estimators described in Section Section 2.3 require the specification of a Markov kernel PP, a coupled kernel Pˉ\bar{P}, and an initial distribution for the chains. Specifying these objects is typically difficult, but not specific to the setting of normalizing constant estimation. Therefore we defer to the large literature on MCMC algorithms (Robert and Casella, 2004; Brooks et al., 2011), as well as the relevant discussions in Jacob et al., 2017 in the context of unbiased MCMC. Ultimately we will care about the expected cost and the variance of the proposed unbiased estimators, in order to maximize the efficiency of the proposed estimators, as discussed in the next section.

4.2 Tuning of the distribution q⁡(d​λ)q(\mathop{d\lambda})

If CλC_{\lambda} is constant over λ\lambda, then the solution of the above minimization problem is given by λ↦q⋆(λ)∝m2(λ)\lambda\mapsto q^{\star}(\lambda)\propto\sqrt{m_{2}(\lambda)}. In Gelman and Meng, 1998 that solution is given, and then the verification that this is indeed a solution is done via Cauchy-Schwarz. Here we provide an informal derivation of the solution, in the case where CλC_{\lambda} is constant over λ\lambda. We write the function to minimize as ∫m2(λ)/q(λ)dλ\int m_{2}(\lambda)/q(\lambda)\mathop{d\lambda}, and introduce the Lagrangian

We would like to differentiate with respect to qq and set the derivative to zero. Introduce the directional derivative ddε(q(λ)+εv(λ))\frac{\mathop{d}}{\mathop{d\varepsilon}}(q(\lambda)+\varepsilon v(\lambda)) where v(λ)v(\lambda) is a function. Replacing q(λ)q(\lambda) by q(λ)+εv(λ)q(\lambda)+\varepsilon v(\lambda) and differentiating with respect to ε\varepsilon in the Lagrangian yields

Setting ε\varepsilon to zero yields ∫{−m2(λ)/q(λ)2+ξ}v(λ)dλ\int\{-m_{2}(\lambda)/q(\lambda)^{2}+\xi\}v(\lambda)\mathop{d\lambda}, and trying to set that expression to zero simultaneously for every choice of vv, we obtain −m2(λ)/(q(λ)2)+ξ=0-m_{2}(\lambda)/(q(\lambda)^{2})+\xi=0, i.e. q(λ)∝m2(λ)q(\lambda)\propto\sqrt{m_{2}(\lambda)}. This gives the candidate solution.

4.3 Proposed tuning procedure

We now combine the above sections into practical guidelines for the proposed estimators.

For λ\lambda in a grid of L+1L+1 values 0=λ≤…≤λ[L]=10=\lambda^{}\leq\ldots\leq\lambda^{[L]}=1, construct and tune an unbiased MCMC (initial distribution, Markov kernel PP, and coupled kernel Pˉ\bar{P}) targeting πλ\pi_{\lambda}, and draw independent samples of the associated meeting times τλ\tau_{\lambda}.

Use these estimates to define a distribution q(dλ)q(\mathop{d\lambda}), such that q(λ)q(\lambda) is approximately proportional to m2(λ)\sqrt{m_{2}(\lambda)} for all λ\lambda in $$.

We describe a concrete way of performing step 5, for completeness. Given a grid of values 0=λ≤…≤λ[L]=10=\lambda^{}\leq\ldots\leq\lambda^{[L]}=1 and associated estimates (m^2(λ[l]))1/2(\hat{m}_{2}(\lambda^{[l]}))^{1/2} of (m2(λ[l]))1/2(m_{2}(\lambda^{[l]}))^{1/2} for l∈{0,…,L}l\in\{0,\dotsc,L\} obtained in step 4, we can define a distribution q(dλ)q(\mathop{d\lambda}) that is piecewise uniform on the intervals [λ[l],λ[l+1]][\lambda^{[l]},\lambda^{[l+1]}], and such that

Sampling from such a distribution can be done in order O(log⁡L)\mathcal{O}(\log L) operations, by first selecting an interval [λ[l],λ[l+1]][\lambda^{[l]},\lambda^{[l+1]}] with probability ∫λ[l]λ[l+1]q(dλ)\int_{\lambda^{[l]}}^{\lambda^{[l+1]}}q(\mathop{d\lambda}), and then sampling uniformly from that interval.

After the preliminary phase described in the five steps above, the generation of estimators r^01\hat{r}_{01} can proceed as follows. First, λ\lambda is drawn from q(dλ)q(\mathop{d\lambda}) obtained in step 5 above. We then find the nearest value λ[l]\lambda^{[l]} in the grid, with index l∈{0,…,L}l\in\{0,\dotsc,L\}. We can look up tuning parameters corresponding to λ[l]\lambda^{[l]} for the unbiased MCMC estimators, stored during step 2 above, and the values of kλ[l]k_{\lambda^{[l]}} and mλ[l]m_{\lambda^{[l]}} stored during step 3 above. Using these tuning values we can generate an unbiased estimator E^(λ)\hat{E}(\lambda) of E(λ)=−\Eλ[∇λUλ(X)]E(\lambda)=-\E_{\lambda}[\nabla_{\lambda}U_{\lambda}(X)]. The estimator r^01=E^(λ)/q(λ)\hat{r}_{01}=\hat{E}(\lambda)/q(\lambda) is finally returned.

Numerical experiments

The numerical experiments are structured as follows. Section 3.1 contains toy examples of unbiased path sampling estimators. Section 3.2 considers logistic regressions with different choices of paths and of unbiased MCMC estimators, and an example taken from Epifani et al., 2008; Vehtari et al., 2017. Section 3.3 considers linear regressions with examples taken from Alqallaf and Gustafson, 2001; Peruggia, 1997; Vehtari et al., 2017. Throughout the experiments, 95% confidence intervals for an estimand μ\mu are obtained as μˉ±1.96s/M\bar{\mu}\pm 1.96s/\sqrt{M}, where μˉ\bar{\mu} is the mean of MM independent unbiased estimators of μ\mu and ss is their sample standard deviation. These confidence intervals are justified asymptotically as M→∞M\to\infty by the central limit theorem for i. i. d. random variables, provided that the variance of the unbiased estimators is finite. On parallel machines and under budget constraints, valid confidence intervals can be constructed following Glynn and Heidelberger, 1991; see also related remarks in Jacob et al., 2017.

We start with a grid of values of λ\lambda: λ[l]=l/L\lambda^{[l]}=l/L for l∈{0,…,L}l\in\{0,\dotsc,L\}, with L=10L=10. For each λ[l]\lambda^{[l]}, we run coupled MH chains until they meet, 100 times independently. We obtain a distribution of meeting times τ\tau for each λ\lambda, represented on 1(a). The overlaid full line represents the 99%99\% quantiles, which we denote by k0,…,kLk_{0},\dotsc,k_{L}. We also compute the average meeting times for each λ[l]\lambda^{[l]}, which we denote τˉ0,…,τˉL\bar{\tau}_{0},\dotsc,\bar{\tau}_{L}. We then define

Given values of klk_{l} and mlm_{l}, for each λ[l]\lambda^{[l]} in the grid of L+1L+1 values defined above, we approximate the first and second moments of πλ\pi_{\lambda} with 100100 independent estimators. We use these moments to redefine the initial distribution of the Markov chains, which we set to a Normal distribution adapted to πλ\pi_{\lambda}, and to tune the proposal standard deviation, which we set to be the estimated standard deviation of πλ\pi_{\lambda}. At this point we could sample meeting times again and choose new values for kλk_{\lambda} and mλm_{\lambda}, but we omit this here. Next, we estimate m2(λ)\sqrt{m_{2}(\lambda)} for each λ[l]\lambda^{[l]} in the grid, and define q(dλ)q(\mathop{d\lambda}) accordingly, following step 5 in Section 2.4. The estimates of m2(λ)\sqrt{m_{2}(\lambda)} are shown in 1(b). This completes the tuning phase, and we can now generate unbiased estimators r^01=E^(λ)/q(λ)\hat{r}_{01}=\hat{E}(\lambda)/q(\lambda) of r01=log⁡(Z1/Z0)r_{01}=\log(Z_{1}/Z_{0}). We show these estimates against λ\lambda in 1(c). These are generated 5,0005,000 times independently. Concretely, they yield the confidence interval [−0.11,0.12][-0.11,0.12] for the estimand r01=0r_{01}=0 at level 95%95\%.

1.2 Double-well example

We perform similar experiments on a path of two-dimensional distributions linking the potential U0:x↦(x1+2)2+(x22/2)U_{0}:x\mapsto(x_{1}+2)^{2}+(x_{2}^{2}/2), corresponding to a Normal distribution centered at (−2,0)(-2,0) and with diagonal variances (1/2,1)(1/2,1), to the potential U1:x↦(1/10)(((x1−1)2−x22)2+10(x12−5)2+(x1+x2)4+(x1−x2)4)U_{1}:x\mapsto(1/10)(((x_{1}-1)^{2}-x_{2}^{2})^{2}+10(x_{1}^{2}-5)^{2}+(x_{1}+x_{2})^{4}+(x_{1}-x_{2})^{4}). The latter is a double-well potential, with modes around (−2,0)(-2,0) and (2,0)(2,0). By numerical integration we find log⁡(Z1/Z0)\log(Z_{1}/Z_{0}) to be approximately −6.9-6.9. We introduce the geometric path Uλ(x)=(1−λ)U0(x)+λU1(x)U_{\lambda}(x)=(1-\lambda)U_{0}(x)+\lambda U_{1}(x). For each λ\lambda, we start chains from a Normal centered at (−2,−2)(-2,-2) and with covariance matrix I2\mathbf{I}_{2}, the identity matrix of size 2×22\times 2. We consider random walk MH schemes with Normal proposal, with covariance 2I22\mathbf{I}_{2}; the coupled version relies on maximal couplings of the proposals, as in the previous section.

We draw 1,0001,000 meeting times independently, for λ[l]=l/L\lambda^{[l]}=l/L with l∈{0,…,L}l\in\{0,\dotsc,L\} and L=10L=10. The distributions are shown in violin plots in 2(a). We observe much larger meeting times for λ\lambda close to one, which corresponds to the MH chains struggling to explore both modes of the double-well potential. We thus conservatively set klk_{l} to be twice the 99%99\% quantiles of the meeting times, instead of the quantiles themselves.

We follow the same heuristics as in Section 3.1.1 for the choice of mlm_{l}. Without modifying the initial distribution nor the proposal distribution of the MH chains, we estimate m2(λ)\sqrt{m_{2}(\lambda)} for each λ[l]\lambda^{[l]} in the grid, based on 100 independent copies, and define q(dλ)q(\mathop{d\lambda}) following again step 5 in Section 2.4. The estimates of m2(λ)\sqrt{m_{2}(\lambda)} are shown in 2(b). Finally we generate unbiased estimators r^01=E^(λ)/q(λ)\hat{r}_{01}=\hat{E}(\lambda)/q(\lambda) of r01=log⁡(Z1/Z0)r_{01}=\log(Z_{1}/Z_{0}), and represent these estimates against λ\lambda in 2(c). These are generated 1,0001,000 times independently and result in the 95%95\% confidence interval [−7.55,−6.37][-7.55,-6.37] for the estimand r01≈−6.9r_{01}\approx-6.9.

2 Logistic regression

With basic manipulations this is equivalent to the following simpler form

The Pólya-Gamma Gibbs (PGG) sampler (Polson et al., 2013; Choi and Hobert, 2013) is a Gibbs sampler that targets \prob(β∣Y)\prob(\beta\mid Y) through the introduction of auxiliary variables WW. First, we recall that the Pólya-Gamma distribution with parameters (1,c)(1,c), denoted by PG(1,c)\text{PG}(1,c), has a density x↦\pg(x;c)x\mapsto\pg(x;c) defined for all c≥0c\geq 0, x>0x>0 as

Introduce nn auxiliary variables W=(W1,…,Wn)W=(W_{1},\dotsc,W_{n}), independent of each other given β\beta, such that WiW_{i} follows PG(1,∣di⊺β∣)(1,\left\lvert d_{i}^{\intercal}\beta\right\rvert) for all 1≤i≤n1\leq i\leq n. An extended target distribution is defined as \prob(β,ω∣Y)∝\prob(β∣Y)g(ω∣β)\prob(\beta,\omega\mid Y)\propto\prob(\beta\mid Y)g(\omega\mid\beta), where ω\omega denotes a realization of WW, and g(ω∣β)=∏i=1n\pg(ωi;∣di⊺β∣)g(\omega\mid\beta)=\prod_{i=1}^{n}\pg(\omega_{i};\left\lvert d_{i}^{\intercal}\beta\right\rvert). The appeal of this extension is that we can write the target as

and therefore the conditional of β\beta given ω,Y\omega,Y simplifies to

given (β(t),W(t))(\beta^{(t)},W^{(t)}), draw β(t+1)∼\normal(μ(W(t)),Σ(W(t)))\beta^{(t+1)}\sim\normal\left(\mu(W^{(t)}),\Sigma(W^{(t)})\right),

draw Wi(t+1)∼PG(1,∣di⊺β(t+1)∣)W_{i}^{(t+1)}\sim\text{PG}(1,\left\lvert d_{i}^{\intercal}\beta^{(t+1)}\right\rvert), independently for all i∈{1,…,n}i\in\left\{1,\dotsc,n\right\}.

In the experiments below, we initialize the chains from the prior distribution N(b,B)\mathcal{N}(b,B).

We first remark that the above reasoning holds when replacing the covariates DD by λD\lambda D for any λ∈\lambda\in. This corresponds to the likelihood β↦∏i=1nexp⁡(λdi⊺βyi)/(1+exp⁡(λdi⊺β))\beta\mapsto\prod_{i=1}^{n}\exp(\lambda d_{i}^{\intercal}\beta y_{i})/(1+\exp(\lambda d_{i}^{\intercal}\beta)), for λ∈\lambda\in. In the case λ=0\lambda=0, the likelihood is equal to 2−n2^{-n} for all β\beta, while with λ=1\lambda=1, we retrieve the original likelihood. For all λ\lambda, we can introduce Pólya-Gamma variables WiW_{i} following PG(1,∣λdi⊺β∣)(1,\left\lvert\lambda d_{i}^{\intercal}\beta\right\rvert) for all 1≤i≤n1\leq i\leq n, and obtain a corresponding PGG sampler.

This enables normalizing constant estimators for the logistic regression model with little tuning, since the PGG sampler itself has no tuning parameters. Here, for all λ,β\lambda,\beta, we define

We consider a synthetic data set with n=1000n=1000 rows and p=7p=7 columns. The covariates are generated from a standard Normal distribution and the outcome is generated from the model with β⋆=(0,0.1,0.2,0.3,0.4,0.5,0.6)\beta^{\star}=(0,0.1,0.2,0.3,0.4,0.5,0.6). The prior mean bb is set to zero and the covariance BB to a diagonal matrix with entries equal to 1010. We start by gridding the interval $,andforeachvalue, and for each value\lambda^{[l]}=l/LwithwithL=10,weset, we setkastheas the99\%quantileofthemeetingtimesforthecoupledPGGsampler,basedon1000independentruns.Wesetquantile of the meeting times for the coupled PGG sampler, based on 1000 independent runs. We setmasintheprevioussections,tomaketheaveragecostapproximatelyconstantoveras in the previous sections, to make the average cost approximately constant over\lambda.Nextweestimatethesecondmomentsof. Next we estimate the second moments of\hat{E}(\lambda)onthegridofvaluesofon the grid of values of\lambda,wedesignaproposal, we design a proposalq(\mathop{d\lambda})$ following step 5 in Section 2.4, and obtain the estimates of 3(a).

We obtain the 1,0001,000 independent estimators E^(λ)/q(λ)\hat{E}(\lambda)/q(\lambda) shown in 3(b), leading to a 95%95\% confidence interval of $ononr_{01}=\log(Z_{1}/Z_{0}).Theactualvalueisfoundtobecloseto. The actual value is found to be close to70usingimportancesamplingbasedonaLaplaceapproximationtotheposterior,accurateinthepresentexample(seebelow,andalsorelateddiscussionsinBardenetetal.,2017).Wecanseefrom3(b)thattheestimatestakeverylargevaluesforusing importance sampling based on a Laplace approximation to the posterior, accurate in the present example (see below, and also related discussions in Bardenet et al., 2017). We can see from 3(b) that the estimates take very large values for\lambdaclosetozero.Thissuggeststhat,insteadofchoosinganequispacedgridofvaluesofclose to zero. This suggests that, instead of choosing an equispaced grid of values of\lambdaononwhendesigningwhen designingq(\mathop{d\lambda}),wecouldaimatahigherresolutiontowardstheleftendoftheinterval, we could aim at a higher resolution towards the left end of the interval$.

Therefore we consider a grid of values of λ\lambda equispaced on the logarithmic scale: λ[l]=exp⁡(−L+l)\lambda^{[l]}=\exp(-L+l) for l=0,…,Ll=0,\dotsc,L with L=10L=10. Going through the exact same tuning steps, we obtain the 1,0001,000 estimators of 3(c), leading to the narrower confidence interval [64.7,74.7][64.7,74.7] at level 95%95\% (with a width of 10 instead of 36 for the previous one). This illustrates the potential gains obtained by carefully choosing the distribution q(dλ)q(\mathop{d\lambda}).

We conclude this section by noting that more dramatic gains can be obtained by changing the path of distributions. In the context of logistic regression with n≫pn\gg p, the Laplace approximation of the posterior, defined as \normal(β^MLE,V^)\normal(\hat{\beta}_{\text{MLE}},\hat{V}) where β^MLE\hat{\beta}_{\text{MLE}} is the maximum likelihood estimator and V^\hat{V} is the inverse of minus the Hessian of the log-likelihood evaluated at β^MLE\hat{\beta}_{\text{MLE}}, seems to be very accurate. We thus introduce a geometric path (πλ)(\pi_{\lambda}) between the Laplace approximation and the posterior distribution. We use a random walk MH algorithm to target πλ\pi_{\lambda} for all λ∈\lambda\in, with proposal covariance matrix equal to V^/p\hat{V}/p where the dimension pp is equal to 77. To couple the MH algorithms, we use strategy that combines reflection and maximal couplings, as described in Jacob et al., 2017. The initial distribution of the chains is chosen to be the Laplace approximation. For λ=0\lambda=0, we obtain k=127k=127 as the 99%99\% quantile of the meeting times, and we set m=5km=5k. We use these values of kk and mm for all λ\lambda, and we choose q(dλ)q(\mathop{d\lambda}) to be uniform on $.With. With100independentestimatorsweobtainaconfidenceintervalofindependent estimators we obtain a confidence interval of[70.24,70.26]atat95\%forfor\log Z_{1}+n\log 2$. This is orders of magnitude narrower than the previous intervals, for a smaller computational cost. The choice of paths can thus play a critical role in the efficiency of the proposed estimators, and approximations of the posterior distribution can be used to construct such paths.

2.2 Cross-validation

We now consider the approximation of CV in (4). We consider a leave-one-out criterion, with nT=n−1n_{T}=n-1 and nV=1n_{V}=1. We thus construct paths between the posterior given the training data TT, with normalizing constant \prob(T)\prob(T), and the posterior given all the data (T,V)(T,V), with normalizing constant \prob(T,V)\prob(T,V).

Our first path follows the reasoning of the previous section: we can multiply the covariates in the validation set by λ∈\lambda\in to preserve the original structure of the likelihood and thus to enable a similar PGG sampler. The unnormalized densities are then

Again we see that this is essentially a linear function of β\beta and thus its moments under πλ\pi_{\lambda} are finite for all λ\lambda.

To tune the procedure, we obtain meeting times for the coupled PGG sampler based on the full data set, and choose kk as a 99%99\% quantile (here equal to 88), and m=5k=40m=5k=40. Recall that the PGG sampler itself has no tuning parameters. Then, drawing a validation set at random 1,0001,000 time independently, generating λ\lambda uniformly on $andobtainingtheassociatedestimatorand obtaining the associated estimator\hat{E}(\lambda),weobtainunbiasedestimatorsofCVin(4).Weplotahistogramoftheseestimatorsin4(a).A, we obtain unbiased estimators of CV in (4). We plot a histogram of these estimators in 4(a). A95\%confidenceintervalfortheCVobjectiveisobtainedasconfidence interval for the CV objective is obtained as[-0.62,-0.56]$.

Alternatively, we introduce a geometric path between the posterior given TT and given T,VT,V, which corresponds to the unnormalized densities

For this path, we use random walk MH as in the previous section, with initial distribution and proposal covariance tuned using a Laplace approximation of the posterior distribution. We obtain a 99%99\% quantile of meetings at k=135k=135 and set m=5km=5k. Over 1,0001,000 independent experiments we obtain unbiased estimators of the CV objective shown in 4(b). The associated 95%95\% confidence interval for CV is [−0.60,−0.56][-0.60,-0.56]. Thus, this second approach appears to be marginally more efficient than the first one; the cost comparison is made slightly difficult by the fact that PGG and MH have different costs per iteration.

2.3 Leukemia survival data

We follow Vehtari et al., 2017 and consider the leukemia data presented in Feigl and Zelen, 1965 and used as illustration in Epifani et al., 2008. We use the data formatted as in the package BGPhazard, see Garcıa-Bueno and Nieto-Barajas, 2016. The outcome is taken to be one if the survival time (column time of leukemiaFZ) is larger or equal to 5050 weeks, zero otherwise, and the two covariates are the columns wbc and AG, corresponding to counts of white blood cells and the outcome of a test related to white blood cell characteristics. There are 31 patients in the sample, so n=31n=31, and we consider leave-one-out cross-validation, i.e. nT=n−1n_{T}=n-1 and nV=1n_{V}=1.

We introduce a path of distributions amenable to PGG sampling, as in the previous sections. Sampling uniformly the index of the observation to be left out, then sampling λ\lambda uniformly in $,andfinallyrunningcoupledPGGchainstargeting, and finally running coupled PGG chains targeting\pi_{\lambda}$, we record the meeting times. We do so 1,000 times independently, and show the results as a function of the index of the observation left out in 5(a).

Based on this plot we select k=100k=100, conservatively, and m=5k=500m=5k=500 for all runs. We then generate 10,00010,000 unbiased estimators of CV. We plot the estimators against the index of the left-out observation in 5(b), and we note that the values are very different for one particular index, here equal to 17. In 5(c) we plot a histogram of the estimates of the CV objective, putting all the indices together. From these estimates we obtain a 95%95\% confidence interval [−0.72,−0.66][-0.72,-0.66] for the leave-one-out CV objective. Thus we see that the proposed estimators can have a larger variance for certain splits of the data compared to others. Investigating further the behavior of the estimators for certain splits, one might be able to reduce the variance, for instance by tuning the proposal distribution q(dλ)q(\mathop{d\lambda}), or by changing the path. Our estimators of CV might also be considered satisfactory as they stand. In any case, they do not suffer from infinite variance issues typically associated with importance sampling, when using a proposal distribution that has lighter tails than the target distribution.

3 Linear regressions

We next consider linear regressions, which have been used to illustrate Bayesian cross-validation e.g. in Alqallaf and Gustafson, 2001; Peruggia, 1997; Vehtari et al., 2017.

The first example is taken from Alqallaf and Gustafson, 2001. The data comprise of n=62n=62 observations, each corresponding to an animal (arctic fox, owl monkey, etc). For each animal, the data set contains the body weight and the brain weight. The covariate did_{i} of animal ii is a vector, with first entry equal to 11 and second entry equal to the logarithm of body weight, while the outcome yiy_{i} is the logarithm of brain weight. As before we write YY for the vector of outcomes and DD for the matrix of covariates, on which we condition throughout. The model is given by

To get the conditional distribution of β\beta given σ2\sigma^{2} under the posterior distribution, note that

where β^=(D⊺D)−1D⊺Y\hat{\beta}=(D^{\intercal}D)^{-1}D^{\intercal}Y. Thus, the conditional distribution is Normal with mean β^\hat{\beta} and covariance matrix σ2(D⊺D)−1\sigma^{2}(D^{\intercal}D)^{-1}. The distribution of σ2\sigma^{2} given β\beta is inverse Gamma, where recall that

Then σ2\sigma^{2} given β\beta is inverse Gamma with a=n/2a=n/2 and b=∥Y−Dβ∥2/2b=\left\lVert Y-D\beta\right\rVert^{2}/2. Coupling this algorithm can be done by maximal coupling of each of the conditional update of a Gibbs sampler.

In Alqallaf and Gustafson, 2001, the predictive performance in this example is measured by the mean squared error, defined conditional on a split as

We implement this procedure and draw 1,0001,000 independent coupled chains. We observe meeting times between 11 and 55. Thus we set k=10k=10, m=25m=25, and draw 1,0001,000 independent unbiased estimators of CV. We obtain a 95%95\% confidence interval of [32.79,33.03][32.79,33.03], and standard error of 0.060.06. By comparison, Alqallaf and Gustafson, 2001 use 200 splits, and run 125 iterations of MCMC for each split, discarding the first 100. The total number of Gibbs iterations performed is approximately the same, and Alqallaf and Gustafson, 2001 obtain standard errors that are similar. An advantage of our method is in its simplicity: if we want more precise results, we simply generate more independent estimators.

We now consider the criterion −log⁡\prob(YV∣YT)-\log\prob(Y_{V}\mid Y_{T}), instead of the point-prediction mean squared error as above. The sequence of distributions defined in (5) is still amenable to a Gibbs sampling strategy and we need to work out the conditional distributions. The joint posterior density is

so that β\beta given the rest is \normal(μλ,Λλ−1)\normal(\mu_{\lambda},\Lambda_{\lambda}^{-1}). On the other hand σ2\sigma^{2} given the rest is inverse Gamma (a,b)(a,b) with

3.2 Stack loss data

We consider the stack loss data example, which was considered in Peruggia, 1997; Vehtari et al., 2017. In the former article, it is shown that importance sampling from the posterior given all the data to the posterior leaving one data point out can lead to infinite variance estimators. Here we use the stackloss data set of (R Core Team, 2015), with the outcome set to be the column stack.loss, and the covariates Air.Flow, Water.Temp, Acid.Conc., and a column of ones. The data are shown in 6(a). We consider leave-one-out cross-validation, with nT=n−1=20n_{T}=n-1=20 here. For simplicity we use the same model as in the previous section, with a flat prior on β\beta given σ2\sigma^{2}, instead of the proper prior given in Peruggia, 1997.

Using the coupled Gibbs sampler described in the previous section, we find meeting times to be less than 1010 with large probability, thus we set k=10k=10 and m=25m=25. We obtain the CV estimators shown in 6(b), based on 10,00010,000 independent replicates, plotted against the index of the left-out observation. As in Section 3.2.3, we can see that the variance of the CV estimators varies across the different ways of partitioning the data into training and validation sets. These CV estimators yield the 95%95\% confidence interval [2.78,2.82][2.78,2.82].

Discussion

Further work will be needed to compare the proposed estimators with state-of-the-art methods such as sequential Monte Carlo samplers for normalizing constant estimation (Lee and Whiteley, 2015; Zhou et al., 2016; Andrieu et al., 2016, e.g.), with alternative approaches such as the ones described in Chen et al., 1997; Johnson, 1999; Neal, 2005; Salomone et al., 2018 and references therein, and with the different existing approaches for Bayesian cross-validation (Alqallaf and Gustafson, 2001; Bornn et al., 2010; Vehtari et al., 2017, e.g.).

Our estimators combine the path sampling identity with unbiased estimators of intractable integrals. As such, they are expected to break if either path sampling or the unbiased estimators break. Path sampling can give poor results if the path of distributions is ill-chosen, thus the design of these paths remains crucial. We have seen in Section 3.2 that different paths can give orders of magnitude differences in efficiencies. We have also seen that the paths can benefit from approximations of the posterior distribution, such as Laplace approximations. Mixtures of distributions fitted on MCMC samples or variational approximations could also be considered. Conditional on a path, the choice of distribution q(dλ)q(\mathop{d\lambda}) is also important and can be guided by preliminary runs. Unbiased MCMC estimators themselves break either if the underlying MCMC algorithms mix poorly, or if the coupling strategy is ineffective; we defer to Jacob et al., 2017 for related discussions, and to Heng and Jacob, 2018 for the case of Hamiltonian Monte Carlo algorithms.

We note that the path sampling identity (3) is an instance of a nested Monte Carlo (MC) problem, as defined and discussed in Rainforth et al., 2016. The target of nested MC is an expectation II of the form

where the functions ff, ϕ\phi and the joint distribution of (x,λ)(x,\lambda) are problem-dependent choices. In the case of path sampling, we obtain I=r01I=r_{01} by choosing:

In this case f(λ,E(λ))f(\lambda,E\left\lparen\lambda\right\rparen) is linear in its second argument, thus, given λ\lambda, unbiased estimators of E(λ)E\left\lparen\lambda\right\rparen directly translate into unbiased estimators of f(λ,E(λ))f(\lambda,E\left\lparen\lambda\right\rparen). We remark that unbiased estimators could also be obtained for functions ff that are nonlinear in the second argument. For instance we can get an unbiased estimator of {E(λ)}k\{E(\lambda)\}^{k}, by sampling kk independent estimators of E^(λ)\hat{E}(\lambda) and taking their product. More generally we can obtain unbiased estimators of f(λ,E(λ))f(\lambda,E\left\lparen\lambda\right\rparen) given λ\lambda for functions ff that are polynomials in the second argument.

Finally it is possible to adapt the proposed approach to estimate the Bayesian cross-validation objective associated with some other scoring rules, such as the one proposed in Hyvärinen, 2005, and considered in the setting of model comparison in e.g. Dawid and Musio, 2015; Shao et al., 2018.

The authors are grateful to Jeremy Heng and Stephane Shao for helpful discussions.

References