Gaussian variational approximation with a factor ...

27
Gaussian variational approximation with a factor covariance structure Victor M.-H. Ong 1 , David J. Nott *1 , and Michael S. Smith 2 1 Department of Statistics and Applied Probability, National University of Singapore, Singapore 117546 2 Melbourne Business School, University of Melbourne, 200 Leicester Street, Carlton, VIC, 3053. Abstract Variational approximation methods have proven to be useful for scaling Bayesian computations to large data sets and highly parametrized models. Applying variational methods involves solving an optimization problem, and recent research in this area has focused on stochastic gradient ascent methods as a general approach to implementation. Here variational approximation is considered for a posterior distribution in high dimen- sions using a Gaussian approximating family. Gaussian variational approximation with an unrestricted covariance matrix can be computationally burdensome in many problems because the number of elements in the covariance matrix increases quadratically with the dimension of the model parameter. To circumvent this problem, low-dimensional factor covariance structures are considered. General stochastic gradient approaches to efficiently perform the optimization are described, with gradient estimates obtained us- ing the so-called “reparametrization trick”. The end result is a flexible and efficient approach to high-dimensional Gaussian variational approximation, which we illustrate using eight real datasets. Keywords. Gaussian variational approximation, variational Bayes. 1 Introduction Variational approximation methods are a promising approach to scalable approximate Bayesian inference in the case of large data sets and highly parametrized models. However, if the * Corresponding author: [email protected] 1 arXiv:1701.03208v1 [stat.ME] 12 Jan 2017

Transcript of Gaussian variational approximation with a factor ...

Page 1: Gaussian variational approximation with a factor ...

Gaussian variational approximation with a factor

covariance structure

Victor M.-H. Ong1, David J. Nott∗1, and Michael S. Smith2

1Department of Statistics and Applied Probability, National University of

Singapore, Singapore 117546

2Melbourne Business School, University of Melbourne, 200 Leicester Street,

Carlton, VIC, 3053.

Abstract

Variational approximation methods have proven to be useful for scaling Bayesian

computations to large data sets and highly parametrized models. Applying variational

methods involves solving an optimization problem, and recent research in this area has

focused on stochastic gradient ascent methods as a general approach to implementation.

Here variational approximation is considered for a posterior distribution in high dimen-

sions using a Gaussian approximating family. Gaussian variational approximation with

an unrestricted covariance matrix can be computationally burdensome in many problems

because the number of elements in the covariance matrix increases quadratically with

the dimension of the model parameter. To circumvent this problem, low-dimensional

factor covariance structures are considered. General stochastic gradient approaches to

efficiently perform the optimization are described, with gradient estimates obtained us-

ing the so-called “reparametrization trick”. The end result is a flexible and efficient

approach to high-dimensional Gaussian variational approximation, which we illustrate

using eight real datasets.

Keywords. Gaussian variational approximation, variational Bayes.

1 Introduction

Variational approximation methods are a promising approach to scalable approximate Bayesian

inference in the case of large data sets and highly parametrized models. However, if the

∗Corresponding author: [email protected]

1

arX

iv:1

701.

0320

8v1

[st

at.M

E]

12

Jan

2017

Page 2: Gaussian variational approximation with a factor ...

variational approximation takes the form of a multivariate Gaussian distribution with an

unrestricted covariance matrix, it is difficult to perform variational inference with a high-

dimensional parameter because the number of elements in the covariance matrix increases

quadratically with the parameter dimension. Hence, in the context of Gaussian variational

approximation, it is important to find parsimonious but flexible ways of parametrizing the

covariance matrix. The contribution of the present paper is to develop general methods for

Gaussian variational approximation when the covariance matrix has a factor structure. By

general here, we mean that the methods do not require any special structure for the prior and

likelihood function. A key feature of our approach is that we obtain efficient gradient estimates

for a stochastic gradient ascent optimization procedure using the so-called “reparametrization

trick”. This leads to a flexible and computationally attractive approach to high-dimensional

Gaussian variational approximation.

Let θ be a continuous parameter of dimension m, and consider Bayesian inference with a

prior density p(θ) and likelihood p(y|θ). Write the posterior density as p(θ|y), and to sim-

plify notation later write h(θ) = p(θ)p(y|θ), so that p(θ|y) ∝ h(θ). Variational approximation

methods (Attias, 1999; Jordan et al., 1999; Winn and Bishop, 2005; Ormerod and Wand, 2010)

provide approximate methods for performing Bayesian calculations having reduced computa-

tional demands compared to exact methods such as Markov chain Monte Carlo (MCMC).

In a variational approach it is assumed that the posterior density can be approximated by

a member of some tractable family of approximations, with typical element qλ(θ) say, where

λ are variational parameters to be chosen indexing different members of the family. Writing

p(y) =∫p(θ)p(y|θ)dθ for the marginal likelihood of y, the following identity holds, for any

qλ(θ):

log p(y) =

∫log

p(θ)p(y|θ)qλ(θ)

qλ(θ)dθ + KL(qλ(θ)||p(θ|y)), (1)

where

KL(qλ(θ)||p(θ|y)) =

∫log

qλ(θ)

p(θ|y)qλ(θ)dθ

is the Kullback-Leibler divergence from qλ(θ) to p(θ|y). Derivation of equation (1) can be

found, for example, in Ormerod and Wand (2010, p. 42). We denote the expectation with

respect to qλ(θ) as Eq(·). Because the Kullback-Leibler divergence is non-negative, from

2

Page 3: Gaussian variational approximation with a factor ...

equation (1),

L(λ) =

∫log

p(θ)p(y|θ)qλ(θ)

qλ(θ)dθ = Eq(log h(θ)− log qλ(θ)) (2)

is a lower bound on log p(y), called the variational lower bound. The Kullback-Leibler di-

vergence is one useful measure of the quality of the approximation of the true posterior by

qλ(θ), and we choose λ so that the approximation is optimal. The lower bound will be tight

when qλ(θ) is equal to the true posterior, since the Kulback-Leibler divergence is zero in this

case. Because the left hand side of (1) doesn’t depend on the variational parameters, min-

imizing the Kullback-Leibler divergence KL(qλ(θ)||p(θ|y)) with respect to λ is equivalent to

maximizing L(λ) with respect to λ. Therefore, maximizing L(λ) with respect to λ provides

the best approximation to our posterior distribution within the approximating class in the

Kullback-Leibler sense. In this manuscript we will be concerned with the situation where

qλ(θ) is multivariate normal, so without any further restriction the variational parameters λ

consist of both the mean vector and distinct elements of the covariance matrix of the normal

variational posterior. As mentioned above, a full normal variational approximation is difficult

to work with in high dimensions. Assuming a diagonal covariance structure is one possible

simplification, but this loses any ability to represent dependence in the posterior distribution.

Various suggestions in the literature exist for parsimonious ways to parametrize covari-

ance matrices in Gaussian variational approximations, while retaining some representation of

dependence between the model parameters. Opper and Archambeau (2009) note that with

a Gaussian prior and a factorizing likelihood, the optimal Gaussian variational distribution

can be specified in terms of a much reduced set of variational parameters. Challis and Barber

(2013) consider posterior distributions which can be expressed as a product of a Gaussian

factor and positive potential, and consider banded Cholesky, Chevron Cholesky and subspace

Cholesky approximations. They are also able to prove concavity of the variational lower bound

in this setup. Titsias and Lazaro-Gredilla (2014) consider both full and diagonal covariance

structures with the covariance matrix parametrized in terms of the Cholesky factor, where

stochastic gradient variational Bayes methods are used to do the optimization in quite a gen-

eral way. Efficient gradient estimates are constructed using the so-called “reparametrization

trick” (Kingma and Welling, 2014; Rezende et al., 2014). Kucukelbir et al. (2016) consider

both unrestricted and diagonal covariance matrices, as well as marginal transformations to

improve normality, working in an automatic differentiation environment and using similar gra-

dient estimates to Titsias and Lazaro-Gredilla (2014). Salimans and Knowles (2013) consider

a variety of stochastic gradient optimization approaches for learning exponential family type

3

Page 4: Gaussian variational approximation with a factor ...

approximations or hierarchical extensions of such approximations. In the Gaussian case, they

mostly consider parametrizations of the covariance matrix in terms of the precision matrix,

and are able to exploit sparsity of Hessian matrices for the joint model in their computations,

with such sparsity being related to conditional independence structure. As well as their algo-

rithm using the Hessian, they also provide algorithms that require only computation of first

order derivatives. Archer et al. (2016) consider Gaussian variational approximation in the

context of smoothing for state space models. They parametrize the variational optimization

in terms of a sparse precision matrix, and exploit the way that this leads to a sparse Cholesky

factor in random variate generation from their variational posterior distribution. The blocks

of the mean vector and non-zero blocks of the precision matrix are parametrized in terms of

global parameters that relate them to local data – an example of so-called amortized varia-

tional inference – which was also introduced in Kingma and Welling (2014). Tan and Nott

(2016) parametrize the variational optimization directly in terms of the Cholesky factor of

the precision matrix and impose sparsity on the Cholesky factor that reflects conditional in-

dependence relationships. They show how the sparsity can be exploited in the computation

of gradients with the reparametrization trick.

In the above work the approximations considered either require some special structure

of the model (such as conditional independence structure, Gaussian priors or a factorizing

likelihood), do not scale well to high dimensions, or are inflexible in the kinds of dependence

they can represent accurately. The goal of the present work is to consider a general method for

Gaussian variational approximation, where the covariance matrix is parametrized in terms of

a factor structure. Factor models are well known to be a very successful approach to modelling

high-dimensional covariance matrices in many circumstances (Bartholomew et al., 2011). By

assuming a factor stucture the number of variational parameters is reduced considerably when

the number of factors is much less than the full dimension of the parameter space. Such a

parsimonious approximation has strong potential in certain applications. For example, in

random effects models dependence among the high-dimensional vector of random effects can

often be explained by their shared dependence on just a small number of global parameters.

We demonstrate this later for a mixed effects logistic regression model. Gaussian variational

approximations with a factor covariance structure have been considered previously by Barber

and Bishop (1998) and Seeger (2000). However, these authors consider models with special

structure in which the variational lower bound can be evaluated analtyically, or using one-

dimensional numerical quadrature. In contrast, here we consider approaches to performing

the required variational optimization without requiring any special structure for the prior or a

factorizing likelihood. In independent work Miller et al. (2016) have recently also suggested the

4

Page 5: Gaussian variational approximation with a factor ...

use of factor parametrizations of covariance structure in Gaussian variational approximation,

using stochastic gradient methods and the reparametrization trick for gradient estimation.

However, their focus is on building mixture of Gaussian variational approximations using

a boosting perspective and they do not give expressions for the gradient estimates for the

Gaussian factor components or the derivation of such results.

In the next section we briefly introduce the main ideas of stochastic gradient variational

Bayes. Section 3 then gives details of our stochastic gradient ascent algorithm for optimization

of the variational parameters in a Gaussian approximation with factor covariance structure.

Efficient gradient estimation based on the reparametrization trick is developed, and we show

that matrix computations in the gradient calculations can be done efficiently using the Wood-

bury formula. Derivation of the gradient experssions are given in the Appendix. Section

4 illustrates the advantages of the method by applying it to eight examples and Section 5

concludes.

2 Stochastic gradient variational Bayes

We note that L(λ) in (5) is defined in terms of an expectation, and when this cannot be

evaluated in closed form a number of authors (Ji et al., 2010; Paisley et al., 2012; Nott

et al., 2012; Salimans and Knowles, 2013; Kingma and Welling, 2014; Rezende et al., 2014;

Hoffman et al., 2013; Ranganath et al., 2014; Titsias and Lazaro-Gredilla, 2015) have suggested

optimizing L(λ) using stochastic gradient ascent methods (Robbins and Monro, 1951). If L(λ)

is the objective function to be optimized, ∇λL(λ) is its gradient, and ∇λL(λ) is an unbiased

estimate of the gradient, then the basic form of a stochastic gradient ascent optimization is as

follows. After choosing an initial value λ(0) for the variational parameters λ, for t = 0, 1, . . .

perform the update

λ(t+1) = λ(t) + ρt ∇λL(λ(t))

until a stopping condition is satisfied. Here, ρt, t ≥ 0, is a sequence of learning rates, typically

chosen to satisfy the Robbins-Monro conditions (Robbins and Monro, 1951)∑

t ρt = ∞ and∑t ρ

2t < ∞. Convergence of the sequence λ(t) will be to a local optimum under regularity

conditions (Bottou, 2010). In practice it is important to consider adaptive learning rates, and

in our later examples we implement the ADADELTA approach (Zeiler, 2012), although there

is a large literature on different adaptive choices of the learning rates.

The references given above differ in the way that the unbiased gradient estimates ∇λL(λ)

5

Page 6: Gaussian variational approximation with a factor ...

are constructed, and the variance reduction methods employed. Reducing the variance of the

gradient estimates is important because this affects the stability and speed of convergence of

the algorithm. Differentiating directly under the integral sign in (2) and using the fact that

Eq(∇λ log qλ(θ)) = 0 (the so-called log-derivative trick) and some simple algebra, the gradient

is

∇λL(λ) =Eq(∇λ log qλ(θ)(log h(θ)− log qλ(θ))). (3)

Since this is an expectation with respect to qλ(θ), it is easy to estimate (3) unbiasedly using

samples from qλ(θ), provided that sampling from qλ(θ) is possible. In large data sets this can

also be combined with unbiased estimation of log h(θ) using subsampling of terms in the log-

likelihood (so-called doubly stochastic variational inference, see Salimans and Knowles (2013);

Kingma and Welling (2014) and Titsias and Lazaro-Gredilla (2014) for example).

In practice, even with sophisticated variance reductions it is often found that deriva-

tives obtained from (3) can have high variance, and an alternative approach was consid-

ered by Kingma and Welling (2014) and Rezende et al. (2014), which they have called the

reparametrization trick. To apply this approach, we need to be able to represent samples from

qλ(θ) as θ = t(ε, λ), where ε is a random vector with a fixed density f(ε) that does not depend

on the variational parameters. In particular, in the case of a Gaussian variational distribution

parametrized in terms of a mean vector µ and the Cholesky factor C of its covariance matrix,

we can write θ = µ+ Cε, where ε ∼ N(0, I). Then

L(λ) =Eq(log h(θ)− log qλ(θ))

=Ef (log h(t(ε, λ))− log qλ(t(ε, λ))), (4)

where we have written Ef (·) to denote expectation with respect to f(·). Differentiating un-

der the integral sign in (4) gives an expectation with respect to f(·) that can be estimated

unbiasedly based on samples from f(·). Because of the reparametrization in terms of ε, the

variational parameters have been moved inside the function h(·) so that when we differentiate

(4) we are using derivative information from the target posterior density. In practice it is

found that when the reparametrization trick can be applied, it helps greatly to reduce the

variance of gradient estimates.

6

Page 7: Gaussian variational approximation with a factor ...

3 Approximation with factor covariance structure

In our factor parametrization of the variational distribution it is assumed that qλ(θ) =

N(µ,BBT +D2) where µ is the mean vector, B is a m×p full rank matrix with p << m and D

is a diagonal matrix with diagonal elements d = (d1, . . . , dm). Without further restrictions B

is unidentified, and here we impose the restriction that the upper triangle of B is zero, similar

to Geweke and Zhou (1996). For uniqueness we may also wish to impose the restriction on

the leading diagonal elements Bii > 0, but we choose not to do this in the present work as it

does not pose any problem for the variational optimization and it is more convenient to work

with the unconstrained parametrization. Note that we can draw θ ∼ N(µ,BBT +D2) by first

drawing (z, ε) ∼ N(0, I) (where z is p-dimensional and ε is m dimensional) and then calculat-

ing θ = µ + Bz + d ◦ ε, where ◦ denotes the Hadamard (element by element) product of two

random vectors. This will be the basis for our application of the reparametrization trick, and

also makes explicit the intuitive idea behind factor models, which is that correlation among

the components may be explained in terms of a smaller number of latent variables (z in this

case) which influence all the components, with component specific “idiosyncratic” variance

being captured through the additional independent error term d ◦ ε.We now explain how to apply the reparametrization trick of Kingma and Welling (2014)

and Rezende et al. (2014) to obtain efficient gradient estimates for stochastic gradient varia-

tional inference in this setting. Write f(z, ε) for the N(0, I) density of (z, ε) in the generative

representation of qλ(θ) described above. The lower bound is an expectation with respect to

qλ(θ), but applying the reparametrization trick gives

L(λ) =Ef (log h(µ+Bz + d ◦ ε) +m

2log 2π +

1

2log|BBT +D2|

+1

2(Bz + d ◦ ε)T (BBT +D2)−1(Bz + d ◦ ε)). (5)

We give some expressions for the components of ∇λL(λ) obtained from differentiating in (5)

under the integral sign, but first we need some notation. For a matrix A, we write vec(A) for

the vector obtained by stacking the columns of A one underneath the other as we go from

left to right. We will not require that A be a square matrix. We write vec−1(·) for the inverse

operation (where in what follows the dimensions of the resulting matrix will be clear from

the context and we will not make this explicit in the notation). Also, for a vector x and real

valued function g(x), we write ∇xg(x) for the gradient vector, written as a column vector,

and for a matrix A and real-valued function g(A) we define ∇Ag(A) = vec−1(∇vec(A)g(A)) so

that ∇Ag(A) is a matrix of the same dimensions as A. Also, we write diag(Z) for the vector

7

Page 8: Gaussian variational approximation with a factor ...

of diagonal entries of the square matrix Z.

With this notation, it is shown in the Appendix that,

∇µL(λ) =Ef (∇θ log h(µ+Bz + d ◦ ε)), (6)

∇BL(λ) =Ef (∇θ log h(µ+Bz + d ◦ ε)zT + (BBT +D2)−1B + (BBT +D2)−1(Bz + d ◦ ε)zT

− (BBT +D2)−1(Bz + d ◦ ε)(Bz + d ◦ ε)T (BBT +D2)−1B) (7)

and

∇dL(λ) =Ef (diag(∇θ log h(µ+Bz + d ◦ ε)εT + (BBT +D2)−1D + (BBT +D2)−1(Bz + d ◦ ε)εT

− (BBT +D2)−1(Bz + d ◦ ε)(Bz + d ◦ ε)T (BBT +D2)−1D)). (8)

However, also noting that the second and fourth terms in (7) and (8) are equal after taking

expectations,

∇BL(λ) =Ef (∇θ log h(µ+Bz + d ◦ ε)zT + (BBT +D2)−1(Bz + d ◦ ε)zT ) (9)

and

∇dL(λ) =Ef (diag(∇θ log h(µ+Bz + d ◦ ε)εT + (BBT +D2)−1(Bz + d ◦ ε)εT ). (10)

Estimating the expectations in these gradient expressions based on one or more samples from

f gives an unbiased estimate ∇λL(λ) of ∇λL(λ). This can be used in a stochastic gradient

ascent algorithm for optimizing the lower bound, resulting in Algorithm 1. Use of expressions

(9) and (10) is preferable to (7) and (8). This is because near the mode of L(λ), if the

true posterior is Gaussian with the assumed covariance structure holding, then the gradient

estimates based on (9) and (10) for just a single sample tend to zero, whereas the alternative

expressions (7) and (8) add noise. Specifically, if h(θ) is proportional to qλ(θ) at the modal λ

value, then by differentiating the expression for log qλ(θ) we obtain

∇θ log h(µ+Bz + d ◦ ε) = −(BBT +D2)−1(Bz + d ◦ ε)

which shows that a gradient estimate based on a single sample of f using (9) and (10) will be

zero at the mode. Similar points are discussed in Salimans and Knowles (2013), Han et al.

(2016) and Tan and Nott (2016) in other contexts and we use the gradient estimates based

8

Page 9: Gaussian variational approximation with a factor ...

on (9) and (10) and a single sample from f in the examples.

Initialize λ = λ(0) = (µ(0), B(0), d(0)), t = 0.Cycle

1. Generate (ε(t), z(t)) ∼ N(0, I)

2. Construct unbiased estimates ∇µL(λ), ∇BL(λ), ∇dL(λ) of the gradi-ents (6), (9) and (10) at λ(t) where the expectations are approximatedfrom the single sample (ε(t), z(t)).

3. Set adaptive learning rate ρ(t) using ADADELTA or other method.

4. Set µ(t+1) = µ(t) + ρt ∇µL(λ(t)).

5. Set B(t+1) = B(t) +ρt ∇BL(λ(t)) for elements of B(t+1) on or below thediagonal, with the upper triangle of B(t+1) fixed at zero.

6. Set d(t+1) = d(t) + ρt ∇dL(λ(t)).

7. Set λ(t+1) = (µ(t+1), B(t+1), d(t+1)), t→ t+ 1.

until some stopping rule is satisfied

Algorithm 1: Gaussian variational approximation algorithm with factor covariance structure.

At first sight it may seem that computing the gradient estimates based on (6), (9) and

(10) is difficult when θ is high-dimensional because of the inverse of the dense m×m matrix

(BBT +D2) in these expressions. However, note that by the Woodbury formula we have

(BBT +D2)−1 =D−2 −D−2B(I +BTD−2B)−1BTD−2

and that on the right hand side the matrix (I + BTD−2B) is p × p with p << m and D

is diagonal. So any computation involving (BBT + D2)−1 or solutions of linear systems in

(BBT +D2) can be done efficiently in terms of both memory and computation time.

4 Examples

We now demonstrate the advantages of our proposed method, which we call variational ap-

proximation with factor covariance structure (VAFC), for the case of a logistic regression

model. Suppose we are given a dataset with response yi ∈ {−1, 1} and covariates xi ∈ Rq

9

Page 10: Gaussian variational approximation with a factor ...

for i = 1, ..., n. For a logistic regression, the likelihood is p(y|θ) =∏n

i=1 1/(1 + e−yixTi θ) where

xi = [1 xTi ]T , θ denotes the coefficient vector, and p(θ|y) ∝ h(θ) = p(y|θ)p(θ). Our VAFC ap-

proach will be compared with the DSVI (Doubly Stochastic Variational Inference) algorithm

proposed by Titsias and Lazaro-Gredilla (2014). Similar to VAFC, these authors use a multi-

variate normal posterior approximation qD(θ) = N(µD,ΣD), where the covariance matrix ΣD

is parametrized as ΣD = CDCDT , with CD an unrestricted lower triangular Cholesky factor.

Both µD and CD can be updated using a stochastic gradient optimization procedure. The

VAFC algorithm differs by parametrizing the covariance matrix through a more parsimonious

factor structure. We write qF (θ) = N(µF ,ΣF ) for the VAFC posterior approximation.

Four examples in Section 4.1 illustrate the performance of DSVI and VAFC when the

number of predictors m is moderate and where m < n, the kind of situation where there

may be most interest in parameter inference and uncertainty quantification. We also compare

the accuracy of the variational approximations to the exact posterior distribution, computed

using MCMC. The three examples in Section 4.2 consider cases in which m >> n and where

the computational gains from using the factor structure are larger. In these saturated models,

we employ a horseshoe prior for parameter shrinkage (Carvalho et al., 2010), so that the

variational approximation is to a high-dimensional posterior for both the covariate coefficients

and the matching local shrinkage parameters. In these examples, interest mostly focuses on

predictive inference. Lastly, in Section 4.3 we consider an example for a mixed effects logistic

regression model. In this case, the variational approximations are to the posterior augmented

with a high-dimensional vector of random effect terms.

In all the examples we set step sizes (learning rates) adaptively using the ADADELTA

method (Zeiler, 2012) for both VAFC and DSVI, with different step sizes for each element of

λ. Specifically, at iteration t+ 1, the ith element λi of λ is updated as

λ(t+1)i = λ

(t)i + ∆λ

(t)i .

Here, the step size ∆λ(t)i is ρ

(t)i g

(t)λi where g

(t)λi denotes the ith component of ∇λL(λ(t)) and ρ

(t)i

is

ρ(t)i =

√E(∆2

λi)(t−1) + ε√

E(g2λi)(t) + ε

where ε is a small positive constant, with E(∆2λi)

(t) and E(g2λi)(t) being decayed running average

10

Page 11: Gaussian variational approximation with a factor ...

estimates of ∆λ(t)i

2and g

(t)λi

2, defined by

E(∆2λi)

(t) = ζE(∆2λi)

(t−1) + (1− ζ)∆λ(t)i

2

E(g2λi)(t) = ζE(g2λi)

(t−1) + (1− ζ)g(t)λi

2.

The variable ζ is a decay constant. In the examples we use the default tuning parameter

choices ε = 10−6 and ζ = 0.95, and initialize E(∆2λi)

(0) = E(g2λi)(0) = 0.

4.1 Bayesian logistic regression

We consider the spam, krkp, ionosphere and mushroom data from the UCI Machine Learning

Repository (Lichman, 2013). Following Gelman et al. (2008), we change the input matrix

into binary variables using the discretization function in R (Kim, 2016). After doing this,

the spam, krkp, ionosphere and mushroom data respectively contain n = 4601, 351, 3196 and

8124 samples and m = 104, 111, 37 and 95 variables, so that m < n in each case. In the

examples in this section we use a N(0, 10I) prior for θ.

The first and second columns of Figure 1 show respectively Monte Carlo estimates of the

lower bounds for DSVI and VAFC with p = 3 factors over 10,000 iterations. Convergence is

slightly faster for the VAFC method in these examples, and each iteration of the optimization

also requires less computation, advantages that are more pronounced in the high-dimensional

case considered in Section 4.2. To examine the quality of marginal inferences, in the third

column of Figure 1 we plot (µFi , µDi ) for i = 1, ...,m (i.e. the variational means for the two

methods) and we see that the variational means are close to each other. The rightmost

column of Figure 1 shows a similar graphical comparison of the estimated posterior standard

deviations of the coefficients for VAFC and DSVI, plotting (√

ΣFi,i,√

ΣDi,i) for i = 1, ...,m. A

variational approximation using an insufficiently flexible approximating family often leads to

underestimation of posterior variances (see, for example, Wang and Titterington (2005)). This

is indicated here for the VAFC method, with many points appearing above the diagonal lines

in the plots. However, this underestimation of the posterior standard deviations is relatively

minor, except for the ionosphere and mushroom datasets. Figure 2 shows what happens

when the number of factors in the VAFC method is increased to p = 20 for these datasets

and, as expected, this reduces the underestimation of the standard deviations in the variational

posterior. Although we compare our VAFC method to DSVI in these plots, the DSVI based

inferences are very similar to those for the exact posterior computed using MCMC. This is

illustrated in Figure 3 where variational posterior means and standard deviations for DSVI

are plotted against posterior means and standard deviations computed using MCMC. For the

11

Page 12: Gaussian variational approximation with a factor ...

0 2000 4000 6000 8000 10000

Iteration index

-6000

-5000

-4000

-3000

-2000

-1000

Low

er B

ound

of V

AF

C

0 2000 4000 6000 8000 10000

Iteration index

-6000

-5000

-4000

-3000

-2000

-1000

Low

er B

ound

of D

VS

I

-4 -2 0 2

Mean of Var Dist (VAFC)

-4

-2

0

2

Mea

n of

Var

Dis

t (D

VS

I)

0 0.5 1 1.5 2 2.5

s.d. of Var Dist (VAFC)

0

0.5

1

1.5

2

2.5

s.d.

of V

ar D

ist (

DV

SI)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Spam data

0 2000 4000 6000 8000 10000

Iteration index

-2500

-2000

-1500

-1000

-500

Low

er B

ound

of V

AF

C

0 2000 4000 6000 8000 10000

Iteration index

-2500

-2000

-1500

-1000

-500

Low

er B

ound

of D

VS

I

-10 0 10 20

Mean of Var Dist (VAFC)

-10

-5

0

5

10

15

20

Mea

n of

Var

Dis

t (D

VS

I)

0 0.5 1 1.5 2

s.d. of Var Dist (VAFC)

0

0.5

1

1.5

2

s.d.

of V

ar D

ist (

DV

SI)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Krkp data

0 2000 4000 6000 8000 10000

Iteration index

-800

-600

-400

-200

Low

er B

ound

of V

AF

C

0 2000 4000 6000 8000 10000

Iteration index

-800

-600

-400

-200

Low

er B

ound

of D

VS

I

-6 -4 -2 0 2 4

Mean of Var Dist (VAFC)

-6

-4

-2

0

2

4

Mea

n of

Var

Dis

t (D

VS

I)

0 1 2 3

s.d. of Var Dist (VAFC)

0

0.5

1

1.5

2

2.5

3

s.d.

of V

ar D

ist (

DV

SI)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Ionosphere data

0 2000 4000 6000 8000 10000

Iteration index

-8000

-6000

-4000

-2000

0

Low

er B

ound

of V

AF

C

0 2000 4000 6000 8000 10000

Iteration index

-8000

-6000

-4000

-2000

0

Low

er B

ound

of D

VS

I

-10 -5 0 5 10

Mean of Var Dist (VAFC)

-10

-5

0

5

10

Mea

n of

Var

Dis

t (D

VS

I)

0 1 2 3

s.d. of Var Dist (VAFC)

0

0.5

1

1.5

2

2.5

3

s.d.

of V

ar D

ist (

DV

SI)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Mushroom data

Figure 1: Monte Carlo estimates of the lower bound, means and standard deviations of thevariational distribution of the regression coefficients for both the VAFC with p = 3 and DVSIapproaches. Each row corresponds to a different dataset. Points near the red lines in the thirdcolumn indicates that the variational means are similar for both VAFC and DVSI. Points abovethe red lines in the plots in the last column indicates that the variational standard deviationsof the regression coefficients are smaller for VAFC than for DSVI.

MCMC computations we used the package rstanarm (Stan Development Team, 2016). In

this example we have considered results of the VAFC method using p = 3 and p = 20 factors.

A reasonable question is how to choose the number of factors in the approximation. One

approach is to calculate the approximation for a sequence of increasing values of p, and to

12

Page 13: Gaussian variational approximation with a factor ...

0 2000 4000 6000 8000 10000

Iteration index

-900

-800

-700

-600

-500

-400

-300

-200

-100

Low

er B

ound

(V

AF

C, p

= 3

)

0 1 2 3

s.d. of Var Dist (VAFC, p = 3)

0

0.5

1

1.5

2

2.5

3

s.d.

of V

ar D

ist,

DV

SI

0 2000 4000 6000 8000 10000

Iteration index

-900

-800

-700

-600

-500

-400

-300

-200

-100

Low

er B

ound

(V

AF

C, p

= 2

0)

0 1 2 3

s.d. of Var Dist (VAFC, p = 20)

0

0.5

1

1.5

2

2.5

3

s.d.

of V

ar D

ist,

DV

SI

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Ionosphere data

0 2000 4000 6000 8000 10000

Iteration index

-8000

-6000

-4000

-2000

0

Low

er B

ound

(V

AF

C, p

= 3

)

0 1 2 3

s.d. of Var Dist (VAFC, p = 3)

0

0.5

1

1.5

2

2.5

3

s.d.

of V

ar D

ist,

DV

SI

0 2000 4000 6000 8000 10000

Iteration index

-8000

-6000

-4000

-2000

0

Low

er B

ound

(V

AF

C, p

= 2

0)0 1 2 3

s.d. of Var Dist (VAFC, p = 20)

0

0.5

1

1.5

2

2.5

3

s.d.

of V

ar D

ist,

DV

SI

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Mushroom data

Figure 2: Monte Carlo estimates of the lower bound, means and standard deviations of thevariational distribution of the regression coefficients for both the VAFC with p = 20 and DVSIapproaches. Results are given for the ionosphere and mushroom datsets. Points near the redlines in the third column indicates that the variational means are similar for both VAFC andDVSI. Points above the red lines in the plots in the last column indicates that the variationalstandard deviations of the regression coefficients are smaller for VAFC than for DSVI.

-4 -2 0 2

Mean of Post Dist (MCMC)

-4

-2

0

2

Mea

n of

Var

Dis

t (D

VS

I)

0 0.5 1 1.5 2 2.5

s.d. of Post Dist (MCMC)

0

0.5

1

1.5

2

2.5

s.d.

of V

ar D

ist (

DV

SI)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 100.51 Spam data

-10 0 10 20

Mean of Post Dist (MCMC)

-10

-5

0

5

10

15

20

Mea

n of

Var

Dis

t (D

VS

I)

0 0.5 1 1.5 2 2.5

s.d. of Post Dist (MCMC)

0

0.5

1

1.5

2

2.5

s.d.

of V

ar D

ist (

DV

SI)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 100.51 Krkp data

-6 -4 -2 0 2

Mean of Post Dist (MCMC)

-6

-4

-2

0

2

Mea

n of

Var

Dis

t (D

VS

I)

0 1 2 3

s.d. of Post Dist (MCMC)

0

0.5

1

1.5

2

2.5

3

s.d.

of V

ar D

ist (

DV

SI)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 100.51 Ionosphere data

-5 0 5 10

Mean of Post Dist (MCMC)

-5

0

5

10

Mea

n of

Var

Dis

t (D

VS

I)

0 1 2 3

s.d. of Post Dist (MCMC)

0

0.5

1

1.5

2

2.5

3

s.d.

of V

ar D

ist (

DV

SI)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 100.51 Mushroom data

Figure 3: Scatter plots of the points (µMCMCi , µDi ) and (

√ΣMCMCi,i ,

√ΣDi,i) for i = 1, ..,m

where µMCMCi and ΣMCMC

i,i uses the MCMC approach rstanarm.

13

Page 14: Gaussian variational approximation with a factor ...

0 2000 4000 6000 8000 10000

Iteration index

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5Lo

wer

Bou

nd o

f VA

FC

×104 Colon Cancer

0 2000 4000 6000 8000 10000

Iteration index

-8

-7

-6

-5

-4

-3

-2

-1

Low

er B

ound

of V

AF

C

×104 Leukemia

0 2000 4000 6000 8000 10000

Iteration index

-8

-7

-6

-5

-4

-3

-2

-1

Low

er B

ound

of V

AF

C

×104 Breast Cancer

Figure 4: Lower bounds for Colon, Leukemia and Breast cancer data using both the VAFCand DVSI approach.

stop when posterior inferences of interest no longer change. We consider an approach of this

kind further in the example of Section 4.3.

VAFC DVSITraining error Test Error Training error Test Error

Spam data 0.046 0.058 0.046 0.057KRKP data 0.027 0.029 0.027 0.031

Ionosphere data 0.004 0.082 0.004 0.077Mushroom data 0 0 0 0

Table 1: Average training and test error rates for the four datasets with m < n estimatedvia five-fold cross validation.

Table 1 reports a five-fold cross-validatory assessment of the predictive performance for

the four datasets. For the fitted logistic regressions based on µD and µF , the average training

and test set error rates are very similar for the two approaches. This is not surprising given

that the variational posterior means tend to be very close for the two methods.

4.2 High-dimensional logistic regression examples

We consider the Colon, Leukemia and Breast cancer datasets available at http://www.csie.

ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html. The Colon dataset has m =

2000 covariates with sample sizes of 42 and 20 in the training and test sets respectively; the

Leukemia dataset has m = 7120 covariates with sample sizes of 38 and 34 in the training and

test set; the Breast dataset has similar dimension and sample size as the Leukemia data in

the training set, but with only a sample size of 4 in the test set. The datasets have m >> n

and the posterior distribution is high-dimensional in each case.

14

Page 15: Gaussian variational approximation with a factor ...

Here, because of the very high dimensionality of the covariate vectors, we consider a sparse

signal shrinkage prior distribution on the coefficients, namely the horseshoe prior (Carvalho

et al., 2010). Continuing to write θ for the regression coefficients as in the last subsection, we

now consider the hierarchical prior

θj|g, δ ∼ N(0, δ2j g2) δj ∼ C+(0, 1),

for j = 1, . . . ,m, where C+(0, 1) denotes the half-Cauchy distribution. The parameters δi

provide local shrinkage for each coefficient, whereas g is a global shrinkage parameter. For

θ0, we use a N(0, 10) prior, and for g we use a half-Cauchy prior, g ∼ C+(0, 1). We let

v = (v1, . . . , vm+1)T = (log δ1, . . . , log δm, log g)T and denote the full vector of parameters as

η = (θT , vT )T . We consider a normal variational approximation for η, using the DSVI and

VAFC methods. Mean field variational methods are considered for some applications of the

horseshoe and other sparse signal shrinkage priors in Neville et al. (2014). Their algorithms

do not extend easily to logistic regression, however.

We ran the VAFC algorithm on all three datasets with p = 4. Figure 4 shows a Monte

Carlo estimate of the lower bound versus iteration number for 10,000 iterations. We found

that in this example the DSVI algorithm often diverges even with carefully chosen starting

values under our prior settings. In terms of computation time, using an iMac computer with

i5 3.2 Ghz Intel Quad Core, we found that running 100 iterations of VAFC implemented in

MATLAB required approximately 32 and 388 seconds for the colon and breast cancer datasets

respectively. On the other hand, DVSI required 46 seconds and more than two hours respec-

tively for the same number of iterations and the same datasets. The very slow implementation

of DSVI for the breast dataset is related to the memory requirements of the DSVI approach,

which is another relevant aspect of the comparison of the algorithms. Note that the timings

presented are for the same fixed number of iterations, and the reduced number of variational

parameters in the VAFC approach often means than the number of iterations required for

convergence is much reduced, so the the reduction in computation time is substantial for the

VAFC method.

In these high-dimensional examples Titsias and Lazaro-Gredilla (2014) considered a version

of their procedure using a diagonal covariance matrix and a feature selection approach based

on automatic relevance determination (DSVI-ARD). We compare predictive performance of

the DSVI-ARD approach with the VAFC method with p = 4 factors and the horseshoe prior

in Table 2. The DSVI-ARD results are those reported in Titsias and Lazaro-Gredilla (2014).

Similar predictive performance is achieved by the two methods.

15

Page 16: Gaussian variational approximation with a factor ...

VAFC DVSI-ARDTraining error Test Error Training error Test Error

Colon 0/42 0/20 0/42 1/20Leukemia 0/38 6/34 0/38 3/34

Ionosphere data 0/38 1/4 0/38 2/4

Table 2: Train and test error rates for the three cancer datasets for the VAFC and DVSI-ARDmethods. Errors rates are reported as the ratio of misclassified data points over the numberof data points.

4.3 Mixed logistic regression

In this example, we consider a random intercept model for the polypharmacy data set de-

scribed in Hosmer et al. (2013). This longitudinal dataset is available at http://www.umass.

edu/statdata/statdata/stat-_logistic.html, and contains data on 500 subjects, who

were followed over seven years. Following Tan and Nott (2016), we consider a logistic mixed

effects model of the form

logit p(yij = 1|θ) = β0 + βgenderGenderi + βraceRacei + βageAgeij

+ βM1MHV1ij + βM2MHV2ij + βM3MHV3ij (11)

+ βIM INPTMHVij + ui

for i = 1, 2, ..., 500 and j = 1, 2, ..., 7. The response variable yij is 1 if subject i in year

j is taking drugs from three or more different classes, and −1 otherwise. The covariate

Genderi = 1 if subject i is male and 0 if female; Racei = 0 if the race of subject i is white

and 1 otherwise; and letting MHVij be the number of outpatient mental health visits for

subject i and year j, we set MHV1ij = 1 if 1 ≤ MHVij ≤ 5 and 0 otherwise, MHV2ij = 1

if 6 ≤ MHVij ≤ 14 and 0 otherwise, and MHV3ij = 1 if MHVij ≥ 15 and 0 otherwise.

The covariate INPTMHVij is 0 if there were no inpatient mental health visits for subject i

in year j and 1 otherwise. Finally ui ∼ N(0, exp(2ζ)) is a subject level random intercept.

Write β = (β0, βgender, βrace, βage, βM1, βM2, βM3, βIM)T , u = (u1, . . . , u500)T and the parame-

ters augmented with the random intercepts as θ = (βT , uT , ζ)T . The prior distribution takes

the form

p(θ) = p(β)p(ζ)n∏i=1

p(ui|ζ)

where p(β) is N(0, 100I8), p(ζ) is N(0, 100) and p(ui|ζ) is N(0, exp(2ζ)).

We ran the VAFC algorithm for 10,000 iterations using p = 0, 1, ...20 factors. Figure 5

16

Page 17: Gaussian variational approximation with a factor ...

0 2 4 6 8 10 12 14 16 18 20

p

0

10

20

30

40

50

60

Figure 5: Kullback-Leibler divergence between the final distribution of VAFC for multiplevalues of p and VAFC using p = 20.

shows the KL divergence between the variational distribution with p factors and that with

20 factors as p varies (note that the KL divergence between two multivariate Gaussian dis-

tributions is computable in closed form). This shows that the variational approximation to

the posterior augmented with the random effects is similar for p ≥ 4. To illustrate this fur-

ther, Figure 6 shows contour plots of some selected bivariate variational posterior marginals.

The results when p = 0 (i.e. a diagonal approximation) are very different, and even a crude

allowance for posterior correlation with a small number of factors can grealy improve estima-

tion of the posterior marginal distributions. Finally, we also compare the variational marginal

density of the regression coefficients with the method in Tan and Nott (2016). The method of

Tan and Nott (2016) gives similar answers to MCMC in this example, as shown in Figure 5

of their manuscript, so the Tan and Nott (2016) can be considered both a gold standard for a

normal approximation as well as a good gold standard more globally. Figure 7 shows that, ex-

cept for some mild underestimation of the random intercept variance parameter ζ, the VAFC

algorithm with p = 4 provides good approximations of the marginal posterior distributions of

the components of β. Figure 8 shows plots of the variational posterior means and standard

deviations of the subject level random intercepts for VAFC with p = 4 against those for the

method of Tan and Nott (2016). The posterior distributions of random intercepts are close

for the two methods.

17

Page 18: Gaussian variational approximation with a factor ...

Figure 6: Bivariate contour plots of the posterior density of coefficients with the five highestcorrelations for the VAFC.

5 Discussion

To construct practical variational approximation methods in high dimensions it is important

to employ parsimonious but flexible parametrizations of variational families. Gaussian approx-

imations are important, both because they are useful in themselves, but also as a building

block for more sophisticated approaches such as variational mixture approximations (Jaakkola

and Jordan, 1998; Gershman et al., 2012; Salimans and Knowles, 2013; Guo et al., 2016; Miller

et al., 2016) or approximations based on Gaussian copulas (Han et al., 2016). Here we have

considered factor covariance structures for Gaussian variational approximation in situations

where there is no natural conditional independence structure that can be exploited in the

model for reducing the number of free covariance parameters. The approximations can be

efficiently formed using the reparametrization trick for gradient estimation and exploiting the

18

Page 19: Gaussian variational approximation with a factor ...

-6 -5 -4 -3 -2

β0

0

0.2

0.4

0.6

0.8

1

1.2

-1 0 1 2

βgender

0

0.2

0.4

0.6

0.8

1

1.2

1.4

-3 -2 -1 0 1

βrace

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.5 2 2.5 3 3.5

βage

0

0.5

1

1.5

2

-1 0 1 2

βM1

0

0.5

1

1.5

0 1 2 3

βM2

0

0.5

1

1.5

0 1 2 3

βM3

0

0.5

1

1.5

0 0.5 1 1.5 2

βIM

0

0.5

1

1.5

2

0.7 0.8 0.9 1 1.1

ζ

0

2

4

6

8

10

12

14

VAFC (p = 4)

Tan & Nott (2016)

Figure 7: Marginal posterior distributions of components of β and ζ using the method of Tanand Nott (2016) and VAFC with p = 4.

-4 -2 0 2 4 6

Mean of Var Dist (VAFC)

-4

-2

0

2

4

6

Mean o

f V

ar

Dis

t (T

an &

Nott)

0 0.5 1 1.5 2

s.d. of Var Dist (VAFC)

0

0.5

1

1.5

2

s.d. of V

ar

Dis

t (T

an &

Nott)

Figure 8: Plot of variational posterior means (left) and standard deviations (right) of thesubject level random intercepts for VAFC with p = 4 against those for the method of Tanand Nott

Woodbury formula to compute the gradient estimates. In applications to logistic regression

and generalized linear mixed models the methods perform very well.

One difficulty in application of the presented method relates to the problem of choosing

a suitable number of factors. As mentioned in the examples, a useful and obvious heuristic

is to apply the method for an increasing sequence of values of p and to stop when inferences

of interest no longer change. In applications where a higher level of accuracy is needed it

19

Page 20: Gaussian variational approximation with a factor ...

will be important to go beyond Gaussian approximations of the type considered here, such

as using mixture or copula approximations and the recently developed variational boosting

approaches of Guo et al. (2016) and Miller et al. (2016) may be particularly useful in this

respect. It is also possible in the Gaussian case to combine factor structure with knowledge of

relevant conditional independence relationships in the model. There is room for much ingenu-

ity in exploiting the structure of the model itself for suggesting parsimonious and expressive

parametrizations of variational families for particular applications.

Acknowledgements

David Nott and Victor Ong were supported by a Singapore Ministry of Education Academic

Research Fund Tier 2 grant (R-155-000-143-112). We thank Linda Tan for helpful comments

on an earlier draft of the manuscript.

20

Page 21: Gaussian variational approximation with a factor ...

Appendix - derivation of gradient expressions

In this subsection we give a derivation of the gradient expressions (6)-(10). We consider

gradients for each term in (5) separately. We will make use of the following identity. If A, B

and C are conformably dimensioned matrices, then vec(ABC) = (CT ⊗ A)vec(B), where ⊗denotes the Kronecker product. Looking at the first term on the right in (5)

∇µEf (log h(µ+Bz + d ◦ ε)) = Ef (∇θ log h(µ+Bz + d ◦ ε)),

∇vec(B)Ef (log h(µ+Bz + d ◦ ε)) = Ef (∇vec(B) log h(µ+ (zT ⊗ I)vec(B) + d ◦ ε))

= Ef ((zT ⊗ I)T∇θ log h(µ+Bz + d ◦ ε))

= Ef ((z ⊗ I)∇θ log h(µ+Bz + d ◦ ε))

= vec(Ef (∇θ log h(µ+Bz + d ◦ ε)zT ))

or ∇BEf (log h(µ+Bz + d ◦ ε)) = Ef (∇θ log h(µ+Bz + d ◦ ε)zT ). Finally, writing d ◦ ε = Dε

and noting the symmetry of the way that Bz and Dε appear in the above expression we can

write

∇DEf (log h(µ+Bz + d ◦ ε)) =Ef (∇θ log h(µ+Bz + d ◦ ε)εT )

which gives ∇dEf (log h(µ+Bz + d ◦ ε)) = Ef (diag(∇θ log h(µ+Bz + d ◦ ε)εT )).

The second term on the right hand side of (5) is constant in the variational parameters and

hence can be neglected. Next, consider the third term. Here we use the following results from

matrix calculus (see, for example, Magnus and Neudecker (1999)). For a square invertible

matrix A, ∇A log|A|= A−1. Also, for A a m × p matrix, writed vec(AAT )d vec(A)

for the m2 ×mp

matrix where the (i, j)th entry is the derivative of the ith entry of vec(AAT ) with respect to

the jth entry of vec(A). Then

dvec(AAT )

dvec(A)= (I +Kmm)(A⊗ I)

where Kpm is the commutation matrix (Magnus and Neudecker, 1999) of dimensions pm×pmwhich satisfies Kpmvec(A) = vec(AT ). A useful property of the commutation matrix we

will need later is the following. If A is a p × m matrix, and C is an r × s matrix, then

Kpr(A⊗ C) = (C ⊗ A)Kms. We have

∇µEf

(1

2log|BBT +D2|

)= 0,

21

Page 22: Gaussian variational approximation with a factor ...

∇vec(B)Ef

(1

2log|BBT +D2|

)=

1

2{(I +Kmm)(B ⊗ I)}T vec((BBT +D2)−1)

=1

2

{(BT ⊗ I)vec((BBT +D2)−1)+

(BT ⊗ I)Kmmvec((BBT +D2)−1)}

=vec((BBT +D2)−1B)

and hence ∇BEf(12

log|BBT +D2|)

= (BBT + D2)−1B. Again noting the symmetry of the

way that BBT and appear we have ∇dEf(12

log|BBT +D2|)

= diag((BBT +D2)−1D).

Finally, consider the last term on the right of (5). We need the following product rule from

matrix differential calculus (again we refer the reader to Magnus and Neudecker (1999)). If

g(A) and k(A) are matrix-valued functions, conformably dimensioned, of the matrix A, then

∇Atr(f(A)Tk(A)) ={∇Atr(f(A)Tk(C)) +∇Atr(k(A)Tf(C))

}∣∣C=A

.

Using this result

∇BEf

(1

2tr((Bz + d ◦ ε)T (BBT +D2)−1(Bz + d ◦ ε))

)=

1

2Ef (T1 + T2) (12)

where

T1 ={∇Btr((Bz + d ◦ ε)(Bz + d ◦ ε)TCCT +D2)−1

}∣∣C=B

,

T2 ={∇Btr((BBT +D2)−1(Cz + d ◦ ε)(Cz + d ◦ ε)T )

}∣∣C=B

.

Evaluating T1 gives

T1 = vec−1(∇vec(B)((zT ⊗ I)vec(B) + d ◦ ε)T (CCT +D2)−1((zT ⊗ I)vec(B) + d ◦ ε))∣∣∣C=B

= vec−1(2(z ⊗ I)(CCT +D2)−1((zT ⊗ I)vec(B) + d ◦ ε))∣∣C=B

= 2(BBT +D2)−1(Bz + d ◦ ε)zT .

To evaluate T2, we need one further result. Write

d vec(A−1)

d vec(A)

for the matrix with (i, j)th entry given by the derivative of the ith entry of vec(A−1) with

22

Page 23: Gaussian variational approximation with a factor ...

respect to the jth entry of vec(A). Then

d vec(A−1)

d vec(A)= −(A−T ⊗ A−1)

We have

T2 = vec−1(∇vec(B)(Cz + d ◦ ε)T (BBT +D2)−1(Cz + d ◦ ε))∣∣∣C=B

= vec−1(∇vec(B)(Cz + d ◦ ε)T{

(Cz + d ◦ ε)T ⊗ I}

vec((BBT +D2)−1))∣∣∣C=B

=−

{{d vec(BBT +D2)

d vec(B)

}T {(BBT +D2)−1 ⊗ (BBT +D2)−1

}{(Cz + d ◦ ε)⊗ I} (Cz + d ◦ ε)}

}∣∣∣∣∣C=B

=− vec−1((BT ⊗ I)(I +Kqq)(BBT +D2)−1 ⊗ (BBT +D2)−1

(Cz + d ◦ ε)⊗ I(Cz + d ◦ ε)|C=B

=− vec−1((BT ⊗ I)(BBT +D2)−1 ⊗ (BBT +D2)−1(Cz + d ◦ ε)⊗ I(Cz + d ◦ ε))∣∣C=B

− vec−1(Kqq(I ⊗BT )(BBT +D2)−1 ⊗ (BBT +D2)−1(Cz + d ◦ ε)⊗ I(Cz + d ◦ ε))∣∣C=B

=− vec−1(BT (BBT +D2)−1(Cz + d ◦ ε)⊗ (BBT +D2)−1)∣∣C=B

− vec−1(Kqq(BBT +D2)−1(Cz + d ◦ ε)⊗BT (BBT +D2)−1(Cz + d ◦ ε))

∣∣C=B

=− 2 vec−1(vec(BT (BBT +D2)−1(Cz + d ◦ ε)(Cz + d ◦ ε)T (BBT +D2)−1))∣∣C=B

=− 2(BBT +D2)−1(Bz + d ◦ ε)(Bz + d ◦ ε)T (BBT +D2)−1B

Hence the required expression at (12) is

1

2Ef (T1 + T2) =Ef ((BB

T +D2)−1(Bz + d ◦ ε)zT

− (BBT +D2)−1(Bz + d ◦ ε)(Bz + d ◦ ε)T (BBT +D2)−1B).

Again noting the symmetry in the way that B and D appear there is immediately a similar

expression to (12) for the gradient with respect to D, and taking the diagonal gives the

appropriate gradient with respect to the vector d of diagonal elements.

Collecting all the previous results together for the terms in the lower bound (5) gives the

gradient expressions (6)-(10).

23

Page 24: Gaussian variational approximation with a factor ...

References

Archer, E., I. M. Park, L. Buesing, J. Cunningham, and L. Paninski (2016). Black box

variational inference for state space models. arXiv:1511.07367.

Attias, H. (1999). Inferring parameters and structure of latent variable models by variational

Bayes. In K. Laskey and H. Prade (Eds.), Proceedings of the 15th Conference on Uncertainty

in Artificial Intelligence, San Francisco, CA, pp. 21–30. Morgan Kaufmann.

Barber, D. and C. M. Bishop (1998). Ensemble learning for multi-layer networks. In M. I.

Jordan, M. J. Kearns, and S. A. Solla (Eds.), Advances in Neural Information Processing

Systems 10, pp. 395–401. MIT Press.

Bartholomew, D. J., M. Knott, and I. Moustaki (2011). Latent variable models and factor

analysis: A unified approach, 3rd edition. John Wiley & Sons.

Bottou, L. (2010). Large-scale machine learning with stochastic gradient descent. In

Y. Lechevallier and G. Saporta (Eds.), Proceedings of the 19th International Conference

on Computational Statistics (COMPSTAT’2010), pp. 177–187. Springer.

Carvalho, C. M., N. G. Polson, and J. G. Scott (2010). The horseshoe estimator for sparse

signals. Biometrika 97, 465–480.

Challis, E. and D. Barber (2013). Gaussian Kullback-Leibler approximate inference. Journal

of Machine Learning Research 14, 2239–2286.

Gelman, A., A. Jakulin, M. G. Pittau, and Y.-S. Su (2008). A weakly informative default prior

distribution for logistic and other regression models. The Annals of Applied Statistics 2 (4),

1360–1383.

Gershman, S., M. D. Hoffman, and D. M. Blei (2012). Nonparametric variational inference.

In Proceedings of the 29th International Conference on Machine Learning, ICML 2012.

Geweke, J. and G. Zhou (1996). Measuring the pricing error of the arbitrage pricing theory.

Review of Financial Studies 9 (2), 557–587.

Guo, F., X. Wang, T. Broderick, and D. B. Dunson (2016). Boosting variational inference.

arXiv: 1611.05559.

Han, S., X. Liao, D. B. Dunson, and L. C. Carin (2016). Variational Gaussian copula in-

ference. In A. Gretton and C. C. Robert (Eds.), Proceedings of the 19th International

24

Page 25: Gaussian variational approximation with a factor ...

Conference on Artificial Intelligence and Statistics, Volume 51, Cadiz, Spain, pp. 829–838.

JMLR Workshop and Conference Proceedings.

Hoffman, M. D., D. M. Blei, C. Wang, and J. Paisley (2013). Stochastic variational inference.

Journal of Machine Learning Research 14, 1303–1347.

Hosmer, D. W., S. Lemeshow, and R. X. Sturdivant (2013). Applied Logistic Regression (3

ed.). Hoboken, NJ: John Wiley & Sons, Inc.

Jaakkola, T. S. and M. I. Jordan (1998). Improving the mean field approximation via the use

of mixture distributions. In M. I. Jordan (Ed.), Learning in Graphical Models, pp. 163–173.

Dordrecht: Springer Netherlands.

Ji, C., H. Shen, and M. West (2010). Bounded approximations for marginal likelihoods.

Technical Report 10-05, Institute of Decision Sciences, Duke University.

Jordan, M. I., Z. Ghahramani, T. S. Jaakkola, and L. K. Saul (1999). An introduction to

variational methods for graphical models. Machine Learning 37, 183–233.

Kim, H. (2016). R package ‘discretization’ reference manual. https://CRAN.R-_project.

org/package=discretization.

Kingma, D. P. and M. Welling (2014). Auto-encoding variational Bayes. In Proceedings of

the 2nd International Conference on Learning Representations (ICLR).

Kucukelbir, A., D. Tran, R. Ranganath, A. Gelman, and D. M. Blei (2016). Automatic

differentiation variational inference. arXiv: 1603.00788.

Lichman, M. (2013). UCI machine learning repository. http://archive.ics.uci.edu/ml,

University of California, Irvine, School of Information and Computer Sciences.

Magnus, J. and H. Neudecker (1999). Matrix Differential Calculus with Applications in Statis-

tics and Econometrics. Wiley Series in Probability and Statistics. Wiley.

Miller, A. C., N. Foti, and R. P. Adams (2016). Variational boosting: Iteratively refining

posterior approximations. arXiv: 1611.06585.

Neville, S. E., J. T. Ormerod, and M. P. Wand (2014). Mean field variational Bayes for

continuous sparse signal shrinkage: Pitfalls and remedies. Electronic Journal of Statistics 8,

1113–1151.

25

Page 26: Gaussian variational approximation with a factor ...

Nott, D. J., S. L. Tan, M. Villani, and R. Kohn (2012). Regression density estimation with

variational methods and stochastic approximation. Journal of Computational and Graphical

Statistics 21, 797–820.

Opper, M. and C. Archambeau (2009). The variational Gaussian approximation revisited.

Neural Computation 21, 786–792.

Ormerod, J. T. and M. P. Wand (2010). Explaining variational approximations. The American

Statistician 64, 140–153.

Paisley, J. W., D. M. Blei, and M. I. Jordan (2012). Variational Bayesian inference with

stochastic search. In Proceedings of the 29th International Conference on Machine Learning

(ICML-12).

Ranganath, R., S. Gerrish, and D. M. Blei (2014). Black box variational inference. In S. Kaski

and J. Corander (Eds.), Proceedings of the 17th International Conference on Artificial In-

telligence and Statistics, Volume 33, Reykjavik, Iceland, pp. 814–822. JMLR Workshop and

Conference Proceedings.

Rezende, D. J., S. Mohamed, and D. Wierstra (2014). Stochastic backpropagation and ap-

proximate inference in deep generative models. In Proceedings of the 31st International

Conference on Machine Learning (ICML-14).

Robbins, H. and S. Monro (1951). A stochastic approximation method. The Annals of

Mathematical Statistics 22, 400–407.

Salimans, T. and D. A. Knowles (2013). Fixed-form variational posterior approximation

through stochastic linear regression. Bayesian Analysis 8, 837–882.

Seeger, M. (2000). Bayesian model selection for support vector machines, gaussian processes

and other kernel classifiers. In S. A. Solla, T. K. Leen, and K. Muller (Eds.), Advances in

Neural Information Processing Systems 12, pp. 603–609. MIT Press.

Stan Development Team (2016). Rstan: the r interface to stan, version 2.10.1. http://mc-_

stan.org.

Tan, L. S. L. and D. J. Nott (2016). Gaussian variational approximation with sparse precision

matrix. arXiv: 1605.05622.

26

Page 27: Gaussian variational approximation with a factor ...

Titsias, M. and M. Lazaro-Gredilla (2014). Doubly stochastic variational Bayes for non-

conjugate inference. In Proceedings of the 31st International Conference on Machine Learn-

ing (ICML-14), pp. 1971–1979.

Titsias, M. and M. Lazaro-Gredilla (2015). Local expectation gradients for black box varia-

tional inference. In C. Cortes, N. Lawrence, D. Lee, M. Sugiyama, and R. Garnett (Eds.),

Advances in Neural Information Processing Systems 28 (NIPS 2015).

Wang, B. and D. M. Titterington (2005). Inadequacy of interval estimates corresponding to

variational Bayesian approximations. In R. G. Cowell and G. Z (Eds.), Proceedings of the

10th International Workshop on Artificial Intelligence and Statistics, pp. 373–380. Society

for Artificial Intelligence and Statistics.

Winn, J. and C. M. Bishop (2005). Variational message passing. Journal of Machine Learning

Research 6, 661–694.

Zeiler, M. D. (2012). ADADELTA: An adaptive learning rate method. arXiv: 1212.5701.

27