Package com.irurueta.algebra
Class QRDecomposer
java.lang.Object
com.irurueta.algebra.Decomposer
com.irurueta.algebra.QRDecomposer
This decomposer computes QR decomposition, which consists on factoring
provided input matrix into an orthogonal matrix (Q) and an upper triangular
matrix (R). In other words, if input matrix is A, then:
A = Q * R
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Constant defining default round error when determining full rank of matrices.static final double
Constant defining minimum allowed round error value when determining full rank of matrices.private Matrix
Internal matrix containing Q factor.private Matrix
Internal matrix containing R factor.(package private) boolean
Boolean indicating whether decomposed matrix is singular.Fields inherited from class com.irurueta.algebra.Decomposer
inputMatrix, locked
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor of this class.QRDecomposer
(Matrix inputMatrix) Constructor of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method computes LU matrix decomposition, which consists on retrieving two triangular matrices (Lower triangular and Upper triangular) as a decomposition of provided input matrix.Returns decomposer type corresponding to QR decomposition.getQ()
Returns the economy-sized orthogonal factor matrix.getR()
Returns upper triangular factor matrix.boolean
Returns boolean indicating whether decomposition has been computed and results can be retrieved.boolean
Returns boolean indicating whether provided input matrix has full rank or not.boolean
isFullRank
(double roundingError) Returns boolean indicating whether provided input matrix has full rank 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.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.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
-
DEFAULT_ROUND_ERROR
public static final double DEFAULT_ROUND_ERRORConstant defining default round error when determining full rank of matrices. This value is zero by default.- See Also:
-
MIN_ROUND_ERROR
public static final double MIN_ROUND_ERRORConstant defining minimum allowed round error value when determining full rank of matrices.- See Also:
-
q
Internal matrix containing Q factor. -
r
Internal matrix containing R factor. -
sing
boolean singBoolean indicating whether decomposed matrix is singular.
-
-
Constructor Details
-
QRDecomposer
public QRDecomposer()Constructor of this class. -
QRDecomposer
Constructor of this class.- Parameters:
inputMatrix
- Reference to input matrix to be decomposed.
-
-
Method Details
-
getDecomposerType
Returns decomposer type corresponding to QR 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 LU matrix decomposition, which consists on retrieving two triangular matrices (Lower triangular and Upper triangular) as a decomposition of provided input matrix. In other words, if input matrix is A, then: A = L * U Note: During execution of this method, this instance will be locked, and hence attempting to set some parameters might raise a LockedException. Note: After execution of this method, LU decomposition will be available and operations such as retrieving L and U matrices or computing determinants among others 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 LU 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 attempting to call this method when this instance is not ready (i.e. no input matrix has been provided).DecomposerException
- Exception thrown if for any reason decomposition fails while executing, like when convergence of results can not be obtained, etc.
-
isFullRank
Returns boolean indicating whether provided input matrix has full rank or not. Squared matrices having full rank also have determinant different from zero. Note: Because of rounding errors testing whether a matrix has full rank or not might obtain unreliable results especially for non-squared matrices. In such cases, matrices usually tend to be considered as full rank even when they are not. Note: DEFAULT_ROUND_ERROR is used to determine whether matrix is full rank or not- Returns:
- Boolean indicating whether provided input matrix has full rank or not.
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.IllegalArgumentException
- Exception thrown if provided rounding error is lower than minimum allowed value (MIN_ROUND_ERROR)- See Also:
-
isFullRank
Returns boolean indicating whether provided input matrix has full rank or not. Squared matrices having full rank also have determinant different from zero. Note: Because of rounding errors testing whether a matrix has full rank or not might obtain unreliable results especially for non-squared matrices. In such cases, matrices usually tend to be considered as full rank even when they are not.- Parameters:
roundingError
- Determines the amount of margin given to determine whether a matrix has full rank or not due to rounding errors. If not provided, by default rounding error is set to zero, but this value can be relaxed if needed.- Returns:
- Boolean indicating whether provided input matrix has full rank or not.
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.IllegalArgumentException
- Exception thrown if provided rounding error is lower than minimum allowed value (MIN_ROUND_ERROR)- See Also:
-
getR
Returns upper triangular factor matrix. QR decomposition decomposes input matrix into Q (orthogonal matrix) and R, which is an upper triangular matrix.- Returns:
- Upper triangular factor matrix.
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.- See Also:
-
getQ
Returns the economy-sized orthogonal factor matrix. QR decomposition decomposes input matrix into Q, which is an orthogonal matrix and R (upper triangular matrix).- Returns:
- Orthogonal factor matrix.
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.- See Also:
-
solve
public void solve(Matrix b, Matrix result) throws NotAvailableException, WrongSizeException, RankDeficientMatrixException Solves a linear system of equations of the following form: A * X = B. Where A is the input matrix provided for QR 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 QR decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise a WrongSizeException will be raised. Note: Provided input matrix "A" must have at least as many rows as columns, otherwise a WrongSizeException will be raised as well. For input matrices having a higher number of rows than columns, the system of equations will be overdetermined and the least squares solution will be found. Note: If provided input matrix A is rank deficient, a RankDeficientMatrixException will be thrown. Note: In order to execute this method, a QR decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first. Note: To solve the linear system of equations DEFAULT_ROUND_ERROR is used Note: Solution of linear system of equations is stored in result matrix, and result matrix is resized if needed.- Parameters:
b
- Parameters matrix that determines a linear system of equations. Provided matrix must have the same number of rows as provided input matrix for QR decomposition. Besides, each column on parameters matrix will represent a new system of equations, whose solution will be returned on appropriate column as an output of this method.result
- Matrix containing solution of linear system of equations on each column for each column of provided parameters matrix b.- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.WrongSizeException
- Exception thrown if attempting to call this method using an input matrix with less rows than columns; or if provided parameters matrix (b) does not have the same number of rows as input matrix being QR decomposed.RankDeficientMatrixException
- Exception thrown if provided input matrix to be QR decomposed is rank deficient. In this case linear system of equations cannot be solved.- See Also:
-
solve
public void solve(Matrix b, double roundingError, Matrix result) throws NotAvailableException, WrongSizeException, RankDeficientMatrixException Solves a linear system of equations of the following form: A * X = B. Where A is the input matrix provided for QR 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 QR decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise a WrongSizeException will be raised. Note: Provided input matrix "A" must have at least as many rows as columns, otherwise a WrongSizeException will be raised as well. For input matrices having a higher number of rows than columns, the system of equations will be overdetermined and the least squares solution will be found. Note: If provided input matrix A is rank deficient, a RankDeficientMatrixException will be thrown. Note: In order to execute this method, a QR decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first. Note: Solution of linear system of equations is stored in result matrix, and result matrix is resized if needed.- Parameters:
b
- Parameters matrix that determines a linear system of equations. Provided matrix must have the same number of rows as provided input matrix for QR decomposition. Besides, each column on parameters matrix will represent a new system of equations, whose solution will be returned on appropriate column as an output of this method.roundingError
- Determines the amount of margin given to determine whether a matrix has full rank or not due to rounding errors. If not provided, by default rounding error is set to zero, but this value can be relaxed if needed.result
- Matrix containing solution of linear system of equations on each column for each column of provided parameters matrix b.- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.WrongSizeException
- Exception thrown if attempting to call this method using an input matrix with less rows than columns; or if provided parameters matrix (b) does not have the same number of rows as input matrix being QR decomposed.RankDeficientMatrixException
- Exception thrown if provided input matrix to be QR decomposed is rank deficient. In this case linear system of equations cannot be solved.IllegalArgumentException
- Exception thrown if provided rounding error is lower than minimum allowed value (MIN_ROUND_ERROR).- See Also:
-
solve
public Matrix solve(Matrix b) throws NotAvailableException, WrongSizeException, RankDeficientMatrixException Solves a linear system of equations of the following form: A * X = B. Where A is the input matrix provided for QR 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 QR decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise a WrongSizeException will be raised. Note: Provided input matrix "A" must have at least as many rows as columns, otherwise a WrongSizeException will be raised as well. For input matrices having a higher number of rows than columns, the system of equations will be overdetermined and the least squares solution will be found. Note: If provided input matrix A is rank deficient, a RankDeficientMatrixException will be thrown. Note: In order to execute this method, a QR decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first. Note: To solve the linear system of equations DEFAULT_ROUND_ERROR is used- Parameters:
b
- Parameters matrix that determines a linear system of equations. Provided matrix must have the same number of rows as provided input matrix for QR decomposition. Besides, each column on parameters matrix will represent a new system of equations, whose solution will be returned on appropriate column as an output of this method.- Returns:
- Matrix containing solution of linear system of equations on each column for each column of provided parameters matrix b.
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.WrongSizeException
- Exception thrown if attempting to call this method using an input matrix with less rows than columns; or if provided parameters matrix (b) does not have the same number of rows as input matrix being QR decomposed.RankDeficientMatrixException
- Exception thrown if provided input matrix to be QR decomposed is rank deficient. In this case linear system of equations cannot be solved.- See Also:
-
solve
public Matrix solve(Matrix b, double roundingError) throws NotAvailableException, WrongSizeException, RankDeficientMatrixException Solves a linear system of equations of the following form: A * X = B. Where A is the input matrix provided for QR 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 QR decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise a WrongSizeException will be raised. Note: Provided input matrix "A" must have at least as many rows as columns, otherwise a WrongSizeException will be raised as well. For input matrices having a higher number of rows than columns, the system of equations will be overdetermined and the least squares solution will be found. Note: If provided input matrix A is rank deficient, a RankDeficientMatrixException will be thrown. Note: In order to execute this method, a QR decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first.- Parameters:
b
- Parameters matrix that determines a linear system of equations. Provided matrix must have the same number of rows as provided input matrix for QR decomposition. Besides, each column on parameters matrix will represent a new system of equations, whose solution will be returned on appropriate column as an output of this method.roundingError
- Determines the amount of margin given to determine whether a matrix has full rank or not due to rounding errors. If not provided, by default rounding error is set to zero, but this value can be relaxed if needed.- Returns:
- Matrix containing solution of linear system of equations on each column for each column of provided parameters matrix b.
- Throws:
NotAvailableException
- Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.WrongSizeException
- Exception thrown if attempting to call this method using an input matrix with less rows than columns; or if provided parameters matrix (b) does not have the same number of rows as input matrix being QR decomposed.RankDeficientMatrixException
- Exception thrown if provided input matrix to be QR decomposed is rank deficient. In this case linear system of equations cannot be solved.IllegalArgumentException
- Exception thrown if provided rounding error is lower than minimum allowed value (MIN_ROUND_ERROR).- See Also:
-