# Interpretation of inverse matrix in mean calculation in Gaussian Process

The formula for mean prediction using Gaussian Process is $$k(x_*, x)k(x, x)^{-1}y$$, where $$k$$ is the covariance function. See e.g. equation 2.23 (in chapter 2) from Gaussian Processes for Machine Learning (2006) by C. E. Rasmussen & C. K. I. Williams.

Oversimplifying, the mean prediction of the new point $$y_*$$ is the weighted average of previously observed $$y$$, where the weights are calculated by the $$k(x_*,x)$$ and normalized by $$k(x,x)^{-1}$$.

Now, the first part $$k(x_*, x)$$ is easy to interpret. The closer the new data point lies to the previously observed data points, the greater their similarity, the higher will be the weight and impact on the prediction.

But how to interpret the second part $$k(x, x)^{-1}$$? I presume this makes the weight of the points in the clusters greater than the outliers. Am I correct?

## Mathematical Interpretation

Note that equation (2.23) is simply calculating the conditional distribution of equation (2.21) and then finding the mean. Your question reduces to:

"Given normal variables $$X$$ and $$Y$$, why is $$\mathbb{E}[Y|X] = \mu_y + Cov(X, Y)Cov(Y, Y)^{-1}(x - \mu_x)$$? (note: in the book, $$\mu_x = \mu_y = 0$$)

Deriving the conditional probability mean is complicated (see The Bivariate Normal Distribution, page 3). A more intuitive look can be seen in the first graph in this page.

Here, the mean of $$Y|X$$ is linear in what value $$X$$ takes. The line starts at the intercept $$\mu_y$$, and increases with slope $$\rho (\frac{\sigma_y}{\sigma_x}) = \frac{Cov(X,Y)}{\sigma_x \sigma_y}\left(\frac{\sigma_y}{\sigma_x}\right)=\frac{Cov(X,Y)}{\sigma_x^2} = \frac{Cov(X,Y)}{Var(x)} = \frac{Cov(X,Y)}{Cov(X,X)}$$. So the mathematical interpretation of $$Cov(X,Y)Cov(X,X)^{-1}$$ is that it is the slope of the relationship between the mean of $$Y|X$$ and the value of $$x$$ that you are given. As you are given a higher value $$x$$, say $$x + \delta$$, then the mean of $$Y|X$$ raises by $$Cov(X,Y)Cov(X,X)^{-1}\delta$$.

Why is there even a $$Cov(X,Y)Cov(X,X)^{-1}$$ term there? For some reason, multiplying $$Y|X$$ by a $$Cov(X,Y)Cov(X,X)^{-1}$$ term makes $$Y|X$$ completely independent of $$X$$ (which makes sense as the definition of "conditional probability", because you are already given a value of $$X$$). This is just a mathematical property, I don't know if there's an intuitive explanation as to why.

## Human Interpretation

In case your post just want an intuition as to why there is a $$Cov(X,X)^{-1}$$ in the prediction of a Gaussian process (and ignoring the conditional probability fluff), I don't think there's a real basis for this, it would only be coincidental as the authors simply used the conditional probability mean formula, but I would guess $$Cov(X,X)^{-1}$$ somehow normalizes the values of covariance matrix $$Cov(X_*, X)$$.

For example, if the training set $$X$$ has a lot of outliers and therefore extremely high variance (e.g. all non-diagonal entries in millions), then it is very likely that $$Cov(X_*, X)$$ would also be extremely high as $$X_*$$ follows the same distribution as $$X$$ (unless each data in $$X_*$$ matches the exact same variance in $$X$$). It doesn't make sense to multiply $$y$$ by millions though, as $$y$$ is already a somewhat decent estimator/prior.

It makes more sense to normalize $$Cov(X_*, X)$$ by dividing it with the training data variance $$Cov(X,X) = Var(X)$$ so that the ratio $$Cov(X_*, X)Cov(X, X)^{-1}$$ tends to be more closer to 1 when $$X_*$$ follows the same distribution as $$X$$ (which should be the case). If the ratio is exactly 1, then $$X_*$$ has the exact same distribution as $$X$$, so you just return the prior estimate $$y$$. If the ratio is far away from $$1$$, then the test set distribution is wildly different than the training set distribution, so you return a number far away from $$y$$.

I interpret this as the following, I will use the uppercase matrix notation $$\mathbf{K_{*}}$$, etc...

The covariance matrix $$\mathbf{K_{xx}}$$ summarizes everything we know about the input feature space. I think of it as a unique signature that describes the data we have in $$\mathbb{R}^{d_x}$$. Along with the example training data, we have the labels $$\mathbf{y}$$, which give us a concrete definition of what the prediction values for $$\mathbf{K_{xx}}$$ should be.

We can then ask the question "What can we multiply the unique signature $$\mathbf{K_{xx}}$$ by in order to get the training outputs?" This takes the familiar form of $$\mathbf{A}\mathbf{x} = \mathbf{b}$$...

\begin{aligned} \mathbf{K}_{xx}\mathbf{z} &= \mathbf{y} \\ \mathbf{z} &= \mathbf{K}_{xx}^{-1}\mathbf{y} \end{aligned}

$$\mathbf{z}$$ then represents the vector that the covariance matrix transforms into the outputs. Then all we have to do is multiply the new covariance of the train/test points by that same vector to get the predictions...

$$\mathbf{\hat{y}} = \mathbf{K_{*x}}\mathbf{K_{xx}^{-1}}\mathbf{y}$$

I should add that I am relatively certain about this, but I am still learning this stuff myself so I am not 100