Skip to contents

A Gaussian process is a stochastic process that assumes that the outputs for any set of input points follows a multivariate normal distribution. To determine the normal distribution, we must select a mean function that gives a mean for each point and a covariance function that gives the covariance between any set of points.

Thus if we have mean function μ\mu, covariance function Σ\Sigma, and the n×dn \times d matrix X with the input vectors 𝐱𝟏,...,𝐱𝐧\mathbf{x_1}, ..., \mathbf{x_n} in its rows, then distribution of the output at these points, 𝐲=[y1,,yn]T\mathbf{y} = [y_1, \ldots, y_n]^T is given by:

𝐲N(μ(X),Σ(X)) \mathbf{y} \sim N(\mu(X),~ \Sigma(X))

Or in full element notation:

[y1yn]N([μ(𝐱𝟏)μ(𝐱𝐧)],[Σ(𝐱𝟏,𝐱𝟏)Σ(𝐱𝟏,𝐱𝐧)Σ(𝐱𝐧,𝐱𝟏)Σ(𝐱𝐧,𝐱𝐧)]) \begin{bmatrix} y_1 \\ \vdots \\ y_n \end{bmatrix} \sim N(\begin{bmatrix} \mu(\mathbf{x_1}) \\ \vdots \\ \mu(\mathbf{x_n}) \end{bmatrix}, \begin{bmatrix} \Sigma(\mathbf{x_1},\mathbf{x_1}) &\cdots &\Sigma(\mathbf{x_1},\mathbf{x_n}) \\ \vdots &\ddots &\vdots \\ \Sigma(\mathbf{x_n},\mathbf{x_1}) &\cdots &\Sigma(\mathbf{x_n},\mathbf{x_n}) \end{bmatrix})

Mean function μ\mu

The mean function can be any function mapping the input space to the real numbers. The most commonly used mean function is a constant, so μ(𝐱)=μ\mu(\mathbf{x}) = \mu. This means that over the entire space the predicted mean given no other information a constant. When fitting a GP model to data, μ\mu is usually estimated using the data. Another commonly used mean function is zero. This works surprisingly well since the GP will interpolated between your data, meaning that the mean function work have much of an effect when there is enough data. A note on notation: for a vector uu, μ(u)\mu(u) is sometimes written as μu\mu_u for simplicity. For a matrix XX, μ(X)=μX\mu(X)=\mu_X is the vector obtained from applying μ\mu to each row of XX.

A more advanced choice of mean function is to use a linear model, so μ(𝐱)=β0+i=1dβixi\mu(\mathbf{x}) = \beta_0 + \sum_{i=1}^d \beta_i x_i. Again these parameters must be estimated. This can be generalized to a linear combination of functions of the input data, f1,,fmf_1, \ldots, f_m so the mean function is μ(𝐱)=β0+i=1mβifi(𝐱)\mu(\mathbf{x}) = \beta_0 + \sum_{i=1}^m \beta_i f_i(\mathbf{x}).

It is generally recommended to just use a constant mean since the data itself should provide enough information to fit the true function. Some researchers say that using a linear model can have negative effects on fitting a good model.

Covariance function Σ\Sigma

The covariance function determines how strong the correlation is between points. A note on notation: the covariance/correlation functions are heavily overloaded, meaning that their meaning depends on the context. For vectors uu and vv, Σ(u,v)\Sigma(u,v) is the covariance between the points, which is also sometimes written as Σu,v\Sigma_{u,v} or Σuv\Sigma_{uv}. Σ(u)\Sigma(u) or Σu\Sigma_u is the same thing as the covariance of uu with itself, or Σ(u,u)\Sigma(u,u). For a matrix XX, Σ(X,u)\Sigma(X,u) or ΣXu\Sigma_{Xu} is a column vector whose elements are the covariance of the rows of XX with uu. For another matrix WW, Σ(X,W)\Sigma(X, W) is a matrix whose (i,j)(i,j) element is the covariance of the ii row of XX and the jj row of WW. Σ(X)\Sigma(X) or ΣX\Sigma_X means the same thing as Σ(X,X)\Sigma(X,X).

Often a correlation function, RR, is used instead of a covariance function. The correlation function should map any pair of points to [0,1][0,1]. The correlation for any point with itself should be 1, i.e. R(𝐱,𝐱)=1R(\mathbf{x}, \mathbf{x}) = 1. When a correlation function is used, a variance parameter σ2\sigma^2 must be estimated to scale the correlation matrix into a covariance matrix. Thus the covariance matrix is C(X)=σ̂2R(X)C(X) = \hat{\sigma}^2 R(X). RR is overloaded similarly to Σ\Sigma.

Gaussian correlation

The most commonly used correlation function is the Gaussian.

R(𝐮,𝐯)=exp(i=1dθi(uivi)2) R(\mathbf{u}, \mathbf{v}) = \exp \left( -\sum_{i=1}^d \theta_i (u_i - v_i)^2 \right)

The parameters 𝛉=(θ1,,θd)\mathbf{\theta} = (\theta_1, \ldots, \theta_d) are the correlation parameters for each dimensions. Generally they must be estimated from the data when fitting a Gaussian process model to data.

Likelihood function and parameter estimation

The parameters are often estimated by finding the parameters that maximize the likelihood given a data set.

The likelihood function is the usual multivariate normal pdf shown below, where 𝛍=μ(X)\mathbf{\mu} = \mu(X), Σ=Σ(X)\Sigma = \Sigma(X)

f(𝛉;X,𝐲)=f(X,𝐲;𝛉)=1(2π)n/2|Σ|1/2exp(12(𝐲𝛍)TΣ1(𝐲𝛍)) f(\mathbf{\theta};~X,~\mathbf{y}) = f(X,~\mathbf{y};~\mathbf{\theta}) = \frac{1}{(2 \pi)^{n/2} |\Sigma|^{1/2} } \exp{(-\frac{1}{2} (\mathbf{y} - \mathbf{\mu})^T \Sigma^{-1} (\mathbf{y} - \mathbf{\mu}))}

As usual, we use negative two times the log-likelihood for simplicity, ignoring the constant terms.

(θ)=ln|Σ|+(𝐲𝛍)TΣ1(𝐲𝛍) \ell(\theta) = \ln |\Sigma| + (\mathbf{y} - \mathbf{\mu})^T \Sigma^{-1} (\mathbf{y} - \mathbf{\mu})

This equation is minimized as a function of the correlation parameters to find the parameters that give the greatest likelihood. Since there is a determinant and matrix solve, this is an expensive function to optimize, with each evaluation being O(n3)O(n^3)

Estimate for constant μ\mu

If the mean is set to be constant, μ(X)=μ𝟏𝐧\mu(X) = \mu \mathbf{1_n}, then there is a single parameter μ\mu to estimate. Differentiating \ell with respect to μ\mu will then give ddμ=𝟏𝐧TΣ1(𝐲μ𝟏𝐧) \frac{d \ell}{d \mu} = \mathbf{1_n}^T \Sigma^{-1}(\mathbf{y} - \mu \mathbf{1_n}) Setting this equal to zero and solving for μ\mu gives the maximum likelihood estimate μ̂\hat{\mu}μ̂=𝟏𝐧TΣ1𝐲𝟏𝐧TΣ1𝟏𝐧 \hat{\mu} = \frac{\mathbf{1_n}^T \Sigma^{-1}\mathbf{y}}{\mathbf{1_n}^T \Sigma^{-1}\mathbf{1_n}}

Estimate for σ\sigma

When using a correlation matrix so that Σ=σ2R\Sigma = \sigma^2 R, σ\sigma must be estimated using maximum likelihood.

ddσ2=nσ21σ4(𝐲𝛍)TR1(𝐲𝛍) \frac{d \ell}{d \sigma^2} = \frac{n}{\sigma^2} - \frac{1}{\sigma^4}(\mathbf{y} - \mathbf{\mu})^T R^{-1} (\mathbf{y} - \mathbf{\mu}) Setting equal to zero and solving for σ2\sigma^2 gives σ̂2=1n(𝐲𝛍)TR1(𝐲𝛍) \hat{\sigma}^2 = \frac{1}{n} (\mathbf{y} - \mathbf{\mu})^T R^{-1} (\mathbf{y} - \mathbf{\mu}) When estimating μ\mu and σ2\sigma^2 simultaneously, these estimates are valid and the estimate can simply be plugged into the equation.

Prediction of new points

Conditional distribution

Suppose there are vectors 𝐲𝟏\mathbf{y_1} and 𝐲𝟐\mathbf{y_2} that are jointly multivariate normal. The joint distribution is [𝐲𝟏𝐲𝟐]N([𝛍𝟏𝛍𝟐],[Σ11Σ12Σ21Σ22]) \begin{bmatrix} \mathbf{y_1} \\ \mathbf{y_2} \end{bmatrix} \sim N( \begin{bmatrix} \mathbf{\mu_1} \\ \mathbf{\mu_2} \end{bmatrix}, ~\begin{bmatrix} \Sigma_{11} \Sigma_{12} \\ \Sigma_{21} \Sigma_{22} \end{bmatrix} )

The conditional distribution of 𝐲𝟏\mathbf{y_1} given 𝐲𝟐\mathbf{y_2} is

𝐲𝟏|𝐲𝟐N(𝛍𝟏+Σ12Σ221(𝐲𝟐𝛍𝟐)),Σ11Σ12Σ221Σ21)\mathbf{y_1} ~|~\mathbf{y_2} \sim N(\mathbf{\mu_1} + \Sigma_{12} \Sigma_{22}^{-1}( \mathbf{y_2} - \mathbf{\mu_2})), ~\Sigma_{11} - \Sigma_{12}\Sigma_{22}^{-1}\Sigma_{21})

Predicting

Suppose there are two input matrices, X1X_1 and X2X_2, whose rows are the input points, with corresponding output vectors 𝐲𝟏\mathbf{y_1} and 𝐲𝟐\mathbf{y_2}. Suppose we have the actual values for 𝐲𝟐\mathbf{y_2}, and want to estimate, or predict, 𝐲𝟏\mathbf{y_1}. We can use the conditional distribution above to get a posterior distribution for 𝐲𝟏\mathbf{y_1}.

If we only want to predict for a single point, i.e. we want to predict the output yy at 𝐱\mathbf{x}, then this equation gives

y|𝐲𝟐N(ŷ,σ̂2(y))y ~|~\mathbf{y_2} \sim N(\hat{y}, ~\hat{\sigma}^2(y)) where ŷ=μ̂+R(𝐱,X2)R(X2)1(𝐲𝟐μ𝟏𝐧)) \hat{y} = \hat{\mu} + R(\mathbf{x},~X_2) R(X_2)^{-1}( \mathbf{y_2} - \mu\mathbf{1_n})) and σ̂2(y)=R(𝐱)R(𝐱,X2)R(X2)1R(X2,𝐱) \hat{\sigma}^2(y) = R(\mathbf{x}) - R(\mathbf{x},~X_2) R(X_2)^{-1} R(X_2,~\mathbf{x})

Notice we get an estimate not only for the value of yy, but also the standard error. This can be useful when we need a way to judge the prediction accuracy of the model.