Why Evaluate Gaussian Likelihoods Through a Factorization?
A Gaussian likelihood combines two quantities that can be numerically delicate: a covariance determinant and a quadratic form involving the inverse covariance. Computing either by explicitly forming a determinant or an inverse is usually unnecessary and can amplify rounding error. For a symmetric positive-definite covariance matrix, a Cholesky factorization gives a direct route to both quantities using logarithms and triangular solves.
The goal here is likelihood evaluation for specified parameter values, not optimization over those values. We will use a Cholesky factor to compute the likelihood and to identify signs that a covariance estimate is close to singularity.
Likelihood Evaluation from a Cholesky Factor
Suppose \(x\in\mathbb{R}^p\) is one observation from \(N(\mu,\Sigma)\), where the specified covariance \(\Sigma\) is symmetric positive definite. Write \(r=x-\mu\). The multivariate normal log-density is
Factor \(\Sigma=LL^T\). Compute the log-determinant from the diagonal of \(L\). For the quadratic form, solve \(Ly=r\) and take the squared Euclidean length of \(y\). Neither calculation requires forming \(\Sigma^{-1}\) or \(|\Sigma|\) directly.
\(\log|\Sigma|=2\sum_{j=1}^p\log L_{jj}\).
If \(y\) is the solution of \(Ly=r\), then \(r^T\Sigma^{-1}r=y^Ty\).
Proof. The determinant product rule gives \(|\Sigma|=|L||L^T|=|L|^2\). Since \(L\) is triangular, \(|L|=\prod_{j=1}^p L_{jj}\); each diagonal entry is positive, so taking logarithms yields the stated log-determinant identity. For the quadratic form, let \(u\) solve \(\Sigma u=r\). Since \(r=Ly\), the vector \(u=L^{-T}y\) satisfies \(\Sigma u=LL^TL^{-T}y=Ly=r\). Therefore \(r^T\Sigma^{-1}r=r^Tu=(Ly)^TL^{-T}y=y^Ty\). The calculation of \(y\) uses a forward triangular solve; this proof does not require computing an inverse in the numerical algorithm. \(\square\)
Compute \(\Sigma=LL^T\), checking that the input is symmetric and the factorization succeeds.
Add the logarithms of the positive diagonal entries of \(L\), then multiply the sum by two.
With \(r=x-\mu\), solve \(Ly=r\) by forward substitution.
Use \(y^Ty\) as the quadratic term in the Gaussian log-density.
The word “whitened” refers here to the transformation \(y=L^{-1}r\): its squared length is the covariance-scaled squared distance of the residual. In implementation, obtain \(y\) by solving a triangular system rather than forming \(L^{-1}\).
Worked Example: A Two-Dimensional Gaussian Log-Density
Let \(\mu=(0,0)^T\), \(x=(1,2)^T\), and \[ \Sigma=\begin{pmatrix}4&1\\1&2\end{pmatrix}. \] The matrix is symmetric positive definite because its leading principal minors are \(4>0\) and \(4(2)-1=7>0\). Its Cholesky factor is \[ L=\begin{pmatrix}2&0\\[2pt]1/2&\sqrt{7}/2\end{pmatrix}, \] as multiplication gives \(LL^T=\begin{pmatrix}4&1\\1&1/4+7/4\end{pmatrix}=\Sigma\).
The log-determinant is \[ \log|\Sigma|=2\left(\log 2+\log(\sqrt{7}/2)\right)=\log 7. \] To obtain the quadratic term, solve \(Ly=x\). The first equation gives \(2y_1=1\), hence \(y_1=1/2\). The second gives \(y_1/2+(\sqrt{7}/2)y_2=2\), so \(y_2=\sqrt{7}/2\). Thus \(x^T\Sigma^{-1}x=y^Ty=1/4+7/4=2\).
Substitution into the bivariate log-density gives \[ \ell=-\log(2\pi)-\frac{1}{2}\log 7-1\approx -3.8108. \] The determinant and quadratic form have both been evaluated without explicitly forming a determinant or inverse.
Multiple Observations and a Fully Derived Formula
For \(n\) independent observations \(x_1,\ldots,x_n\) from the same \(N(\mu,\Sigma)\), the log-likelihood is the sum of the individual log-densities. Let \(r_i=x_i-\mu\), and let \(y_i\) solve \(Ly_i=r_i\). Summing the one-observation formula gives
Derivation. Independence means the joint density is the product of the \(n\) individual densities, so its log is their sum. Each observation contributes \(-p\log(2\pi)/2\) and \(-\log|\Sigma|/2=-\sum_j\log L_{jj}\). Its remaining contribution is \(-y_i^Ty_i/2\), by the triangular-solve identity. Summing these three terms over \(i=1,\ldots,n\) yields the displayed expression. \(\square\)
In computation, place the residuals in a matrix \(R=[r_1,\ldots,r_n]\) and solve \(LY=R\) with one triangular-system routine. The final quadratic contribution is \(-\|Y\|_F^2/2\), where \(\|Y\|_F^2\) is the sum of squares of all entries of \(Y\). This is the same calculation as summing \(y_i^Ty_i\) one observation at a time.
Worked Example: A Three-Dimensional Quadratic Form
Take \[ \Sigma=\begin{pmatrix}4&2&0\\2&5&1\\0&1&2\end{pmatrix}, \qquad r=\begin{pmatrix}2\\1\\1\end{pmatrix}. \] A Cholesky factor is \[ L=\begin{pmatrix}2&0&0\\1&2&0\\0&1/2&\sqrt{7}/2\end{pmatrix}. \] Indeed, its product with its transpose has diagonal entries \(4,5,1/4+7/4=2\), and off-diagonal entries \(2,0,1\), as required.
The diagonal gives \(|\Sigma|=(2\cdot2\cdot\sqrt{7}/2)^2=28\), so \(\log|\Sigma|=\log 28\). Solve \(Ly=r\): the first equation gives \(y_1=1\); the second gives \(y_1+2y_2=1\), hence \(y_2=0\); the third gives \(y_2/2+(\sqrt{7}/2)y_3=1\), hence \(y_3=2/\sqrt{7}\). Therefore \[ r^T\Sigma^{-1}r=y^Ty=1+\frac{4}{7}=\frac{11}{7}. \]
For a single observation in dimension three, the log-density at this residual is \[ -\frac{3}{2}\log(2\pi)-\frac{1}{2}\log 28-\frac{11}{14}\approx -5.2086. \] The calculation uses only a factorization, its diagonal, and forward substitution.
Near-Singularity: What the Factorization Can Tell You
A covariance matrix near singularity has one or more very small eigenvalues relative to its overall scale. In the Gaussian likelihood, this can make the log-determinant strongly negative and make quadratic forms vary sharply with the direction of the residual. Cholesky factorization is useful for evaluating a positive-definite covariance, but a successful factorization alone does not guarantee that the covariance is well-conditioned or statistically well determined.
The identity \(\log|\Sigma|=\sum_{j=1}^p\log\lambda_j\), where \(\lambda_j\) are the positive eigenvalues, shows why a very small eigenvalue matters: its logarithm can make a large negative contribution. The condition number in the Euclidean norm is \(\lambda_{\max}/\lambda_{\min}\). A large value signals that small perturbations to the matrix or arithmetic can have substantial effects on some computed quantities. Cholesky diagonal entries can help reveal a problematic factorization, but they depend on variable ordering and are not, by themselves, a condition-number estimate.
Worked Example: A Nearly Singular Covariance
Consider \[ \Sigma=\begin{pmatrix}1&0.9999\\0.9999&1\end{pmatrix}. \] Its eigenvalues are \(1+0.9999=1.9999\) and \(1-0.9999=0.0001\), so it is positive definite but has condition number \(1.9999/0.0001=19999\). A Cholesky factor is \[ L=\begin{pmatrix}1&0\\0.9999&\sqrt{0.00019999}\end{pmatrix}, \] because \(1-0.9999^2=0.00019999\). Consequently, \(\log|\Sigma|=\log(0.00019999)\approx -8.51724\).
For \(r=(1,1)^T\), the exact quadratic form follows from the eigenvector in the common direction: \(r^T\Sigma^{-1}r=2/(1+0.9999)\approx1.00005\). For \(r=(1,-1)^T\), which points in the small-eigenvalue direction, it is \(2/(1-0.9999)=20000\). Thus the same covariance assigns a modest quadratic distance to one residual direction and an enormous one to another. The contrast is a substantive consequence of the fitted covariance as well as a warning about numerical sensitivity.
If the model uses different measurement scales, scaling can make computation and interpretation clearer. For a positive diagonal matrix \(D\), write \(\Sigma=DRD\), where \(R=D^{-1}\Sigma D^{-1}\). Then \(\log|\Sigma|=2\sum_j\log D_{jj}+\log|R|\), and the quadratic form can be evaluated by solving with the correspondingly scaled residual. This is a change of scale, not a repair for a genuinely near-singular covariance.
When a factorization fails, first check whether the input is symmetric to the accuracy expected from its construction, and inspect its eigenvalues or a condition estimate. Small asymmetries caused by rounding may sometimes be removed by replacing the matrix with \((\Sigma+\Sigma^T)/2\), but this should follow a diagnostic check rather than conceal a substantive problem. Adding a small multiple of the identity (“jitter”) changes the covariance model and therefore changes the likelihood. It should be reported and justified, not treated as an invisible numerical fix. A singular covariance requires a different, support-specific treatment; it does not have an ordinary full-dimensional Gaussian density with respect to Lebesgue measure.
Common Pitfalls and Practical Checks
- Forming an inverse to get the quadratic form. This adds needless computation and can worsen numerical error. Solve \(Ly=r\) and use \(y^Ty\).
- Taking the logarithm of a computed determinant. A determinant can overflow, underflow, or lose precision. Sum \(2\log L_{jj}\) instead.
- Ignoring scaling in the log-determinant. The formula has a factor of two: each Cholesky diagonal contributes \(2\log L_{jj}\).
- Treating Cholesky failure as harmless. Failure can indicate non-positive definiteness, material asymmetry, or a serious conditioning problem. Diagnose before modifying the matrix.
- Assuming a finite likelihood means a reliable covariance estimate. A successful factorization evaluates the supplied matrix; it does not establish that the matrix is well estimated or numerically stable.
Check Your Understanding
Use the factorization identities and numerical cautions developed above.
- Given \(\Sigma=LL^T\), why does \(\log|\Sigma|\) equal twice the sum of the logarithms of the diagonal entries of \(L\)?
- If \(Ly=r\), how can you evaluate \(r^T\Sigma^{-1}r\) without forming \(\Sigma^{-1}\)?
- For multiple independent Gaussian observations with a common covariance, how can the residual solves be organized as one matrix triangular solve?
- Why can a covariance matrix be positive definite and still produce numerically sensitive likelihood calculations?
- What does adding a small multiple of the identity do to the likelihood, and why should it be reported?