Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Gaussian Regression with the Elliptical Slice Sampler

Given a vector of obervations y\mathbf{y} with known variance σ2I\sigma^2\mathbb{I} and Gaussian likelihood, we model the mean parameter of these observations as a Gaussian process given input/feature matrix X\mathbf{X}

y∣f∼N(f,σ2I)f∼GP(0,Σ),\begin{align*} \mathbf{y}|\mathbf{f} &\sim N(\mathbf{f}, \sigma^2\mathbb{I}) \\ \mathbf{f} &\sim GP(0, \Sigma), \end{align*}

where Σ\Sigma is a covariance function of the feature vector derived from the squared exponential kernel. Thus, for any pair of observations ii and jj the covariance of these two observations is given by

Σi,j=σf2exp⁡(−∣∣Xi,⋅−Xj,⋅∣∣22l2)\Sigma_{i,j} = \sigma^2_f \exp\left(-\frac{||\mathbf{X}_{i, \cdot} - \mathbf{X}_{j, \cdot}||^2}{2 l^2}\right)

for some lengthscale parameter ll and signal variance parameter σf2\sigma_f^2.

In this example we will limit our analysis to the posterior distribution of the mean parameter f\mathbf{f}, by conjugacy the posterior is Gaussian with mean and covariance

f∣y∼N(μf,Σf)Σf−1=Σ−1+σ−2Iμf=σ−2Σfy.\begin{align*} \mathbf{f}|\mathbf{y} &\sim N(\mu_f, \Sigma_f) \\ \Sigma_f^{-1} &= \Sigma^{-1} + \sigma^{-2}\mathbf{I} \\ \mu_f &= \sigma^{-2} \Sigma_f \mathbf{y}. \end{align*}

Using this analytic result we can check the correct convergence of our sampler towards the posterior distribution. It is important to note, however, that the Elliptical Slice sampler can be used to sample from any vector of parameters so long as these parameters have a prior Multivariate Gaussian distribution.

Notebook Cell

We fix the lengthscale ll, signal variance σf2\sigma_f^2 and likelihood variance σ2\sigma^2 parameters to 1. and generate data from the model described above. Deliberately, we set a large value (2000) for the dimension of the target variable f\mathbf{f} to showcase the gradient-free Elliptical Slice sampler on a situation where its efficiency is apparent in comparison to gradient-based black box samplers such as NUTS. The dynamics of the sampler are equivalent to those of the preconditioned Crank–Nicolson algorithm (with its Metropolis-Hastings step replaced by a slice sampling step), thus making it robust to increasing dimensionality.

Source
<Figure size 800x500 with 1 Axes>

Sampling

The Elliptical Slice sampler samples a latent parameter from the Gaussian prior, builds an ellipse passing though the previous position and the latent variable, and samples points from this ellipse which it then corrects for the likelihood using slice sampling. More details can be found in the original paper Murray et al., 2010.

We compare the sampling time to NUTS, notice the difference in computation times. A couple of important considerations when using the elliptical slice sampler:

CPU times: user 3.83 s, sys: 77.3 ms, total: 3.9 s
Wall time: 2.28 s
CPU times: user 14.5 s, sys: 467 ms, total: 15 s
Wall time: 9.26 s

We check that the sampler is targeting the correct distribution by comparing the sample’s mean and covariance to the conjugate results, and plotting the predictive distribution of our samples over the real observations.

Mean squared error for the mean vector 0.00020767493697348982 and covariance matrix 1.3208487814608816e-07
Source
<Figure size 800x500 with 1 Axes>

Diagnostics

The Elliptical slice sampler does not have a Metropolis-Hastings step, at every iteration it proposes a new position using slice sampling on the likelihood. The sampler is more efficient the less informative the likelihood is in comparison to the prior.

Assuming the degenerate case when the likelihood is always equal to 1 (infinite variance, not informative), we have that the slice sampler will always accept the first point it samples from the ellipsis, hence the number of sub iterations per iteration of the sampler will always be 1. To see this, notice that all the points on the ellipsis keep the joint distribution given by the prior measure for the target variable f\mathbf{f} and the same measure but for the latent variable, invariant. We can get an idea of how efficient the sampler is by looking at the number of sub iterations per iteration of the sampler, below we plot a histogram for our current example.

Another parameter of interest for diagnostics is the location on the ellipse the returned sample is from. This parameter, dubbed theta, is expressed in radians hence putting it on the interval [−2π,2π][-2\pi, 2\pi] (i.e. moving around the ellipse clockwise for positive numbers and counter clockwise for negative numbers). If theta ∈{0,−2π,2π}\in \{0, -2\pi, 2\pi\} we are at the initial position of the iteration, i.e. the closer theta is to any of these three values the closer the new sample is to the previous one. A histogram for this parameter is plotted below.

Since the likelihood’s variance is set at 1., it is quite informative. Increasing the likelihood’s variance leads to less sub iterations per iteration of the Elliptical Slice sampler and the parameter theta becoming more uniform on its range.

Source
<Figure size 1000x500 with 1 Axes>
Source
<Figure size 1000x500 with 1 Axes>
References
  1. Murray, I., Adams, R. P., & MacKay, D. J. C. (2010). Elliptical slice sampling. arXiv. 10.48550/ARXIV.1001.0175