Post · 8 min read· pp. 603–606

What Is a Cholesky Factorization?

The Cholesky factorization of a symmetric positive definite matrix AA is the factorization A=RT ⁣RA = R^T\!R, where RR is upper triangular with positive diagonal elements. It is a generalization of the property that a positive real number has a unique positive square root. The Cholesky factorization always exists and the requirement that the diagonal of RR be positive ensures that it is unique.

As an example, the Cholesky factorization of the 4×44\times 4 matrix with (i,j)(i,j) element gcd⁡(i,j)\gcd(i,j) (gallery('gcdmat',4) in MATLAB) is

G4=[1111121211311214]=[1000110010201102][1111010100200002].G_4 = \left[\begin{array}{cccc} 1 & 1 & 1 & 1\\ 1 & 2 & 1 & 2\\ 1 & 1 & 3 & 1\\ 1 & 2 & 1 & 4 \end{array}\right] = \left[\begin{array}{cccc} 1 & 0 & 0 & 0\\ 1 & 1 & 0 & 0\\ 1 & 0 & \sqrt{2} & 0\\ 1 & 1 & 0 & \sqrt{2} \end{array}\right] \left[\begin{array}{cccc} 1 & 1 & 1 & 1\\ 0 & 1 & 0 & 1\\ 0 & 0 & \sqrt{2} & 0\\ 0 & 0 & 0 & \sqrt{2} \end{array}\right].

The Cholesky factorization of an n×nn\times n matrix contains n−1n-1 other Cholesky factorizations within it: Ak=RkTRkA_k = R_k^TR_k, k=1:n−1k=1:n-1, where Ak=A(1 ⁣:k,1 ⁣:k)A_k = A(1\colon k,1\colon k) is the leading principal submatrix of order kk. For example, for G4G_4 with k=2k = 2, [1112]=[1011][1101]\bigl[\begin{smallmatrix}1 & 1\\ 1& 2\end{smallmatrix}\bigr]= \bigl[\begin{smallmatrix}1 & 0\\ 1& 1\end{smallmatrix}\bigr] \bigl[\begin{smallmatrix}1 & 1\\ 0& 1\end{smallmatrix}\bigr].

Inverting the Cholesky equation gives A−1=R−1R−TA^{-1} = R^{-1} R^{-T}, which implies the interesting relation that the (n,n)(n,n) element of A−1A^{-1} is rnn−2r_{nn}^{-2}. So G4−1G_4^{-1} has (4,4)(4,4) element 1/21/2. We also have det⁡(A)=det⁡(R)2=(r11…rnn)2\det(A) = \det(R)^2 = (r_{11}\dots r_{nn})^2, so det⁡(G4)=4\det(G_4) = 4 for this matrix.

The Cholesky factorization is named after André-Louis Cholesky (1875–1918), a French military officer involved in geodesy and surveying in Crete and North Africa, who developed it for solving the normal equations arising in least squares problems.

The existence and uniqueness of the factorization can be proved by induction on nn, and the proof also serves as a method for computing it. Partition A∈Rn×nA\in\mathbb{R}^{n\times n} as

A=[An−1ccTα].A = \begin{bmatrix} A_{n-1} & c \\ c^T & \alpha \end{bmatrix}.

We know that An−1A_{n-1} is positive definite (any principal submatrix of a positive definite matrix is easily shown to be positive definite). Assume that An−1A_{n-1} has a unique Cholesky factorization An−1=Rn−1TRn−1A_{n-1} = R_{n-1}^TR_{n-1} and define the upper triangular matrix

R=[Rn−1r0β].R = \begin{bmatrix} R_{n-1} & r \\ 0 & \beta \end{bmatrix}.

Then

RT ⁣R=[Rn−1TRn−1Rn−1TrrTRn−1rTr+β2],R^T\!R = \begin{bmatrix} R_{n-1}^T R_{n-1} & R_{n-1}^T r \\ r^T R_{n-1} & r^Tr + \beta^2 \end{bmatrix},

which equals AA if and only if

Rn−1Tr=c,rTr+β2=α.\begin{aligned} R_{n-1}^T r &= c, \\ r^Tr + \beta^2 &= \alpha. \end{aligned}

The first equation has a unique solution since Rn−1R_{n-1} is nonsingular. Then the second equation gives β2=α−rTr\beta^2 = \alpha - r^Tr. It remains to check that there is a unique real, positive β\beta satisfying this equation. From the inequality

0<det⁡(A)=det⁡(RT)det⁡(R)=det⁡(Rn−1)2β20 < \det(A) = \det(R^T) \det(R) = \det(R_{n-1})^2 \beta^2

we see that β2>0\beta^2>0, hence there is a unique β>0\beta>0. This completes the inductive step.

The quantity α−rTr=α−cTAn−1−1c\alpha - r^Tr = \alpha - c^T A_{n-1}^{-1}c is the Schur complement of An−1A_{n-1} in AA. The essential reason why Cholesky factorization works is that the Schur complements of a positive definite matrix are themselves positive definite. Indeed we have the congruence

[I0−cTAn−1−11][An−1ccTα][I−An−1−1c01]=[An−100α−cTAn−1−1c],\begin{bmatrix} I & 0 \\ -c^T A_{n-1}^{-1} & 1 \end{bmatrix} \begin{bmatrix} A_{n-1} & c \\ c^T & \alpha \end{bmatrix} \begin{bmatrix} I & -A_{n-1}^{-1}c\\ 0 & 1 \end{bmatrix} = \begin{bmatrix} A_{n-1} & 0 \\ 0 & \alpha - c^T A_{n-1}^{-1} c \end{bmatrix},

and since congruences preserve definiteness it follows that α−cTAn−1−1c>0\alpha - c^T A_{n-1}^{-1} c > 0.

In textbooks it is common to see element-level equations for computing the Cholesky factorization, which come from directly solving the matrix equation A=RT ⁣RA = R^T\!R. If we equate elements on both sides, taking them a column at a time, starting with a11=r112a_{11} = r_{11}^2, then the following algorithm is obtained:

1 \mboxfor j=1:n2 \mboxfor i=1:j−13 rij=(aij−∑k=1i−1rkirkj)/rii4 \mboxend5 rjj=(ajj−∑k=1j−1rkj2)1/26 \mboxend\begin{array}{l} 1~ \mbox{for}~j=1:n \\ 2~ \quad \mbox{for}~ i=1:j-1 \\ 3~ \qquad r_{ij} = \bigl(a_{ij} - \sum_{k=1}^{i-1} r_{ki}r_{kj} \bigr) /r_{ii} \\ 4~ \quad \mbox{end} \\ 5~ \quad r_{jj} = \bigl(a_{jj} - \sum_{k=1}^{j-1} r_{kj}^2\bigr)^{1/2} \\ 6~ \mbox{end} \end{array}

What happens if this algorithm is executed on a general (indefinite) symmetric matrix that is, one that has both positive and negative eigenvalues? Line 5 will either attempt to take the square root of a negative number for some jj or it will produce rjj=0r_{jj} = 0 and on the next iteration of the loop we will have a division by zero. In floating-point arithmetic it is possible for the algorithm to fail for a positive definite matrix, but only if it is numerically singular: the algorithm is guaranteed to run to completion if the condition number κ2(A)=∥A∥2∥A−1∥2\kappa_2(A) = \|A\|_2 \|A^{-1}\|_2 is safely less than u−1u^{-1}, where uu is the unit roundoff.

The MATLAB function chol normally returns an error message if the factorization fails. But a second output argument can be requested, which is set to the number of the stage on which the factorization failed, or to zero if the factorization succeeded. In the case of failure, the partially computed RR factor, returned in the first argument, can be used to compute a direction of negative curvature for AA, which is a vector zz such that zT ⁣Az<0z^T\!Az < 0. Here is an example. The code

text
n = 8;
A = gallery('lehmer',n) - 0.3*eye(n); % Indefinite matrix.
[R,p] = chol(A)
z = [-R\(R'\A(1:p-1,p)); 1; zeros(n-p,1)];
neg_curve = z'*A*z

produces the output

text
R =
   8.3666e-01   5.9761e-01   3.9841e-01
            0   5.8554e-01   7.3193e-01
            0            0   7.4536e-02
p =
     4
neg_curve =
  -9.1437e+00

Cholesky factorization has excellent numerical stability. The computed factor R^\widehat{R} satisfies

A+ΔA=R^TR^,∥ΔA∥2≤cnu∥A∥2,A + \Delta A = \widehat{R}^T\widehat{R}, \quad \|\Delta A\|_2 \le c_nu\|A\|_2,

where cnc_n is a constant. Unlike for LU factorization there is no possibility of element growth; indeed for i≤ji\le j,

rij2≤∑k=1jrkj2=aij,r_{ij}^2 \le \displaystyle \sum_{k=1}^j r_{kj}^2 = a_{ij},

so the elements of RR are nicely bounded relative to those of AA.

Once we have a Cholesky factorization we can use it to solve a linear system Ax=bAx = b, by solving the lower triangular system RTy=bR^Ty = b and then the upper triangular system Rx=yRx = y. The computed solution x^\widehat{x} can be shown to satisfy

(A+ΔA)x^=b,∥ΔA∥2≤dnu∥A∥2(A+\Delta A)\widehat{x} = b, \quad \|\Delta A\|_2 \le d_nu\|A\|_2

where dnd_n is another constant. Thus x^\widehat{x} has a small backward error.

Finally, what if AA is only symmetric positive semidefinite, that is, xT ⁣Ax≥0x^T\!Ax \ge 0 for all xx, so that AA is possibly singular? There always exists a Cholesky factorization (we can take the RR factor in the QR factorization of the positive semidefinite square root of AA) but it may not be unique. For example, we have

A=[1111111111221124]=[10001000110011xy][11110011000x000y]=RT ⁣RA = \left[\begin{array}{cccc} 1 & 1 & 1 & 1\\ 1 & 1 & 1 & 1\\ 1 & 1 & 2 & 2\\ 1 & 1 & 2 & 4\\ \end{array}\right] = \left[\begin{array}{cccc} 1 & 0 & 0 & 0\\ 1 & 0 & 0 & 0\\ 1 & 1 & 0 & 0\\ 1 & 1 & x & y\\ \end{array}\right] \left[\begin{array}{cccc} 1 & 1 & 1 & 1\\ 0 & 0 & 1 & 1\\ 0 & 0 & 0 & x\\ 0 & 0 & 0 & y\\ \end{array}\right] = R^T\!R

for any xx and yy such that x2+y2=2x^2 + y^2 = 2. Note that AA has rank 3 but RR has two zero diagonal elements. When AA is positive semidefinite of rank rr what is usually wanted is a Cholesky factorization in which RR is zero in its last n−rn-r rows. Such a factorization can be obtained by using complete pivoting, which at each stage permutes the largest remaining diagonal element into the pivot position, which gives a factorization

ΠT ⁣AΠ=RT ⁣R,R=[R11R1200],R11∈Rr×r,\Pi^T\mskip-5mu A\Pi = R^T\!R, \quad R = \begin{bmatrix} R_{11} & R_{12} \\ 0 & 0 \end{bmatrix}, \quad R_{11}\in\mathbb{R}^{r \times r},

where Π\Pi is a permutation matrix. For example, with Π\Pi the identity matrix with its columns in reverse order,

ΠT ⁣AΠ=[4211221111111111]=[2000110012122201212220][2112120112120022220000],\Pi^T\mskip-5mu A\Pi = \left[\begin{array}{cccc} 4 & 2 & 1 & 1\\ 2 & 2 & 1 & 1\\ 1 & 1 & 1 & 1\\ 1 & 1 & 1 & 1 \end{array}\right] = \left[\begin{array}{cccc} 2 & 0 & 0 & 0\\ 1 & 1 & 0 & 0\\ \frac{1}{2} & \frac{1}{2} & \frac{\sqrt{2}}{2} & 0\\[2pt] \frac{1}{2} & \frac{1}{2} & \frac{\sqrt{2}}{2} & 0 \end{array}\right] \left[\begin{array}{cccc} 2 & 1 & \frac{1}{2} & \frac{1}{2}\\[2pt] 0 & 1 & \frac{1}{2} & \frac{1}{2}\\[2pt] 0 & 0 & \frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2}\\ 0 & 0 & 0 & 0 \end{array}\right],

which clearly displays the rank of AA.

References

This is a minimal set of references, which contain further useful references within.

This article is part of the “What Is” series, available from https://nhigham.com/category/what-is and in PDF form from the GitHub repository https://github.com/higham/what-is.