Package ubic.basecode.math.linalg
Class QRDecomposition
java.lang.Object
ubic.basecode.math.linalg.QRDecomposition
QR with pivoting. See http://www.netlib.org/lapack/lug/node42.html and http://www.netlib.org/lapack/lug/node27.html,
and Golub and VanLoan, section 5.5.6+. Designed to mimic the way R does this by default.
- Author:
- paul
-
Constructor Summary
ConstructorsConstructorDescriptionQRDecomposition
(DoubleMatrix2D A, boolean pivoting) Construct the QR decomposition of A. -
Method Summary
Modifier and TypeMethodDescriptionchol2inv()
Used for computing standard errors of parameter estimates for least squares; copies functionality of R chol2inv.protected String
diagnose()
Compute effects matrix Q'y (as in Rb = Q'y).Compute effects matrix Q'y (as in Rb = Q'y)getQ()
Generates and returns the (economy-sized - first p columns only) orthogonal factor Q.protected DoubleMatrix2D
getQR()
For testing.getQraux()
getR()
Returns the upper triangular factor, R.int
getRank()
double
boolean
Returns whether the matrix A has full rank.boolean
Least squares solution of A*X = y; returns X using the stored QR decomposition of A.toString()
Returns a String with (propertyName, propertyValue) pairs.
-
Constructor Details
-
QRDecomposition
- Parameters:
A
- the matrix to decompose, pivoting will be used.
-
QRDecomposition
Construct the QR decomposition of A. With pivoting = true, this reproduces quite closely the behaviour of R qr().- Parameters:
A
- the matrix to decomposepivoting
- set to false to obtain standard QR behaviour.
-
-
Method Details
-
chol2inv
Used for computing standard errors of parameter estimates for least squares; copies functionality of R chol2inv.- Returns:
-
effects
Compute effects matrix Q'y (as in Rb = Q'y)."Tthe effects are the uncorrelated single-degree-of-freedom values obtained by projecting the data onto the successive orthogonal subspaces generated by the QR decomposition during the fitting process. The first r (the rank of the model) are associated with coefficients and the remainder span the space of residuals (but are not associated with particular residuals)."
- Parameters:
y
- vector Missing values are ignored, otherwise assumed to be of the right size- Returns:
- vector of effects - these are the projections of y into Q column space
-
effects
Compute effects matrix Q'y (as in Rb = Q'y)- Parameters:
y
- matrix of data, assumed to be of right size, missing values are not supported- Returns:
- matrix of effects - these are the projections of y's columns into Q column subspace associated with the parameters, so values are "effects" each basis vector on the data
-
getPivotOrder
- Returns:
-
getQ
Generates and returns the (economy-sized - first p columns only) orthogonal factor Q.- Returns:
- first p columns of Q
-
getQraux
- Returns:
-
getR
Returns the upper triangular factor, R.- Returns:
- R
-
getRank
public int getRank()- Returns:
- rank
-
getTolerance
public double getTolerance() -
hasFullRank
public boolean hasFullRank()Returns whether the matrix A has full rank.- Returns:
- true if R, and hence A, has full rank.
-
isPivoting
public boolean isPivoting()- Returns:
- true if pivoting was used (just whether it was set; not whether any actual pivoting happened)
-
solve
Least squares solution of A*X = y; returns X using the stored QR decomposition of A.- Parameters:
y
- A matrix with as many rows as A and any number of columns. Least squares is fit for each column of y.- Returns:
- X that minimizes the two norm of Q*R*X - B.
- Throws:
IllegalArgumentException
- if y.rows() != A.rows().IllegalArgumentException
- if !this.hasFullRank() (A is rank deficient). However, rank-deficient cases are handled by pivoting, so if you are using pivoting you should not see this happening.
-
toString
Returns a String with (propertyName, propertyValue) pairs. Useful for debugging or to quickly get the rough picture. -
diagnose
-
getQR
For testing.- Returns:
-