Package com.irurueta.algebra
Class CholeskyDecomposer
java.lang.Object
com.irurueta.algebra.Decomposer
com.irurueta.algebra.CholeskyDecomposer
This class allows decomposition of matrices using Cholesky decomposition,
which consists on retrieving a lower or upper triangular matrix so that input
matrix can be decomposed as: A = L * L' = R' * R, where A is provided input
matrix, L is a lower triangular matrix and R is an upper triangular matrix.
Note: Cholesky decomposition can only be correctly computed on positive
definite matrices.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Matrix
Internal storage of Cholesky decomposition for provided input matrix.private boolean
Boolean indicating whether provided input matrix is symmetric and positive definite.Fields inherited from class com.irurueta.algebra.Decomposer
inputMatrix, locked
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor of this class.CholeskyDecomposer
(Matrix inputMatrix) Constructor of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method computes Cholesky matrix decomposition, which consists on factoring provided input matrix whenever it is square, symmetric and positive definite into a lower triangulator factor such that it follows next expression: A = L * L' where A is input matrix and L is lower triangular factor (L' is its transposed).Returns decomposer type corresponding to Cholesky decomposition.getL()
Returns Cholesky matrix factor corresponding to a Lower triangular matrix following this expression: A = L * L'.getR()
Returns Cholesky matrix factor corresponding to an upper triangular matrix following this expression: A = R' * R.boolean
Returns boolean indicating whether decomposition has been computed and results can be retrieved.boolean
isSPD()
Returns boolean indicating whether provided input matrix is Symmetric Positive Definite or not.void
setInputMatrix
(Matrix inputMatrix) Sets reference to input matrix to be decomposed.Solves a linear system of equations of the following form: A * X = B.void
Solves a linear system of equations of the following form: A * X = B.Methods inherited from class com.irurueta.algebra.Decomposer
getInputMatrix, isLocked, isReady
-
Field Details
-
r
Internal storage of Cholesky decomposition for provided input matrix. -
spd
private boolean spdBoolean indicating whether provided input matrix is symmetric and positive definite.
-
-
Constructor Details
-
CholeskyDecomposer
public CholeskyDecomposer()Constructor of this class. -
CholeskyDecomposer
Constructor of this class.- Parameters:
inputMatrix
- Reference to input matrix to be decomposed.
-
-
Method Details
-
getDecomposerType
Returns decomposer type corresponding to Cholesky decomposition.- Specified by:
getDecomposerType
in classDecomposer
- Returns:
- Decomposer type.
-
setInputMatrix
Sets reference to input matrix to be decomposed.- Overrides:
setInputMatrix
in classDecomposer
- Parameters:
inputMatrix
- Reference to input matrix to be decomposed.- Throws:
LockedException
- Exception thrown if attempting to call this method while this instance remains locked.
-
isDecompositionAvailable
public boolean isDecompositionAvailable()Returns boolean indicating whether decomposition has been computed and results can be retrieved. Attempting to retrieve decomposition results when not available, will probably raise a NotAvailableException.- Specified by:
isDecompositionAvailable
in classDecomposer
- Returns:
- Boolean indicating whether decomposition has been computed and results can be retrieved.
-
decompose
This method computes Cholesky matrix decomposition, which consists on factoring provided input matrix whenever it is square, symmetric and positive definite into a lower triangulator factor such that it follows next expression: A = L * L' where A is input matrix and L is lower triangular factor (L' is its transposed). Cholesky decomposition can also be computed using Right Cholesky decomposition, in which case A = R' * R, where R is an upper triangular factor equal to L'. Both factors L and R will be accessible once Cholesky decomposition has been computed. Note: During execution of this method, this instance will remain locked, and hence attempting to set some parameters might raise a LockedException Note: After execution of this method, Cholesky decomposition will be available and operations such as retrieving L matrix factor or solving systems of linear equations will be able to be done. Attempting to call any of such operations before calling this method will raise a NotAvailableException because they require computation of Cholesky decomposition first.- Specified by:
decompose
in classDecomposer
- Throws:
NotReadyException
- Exception thrown if attempting to call this method when this instance is not ready (i.e. no input matrix has been provided).LockedException
- Exception thrown if this decomposer is already locked before calling this method. Notice that this method will actually lock this instance while it is being executed.DecomposerException
- Exception thrown if for any reason decomposition fails while being executed, like when convergence of results cannot be obtained, etc.
-
getL
Returns Cholesky matrix factor corresponding to a Lower triangular matrix following this expression: A = L * L'. Where A is provided input matrix that has been decomposed and L is the left lower triangular matrix factor.- Returns:
- Returns Cholesky Lower triangular matrix
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before actually computing Cholesky decomposition. To avoid this exception call decompose() method first.- See Also:
-
getR
Returns Cholesky matrix factor corresponding to an upper triangular matrix following this expression: A = R' * R. Where A is provided input matrix that has been decomposed and R is the right upper triangular matrix factor.- Returns:
- Returns Cholesky upper triangular matrix
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before actually computing Cholesky decomposition. To avoid this exception call decompose() method first.- See Also:
-
isSPD
Returns boolean indicating whether provided input matrix is Symmetric Positive Definite or not. Notice that if returned value is false, then Cholesky decomposition should be ignored, as Cholesky decomposition can only be computed on symmetric positive definite matrices.- Returns:
- Boolean indicating whether provided input matrix is symmetric positive definite or not.
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing Cholesky decomposition. To avoid this exception call decompose() method first.- See Also:
-
solve
public void solve(Matrix b, Matrix result) throws NotAvailableException, WrongSizeException, NonSymmetricPositiveDefiniteMatrixException Solves a linear system of equations of the following form: A * X = B. Where A is the input matrix provided for Cholesky decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix. Note: This method can be reused for different b vectors/matrices without having to recompute Cholesky decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise an IllegalArgumentException will be raised Note: Provided input matrix A must be square, otherwise a WrongSizeException will be raised. Note: If provided input matrix A is not symmetric positive definite, a NonSymmetricPositiveDefiniteMatrixException will be thrown. Note: In order to be able to execute this method, a Cholesky decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first Note: result matrix contains solution of linear system of equations. It will be resized if provided matrix does not have proper size- Parameters:
b
- Parameters of linear system of equationsresult
- instance where solution X will be stored.- Throws:
NotAvailableException
- if decomposition has not yet been computed.WrongSizeException
- if the number of rows of b matrix is not equal to the number of rows of input matrix provided to Cholesky decomposer.NonSymmetricPositiveDefiniteMatrixException
- if input matrix provided to Cholesky decomposer is not positive definite.
-
solve
public Matrix solve(Matrix b) throws NotAvailableException, WrongSizeException, NonSymmetricPositiveDefiniteMatrixException Solves a linear system of equations of the following form: A * X = B. Where A is the input matrix provided for Cholesky decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix. Note: This method can be reused for different b vectors/matrices without having to recompute Cholesky decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise an IllegalArgumentException will be raised Note: Provided input matrix A must be square, otherwise a WrongSizeException will be raised. Note: If provided input matrix A is not symmetric positive definite, a NonSymmetricPositiveDefiniteMatrixException will be thrown. Note: In order to be able to execute this method, a Cholesky decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first- Parameters:
b
- Parameters of linear system of equations- Returns:
- a new matrix containing solution X.
- Throws:
NotAvailableException
- if decomposition has not yet been computed.WrongSizeException
- if the number of rows of b matrix is not equal to the number of rows of input matrix provided to Cholesky decomposer.NonSymmetricPositiveDefiniteMatrixException
- if input matrix provided to Cholesky decomposer is not positive definite.
-