Unathi's personal website

HomePostsTil Cholesky Decomposition

Today I Learned the Cholesky Decomposition

Published Nov 24, 2022
Updated Nov 30, 2024
1 minutes read

Cholesky decomposition

Not long ago I picked up a Matrix Analysis textbook and came across a matrix factorization with this entry's namesake. The Cholesky decomposition factorizes a positive-definite matrix A\mathbf{A}; xTAx>0x^{T} \mathbf{A} x > 0 for all non-zero xRdx \in \mathbb{R}^{d} into a product of a lower triangular matrix L\mathbf{L} and its adjoint:

A=LL. \mathbf{A} = \mathbf{L}\mathbf{L}^{\dagger}.

For a positive-definite matrices such a factorization always exists and is unique. The numerical algorithm for constructing the lower triangular matrix L\mathbf{L} is relatively straightforward. Initially, the matrix L\mathbf{L} begins as a zero matrix with appropriate dimensions. Taking the diagonal elements of A\mathbf{A} (AjjA_{jj}) and arranging them in a non-increasing order, the algorithm proceeds as follows:

A Python implementation of this algorithm can fit in a tweet

import numpy as np
 
def cholesky(A):
  m, _ = A.shape
  for i in range(m):
      A[i,i] = np.sqrt(A[i,i])
      A[i+1:, i] /= A[i, i]
      A[i, i+1:] = 0
      A[i+1:, i+1:] = np.outer(A[i+1:, i], A[i+1:,i])

The above algorithm can be slightly modified to obtain a low rank approximation of A\mathbf{A}, by stopping when all the remaining updated diagonal elements AjjA_{jj} are below some specified tolerance δ\delta. For some instances of A\mathbf{A}, e.g. electron repulsion integrals in quantum chemistry, the rank ν\nu of the resulting matrix can be much smaller than its maximum possible value.

Here's an animated GIF of what the algorithm does for a 20×2020 \times 20 positive-definite matrix:

Animation of Cholesky decomposition of a 20 by 20 positive-definite matrix
Animation of Cholesky decomposition of a 20 by 20 positive-definite matrix. Click to enlarge image.

Fin.