The rank-revealing QR-decomposition of a matrix A consists of three matrices Q, R and P such that AP=QR. Q is orthogonal (QTQ = I), and R is upper triangular. If A is m×n, Q is m×m and R is m×n and P is n×n.
QR decomposition with column pivoting produces a rank-revealing QR
decomposition and the getRank(double) method may be used to return the rank of the
input matrix A.
This class compute the decomposition using Householder reflectors.
For efficiency purposes, the decomposition in packed form is transposed. This allows inner loop to iterate inside rows, which is much more cache-efficient in Java.
This class is based on the class with similar name from the JAMA library, with the following changes:
getQT method has been added,solve and isFullRank methods have been replaced
by a getSolver method and the equivalent methods
provided by the returned DecompositionSolver.| Modifier and Type | Class and Description |
|---|---|
| private static class | RRQRDecomposition.
Specialized solver. |
| Modifier and Type | Field and Description |
|---|---|
| private RealMatrix | cachedP
Cached value of P. |
| private int[] | p
An array to record the column pivoting for later creation of P. |
| Access | Constructor and Description |
|---|---|
| public | RRQRDecomposition(RealMatrix
The matrix to decompose. matrix)Calculates the QR-decomposition of the given matrix. |
| public | RRQRDecomposition(RealMatrix
The matrix to decompose. matrix, double Singularity threshold. threshold)Calculates the QR-decomposition of the given matrix. |
| Modifier and Type | Method and Description |
|---|---|
| protected void | decompose(double[][]
transposed matrix qrt)Overrides org. Decompose matrix. |
| public RealMatrix | Returns: a permutation matrix.Returns the pivot matrix, P, used in the QR Decomposition of matrix A such that AP = QR. |
| public int | Returns: effective numerical matrix rankthreshold triggering rank computation dropThreshold)Return the effective numerical matrix rank. |
| public DecompositionSolver | Returns: a solverOverrides org. Get a solver for finding the A × X = B solution in least square sense. |
| protected void | performHouseholderReflection(int
minor index minor, double[][] transposed matrix qrt)Overrides org. Perform Householder reflection for a minor A(minor, minor) of A. |
| cachedP | back to summary |
|---|---|
| private RealMatrix cachedP Cached value of P. | |
| p | back to summary |
|---|---|
| private int[] p An array to record the column pivoting for later creation of P. | |
| RRQRDecomposition | back to summary |
|---|---|
| public RRQRDecomposition(RealMatrix matrix) Calculates the QR-decomposition of the given matrix. The singularity threshold defaults to zero.
| |
| RRQRDecomposition | back to summary |
|---|---|
| public RRQRDecomposition(RealMatrix matrix, double threshold) Calculates the QR-decomposition of the given matrix.
| |
| decompose | back to summary |
|---|---|
| protected void decompose(double[][] qrt) Overrides org. Decompose matrix.
| |
| getP | back to summary |
|---|---|
| public RealMatrix getP() Returns the pivot matrix, P, used in the QR Decomposition of matrix A such that AP = QR. If no pivoting is used in this decomposition then P is equal to the identity matrix.
| |
| getRank | back to summary |
|---|---|
| public int getRank(final double dropThreshold) Return the effective numerical matrix rank. The effective numerical rank is the number of non-negligible singular values. This implementation looks at Frobenius norms of the sequence of bottom right submatrices. When a large fall in norm is seen, the rank is returned. The drop is computed as: (thisNorm/lastNorm) * rNorm < dropThreshold where thisNorm is the Frobenius norm of the current submatrix, lastNorm is the Frobenius norm of the previous submatrix, rNorm is is the Frobenius norm of the complete matrix
| |
| getSolver | back to summary |
|---|---|
| public DecompositionSolver getSolver() Overrides org. Get a solver for finding the A × X = B solution in least square sense.
Least Square sense means a solver can be computed for an overdetermined system,
(i.e. a system with more equations than unknowns, which corresponds to a tall A
matrix with more rows than columns). In any case, if the matrix is singular
within the tolerance set at
| |
| performHouseholderReflection | back to summary |
|---|---|
| protected void performHouseholderReflection(int minor, double[][] qrt) Overrides org. Perform Householder reflection for a minor A(minor, minor) of A.
| |
| Modifier and Type | Field and Description |
|---|---|
| private RealMatrix | p
A permutation matrix for the pivots used in the QR decomposition |
| private final DecompositionSolver | upper
Upper level solver. |
| Access | Constructor and Description |
|---|---|
| private | Solver(final DecompositionSolver
upper level solver. upper, final RealMatrix permutation matrix p)Build a solver from decomposed matrix. |
| Modifier and Type | Method and Description |
|---|---|
| public RealMatrix | getInverse()
Implements org. Get the pseudo-inverse of the decomposed matrix. |
| public boolean | isNonSingular()
Implements org. Check if the decomposed matrix is non-singular. |
| public RealVector | solve(RealVector
right-hand side of the equation A × X = B b)Implements org. 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. Solve the linear equation A × X = B for matrices A. |
| p | back to summary |
|---|---|
| private RealMatrix p A permutation matrix for the pivots used in the QR decomposition | |
| upper | back to summary |
|---|---|
| private final DecompositionSolver upper Upper level solver. | |
| Solver | back to summary |
|---|---|
| private Solver(final DecompositionSolver upper, final RealMatrix p) Build a solver from decomposed matrix.
| |
| getInverse | back to summary |
|---|---|
| public RealMatrix getInverse() Implements org. Doc from org. Get the pseudo-inverse of the decomposed matrix. This is equal to the inverse of the decomposed matrix, if such an inverse exists. If no such inverse exists, then the result has properties that resemble that of an inverse. In particular, in this case, if the decomposed matrix is A, then the system of equations \( A x = b \) may have no solutions, or many. If it has no solutions, then the pseudo-inverse \( A^+ \) gives the "closest" solution \( z = A^+ b \), meaning \( \left \| A z - b \right \|_2 \) is minimized. If there are many solutions, then \( z = A^+ b \) is the smallest solution, meaning \( \left \| z \right \|_2 \) is minimized.
Note however that some decompositions cannot compute a pseudo-inverse for all matrices.
For example, the
| |
| isNonSingular | back to summary |
|---|---|
| public boolean isNonSingular() Implements org. Doc from org. Check if the decomposed matrix is non-singular.
| |
| solve | back to summary |
|---|---|
| public RealVector solve(RealVector b) Implements org. Doc from org. Solve the linear equation A × X = B for matrices A. The A matrix is implicit, it is provided by the underlying decomposition algorithm.
| |
| solve | back to summary |
|---|---|
| public RealMatrix solve(RealMatrix b) Implements org. Doc from org. Solve the linear equation A × X = B for matrices A. The A matrix is implicit, it is provided by the underlying decomposition algorithm.
| |