Top Description Inners Fields Constructors Methods
org.apache.commons.math3.linear

public Class CholeskyDecomposition

extends Object
Class Inheritance
Imports
org.apache.commons.math3.exception.DimensionMismatchException, org.apache.commons.math3.util.FastMath

Calculates the Cholesky decomposition of a matrix.

The Cholesky decomposition of a real symmetric positive-definite matrix A consists of a lower triangular matrix L with same size such that: A = LLT. In a sense, this is the square root of A.

This class is based on the class with similar name from the JAMA library, with the following changes:

Since
2.0 (changed to concrete class in 3.0)
See Also
MathWorld, Wikipedia

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
CholeskyDecomposition.Solver

Specialized solver.

Field Summary

Modifier and TypeField and Description
private RealMatrix
cachedL

Cached value of L.

private RealMatrix
cachedLT

Cached value of LT.

public static final double
DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD

Default threshold below which diagonal elements are considered null and matrix not positive definite.

public static final double
DEFAULT_RELATIVE_SYMMETRY_THRESHOLD

Default threshold above which off-diagonal elements are considered too different and matrix not symmetric.

private double[][]
lTData

Row-oriented storage for LT matrix data.

Constructor Summary

AccessConstructor and Description
public
CholeskyDecomposition(final RealMatrix
the matrix to decompose
matrix
)

Calculates the Cholesky decomposition of the given matrix.

public
CholeskyDecomposition(final RealMatrix
the matrix to decompose
matrix
,
final double
threshold above which off-diagonal elements are considered too different and matrix not symmetric
relativeSymmetryThreshold
,
final double
threshold below which diagonal elements are considered null and matrix not positive definite
absolutePositivityThreshold
)

Calculates the Cholesky decomposition of the given matrix.

Method Summary

Modifier and TypeMethod and Description
public double

Returns:

determinant of the matrix
getDeterminant
()

Return the determinant of the matrix

public RealMatrix

Returns:

the L matrix
getL
()

Returns the matrix L of the decomposition.

public RealMatrix

Returns:

the transpose of the matrix L of the decomposition
getLT
()

Returns the transpose of the matrix L of the decomposition.

public DecompositionSolver

Returns:

a solver
getSolver
()

Get a solver for finding the A × X = B solution in least square sense.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachedLback to summary
private RealMatrix cachedL

Cached value of L.

cachedLTback to summary
private RealMatrix cachedLT

Cached value of LT.

DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLDback to summary
public static final double DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD

Default threshold below which diagonal elements are considered null and matrix not positive definite.

DEFAULT_RELATIVE_SYMMETRY_THRESHOLDback to summary
public static final double DEFAULT_RELATIVE_SYMMETRY_THRESHOLD

Default threshold above which off-diagonal elements are considered too different and matrix not symmetric.

lTDataback to summary
private double[][] lTData

Row-oriented storage for LT matrix data.

Constructor Detail

CholeskyDecompositionback to summary
public CholeskyDecomposition(final RealMatrix matrix)

Calculates the Cholesky decomposition of the given matrix.

Calling this constructor is equivalent to call CholeskyDecomposition(RealMatrix, double, double) with the thresholds set to the default values DEFAULT_RELATIVE_SYMMETRY_THRESHOLD and DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD

Parameters
matrix:RealMatrix

the matrix to decompose

Exceptions
NonSquareMatrixException:
if the matrix is not square.
NonSymmetricMatrixException:
if the matrix is not symmetric.
NonPositiveDefiniteMatrixException:
if the matrix is not strictly positive definite.
See Also
CholeskyDecomposition(RealMatrix, double, double), DEFAULT_RELATIVE_SYMMETRY_THRESHOLD, DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD
CholeskyDecompositionback to summary
public CholeskyDecomposition(final RealMatrix matrix, final double relativeSymmetryThreshold, final double absolutePositivityThreshold)

Calculates the Cholesky decomposition of the given matrix.

Parameters
matrix:RealMatrix

the matrix to decompose

relativeSymmetryThreshold:double

threshold above which off-diagonal elements are considered too different and matrix not symmetric

absolutePositivityThreshold:double

threshold below which diagonal elements are considered null and matrix not positive definite

Exceptions
NonSquareMatrixException:
if the matrix is not square.
NonSymmetricMatrixException:
if the matrix is not symmetric.
NonPositiveDefiniteMatrixException:
if the matrix is not strictly positive definite.
See Also
CholeskyDecomposition(RealMatrix), DEFAULT_RELATIVE_SYMMETRY_THRESHOLD, DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD

Method Detail

getDeterminantback to summary
public double getDeterminant()

Return the determinant of the matrix

Returns:double

determinant of the matrix

getLback to summary
public RealMatrix getL()

Returns the matrix L of the decomposition.

L is an lower-triangular matrix

Returns:RealMatrix

the L matrix

getLTback to summary
public RealMatrix getLT()

Returns the transpose of the matrix L of the decomposition.

LT is an upper-triangular matrix

Returns:RealMatrix

the transpose of the matrix L of the decomposition

getSolverback to summary
public DecompositionSolver getSolver()

Get a solver for finding the A × X = B solution in least square sense.

Returns:DecompositionSolver

a solver

org.apache.commons.math3.linear back to summary

private Class CholeskyDecomposition.Solver

extends Object
implements DecompositionSolver
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.linear.DecompositionSolver

Specialized solver.

Field Summary

Modifier and TypeField and Description
private final double[][]
lTData

Row-oriented storage for LT matrix data.

Constructor Summary

AccessConstructor and Description
private
Solver(final double[][]
row-oriented storage for LT matrix data
lTData
)

Build a solver from decomposed matrix.

Method Summary

Modifier and TypeMethod and Description
public RealMatrix

Returns:

the inverse matrix.
getInverse
()

Implements org.apache.commons.math3.linear.DecompositionSolver.getInverse.

Get the inverse of the decomposed matrix.

public boolean
isNonSingular()

Implements org.apache.commons.math3.linear.DecompositionSolver.isNonSingular.

Check if the decomposed matrix is non-singular.

public RealVector
solve(final RealVector
right-hand side of the equation A × X = B
b
)

Implements org.apache.commons.math3.linear.DecompositionSolver.solve.

Solve the linear equation A × X = B for matrices A.

public RealMatrix
solve(RealMatrix
right-hand side of the equation A × X = B
b
)

Implements org.apache.commons.math3.linear.DecompositionSolver.solve.

Solve the linear equation A × X = B for matrices A.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lTDataback to summary
private final double[][] lTData

Row-oriented storage for LT matrix data.

Constructor Detail

Solverback to summary
private Solver(final double[][] lTData)

Build a solver from decomposed matrix.

Parameters
lTData:double[][]

row-oriented storage for LT matrix data

Method Detail

getInverseback to summary
public RealMatrix getInverse()

Implements org.apache.commons.math3.linear.DecompositionSolver.getInverse.

Get the inverse of the decomposed matrix.

Returns:RealMatrix

the inverse matrix.

isNonSingularback to summary
public boolean isNonSingular()

Implements org.apache.commons.math3.linear.DecompositionSolver.isNonSingular.

Doc from org.apache.commons.math3.linear.DecompositionSolver.isNonSingular.

Check if the decomposed matrix is non-singular.

Returns:boolean

true if the decomposed matrix is non-singular.

solveback to summary
public RealVector solve(final RealVector b)

Implements org.apache.commons.math3.linear.DecompositionSolver.solve.

Doc from org.apache.commons.math3.linear.DecompositionSolver.solve.

Solve the linear equation A × X = B for matrices A.

The A matrix is implicit, it is provided by the underlying decomposition algorithm.

Parameters
b:RealVector

right-hand side of the equation A × X = B

Returns:RealVector

a vector X that minimizes the two norm of A × X - B

solveback to summary
public RealMatrix solve(RealMatrix b)

Implements org.apache.commons.math3.linear.DecompositionSolver.solve.

Doc from org.apache.commons.math3.linear.DecompositionSolver.solve.

Solve the linear equation A × X = B for matrices A.

The A matrix is implicit, it is provided by the underlying decomposition algorithm.

Parameters
b:RealMatrix

right-hand side of the equation A × X = B

Returns:RealMatrix

a matrix X that minimizes the two norm of A × X - B