Open In App

Choleski Decomposition in R

Improve
Improve
Like Article
Like
Save
Share
Report

Cholesky Decomposition is a popular numerical method used in linear algebra for decomposing a Hermitian positive-definite matrix into the product of a lower triangular matrix and its transpose. In this article, we’ll learn how to perform Cholesky Decomposition in R programming language.

Before diving into the implementation, let’s first understand some key concepts that are important to know:

  • A symmetric matrix is a square matrix that is equal to its transpose.
  • A Hermitian matrix is a square matrix of complex numbers, which is equal to its own conjugate transpose. 
  • A positive-definite matrix is a symmetric matrix with positive eigenvalues.
  • The lower triangular matrix is a square matrix that has all the entries above the main diagonal set to zero.

Cholesky Decomposition Algorithm:

Suppose A is a Hermitian positive-definitive matrix, then it can be decomposed by Cholesky decomposition as the product of lower triangular matrix L and the conjugate transpose of this lower triangular matrix L as A = LL^*

If A is a symmetric positive-definitive matrix (or having real values), then it can be decomposed by Cholesky decomposition as the product of lower triangular matrix L and the transpose of this lower triangular matrix L as :

A = LM \\ \text{where}, \\\;\;\;\;\;\;\; L_{j,j}=\sqrt {A_{j,j}-\sum_{k=0}^{j-1}(L_{j,k})^{2}} \\\;\;\;\;\;\;\; M = L^T \text{   Transpose of \;L}

Let \begin{bmatrix} A_{00} & A_{01} & A_{02}\\ A_{10} & A_{11} & A_{12}\\ A_{20} & A_{21} & A_{22} \end{bmatrix}    then it can be decomposed as :

\left[\begin{array}{lll} A_{00} & A_{01} & A_{02} \\ A_{10} & A_{11} & A_{12} \\ A_{20} & A_{21} & A_{22} \end{array}\right]=\left[\begin{array}{lll} L_{00} & 0 & 0 \\ L_{10} & L_{11} & 0 \\ L_{20} & L_{21} & L_{22} \end{array}\right]\left[\begin{array}{ccc} L_{00} & L_{10} & L_{20} \\ 0 & L_{11} & L_{21} \\ 0 & 0 & L_{22} \end{array}\right]    \\ \text{where}, \\\;\;\;\;\;\;\; L_{j,j}=\sqrt {A_{j,j}-\sum_{k=0}^{j-1}(L_{j,k})^{2}}

Example 1: With a symmetric positive-definitive matrix

Step 1: Load Required Libraries

The first step is to load the required libraries in R. In this case, we’ll be using the Matrix library, which provides functions for linear algebraic operations.

library(Matrix)

Step 2: Define the Matrix

Next, we’ll define the symmetric, positive-definite matrix that we want to decompose. In this example, we’ll use the following matrix:

R

A <- matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow = 3)
A

                    

Output:

A matrix: 3 × 3 of type dbl
25    15    -5
15    18    0
-5    0    11

Step 3: Perform Cholesky Decomposition

Now, we’ll perform the Cholesky Decomposition on the defined matrix using the chol() function. The function returns the lower triangular matrix L such that A = t(L) %*% L.

R

L <- chol(A)
L

                    

Output:

A matrix: 3 × 3 of type dbl
5    3    -1
0    3    1
0    0    3

Step 4: Find the transpose of the lower triangular matrix L

R

M = t(L)
M

                    

Output:

A matrix: 3 × 3 of type dbl
5    0    0
3    3    0
-1    1    3

Step 5: Verify the Decomposition

To verify the decomposition, we can multiply the lower triangular matrix L with its transpose t(L) and compare the result with the original matrix A.

R

A_new <- M %*% L
A_new

                    

Output:

A matrix: 3 × 3 of type dbl
25    15    -5
15    18    0
-5    0    11

R

all.equal(A, A_new)

                    

Output:

TRUE

The output of the all.equal() function is TRUE, indicating that the decomposition is correct.

Note: Currently, Hermitian positive-definite matrices (or complex matrices) are not permitted to present with chol() function.

Use Cholesky Decomposition for Solving Linear Equations

One of the primary applications of Cholesky Decomposition is solving linear equations. Given a system of linear equations Ax = b, we can solve for x using the following steps:

  • Decompose the matrix A using Cholesky Decomposition to get L and t(L).
  • Solve the lower triangular system Lx = b for x using forward substitution.
  • Solve the upper triangular system t(L)x = y for x using backward substitution.

Conclusion

The Cholesky decomposition is efficient and has many useful properties, such as being a stable and exact factorization for positive-definite matrices, and having the triangular factor being easy to invert. The decomposition can also be computed in a distributed computing environment, making it useful for large-scale problems.



Last Updated : 21 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads