Class RRQRDecomposition
- java.lang.Object
-
- org.apache.commons.math4.legacy.linear.QRDecomposition
-
- org.apache.commons.math4.legacy.linear.RRQRDecomposition
-
public class RRQRDecomposition extends QRDecomposition
Calculates the rank-revealing QR-decomposition of a matrix, with column pivoting.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:
- a
getQT
method has been added, - the
solve
andisFullRank
methods have been replaced by agetSolver
method and the equivalent methods provided by the returnedDecompositionSolver
.
- a
-
-
Constructor Summary
Constructors Constructor Description RRQRDecomposition(RealMatrix matrix)
Calculates the QR-decomposition of the given matrix.RRQRDecomposition(RealMatrix matrix, double threshold)
Calculates the QR-decomposition of the given matrix.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
decompose(double[][] qrt)
Decompose matrix.RealMatrix
getP()
Returns the pivot matrix, P, used in the QR Decomposition of matrix A such that AP = QR.int
getRank(double dropThreshold)
Return the effective numerical matrix rank.DecompositionSolver
getSolver()
Get a solver for finding the A × X = B solution in least square sense.protected void
performHouseholderReflection(int minor, double[][] qrt)
Perform Householder reflection for a minor A(minor, minor) of A.-
Methods inherited from class org.apache.commons.math4.legacy.linear.QRDecomposition
getH, getQ, getQT, getR
-
-
-
-
Constructor Detail
-
RRQRDecomposition
public RRQRDecomposition(RealMatrix matrix)
Calculates the QR-decomposition of the given matrix. The singularity threshold defaults to zero.- Parameters:
matrix
- The matrix to decompose.- See Also:
RRQRDecomposition(RealMatrix, double)
-
RRQRDecomposition
public RRQRDecomposition(RealMatrix matrix, double threshold)
Calculates the QR-decomposition of the given matrix.- Parameters:
matrix
- The matrix to decompose.threshold
- Singularity threshold.- See Also:
RRQRDecomposition(RealMatrix)
-
-
Method Detail
-
decompose
protected void decompose(double[][] qrt)
Decompose matrix.- Overrides:
decompose
in classQRDecomposition
- Parameters:
qrt
- transposed matrix
-
performHouseholderReflection
protected void performHouseholderReflection(int minor, double[][] qrt)
Perform Householder reflection for a minor A(minor, minor) of A.- Overrides:
performHouseholderReflection
in classQRDecomposition
- Parameters:
minor
- minor indexqrt
- transposed matrix
-
getP
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.- Returns:
- a permutation matrix.
-
getRank
public int getRank(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
- Parameters:
dropThreshold
- threshold triggering rank computation- Returns:
- effective numerical matrix rank
-
getSolver
public DecompositionSolver getSolver()
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
construction
, an error will be triggered when thesolve
method will be called.- Overrides:
getSolver
in classQRDecomposition
- Returns:
- a solver
-
-