Tutorials › Stochastic Processes › Conditioning a Gaussian Process at Finite Inputs

Gaussian Processes · Tutorial 876 of 994

Conditioning a Gaussian Process at Finite Inputs

Learn to compute and verify the conditional mean and covariance of Gaussian-process values at test inputs given exact observations.

Advanced 12 min read

What You'll Learn

  • Set up observation and test vectors for a Gaussian process at finite inputs.
  • Identify the dimensions and roles of the four joint covariance blocks.
  • Derive the conditional mean and covariance when the observation covariance is invertible.
  • Explain why the conditional covariance is positive semidefinite.
  • Handle redundant exact observations with a Moore–Penrose pseudoinverse.
  • Check conditional calculations using residual covariances and support conditions.

From a Gaussian Process to a Finite Conditional Law

A Gaussian process describes a collection of random variables, but a finite prediction question involves only finitely many of them. Choose observation inputs and test inputs, collect the corresponding process values into vectors, and their joint distribution is multivariate Gaussian. Conditioning then reduces to a block-matrix calculation. The essential bookkeeping is to keep the observation and test dimensions straight, and to distinguish an invertible observation covariance from a singular one.

Let \((\Omega,\mathcal{F},\mathbb{P})\) be a probability space, let \(\mathcal{X}\) be an input set, and let \((X(x))_{x\in\mathcal{X}}\) be a real Gaussian process: every finite vector of its values has a multivariate Gaussian distribution, possibly singular. Write its mean function as \(m(x)=\mathbb{E}[X(x)]\) and covariance function as \(k(x,x')=\operatorname{Cov}(X(x),X(x'))\). Select \(n\) observation inputs \(x_1,\ldots,x_n\) and \(r\) test inputs \(z_1,\ldots,z_r\). Repeated inputs are allowed, though they can make the observation covariance singular.

Use column vectors for process values and their means. Define the observation vector \(Y=(X(x_1),\ldots,X(x_n))^{\mathsf T}\) and the test vector \(Z=(X(z_1),\ldots,X(z_r))^{\mathsf T}\). Their means are \(m_o\in\mathbb{R}^n\) and \(m_*\in\mathbb{R}^r\). Define the covariance blocks

$$ A=\operatorname{Cov}(Y,Y)\in\mathbb{R}^{n\times n},\qquad B=\operatorname{Cov}(Z,Y)\in\mathbb{R}^{r\times n},\qquad C=\operatorname{Cov}(Z,Z)\in\mathbb{R}^{r\times r}. $$

Thus \(A_{ij}=k(x_i,x_j)\), \(B_{\ell i}=k(z_\ell,x_i)\), and \(C_{\ell q}=k(z_\ell,z_q)\). In particular, the block in the upper-right corner of the joint covariance is \(B^{\mathsf T}\), not \(B\). The full joint distribution is

$$ \begin{bmatrix}Y\\Z\end{bmatrix} \sim \mathcal{N}\!\left( \begin{bmatrix}m_o\\m_*\end{bmatrix}, \begin{bmatrix}A&B^{\mathsf T}\\B&C\end{bmatrix} \right). $$

Here \(\mathcal{N}\) denotes a multivariate Gaussian law, including a degenerate law when its covariance is singular. Conditioning on exact observed values means specifying \(Y=y\). If \(A\) is invertible, \(Y\) has a density and every \(y\in\mathbb{R}^n\) is in its support. If \(A\) is singular, only values in the support of \(Y\) are possible. In either case, the conditional law at a specified value is understood as a regular conditional distribution; for a nonsingular Gaussian vector the usual density-based conditional formula gives a version defined for every \(y\).

Theorem (Finite-input Gaussian conditioning): In the setup above, if \(A\) is invertible, then $$ Z\mid Y=y\ \sim\ \mathcal{N}\!\left( m_*+BA^{-1}(y-m_o),\ C-BA^{-1}B^{\mathsf T} \right). $$ The conditional mean is an \(r\)-vector and the conditional covariance is an \(r\times r\) matrix. If \(A\) is singular and \(y-m_o\) belongs to the range of \(A\), the same statement holds with \(A^{-1}\) replaced by the Moore–Penrose pseudoinverse \(A^+\). For \(y\) outside this support, conditioning on \(Y=y\) is not defined by the joint law.

Proof. First suppose \(A\) is invertible. Define the residual vector \(R=Z-m_*-BA^{-1}(Y-m_o)\). Its mean is zero. By the covariance definitions and symmetry of covariance,

$$ \operatorname{Cov}(R,Y)=B-BA^{-1}A=0,\qquad \operatorname{Cov}(R,R)=C-BA^{-1}B^{\mathsf T}. $$

The vectors \(R\) and \(Y\) are jointly Gaussian because they are affine transformations of the jointly Gaussian vector \((Y,Z)\). For jointly Gaussian vectors, zero cross-covariance implies independence; this follows, for example, by factoring their joint Gaussian characteristic function when the cross-covariance block is zero. Hence \(R\) is independent of \(Y\). The identity \(Z=m_*+BA^{-1}(Y-m_o)+R\) now shows that, given \(Y=y\), the first two terms are fixed and \(R\) retains its unconditional Gaussian law. This gives the asserted conditional mean and covariance. The covariance is positive semidefinite because it is \(\operatorname{Cov}(R,R)\).

For singular \(A\), define \(A^+\) by diagonalizing the symmetric positive semidefinite matrix \(A\): invert each positive eigenvalue and leave each zero eigenvalue at zero. If \(v\) is in the null space of \(A\), then \(\operatorname{Var}(v^{\mathsf T}Y)=v^{\mathsf T}Av=0\), so \(v^{\mathsf T}(Y-m_o)=0\) almost surely. Its covariance with \(Z\) is \(Bv\), which must therefore be zero. Thus \(Bv=0\) for every \(v\) in the null space of \(A\), and consequently \(BA^+A=B\). Set \(R=Z-m_*-BA^+(Y-m_o)\). Direct calculation gives \(\operatorname{Cov}(R,Y)=B-BA^+A=0\). The same joint-Gaussian independence argument shows \(R\) is independent of \(Y\), while its covariance is \(C-BA^+B^{\mathsf T}\). For \(y-m_o\) in the range of \(A\), the identity \(AA^+(y-m_o)=y-m_o\) gives the conditional representation and formula. If \(y-m_o\) is outside that range, it has probability zero under a law supported on \(m_o+\operatorname{range}(A)\), and is not a possible observation. \(\square\)

Computing the Conditional Distribution

The block formula can be used directly once the inputs, means, and covariance blocks are specified. A useful way to understand its correction term is through the residual in the proof: \(BA^{-1}(Y-m_o)\) is the part of the test vector explained linearly by the observations, and the remaining residual is independent of them. The covariance subtracts the covariance explained by that linear term. The following examples show the calculation, including checks of dimensions and results.

Worked Example: One Observation and One Test Input

Suppose \(Y=X(a)\) and \(Z=X(b)\) have zero means and joint covariance $$ \begin{bmatrix}4&2\\2&3\end{bmatrix}. $$ Find the conditional distribution of \(Z\) given \(Y=1\). The observation covariance \(A=[4]\) is invertible. Its determinant is \(4\), and the joint covariance is positive definite because its determinant is \(4\cdot3-2\cdot2=8>0\).

Here \(n=r=1\), \(B=[2]\), \(C=[3]\), and \(y-m_o=1\). The conditional mean is $$ 0+[2][\tfrac14][1]=\tfrac12. $$ The conditional variance is $$ 3-[2][\tfrac14][2]=3-1=2. $$ Therefore \(Z\mid Y=1\sim\mathcal{N}(\tfrac12,2)\).

Check by the residual. The residual is \(R=Z-\tfrac12Y\). Its covariance with \(Y\) is \(2-\tfrac12(4)=0\), and its variance is \(3+(\tfrac12)^2(4)-2(\tfrac12)(2)=3+1-2=2\). This agrees with the conditional calculation.

Worked Example: Two Observations and Two Test Inputs

Let the observation and test vectors have means \(m_o=(0,1)^{\mathsf T}\) and \(m_*=(1,-1)^{\mathsf T}\), with covariance blocks $$ A=\begin{bmatrix}2&1\\1&2\end{bmatrix},\qquad B=\begin{bmatrix}1&0\\0&1\end{bmatrix},\qquad C=\begin{bmatrix}2&0\\0&2\end{bmatrix}. $$ These specify a valid joint Gaussian covariance: \(A\) is positive definite, and the Schur complement \(C-BA^{-1}B^{\mathsf T}\), computed below, is positive definite. Find the conditional law at \(y=(2,0)^{\mathsf T}\). The dimensions are \(A:2\times2\), \(B:2\times2\), and \(C:2\times2\); the update \(BA^{-1}(y-m_o)\) is a two-vector.

The determinant of \(A\) is \(2\cdot2-1\cdot1=3\), so $$ A^{-1}=\frac13\begin{bmatrix}2&-1\\-1&2\end{bmatrix}. $$ The data deviation is \(y-m_o=(2,-1)^{\mathsf T}\), and hence $$ A^{-1}(y-m_o) =\frac13\begin{bmatrix}2&-1\\-1&2\end{bmatrix} \begin{bmatrix}2\\-1\end{bmatrix} =\begin{bmatrix}\tfrac53\\-\tfrac43\end{bmatrix}. $$ Since \(B\) is the identity, the conditional mean is $$ m_*+BA^{-1}(y-m_o) =\begin{bmatrix}1\\-1\end{bmatrix} +\begin{bmatrix}\tfrac53\\-\tfrac43\end{bmatrix} =\begin{bmatrix}\tfrac83\\-\tfrac73\end{bmatrix}. $$ For the conditional covariance, $$ C-BA^{-1}B^{\mathsf T} =\begin{bmatrix}2&0\\0&2\end{bmatrix} -\frac13\begin{bmatrix}2&-1\\-1&2\end{bmatrix} =\begin{bmatrix}\tfrac43&\tfrac13\\\tfrac13&\tfrac43\end{bmatrix}. $$ Its eigenvalues are \(\tfrac53\) and \(1\), both positive, so it is a valid covariance. Thus the conditional distribution is the bivariate Gaussian with the mean and covariance just calculated.

Check the mean and covariance. Multiplying \(A\) by the displayed \(A^{-1}\) gives the identity matrix: the diagonal entries are \((4-1)/3=1\), and the off-diagonal entries are \((-2+2)/3=0\). The Schur-complement determinant is \((\tfrac43)^2-(\tfrac13)^2=\tfrac{15}{9}=\tfrac53>0\), confirming positive definiteness. The covariance is symmetric, as required.

Worked Example: Redundant Exact Observations

Suppose two observation entries repeat the same process value: \(Y=(X(a),X(a))^{\mathsf T}\). Let \(Z=X(b)\), and suppose their means are zero and their joint covariance is $$ A=\begin{bmatrix}1&1\\1&1\end{bmatrix},\qquad B=\begin{bmatrix}\tfrac12&\tfrac12\end{bmatrix},\qquad C=[1]. $$ The observation covariance has rank one, so its ordinary inverse does not exist. The only possible observations have the form \(y=(c,c)^{\mathsf T}\), because the two entries are the same random variable. Consider \(c=2\).

The matrix \(A\) has eigenvalue \(2\) in the direction \((1,1)^{\mathsf T}\) and eigenvalue \(0\) in the direction \((1,-1)^{\mathsf T}\). Therefore $$ A^+=\frac14\begin{bmatrix}1&1\\1&1\end{bmatrix}. $$ The support condition holds because \(y=(2,2)^{\mathsf T}\) lies in the span of \((1,1)^{\mathsf T}\). The pseudoinverse update is $$ BA^+y =\begin{bmatrix}\tfrac12&\tfrac12\end{bmatrix} \frac14\begin{bmatrix}1&1\\1&1\end{bmatrix} \begin{bmatrix}2\\2\end{bmatrix} =1. $$ The conditional variance is $$ C-BA^+B^{\mathsf T} =1-\begin{bmatrix}\tfrac12&\tfrac12\end{bmatrix} \frac14\begin{bmatrix}1&1\\1&1\end{bmatrix} \begin{bmatrix}\tfrac12\\\tfrac12\end{bmatrix} =1-\tfrac14=\tfrac34. $$ So \(Z\mid Y=(2,2)^{\mathsf T}\sim\mathcal{N}(1,\tfrac34)\).

Check by a scalar residual. Since the repeated entries contain only the information \(X(a)=2\), the scalar covariance between \(X(b)\) and \(X(a)\) is \(\tfrac12\), and the variance of \(X(a)\) is \(1\). The residual \(X(b)-\tfrac12X(a)\) has mean zero, covariance \(\tfrac12-\tfrac12(1)=0\) with \(X(a)\), and variance \(1+(\tfrac12)^2-2(\tfrac12)(\tfrac12)=\tfrac34\). This independently confirms both conditional parameters.

Interpretation and a Common Error

The conditional distribution is itself Gaussian, but it is a distribution for the finite test vector, not a deterministic set of fitted values. The conditional mean gives the center of that distribution; the conditional covariance describes the remaining joint uncertainty at the test inputs. Its off-diagonal entries matter: they describe how uncertainty at different test inputs varies together after conditioning. The covariance may be singular, for example if test values are repeated or determined exactly by the observations; a Gaussian distribution need not have a density to be a valid conditional law.

A common mistake is to add the covariance correction instead of subtracting it. In the first example, this incorrect calculation gives \(3+2\cdot\tfrac14\cdot2=4\). But the residual variance is \(3+1-2=2\), and the correct formula gives \(3-2\cdot\tfrac14\cdot2=2\). Conditioning removes the part of test variation explained by the observations; it cannot increase the covariance in this fixed jointly Gaussian setup. Another frequent error is reversing the cross-covariance block: \(B\) is \(r\times n\), so it acts on the \(n\)-vector \(A^{-1}(y-m_o)\) to produce an \(r\)-vector. This is why the update is \(BA^{-1}(y-m_o)\).

Before applying the formula, check that the stated joint covariance is symmetric positive semidefinite, that \(A\) is invertible before using \(A^{-1}\), and that a singular-observation value lies in the support before using \(A^+\). For a singular \(A\), inconsistent repeated observations such as \(Y=(1,2)^{\mathsf T}\) in the last example have probability zero and cannot be treated as an ordinary conditioning event. The pseudoinverse does not make impossible data possible; it gives the conditional law only on the support.

Check Your Understanding

For each question, identify the observation and test dimensions before calculating.

  1. If there are \(n\) observation inputs and \(r\) test inputs, what are the dimensions of \(A\), \(B\), and \(C\)?
  2. In the first worked example, compute the conditional mean and variance at \(Y=3\) rather than \(Y=1\), and verify the variance with the residual.
  3. Why does zero covariance between the Gaussian residual \(R\) and \(Y\) imply that the residual is independent of the observations?
  4. In the redundant-observation example, does \(y=(2,1)^{\mathsf T}\) lie in the support of \(Y\)? Explain why the conditional formula is not applicable there.
  5. State why \(C-BA^{-1}B^{\mathsf T}\) is positive semidefinite whenever the block covariance is jointly Gaussian and \(A\) is invertible.