# Cholesky decomposition

In linear algebra, the **Cholesky decomposition** or **Cholesky factorization** is a decomposition of a Hermitian, positive-definite matrix into the product of a lower triangular matrix and its conjugate transpose, useful for efficient numerical solutions and Monte Carlo simulations. It was discovered by André-Louis Cholesky for real matrices. When it is applicable, the Cholesky decomposition is roughly twice as efficient as the LU decomposition for solving systems of linear equations.^{[1]}

## Contents

## Statement

The Cholesky decomposition of a Hermitian positive-definite matrix **A** is a decomposition of the form

where **L** is a lower triangular matrix with real and positive diagonal entries, and **L*** denotes the conjugate transpose of **L**. Every Hermitian positive-definite matrix (and thus also every real-valued symmetric positive-definite matrix) has a unique Cholesky decomposition.^{[2]}

If the matrix **A** is Hermitian and positive semi-definite, then it still has a decomposition of the form **A** = **LL*** if the diagonal entries of **L** are allowed to be zero.^{[3]}

When **A** has real entries, **L** has real entries as well and the factorization may be written **A = LL ^{T}**

^{[4]}

The Cholesky decomposition is unique when **A** is positive definite; there is only one lower triangular matrix **L** with strictly positive diagonal entries such that **A** = **LL***. However, the decomposition need not be unique when **A** is positive semidefinite.

The converse holds trivially: if **A** can be written as **LL*** for some invertible **L**, lower triangular or otherwise, then **A** is Hermitian and positive definite.

## LDL decomposition

A closely related variant of the classical Cholesky decomposition is the LDL decomposition,

where **L** is a lower unit triangular (unitriangular) matrix and **D** is a diagonal matrix.

This decomposition is related to the classical Cholesky decomposition, of the form **LL***, as follows:

The LDL variant, if efficiently implemented, requires the same space and computational complexity to construct and use but avoids extracting square roots.^{[5]} Some indefinite matrices for which no Cholesky decomposition exists have an LDL decomposition with negative entries in **D**. For these reasons, the LDL decomposition may be preferred.
For real matrices, the factorization has the form **A = LDL ^{T}** and is often referred to as

**LDLT decomposition**(or LDL

^{T}decomposition). It is closely related to the eigendecomposition of real symmetric matrices,

**A=QΛQ**.

^{T}## Example

Here is the Cholesky decomposition of a symmetric real matrix:

And here is the LDL^{T} decomposition of the same matrix:

## Applications

The Cholesky decomposition is mainly used for the numerical solution of linear equations **Ax** = **b**. If **A** is symmetric and positive definite, then we can solve **Ax** = **b** by first computing the Cholesky decomposition **A** = **LL***, then solving **Ly** = **b** for **y** by forward substitution, and finally solving **L*****x** = **y** for **x** by back substitution.

For linear systems that can be put into symmetric form, the Cholesky decomposition (or its LDL variant) is the method of choice, for superior efficiency and numerical stability. Compared to the LU decomposition, it is roughly twice as efficient.

### Linear least squares

Systems of the form **Ax** = **b** with **A** symmetric and positive definite arise quite often in applications. For instance, the normal equations in linear least squares problems are of this form. It may also happen that matrix **A** comes from an energy functional which must be positive from physical considerations; this happens frequently in the numerical solution of partial differential equations.

### Non-linear optimization

Non-linear multi-variate functions may be minimized over their parameters using variants of Newton's method called *quasi-Newton* methods. At each iteration, the search takes a step **s** defined by solving **Hs** = **-g** for **s**, where **s** is the step, **g** is the *gradient* vector of the function's partial first derivatives with respect to the parameters, and **H** is an approximation to the Hessian matrix of partial second derivatives formed by repeated rank 1 updates at each iteration. Two well-known update formulae are called Davidon-Fletcher-Powell (DFP) and Broyden-Fletcher-Goldfarb-Shanno (BFGS). Loss of the positive-definite condition through round-off error is avoided if rather than updating an approximation to the inverse of the Hessian, one updates the Cholesky decomposition of an approximation of the Hessian matrix itself.{{ safesubst:#invoke:Unsubst||date=__DATE__ |$B=
{{#invoke:Category handler|main}}{{#invoke:Category handler|main}}^{[citation needed]}
}}

### Monte Carlo simulation

The Cholesky decomposition is commonly used in the Monte Carlo method for simulating systems with multiple correlated variables: The correlation matrix is decomposed, to give the lower-triangular **L**. Applying this to a vector of uncorrelated samples, **u**, produces a sample vector **Lu** with the covariance properties of the system being modeled.^{[6]}

For a simplified example that shows the economy one gets from Cholesky's decomposition, say one needs to generate two correlated normal variables and . All one needs to do is generate two uncorrelated Gaussian random variables and . We set and .

### Kalman filters

Unscented Kalman filters commonly use the Cholesky decomposition to choose a set of so-called sigma points. The Kalman filter tracks the average state of a system as a vector **x** of length *N* and covariance as an *N*-by-*N* matrix **P**. The matrix **P** is always positive semi-definite, and can be decomposed into **LL**^{T}. The columns of **L** can be added and subtracted from the mean **x** to form a set of 2*N* vectors called *sigma points*. These sigma points completely capture the mean and covariance of the system state.

### Matrix inversion

The explicit inverse of a Hermitian matrix can be computed via Cholesky decomposition, in a manner similar to solving linear systems, using operations ( multiplications).^{[5]} The entire inversion can even be efficiently performed in-place.

A non-Hermitian matrix **B** can also be inverted using the following identity, where **BB*** will always be Hermitian:

## Computation

There are various methods for calculating the Cholesky decomposition. The computational complexity of commonly used algorithms is *O*(*n*^{3}) in general.{{ safesubst:#invoke:Unsubst||date=__DATE__ |$B=
{{#invoke:Category handler|main}}{{#invoke:Category handler|main}}^{[citation needed]}
}} The algorithms described below all involve about *n*^{3}/3 FLOPs, where *n* is the size of the matrix **A**. Hence, they are half the cost of the LU decomposition, which uses 2*n*^{3}/3 FLOPs (see Trefethen and Bau 1997).

Which of the algorithms below is faster depends on the details of the implementation. Generally, the first algorithm will be slightly slower because it accesses the data in a less regular manner.

### The Cholesky algorithm

The **Cholesky algorithm**, used to calculate the decomposition matrix *L*, is a modified version of Gaussian elimination.

The recursive algorithm starts with *i* := 1 and

**A**^{(1)}:=**A**.

At step *i*, the matrix **A**^{(i)} has the following form:

where **I**_{i−1} denotes the identity matrix of dimension *i* − 1.

If we now define the matrix **L**_{i} by

then we can write **A**^{(i)} as

where

Note that **b**_{i} **b***_{i} is an outer product, therefore this algorithm is called the *outer product version* in (Golub & Van Loan).

We repeat this for *i* from 1 to *n*. After *n* steps, we get **A**^{(n+1)} = **I**. Hence, the lower triangular matrix *L* we are looking for is calculated as

### The Cholesky–Banachiewicz and Cholesky–Crout algorithms

If we write out the equation **A** = **LL***,

we obtain the following formula for the entries of **L**:

The expression under the square root is always positive if **A** is real and positive-definite.

For complex Hermitian matrix, the following formula applies:

So we can compute the (*i*, *j*) entry if we know the entries to the left and above. The computation is usually arranged in either of the following orders.

- The
**Cholesky–Banachiewicz algorithm**starts from the upper left corner of the matrix*L*and proceeds to calculate the matrix row by row. - The
**Cholesky–Crout algorithm**starts from the upper left corner of the matrix*L*and proceeds to calculate the matrix column by column.

Either pattern of access allows the entire computation to be performed in-place if desired.

### Stability of the computation

Suppose that we want to solve a well-conditioned system of linear equations. If the LU decomposition is used, then the algorithm is unstable unless we use some sort of pivoting strategy. In the latter case, the error depends on the so-called growth factor of the matrix, which is usually (but not always) small.

Now, suppose that the Cholesky decomposition is applicable. As mentioned above, the algorithm will be twice as fast. Furthermore, no pivoting is necessary and the error will always be small. Specifically, if we want to solve **Ax** = **b**, and **y** denotes the computed solution, then **y** solves the disturbed system (**A** + **E**)**y** = **b** where

Here, || ||_{2} is the matrix 2-norm, *c _{n}* is a small constant depending on

*n*, and ε denotes the unit round-off.

One concern with the Cholesky decomposition to be aware of is the use of square roots. If the matrix being factorized is positive definite as required, the numbers under the square roots are always positive *in exact arithmetic*. Unfortunately, the numbers can become negative because of round-off errors, in which case the algorithm cannot continue. However, this can only happen if the matrix is very ill-conditioned. One way to address this is to add a diagonal correction matrix to the matrix being decomposed in an attempt to promote the positive-definiteness.^{[7]} While this might lessen the accuracy of the decomposition, it can be very favorable for other reasons; for example, when performing Newton's method in optimization, adding a diagonal matrix can improve stability when far from the optimum.

### LDL decomposition

An alternative form, eliminating the need to take square roots, is the symmetric indefinite factorization^{[8]}

If **A** is real, the following recursive relations apply for the entries of **D** and **L**:

For complex Hermitian matrix **A**, the following formula applies:

Again, the pattern of access allows the entire computation to be performed in-place if desired.

### Block variant

When used on indefinite matrices, the **LDL*** factorization is known to be unstable without careful pivoting;^{[9]} specifically, the elements of the factorization can grow arbitrarily. A possible improvement is to perform the factorization on block sub-matrices, commonly 2x2:^{[10]}

where every element in the matrices above is a square submatrix. From this, these analogous recursive relations follow:

Note the presence of matrix products and explicit inversion, this limits the practical block size.

### Updating the decomposition

A task that often arises in practice is that one needs to update a Cholesky decomposition. In more details, one has already computed the Cholesky decomposition **A** = **LL*** of some matrix **A**, then one changes the matrix **A** in some way into another matrix, say , and one wants to compute the Cholesky decomposition of the updated matrix: . The question is now whether one can use the Cholesky decomposition of **A** that was computed before to compute the Cholesky decomposition of .

#### Rank-one update

The specific case, where the updated matrix is related to the matrix **A** by , is known as a *rank-one update*.

Here is a little function based on ^{[11]} written in Matlab syntax which realizes a rank-one update:

```
function [L] = cholupdate(L,x)
p = length(x);
x = x';
for k=1:p
r = sqrt(L(k,k)^2 + x(k)^2);
c = r / L(k, k);
s = x(k) / L(k, k);
L(k, k) = r;
L(k,k+1:p) = (L(k,k+1:p) + s*x(k+1:p)) / c;
x(k+1:p) = c*x(k+1:p) - s*L(k, k+1:p);
end
end
```

#### Rank-one downdate

A *rank-one downdate* is similar to a rank-one update, except that the addition is replaced by subtraction: . This only works if the new matrix is still positive definite.

The code for the rank-one update shown above can easily be adapted to do a rank-one downdate: one merely needs to replace the two additions in the assignment to ` r `

and ` L(k,k+1:p) `

by subtractions.

## Proof for positive semi-definite matrices

The above algorithms show that every positive definite matrix **A** has a Cholesky decomposition. This result can be extended to the positive semi-definite case by a limiting argument. The argument is not fully constructive, i.e., it gives no explicit numerical algorithms for computing Cholesky factors.

If **A** is an *n*-by-*n* positive semi-definite matrix, then the sequence {**A**_{k}} = {**A** + (1/*k*)**I**_{n}} consists of positive definite matrices. (This is an immediate consequence of, for example, the spectral mapping theorem for the polynomial functional calculus.) Also,

**A**_{k}→**A**

in operator norm. From the positive definite case, each **A**_{k} has Cholesky decomposition **A**_{k} = **L**_{k}**L***_{k}. By property of the operator norm,

So {**L**_{k}} is a bounded set in the Banach space of operators, therefore relatively compact (because the underlying vector space is finite-dimensional). Consequently it has a convergent subsequence, also denoted by {**L**_{k}}, with limit **L**. It can be easily checked that this **L** has the desired properties, i.e. **A** = **LL*** and **L** is lower triangular with non-negative diagonal entries: for all *x* and *y*,

Therefore **A** = **LL***. Because the underlying vector space is finite-dimensional, all topologies on the space of operators are equivalent. So **L**_{k} tends to **L** in norm means **L**_{k} tends to **L** entrywise. This in turn implies that, since each **L**_{k} is lower triangular with non-negative diagonal entries, **L** is also.

## Generalization

The Cholesky factorization can be generalized to (not necessarily finite) matrices with operator entries. Let be a sequence of Hilbert spaces. Consider the operator matrix

acting on the direct sum

where each

is a bounded operator. If **A** is positive (semidefinite) in the sense that for all finite *k* and for any

we have , then there exists a lower triangular operator matrix **L** such that **A** = **LL***. One can also take the diagonal entries of **L** to be positive.

## Implementations in programming languages

In Python, the command "cholesky" from the numpy.linalg module performs Cholesky decomposition. In Matlab Programming, the "chol" command can be used to simply apply this to a matrix. In R the "chol" gives Cholesky decomposition.

## See also

- Symbolic Cholesky decomposition
- Minimum degree algorithm
- Matrix decomposition
- Sylvester's law of inertia
- Cycle rank
- Matrix square root

## Notes

- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ Template:Harvtxt, Template:Harvtxt, Template:Harvtxt
- ↑ Template:Harvtxt
- ↑ Template:Harvtxt
- ↑
^{5.0}^{5.1}{{#invoke:Citation/CS1|citation |CitationClass=journal }} - ↑ Matlab randn documentaion.
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}
- ↑ {{#invoke:Citation/CS1|citation |CitationClass=journal }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=book }}

## References

- {{#invoke:Citation/CS1|citation

|CitationClass=journal }}.

- {{#invoke:citation/CS1|citation

|CitationClass=book }}.

- {{#invoke:citation/CS1|citation

|CitationClass=book }}.

- S. J. Julier and J. K. Uhlmann. "A General Method for Approximating Nonlinear Transformations of ProbabilityDistributions".
- S. J. Julier and J.K. Uhlmann, "A new extension of the Kalman filter to nonlinear systems," in Proc. AeroSense: 11th Int. Symp. Aerospace/Defence Sensing, Simulation and Controls, 1997, pp. 182–193.
- {{#invoke:citation/CS1|citation

|CitationClass=book }}.

## External links

### Information

- {{#invoke:citation/CS1|citation

|CitationClass=citation }}

- Template:Planetmath reference
- Cholesky Decomposition, The Data Analysis BriefBook
- Module for Cholesky Factorization
- Cholesky Decomposition on www.math-linux.com
- Cholesky Decomposition Made Simple on Science Meanderthal

### Computer code

- LAPACK is a collection of FORTRAN subroutines for solving dense linear algebra problems
- ALGLIB includes a partial port of the LAPACK to C++, C#, Delphi, Visual Basic, etc.
- libflame is a C library with LAPACK functionality.
- Notes and video on high-performance implementation of Cholesky factorization at The University of Texas at Austin.
- Cholesky : TBB + Threads + SSE is a book explaining the implementation of the CF with TBB,threads and SSE (in Spanish).
- library "Ceres Solver" by Google.
- LDL decomposition routines in Matlab.

### Use of the matrix in simulation

- Simulation of correlated normal random variables
- Generating Correlated Random Variables, Martin Haugh, Columbia University

### Online calculators

- Online Matrix Calculator Performs Cholesky decomposition of matrices online.