Sparse Variational Gaussian Processes#
Exact Gaussian process regression factors an \(n\times n\) covariance matrix. The resulting \(\mathcal{O}(n^3)\) time and \(\mathcal{O}(n^2)\) storage costs become prohibitive as the number of observations \(n\) grows. A sparse variational Gaussian process retains the Gaussian process prior and approximates its posterior through \(m\ll n\) inducing variables. Titsias introduced this variational inducing-point construction for regression, and Hensman, Fusi, and Lawrence developed the stochastic formulation used for minibatches (Hensman et al., 2013; Titsias, 2009).
Inducing variables#
Let \(\mathcal{X}\) be the input space, let \(X=(\mathbf{x}_1,\ldots,\mathbf{x}_n)\) with \(\mathbf{x}_i\in\mathcal{X}\) be the training inputs, let \(\mathbf{y}=(y_1,\ldots,y_n)^{\mathsf T}\) be the observations, and place the prior
on the latent function, where \(k:\mathcal{X}\times\mathcal{X}\to\mathbb{R}\) is the covariance kernel. Define \(\mathbf{f}=(f_1,\ldots,f_n)^{\mathsf T}\), where \(f_i=f(\mathbf{x}_i)\), and assume that observations are conditionally independent:
Gaussian regression, for example, uses \(p(y_i\mid f_i)=\mathcal{N}(y_i\mid f_i,\sigma_n^2)\). We write \(I_s\) for the \(s\times s\) identity matrix.
Choose inducing inputs \(Z=(\mathbf{z}_1,\ldots,\mathbf{z}_m)\) in the same input space as \(X\) and define the inducing variables
Write \(K_{nn}=k(X,X)\), \(K_{nm}=k(X,Z)\), \(K_{mn}=K_{nm}^{\mathsf T}\), and \(K_{mm}=k(Z,Z)\); for example, \((K_{nm})_{ij}=k(\mathbf{x}_i,\mathbf{z}_j)\). These four matrices have sizes \(n\times n\), \(n\times m\), \(m\times n\), and \(m\times m\), respectively. Assuming that \(K_{mm}\) is positive definite, the GP prior gives
Gaussian conditioning then gives
In particular, the marginal prior of the inducing variables is \(p(\mathbf{u})=\mathcal{N}(\mathbf{0},K_{mm})\).
The inducing variables describe the part of the latent function represented by the selected locations. The conditional covariance retains the uncertainty that remains after their values are known. The formulas use inverse notation; implementations use a Cholesky factorization and linear solves, usually with a small diagonal jitter for numerical stability.
Variational posterior#
We approximate the posterior over the inducing variables with
where \(\boldsymbol{\mu}_u\in\mathbb{R}^m\) and the symmetric positive-definite matrix \(\Sigma_u\in\mathbb{R}^{m\times m}\) are variational parameters. The joint approximation preserves the exact GP conditional:
Marginalizing \(\mathbf{u}\) gives a Gaussian distribution over the training values with
The same construction gives predictions. For test inputs \(X_*=(\mathbf{x}_{*1},\ldots,\mathbf{x}_{*r})\), let \(\mathbf{f}_*=(f(\mathbf{x}_{*1}),\ldots,f(\mathbf{x}_{*r}))^{\mathsf T}\) and define \(K_{*m}=k(X_*,Z)\), \(K_{m*}=K_{*m}^{\mathsf T}\), and \(K_{**}=k(X_*,X_*)\). Then
These expressions describe the latent function. For Gaussian regression, the predictive distribution of a noisy observation adds \(\sigma_n^2 I_r\) to the latent covariance.
Evidence lower bound#
The Kullback–Leibler divergence from a density \(q\) to a density \(p\) is
Using the factorization \(p(\mathbf{y},\mathbf{f},\mathbf{u}) =p(\mathbf{y}\mid\mathbf{f})p(\mathbf{f}\mid\mathbf{u})p(\mathbf{u})\) and applying Jensen’s inequality with \(q(\mathbf{f},\mathbf{u})\) gives the evidence lower bound (ELBO)
where \(q(f_i)\) is the one-dimensional marginal of \(q(\mathbf{f})\). For fixed model parameters and inducing inputs, the gap satisfies
Maximizing the ELBO therefore brings the approximate joint posterior closer to the exact joint posterior in this direction of Kullback–Leibler divergence.
Gaussian regression#
The Gaussian likelihood permits an analytic optimization over the variational distribution. Define
For fixed kernel parameters and inducing inputs, the maximizing Gaussian has
Substituting this distribution into the ELBO gives the collapsed Titsias bound (Titsias, 2009):
The trace penalty measures the prior variance not represented by the inducing variables. When \(m=n\) and \(Z=X\), we have \(Q_{nn}=K_{nn}\), the penalty vanishes, and the bound recovers exact Gaussian process regression without a computational saving. Evaluating the collapsed bound for all observations costs \(\mathcal{O}(nm^2+m^3)\) time with dense matrices.
For a non-Gaussian likelihood, the optimal Gaussian \(q(\mathbf{u})\) is generally unavailable in closed form, and the expected log likelihood can be evaluated with one-dimensional numerical quadrature (Hensman et al., 2015). Retaining \(\boldsymbol{\mu}_u\) and \(\Sigma_u\) as explicit parameters also produces the separable objective needed for stochastic optimization (Hensman et al., 2013).
Minibatches and computational cost#
Let \(B\) be a uniformly sampled minibatch of \(b\) observations. Replacing the data term by its scaled minibatch estimate gives
The estimator satisfies \(\mathbb{E}_B[\widehat{\mathcal{L}}_B]=\mathcal{L}\). The factor \(n/b\) scales only the sampled data term; the global Kullback–Leibler term appears once.
With dense matrices, a typical update costs \(\mathcal{O}(m^3+bm^2)\) time and stores \(\mathcal{O}(m^2+bm)\) working quantities, in addition to the data set (Sun et al., 2021). The cubic term comes from operations on the \(m\times m\) inducing covariance or variational covariance, while the batch term evaluates the required marginal means and variances. These working costs depend on \(n\) only through the chosen minibatch size. The variational parameters, inducing locations, kernel parameters, and likelihood parameters can be optimized together.
The number and placement of inducing inputs determine the approximation–cost tradeoff. Increasing \(m\) generally gives a more flexible approximation and increases the computational cost. Independent predictive diagnostics remain necessary because a high ELBO alone does not establish that the surrogate is accurate for its intended scientific use.
Exercise#
Use the laws of total expectation and total covariance to derive the mean and covariance of \(q(\mathbf{f})\). Then verify that the scaled minibatch objective is unbiased and explain why its Kullback–Leibler term is not multiplied by \(n/b\). For Gaussian regression, examine the limiting choice \(m=n\) and \(Z=X\).
The following notebook applies the sparse variational construction to the autoinjector data and evaluates its predictions with the diagnostics used for the exact Gaussian process surrogate.