Gaussian process regression posterior (source code)

= Gaussian process regression posterior
{c}

Let $f$ have a zero-mean <Gaussian process> prior with <covariance> <function> $k$. Observe $y_i=f(x_i)+\varepsilon_i$ with <independent random variables>[independent] normal noise of <variance> $\sigma_n^2>0$, <independent random variables>[independent] of $f$. Write $K_{ij}=k(x_i,x_j)$, $k_*=(k(x_i,x_*))_{i=1}^n$ and $k_{**}=k(x_*,x_*)$. The <Gaussian process regression posterior> at a new input is
$$
f(x_*)\mid y\sim N(m_*,v_*),\qquad m_*=k_*^{\mathsf T}(K+\sigma_n^2I)^{-1}y,\quad v_*=k_{**}-k_*^{\mathsf T}(K+\sigma_n^2I)^{-1}k_*.
$$
This is the <Conditional multivariate normal distribution> applied to the joint prior of $y$ and $f(x_*)$. The <kernel matrix> $K$ is <positive semidefinite matrix>[positive semidefinite]; positive observation-noise <variance> makes the <matrix> being inverted positive definite. The subtracted quadratic form is the uncertainty removed by the observations. The <variance> of a new noisy observation is $v_*+\sigma_n^2$, which differs from the latent <function> <variance> $v_*$.<Gaussian Processes for Machine Learning by Carl Edward Rasmussen and Christopher K. I. Williams>[Chapter 2, equations (2.23)–(2.26)]{ref}

For one observation at the prediction input with prior <variance> $s^2$, $m_*=s^2y_1/(s^2+\sigma_n^2)$ and $v_*=s^2\sigma_n^2/(s^2+\sigma_n^2)$. The posterior interpolates between trusting a precise observation and retaining a noisy prior prediction.