22.3. More on Gaussian processes#
Inference using Gaussian processes#
Assume that there is a set of input vectors with independent, predictor, variables
and a set of target values
Note that we will use the symbol \(t\) to denote the target, or response, variables in the context of Gaussian Processes. Here we will consider single, scalar outputs \(t^{(i)}\). The extension to vector outputs \(\boldsymbol{t}^{(i)}\) is straightforward.
Furthermore, we will use the subscript \(N\) to denote a set of \(N\) vectors (or scalars): \(\boldsymbol{X}_N\) (\(\boldsymbol{t}_N\)),
β¦ while a single instance \(i\) is denoted by a superscript: \(\boldsymbol{x}^{(i)}\) (\(t^{(i)}\)).
Notation
We will use the notation \(\mathcal{D}_N = [\boldsymbol{X}_N, \boldsymbol{t}_N]\) for the data.
Note that a target is always associated with an input vector. When our focus is on the prediction of targets, we sometimes write \(p(\boldsymbol{t}_N)\) without including \(\boldsymbol{X}_N\) explcitly.
We will consider two different inference problems:
The prediction of a new target \(t^{(N+1)}\) given the data \(\mathcal{D}_N\) and a new input \(\boldsymbol{x}^{(N+1)}\).
The inference of a model function \(y(\boldsymbol{x})\) from the data \(\mathcal{D}_N\).
The former can be expressed with the pdf
while the latter can be written using Bayesβ formula (in these notes we will not be including information \(I\) explicitly in the conditional probabilities)
The inference of a function will obviously also allow to make predictions for new targets. However, we will need to consider in particular the second term in the numerator, which is the prior distribution on functions assumed in the model.
This prior is implicit in parametric models with priors on the parameters.
The idea of Gaussian process modeling is to put a prior directly on the space of functions without parameterizing \(y(\boldsymbol{x})\).
A Gaussian process can be thought of as a generalization of a Gaussian distribution over a finite vector space to a function space of infinite dimension.
Just as a Gaussian distribution is specified by its mean and covariance matrix, a Gaussian process is specified by a mean and covariance function.
Gaussian process. A Gaussian process is a stochastic process (a collection of random variables indexed by time or space), such that every finite collection of those random variables has a multivariate normal distribution
References:#
Gaussian Processes for Machine Learning, Carl Edward Rasmussen and Chris Williams [RW05], online version.
GPy: a Gaussian Process (GP) framework written in python, from the Sheffield machine learning group.
Parametric approach#
Let us express \(y(\boldsymbol{x})\) in terms of a model function \(y(\boldsymbol{x}; \boldsymbol{\theta})\) that depends on a vector of model parameters \(\boldsymbol{\theta}\).
For example, using a set of basis functions \(\left\{ \phi_{h} (\boldsymbol{x}) \right\}_{h=1}^H\) with linear weights \(\boldsymbol{\theta} \in \mathbb{R}^H\) we have
Notice. The basis functions can be non-linear in \(\boldsymbol{x}\) such as Gaussians (aka radial basis functions). Still, this constitutes a linear model since \(y (\boldsymbol{x}, \boldsymbol{\theta})\) depends linearly on the parameters \(\boldsymbol{\theta}\).
The inference of model parameters should be a well-known problem by now. We state it in terms of Bayes theorem
Having solved this inference problem (note that the likelihood is Gaussian, cf linear regression) a prediction can be made through marginalization
Here it is important to note that the final answer does not make any explicit reference to our parametric representation of the unknown function \(y(\boldsymbol{x})\).
Assuming that we have a fixed set of basis functions and Gaussian prior distributions (with zero mean) on the weights \(\boldsymbol{\theta}\) we will show that:
The joint pdf of the observed data given the model \(p( \mathcal{D}_N)\), is a multivariate Gaussian with mean zero and with a covariance matrix that is determined by the basis functions.
This implies that the conditional distribution \(p( t^{(N+1)} | \mathcal{D}_N, \boldsymbol{X}_{N+1})\), is also a multivariate Gaussian whose mean depends linearly on \(\boldsymbol{t}_N\).
Sum of normally distributed random variables.
If \(X\) and \(Y\) are independent random variables that are normally distributed (and therefore also jointly so), then their sum is also normally distributed. i.e., \(Z=X+Y\) is normally distributed with its mean being the sum of the two means, and its variance being the sum of the two variances.
Consider the linear model and define the \(N \times H\) design matrix \(\boldsymbol{R}\) with elements
Then \(\boldsymbol{y}_N = \boldsymbol{R} \boldsymbol{\theta}\) is the vector of model predictions, i.e.
Assume that we have a Gaussian prior for the linear model weights \(\boldsymbol{\theta}\) with zero mean and a diagonal covariance matrix
Now, since \(y\) is a linear function of \(\boldsymbol{\theta}\), it is also Gaussian distributed with mean zero. Its covariance matrix becomes
which implies that
This will be true for any set of points \(\boldsymbol{X}_N\); which is the defining property of a Gaussian process.
What about the target values \(\boldsymbol{t}_N\)?
Well, if \(t^{(n)}\) is assumed to differ by additive Gaussian noise, i.e.,
where \(\varepsilon^{(n)} \sim \mathcal{N} \left( 0, \sigma_\nu^2 \right)\); then \(\boldsymbol{t}_N\) also has a Gaussian distribution
where the covariance matrix of this target distribution is given by
The covariance matrix as the central object#
The covariance matrices are given by
and
This means that the correlation between target values \(t^{(n)}\) and \(t^{(n')}\) is determined by the points \(\boldsymbol{x}^{(n)}\), \(\boldsymbol{x}^{(n')}\) and the behaviour of the basis functions.
Non-parametric approach: Mean and covariance functions#
In fact, we donβt really need the basis functions and their parameters anymore. The influence of these appear only in the covariance matrix that describes the distribution of the targets, which is our key object. We can replace the parametric model altogether with a covariance function \(C( \boldsymbol{x}, \boldsymbol{x}' )\) which generates the elements of the covariance matrix
for any set of points \(\left\{ \boldsymbol{x}^{(n)} \right\}_{n=1}^N\).
Note, however, that \(\boldsymbol{Q}\) must be positive-definite. This constrains the set of valid covariance functions.
Once we have defined a covariance function, the covariance matrix for the target values will be given by
A wide range of different covariance contributions can be constructed. These standard covariance functions are typically parametrized with hyperparameters \(\boldsymbol{\alpha}\) so that
where \(\Delta\) is often included as a flexible white noise component. It is usually good practice to include a small white noise term, \(\Delta = \sigma_\nu^2 \ll 1\), even if your data has negligible errors, since it helps with numerical stability and making sure that your covariance matrix is positive definite.
Stationary kernels#
The most common types of covariance functions are stationary, or translationally invariant, which implies that
where the function \(D\) is often referred to as a kernel. Note that the \((\boldsymbol{x} - \boldsymbol{x}')\)-dependence must be such that the kernel is symmetric.
A very standard kernel is the RBF (radial basis function, but also known as Exponentiated Quadratic or Gaussian kernel) which is differentiable infinitely many times (hence, very smooth),
where \(p\) denotes the dimensionality of the input space (i.e., \(\mathbf{x} \in \mathbb{R}^p\)). The hyperparameters of the RBF kernel, \(\boldsymbol{\alpha} = \vec{l}\), are known as the correlation length(s). Sometimes, a single correlation length \(l_i=l\) is used for all dimensions.
Different kernels can be combined to build the most relevant covariance function. For example, the RBF kernel is often multiplied by a constant kernel (which then becomes known as signal noise) followed by the addition of a diagonal white noise kernel. This would result in
with the complete set of hyperparameters \(\boldsymbol{\alpha} = \{ \sigma_\nu^2, \sigma_f^2, \vec{l} \}\) known as the white noise variance, signal variance, and RBF correlation length(s).
GP models for regression#
Let us return to the problem of predicting \(t^{(N+1)}\) given \(\boldsymbol{t}_N\). The independent variables \(\boldsymbol{X}_{N+1}\) are also given, but will be omitted from the conditional pdfs below.
The joint density is
First, let us note that \(\boldsymbol{t}_{N+1} = \left\{ \boldsymbol{t}_N, t^{(N+1)} \right\}\) such that \(p \left( t^{(N+1)}, \boldsymbol{t}_N \right) = p \left( \boldsymbol{t}_{N+1} \right)\).
Since both \(p \left( \boldsymbol{t}_{N+1} \right)\) and \(p \left( \boldsymbol{t}_N \right)\) are Gaussian distributions, then the conditional distribution, obtained by the ratio, must also be a Gaussian. Let us use the notation \(\boldsymbol{C}_{N+1}\) for the \((N+1) \times (N+1)\) covariance matrix for \(\boldsymbol{t}_{N+1}\). This implies that
Summary
The prediction of the (Gaussian) pdf for \(t^{(N+1)}\) requires an inversion of the covariance matrix \(\boldsymbol{C}_{N+1}\).
Elegant linear algebra tricks to obtain \(\boldsymbol{C}_{N+1}^{-1}\)#
Let us split the \(\boldsymbol{C}_{N+1}\) covariance matrix into four different blocks
where \(\boldsymbol{C}_N\) is the \(N \times N\) covariance matrix (which depends on the positions \(\boldsymbol{X}_N\)), \(\boldsymbol{k}\) is an \(N \times 1\) vector (that describes the covariance of \(\boldsymbol{X}_N\) with \(\boldsymbol{x}^{(N+1)}\)), while \(\kappa\) is the single diagonal element obtained from \(\boldsymbol{x}^{(N+1)}\).
We can use the partitioned inverse equations (Barnett, 1979) to rewrite \(\boldsymbol{C}_{N+1}^{-1}\) in terms of \(\boldsymbol{C}_{N}^{-1}\) and \(\boldsymbol{C}_{N+1}\) as follows
where
Question
Check that the dimensions of the different blocks are correct.
The prediction for \(t^{(N+1)}\) is a Gaussian
which can be written as a univariate Gaussian (see below).
A new target prediction using a GP
The prediction for \(t^{(N+1)}\) is a Gaussian
The mean and variance are obtained from (22.29) after some algebra
This implies that we can make a prediction for the Gaussian pdf of \(t^{(N+1)}\) (meaning that we predict its value with an associated uncertainty) for an \(N^3\) computational cost (the inversion of an \(N \times N\) matrix).
In fact, since the prediction only depends on the \(N\) available data we might as well predict several new target values at once. Consider \(\boldsymbol{t}_M = \{ t^{(N+i)} \}_{i=1}^M\) so that
where \(\boldsymbol{k}\) is now an \(N \times M\) matrix and \(\boldsymbol{\kappa}\) an \(M \times M\) matrix.
Many new target predictions using a GP
The prediction for \(M\) new targets \(\boldsymbol{t}_M\) becomes a multivariate Gaussian
where the \(M \times 1\) mean vector and \(M \times M\) covariance matrix are
Choosing the GP model hyperparameters#
Predictions can be made once we have
Chosen an appropriate covariance function.
Determined the hyperparameters.
Evaluated the relevant blocks in the covariance function and inverted \(\boldsymbol{C}_N\).
How do we determine the hyperparameters \(\boldsymbol{\alpha}\)? Well, recall that
This pdf is basically a data likelihood.
The simplest approach is therefore to find the set of hyperparameters \(\boldsymbol{\alpha}^*\) that maximizes the data likelihood, i.e.,
A Bayesian approach would be to assign a prior to the hyperparameters and seek a posterior pdf \(p(\boldsymbol{\alpha} | \boldsymbol{t}_N)\) instead which is then propagated using marginalization
The optimization approach is absolutely dominating the literature on GP regression. The data likelihood is maximized with respect to the hyperparameters and the resulting covariance function is then used for regression. The second approach gives a better quantification of the uncertainties, but is more computationally demanding.