# How to make new predictions via a trained Gaussian Process?

I've been interested in GP for the past few weeks, and so far, I get how to determine the posterior mean and covariance. But, maybe it's just me, I do not see how, given a new input x, find its image y via the GP model.

For instance, let's say I have an unknown function (blue) and a few observations (red dots) allowed me to compute a mean function (black), an uncertainty domain (green) and some candidates functions (light green)

How can I get the value provided by a candidate function, or more simply, the mean function at a new input, say $$x = -0.5$$? (I do see the value for $$x$$ on the figure, but how can we compute it is my question)

EDIT

On the presented figure, the black, green curves and green shaded area were obtained using informations from the book of Rasmussen. The problem is that the posterior mean or candidates functions are under the form of an $$n$$-dimensional vector. Now, if I want the value of, say, $$x = -0.5,$$ does it mean that I have to manually browse through zip(meanFunction, xSpace) until I have xSpace$${} = -0.5$$ and get the according model value? Or is there another way to extract this knowledge?

• Can you be more specific about what you've tried so far? Do you have the kernel covariance matrices for the 'training' observations and the new input? Are you looking at theory or trying to write some code? Commented Oct 27, 2017 at 14:02
• Adding to the answer given by Kevin Yang, a more general Equation for mean prediction is 2.38 if you have not assumed you mean function as zero. (Earlier I was confused a lot not knowing this, so trying to make it clear for the OP and others :) Commented Feb 3, 2021 at 3:03
• I know this was posted for a while ago. But finally I see someone having the same basic intuitive question as me. Why is no one talking about this??? So, have you gained more understanding since the post? Could you please explain to me? Best regards!
– Anna
Commented Aug 24, 2022 at 15:33

The closed form expressions for the posterior mean and variance can be found in Equations 2.25 and 2.26 on page 17 of Gaussian Processes for Machine Learning. If you need help with those, feel free to add comments here.

The mean function is typically used to make predictions at a new point.

To make a prediction for an $$\mathbf{x}^*$$, one can find the expected value $$y^*$$ from the expected value of the posterior probability of $$f(\mathbf{x}^*)$$. [1]

The posterior variance serves to describe the uncertainty in our prediction. If your training set consists of points $$\mathbf{x}\in[0, 5]$$, then you can predict a value for $$\mathbf{x}^* = 20$$ (a bold $$\mathbf{x}^*$$ to show that it can be a $$d$$-dimensional input also, not just 1-dimensional) using the mean function.

However, the wide bands at this point remind you of the high uncertainty of your prediction at a point so far away from the training set. The mean function (joining the expected value at every point) serves as a nice "default value" of the function at that point, among all the different function values that can be sampled from the posterior.

The expected value at $$\mathbf{x}^*$$ is also the mode of the Gaussian at that point, so it makes sense to predict it. At least, that's how I make sense of it. Anyone with any corrections/further comments is welcome to respond.