Introduction to Gaussian Processes
Collin Erickson
2026-05-11
Source:vignettes/IntroductionToGPs.Rmd
IntroductionToGPs.RmdA 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 , covariance function , and the matrix X with the input vectors in its rows, then distribution of the output at these points, is given by:
Or in full element notation:
Mean function
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 . This means that over the entire space the predicted mean given no other information a constant. When fitting a GP model to data, 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 , is sometimes written as for simplicity. For a matrix , is the vector obtained from applying to each row of .
A more advanced choice of mean function is to use a linear model, so . Again these parameters must be estimated. This can be generalized to a linear combination of functions of the input data, so the mean function is .
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
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 and , is the covariance between the points, which is also sometimes written as or . or is the same thing as the covariance of with itself, or . For a matrix , or is a column vector whose elements are the covariance of the rows of with . For another matrix , is a matrix whose element is the covariance of the row of and the row of . or means the same thing as .
Often a correlation function, , is used instead of a covariance function. The correlation function should map any pair of points to . The correlation for any point with itself should be 1, i.e. . When a correlation function is used, a variance parameter must be estimated to scale the correlation matrix into a covariance matrix. Thus the covariance matrix is . is overloaded similarly to .
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 ,
As usual, we use negative two times the log-likelihood for simplicity, ignoring the constant terms.
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
Prediction of new points
Conditional distribution
Suppose there are vectors and that are jointly multivariate normal. The joint distribution is
The conditional distribution of given is
Predicting
Suppose there are two input matrices, and , whose rows are the input points, with corresponding output vectors and . Suppose we have the actual values for , and want to estimate, or predict, . We can use the conditional distribution above to get a posterior distribution for .
If we only want to predict for a single point, i.e. we want to predict the output at , then this equation gives
where and
Notice we get an estimate not only for the value of , but also the standard error. This can be useful when we need a way to judge the prediction accuracy of the model.