Extreme Optimization >
User's Guide >
Vector and Matrix Library >
Matrix Decompositions >
The Cholesky Decomposition
Extreme Optimization User's Guide
User's Guide
Up: Matrix Decompositions Next: The Symmetric Eigenvalue Decomposition Previous: The QR Decomposition Contents
The Cholesky Decomposition
The Cholesky decomposition or Cholesky factorization
is defined only for positive-definite symmetric matrices. It
expresses a matrix as the product of a lower triangular matrix and
its transpose.
The Cholesky decomposition algorithm exploits the special
structure of symmetric matrices. As a result, it is about twice as
fast as the LU decomposition. Moreover, the decomposition is fairly
stable, so it is suitable for use in a broader range of
problems.
In the Extreme Optimization Mathematics Library for
.NET, the Cholesky decomposition is implemented by the
CholeskyDecomposition
class.
class
The CholeskyDecomposition
class represents the Cholesky decomposition of a matrix. It has two
constructors. The first variant takes a SymmetricMatrix
as its only parameter.
| C# | Copy Code |
SymmetricMatrix aC = new SymmetricMatrix(4,
new double[]
{
4.16,-3.12, 0.56,-0.10,
0, 5.03,-0.83, 1.18,
0,0, 0.76, 0.34,
0,0,0, 1.18
}, MatrixTriangleMode.Lower);
CholeskyDecomposition c = new CholeskyDecomposition(aC); |
| Visual Basic | Copy Code |
Dim aC As SymmetricMatrix = New SymmetricMatrix(4, _
New Double() _
{ _
4.16, -3.12, 0.56, -0.1, _
0, 5.03, -0.83, 1.18, _
0, 0, 0.76, 0.34, _
0, 0, 0, 1.18 _
}, MatrixTriangleMode.Lower)
Dim c As CholeskyDecomposition = New CholeskyDecomposition(aC) |
The second constructor has an additional Boolean
parameter that specifies whether the contents of the first
parameter should be overwritten by the Cholesky decomposition. The
matrix must be positive definite.
| C# | Copy Code |
CholeskyDecomposition c2 = new CholeskyDecomposition(aC, true); |
| Visual Basic | Copy Code |
Dim c2 As CholeskyDecomposition = New CholeskyDecomposition(aC, True) |
The
Decompose method performs the actual decomposition.
This method copies the matrix if necessary. It then calls the
appropriate LAPACK routine to perform the actual decomposition. If
the matrix is not positive definite, an exception of type
MatrixNotPositiveDefiniteException is thrown. This
method is called by other methods as needed. You will rarely need
to call it explicitly.
Once the decomposition is computed, a number of operations can
be performed in much less time. You can repeatedly solve a system
of simultaneous linear equations with different right-hand sides.
You can also calculate the determinant and the inverse of the base
matrix:
| C# | Copy Code |
GeneralMatrix bC = new GeneralMatrix(4, 2,
new double[] {8.70,-13.35,1.89,-4.14,8.30,2.13,1.61,5.00});
Matrix xC = c.Solve(bC);
Console.WriteLine("x = {0}", xC);
Console.WriteLine("Inv A = {0}", c.GetInverse().ToString("F4"));
Console.WriteLine("Det A = {0}", c.GetDeterminant()); |
| Visual Basic | Copy Code |
Dim bC As GeneralMatrix = New GeneralMatrix(4, 2, _
New Double() {8.7, -13.35, 1.89, -4.14, 8.3, 2.13, 1.61, 5.0})
Dim xC As Matrix = c.Solve(bC)
Console.WriteLine("x = {0}", xC)
Console.WriteLine("Inv A = {0}", c.GetInverse().ToString("F4"))
Console.WriteLine("Det A = {0}", c.GetDeterminant()) |
The
LowerTriangularFactor property returns a
TriangularMatrix
containing the lower triangular matrix, G, of the
decomposition.
| C# | Copy Code |
Console.WriteLine("L = {0}", c.LowerTriangularFactor.ToString("F4")); |
| Visual Basic | Copy Code |
Console.WriteLine("L = {0}", c.LowerTriangularFactor.ToString("F4")) |
Band Cholesky Decomposition
The Cholesky decomposition of a symmetric band matrix is made up
of a lower band matrix with lower bandwidth the same as the
original matrix, and its transpose. The band structure allows for
significant savings in computation time over a full Cholesky
decomposition. The BandCholeskyDecomposition
class takes advantage of the band structure. This class has the
equivalent functionality as the general
CholeskyDecomposition class, but takes band matrices
as parameters and returns a band matrix where applicable.
Up: Matrix Decompositions Next: The Symmetric Eigenvalue Decomposition Previous: The QR Decomposition Contents
Copyright 2004-2008,
Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M
Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual
Studio.NET, and the Visual Studio Logo are registered trademarks of Microsoft Corporation