Tutorials › Stochastic Processes › Diagnosing Gaussian Process Conditioning Errors

Gaussian Processes · Tutorial 887 of 994

Diagnosing Gaussian Process Conditioning Errors

Trace each conditioning calculation from its covariance blocks to a verified prediction, and identify when a result fails because of modeling, algebra, or numerical precision.

Advanced 12 min read

What You'll Learn

  • Match observation, target, and covariance dimensions before multiplying matrices.
  • Include measurement-noise covariance in the observation covariance when conditioning on noisy data.
  • Test covariance matrices for positive semidefiniteness before using conditioning formulas.
  • Recognize why a valid but nearly singular matrix can make numerical solutions unstable.
  • Verify posterior means and covariances by substitution and structural checks.

A Diagnostic Framework for Gaussian Conditioning

Gaussian process conditioning calculations combine modeling assumptions, matrix dimensions, and linear algebra. A prediction that looks plausible can still be wrong because the observation vector was transposed, measurement noise was omitted, or an invalid covariance matrix was inverted. A nearly singular covariance matrix creates a different problem: the model may be valid, while finite-precision computation gives an unreliable answer.

Let \(f=(f(x_1),\ldots,f(x_n))^\mathsf{T}\) be the latent process at \(n\) observed inputs, and let \(f_*=(f(x^*_1),\ldots,f(x^*_r))^\mathsf{T}\) be its values at \(r\) prediction inputs. These are finite-dimensional random vectors on a probability space \((\Omega,\mathcal{F},\mathbb{P})\), with means \(m_X\) and \(m_*\). Write \(K_{XX}\) for the \(n\) by \(n\) covariance matrix of \(f\), \(K_{*X}\) for the \(r\) by \(n\) cross-covariance matrix between \(f_*\) and \(f\), and \(K_{**}\) for the \(r\) by \(r\) covariance matrix of \(f_*\). Thus \(K_{X*}=K_{*X}^\mathsf{T}\).

For noisy observations, suppose \(Y=f+\varepsilon\), where \(\varepsilon\) is an independent, mean-zero Gaussian noise vector with covariance matrix \(R\). The observation covariance is \(C=K_{XX}+R\). If \(C\) is invertible, the conditional distribution is given by the following formula.

Theorem (Finite-dimensional Gaussian conditioning): If \((f_*,Y)\) is jointly Gaussian and \(C=\operatorname{Cov}(Y)\) is positive definite, then, for each observed value \(Y=y\), the conditional mean and covariance are \(\mathbb{E}[f_*\mid Y=y]=m_*+K_{*X}C^{-1}(y-m_X)\) and \(\operatorname{Cov}(f_*\mid Y)=K_{**}-K_{*X}C^{-1}K_{X*}\). Here \(K_{*X}=\operatorname{Cov}(f_*,Y)\); independent observation noise makes this equal to the latent cross-covariance.

Proof. Set \(U=f_*-m_*-K_{*X}C^{-1}(Y-m_X)\). The pair \((U,Y)\) is jointly Gaussian because it is a linear transformation of the jointly Gaussian pair \((f_*,Y)\). Its cross-covariance is \(\operatorname{Cov}(U,Y)=K_{*X}-K_{*X}C^{-1}C=0\). For jointly Gaussian vectors, zero cross-covariance implies independence: their joint characteristic function has exponent given by the covariance quadratic form, and a zero cross-block makes that function the product of the two marginal characteristic functions. Therefore \(U\) is independent of \(Y\), has mean zero, and has covariance \(K_{**}-K_{*X}C^{-1}K_{X*}\), by expanding the covariance of its defining expression. Since \(f_*=m_*+K_{*X}C^{-1}(Y-m_X)+U\), conditioning on \(Y=y\) gives the stated mean and covariance. \(\square\)

This formula also provides a systematic audit. The vector \(y-m_X\) has length \(n\); \(C^{-1}\) has size \(n\) by \(n\); and \(K_{*X}\) has size \(r\) by \(n\). The mean correction therefore has length \(r\), while the covariance correction has size \(r\) by \(r\). In the noiseless case, take \(Y=f\), \(C=K_{XX}\), and require \(K_{XX}\) to be invertible. For noisy observations, do not replace \(C\) with \(K_{XX}\) unless the noise covariance is zero.

Worked Checks on Dimensions and Noise

Worked Example: Three Prediction Inputs and Two Observations

Consider a zero-mean Gaussian process defined by feature vectors in \(\mathbb{R}^5\) and the kernel \(k(u,v)=\phi(u)^\mathsf{T}\phi(v)\). At the two observed inputs, let \(\phi(x_1)=e_1\) and \(\phi(x_2)=e_2\). At three prediction inputs, let \(\phi(x^*_1)=\tfrac12e_1+e_3\), \(\phi(x^*_2)=\tfrac13e_2+e_4\), and \(\phi(x^*_3)=\tfrac12e_1+\tfrac13e_2+e_5\). The observed values are \(y=(2,-1)^\mathsf{T}\). Find the conditional mean and covariance, with no observation noise.

Because the kernel is an inner product of feature vectors, its covariance matrices are Gram matrices and are positive semidefinite. The observation covariance and target-to-observation covariance are

$$ K_{XX}=\begin{bmatrix}1&0\\0&1\end{bmatrix}, \qquad K_{*X}=\begin{bmatrix} \tfrac12&0\\ 0&\tfrac13\\ \tfrac12&\tfrac13 \end{bmatrix}. $$

The target covariance, found by taking inner products of the three target feature vectors, is

$$ K_{**}=\begin{bmatrix} \tfrac54&0&\tfrac14\\ 0&\tfrac{10}{9}&\tfrac19\\ \tfrac14&\tfrac19&\tfrac{49}{36} \end{bmatrix}. $$

In particular, the diagonal entries are \(1+\tfrac14=\tfrac54\), \(1+\tfrac19=\tfrac{10}{9}\), and \(1+\tfrac14+\tfrac19=\tfrac{49}{36}\). The off-diagonal entries are the shared feature contributions: \(0\), \(\tfrac14\), and \(\tfrac19\). Since \(K_{XX}^{-1}\) is the two by two identity matrix, the conditional mean is

$$ K_{*X}y = \begin{bmatrix} \tfrac12&0\\ 0&\tfrac13\\ \tfrac12&\tfrac13 \end{bmatrix} \begin{bmatrix}2\\-1\end{bmatrix} = \begin{bmatrix}1\\-\tfrac13\\\tfrac23\end{bmatrix}. $$

For the covariance correction, multiplication gives \(K_{*X}K_{X*}= \begin{bmatrix} \tfrac14&0&\tfrac14\\ 0&\tfrac19&\tfrac19\\ \tfrac14&\tfrac19&\tfrac{13}{36} \end{bmatrix}\). Subtracting it entry by entry from \(K_{**}\) gives the three by three identity matrix. Check: the posterior covariance is positive semidefinite, and its dimensions match the three prediction inputs. An attempted product \(K_{XX}^{-1}y\) is well-defined here, but multiplying that two-entry result directly into a three-entry prediction vector would not be; the correctly oriented cross-covariance \(K_{*X}\) maps from observation space to prediction space.

Worked Example: The Effect of Leaving Out Measurement Noise

Let one latent value \(f\) have distribution \(N(0,1)\), and observe \(Y=f+\varepsilon\), where \(\varepsilon\) is independent with distribution \(N(0,1)\). If the observed value is \(y=2\), calculate the conditional distribution of \(f\).

The latent variance is \(K_{XX}=1\), the noise variance is \(R=1\), and hence \(C=K_{XX}+R=2\). The covariance between \(f\) and \(Y\) is \(\operatorname{Cov}(f,f+\varepsilon)=1+0=1\). The conditional mean is \(0+1\cdot(1/2)\cdot2=1\). The conditional variance is \(1-1\cdot(1/2)\cdot1=1/2\). Thus \(f\mid Y=2\) has mean \(1\) and variance \(1/2\).

If noise is incorrectly omitted, the calculation instead uses \(C=1\), giving mean \(1\cdot1^{-1}\cdot2=2\) and variance \(1-1\cdot1^{-1}\cdot1=0\). This is the noiseless interpolation answer: it treats \(Y=2\) as the exact latent value. Check: in the correct model, the observation variance is \(1+1=2\), and the covariance of \(f\) with the observation is \(1\); those two values reproduce the conditional mean \(1\) and variance \(1/2\). The zero variance from the incorrect calculation contradicts the stated positive measurement-noise variance.

Validate Covariance Matrices Before Conditioning

A covariance matrix must be symmetric and positive semidefinite. Positive semidefinite means that \(v^\mathsf{T}Kv\ge0\) for every real vector \(v\); this condition is necessary even if the matrix is not invertible.

Proposition: Every covariance matrix \(K\) is positive semidefinite. Consequently, if a symmetric candidate covariance matrix has a vector \(v\) with \(v^\mathsf{T}Kv<0\), it cannot be the covariance matrix of any random vector with finite second moments.

Proof. Let \(Z\) be a random vector with finite second moments, mean \(\mathbb{E}Z\), and covariance \(K\). For any fixed vector \(v\), the scalar \(v^\mathsf{T}(Z-\mathbb{E}Z)\) has variance \(\mathbb{E}[(v^\mathsf{T}(Z-\mathbb{E}Z))^2]=v^\mathsf{T}Kv\). A variance is the expectation of a nonnegative random variable, so it cannot be negative. This holds for every \(v\), which is exactly positive semidefiniteness. \(\square\)

Worked Example: An Invalid Covariance Produces an Impossible Conditional Variance

Consider the proposed observation covariance \(K=\begin{bmatrix}1&2\\2&1\end{bmatrix}\). Before using it in a conditioning formula, test \(v=(1,-1)^\mathsf{T}\). Direct multiplication gives

$$ v^\mathsf{T}Kv = \begin{bmatrix}1&-1\end{bmatrix} \begin{bmatrix}-1\\1\end{bmatrix} =-2. $$

The negative value rules out this matrix as a covariance. Its determinant is \(1-4=-3\), and its inverse is \(K^{-1}=\begin{bmatrix}-\tfrac13&\tfrac23\\\tfrac23&-\tfrac13\end{bmatrix}\). For instance, if one also supplies cross-covariance \(c=(1,1)^\mathsf{T}\) and target variance \(1/2\), the formal conditional variance becomes \(\tfrac12-c^\mathsf{T}K^{-1}c\). Since \(K^{-1}c=(\tfrac13,\tfrac13)^\mathsf{T}\), this is \(\tfrac12-\tfrac23=-\tfrac16\), also impossible for a variance.

Correction: reject the covariance specification rather than interpreting the negative conditional variance as a prediction. A covariance kernel must generate positive-semidefinite Gram matrices at every finite set of inputs. If a computed matrix fails that check, first investigate the kernel, indexing, and assembly of its entries; numerical adjustments should not be used to disguise an invalid model.

Distinguish Numerical Instability from a Modeling Error

A positive-definite observation covariance can still be poorly conditioned: small perturbations in its entries or right-hand side may cause large changes in the solution of a linear system. Gaussian prediction uses such a solve, since \(C^{-1}(y-m_X)\) is ordinarily computed by solving \(C\alpha=y-m_X\), not by explicitly forming \(C^{-1}\). The following exact calculation shows why a small determinant deserves attention, without implying that every small determinant alone proves a problem.

Worked Example: A Valid Matrix Sensitive to Small Perturbations

Consider the covariance matrix and cross-covariance vector

$$ K=\begin{bmatrix}1&1\\1&\tfrac{101}{100}\end{bmatrix}, \qquad c=\begin{bmatrix}1\\0\end{bmatrix}. $$

The first leading principal minor is \(1\), and the determinant is \(\tfrac{101}{100}-1=\tfrac1{100}>0\); thus this symmetric matrix is positive definite. Take target variance \(102\), so the joint covariance is valid as well: the conditional target variance is \(102-c^\mathsf{T}K^{-1}c=102-101=1\). The inverse is

$$ K^{-1}= \begin{bmatrix}101&-100\\-100&100\end{bmatrix}, \qquad K^{-1}c=\begin{bmatrix}101\\-100\end{bmatrix}. $$

For observed value vector \(y=(1,1)^\mathsf{T}\), the solution is \(\alpha=K^{-1}y=(101-100,-100+100)^\mathsf{T}=(1,0)^\mathsf{T}\). The conditional mean correction is \(c^\mathsf{T}\alpha=1\). Now change only the second observation by \(\tfrac1{1000}\), so \(y'=(1,\tfrac{1001}{1000})^\mathsf{T}\). Then

$$ \alpha'=K^{-1}y' = \begin{bmatrix} 101-100\cdot\tfrac{1001}{1000}\\ -100+100\cdot\tfrac{1001}{1000} \end{bmatrix} = \begin{bmatrix}\tfrac9{10}\\\tfrac1{10}\end{bmatrix}. $$

The target mean correction is now \(c^\mathsf{T}\alpha'=\tfrac9{10}\): a change of \(\tfrac1{1000}\) in one observation changed this prediction by \(\tfrac1{10}\). Substitution checks the solve: the first component of \(K\alpha'\) is \(\tfrac9{10}+\tfrac1{10}=1\), and the second is \(\tfrac9{10}+\tfrac{101}{100}\cdot\tfrac1{10}=\tfrac{1001}{1000}\).

If \(\tfrac{101}{100}\) is rounded to \(1\), the displayed matrix becomes \(\begin{bmatrix}1&1\\1&1\end{bmatrix}\), which is singular and cannot be inverted. The exact matrix was valid; rounding made the numerical problem unusable. In practice, use a stable linear solve, retain adequate precision, and check the residual \(K\alpha-y\). If measurement noise is part of the model, include its covariance in \(C\); adding an arbitrary diagonal term changes the model unless that term represents an explicit modeling choice.

A Practical Audit and Common Mistakes

Before accepting a Gaussian conditioning result, check the calculation in a fixed order:

  1. Identify the random vector being predicted. A prediction for latent process values uses the latent target covariance. A prediction for future noisy measurements also includes their noise covariance in the target variance.
  2. Write the dimensions. With \(n\) observations and \(r\) targets, \(C\) is \(n\) by \(n\), \(y-m_X\) has length \(n\), \(K_{*X}\) is \(r\) by \(n\), and the posterior covariance is \(r\) by \(r\).
  3. Assemble the observation covariance. For independent noise with covariance \(R\), use \(C=K_{XX}+R\), not \(K_{XX}\). Noise affects the covariance of the observations, while independent noise does not add to the latent cross-covariance.
  4. Check validity and solvability. Covariance matrices must be symmetric positive semidefinite. The displayed inverse formula requires \(C\) to be positive definite; a positive-definite noise covariance added to a positive-semidefinite \(K_{XX}\) guarantees this.
  5. Verify the output. Check the dimensions, symmetry and positive semidefiniteness of the posterior covariance, and the residual of each linear solve. A dimensionally valid answer is not automatically a correct one.

Common mistake. Multiplying a row-oriented observation vector by \(K_{*X}\) or using \(K_{XX}\) for noisy observations can produce an expression that is either dimensionally impossible or answers a different statistical question. The correction is to keep observations as a length-\(n\) column vector in the conditioning formula, use \(K_{*X}\) on its left, and place the full observation covariance \(C\) in the solve. A result with the wrong output dimension, negative variance, or a failed residual check is a diagnostic signal, not a value to report.

Check Your Understanding

For each question, identify the relevant assumption or calculate the requested quantity before checking the explanations above.

  1. There are four observations and two target inputs. What are the dimensions of \(K_{*X}\), \(C^{-1}\), and the posterior covariance?
  2. A scalar latent value has variance \(3\), independent measurement noise has variance \(1\), and the observed value is \(4\). Find the conditional mean and variance under a zero prior mean.
  3. For \(K=\begin{bmatrix}2&1\\1&2\end{bmatrix}\), test positive definiteness by checking the leading principal minors. What does this check establish?
  4. Why can rounding a positive-definite covariance matrix make a conditioning calculation fail even when the exact matrix is invertible?
  5. In a noisy-observation model, why does independent measurement noise change \(C\) but not \(K_{*X}\)?