Package smile.math.matrix
Class QR
- java.lang.Object
-
- smile.math.matrix.QR
-
public class QR extends java.lang.ObjectFor an m-by-n matrix A with m ≥ n, the QR decomposition is an m-by-n orthogonal matrix Q and an n-by-n upper triangular matrix R such that A = Q*R.The QR decomposition always exists, even if the matrix does not have full rank. The primary use of the QR decomposition is in the least squares solution of non-square systems of simultaneous linear equations, where
isSingular()has to be false.QR decomposition is also the basis for a particular eigenvalue algorithm, the QR algorithm.
- Author:
- Haifeng Li
-
-
Field Summary
Fields Modifier and Type Field Description protected DenseMatrixqrArray for internal storage of decomposition.protected booleansingularIndicate if the matrix is singular.protected double[]tauThe diagonal of R for this implementation.
-
Constructor Summary
Constructors Constructor Description QR(DenseMatrix qr, double[] tau, boolean singular)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CholeskyCholeskyOfAtA()Returns the Cholesky decomposition of A'A.DenseMatrixgetQ()Returns the orthogonal factor.DenseMatrixgetR()Returns the upper triangular factor.booleanisSingular()Returns true if the matrix is singular (not full column rank).voidsolve(double[] b, double[] x)Solve the least squares A*x = b.voidsolve(DenseMatrix B)Solve the least squares A * X = B.
-
-
-
Field Detail
-
qr
protected DenseMatrix qr
Array for internal storage of decomposition.
-
tau
protected double[] tau
The diagonal of R for this implementation. For netlib based QR, this is the scales for the reflectors.
-
singular
protected boolean singular
Indicate if the matrix is singular.
-
-
Constructor Detail
-
QR
public QR(DenseMatrix qr, double[] tau, boolean singular)
Constructor.
-
-
Method Detail
-
isSingular
public boolean isSingular()
Returns true if the matrix is singular (not full column rank).
-
CholeskyOfAtA
public Cholesky CholeskyOfAtA()
Returns the Cholesky decomposition of A'A.
-
getR
public DenseMatrix getR()
Returns the upper triangular factor.
-
getQ
public DenseMatrix getQ()
Returns the orthogonal factor.
-
solve
public void solve(double[] b, double[] x)Solve the least squares A*x = b.- Parameters:
b- right hand side of linear system.x- the output solution vector that minimizes the L2 norm of A*x - b.- Throws:
java.lang.RuntimeException- if matrix is rank deficient.
-
solve
public void solve(DenseMatrix B)
Solve the least squares A * X = B. B will be overwritten with the solution matrix on output.- Parameters:
B- right hand side of linear system. B will be overwritten with the solution matrix on output.- Throws:
java.lang.RuntimeException- Matrix is rank deficient.
-
-