SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.doubles.factorization.qr
Class HouseholderReflection

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.doubles.factorization.qr.HouseholderReflection
All Implemented Interfaces:
QRDecomposition

public class HouseholderReflection
extends java.lang.Object
implements QRDecomposition

Successive Householder reflections gradually transform a matrix A to the upper triangular form.

For example, the first step is to multiply A with the Householder matrix Q1 so that matrix Q1 %*% A has zeros in the left column (except for the first row). That is,

             | a1 * ... * |
             | 0          |
 Q1 %*% A =  | .          |
             | .     A'   |
             | .          |
             | 0          |
 
At the end,
 Qn %*% ... %*% Q1 %*% A = R
 
where R is upper triangular.

Householder reflection has a better numerical stability than the Gram-Schmidt process.

See Also:
Wikipedia: Using Householder reflections

Field Summary
 double epsilon
          a precision parameter: when a number |x| ≤ ε, it is considered 0
 int ncols
          number of columns
 int nrows
          number of rows
 
Constructor Summary
HouseholderReflection(Matrix A)
          Construct an instance of the Householder reflection process to orthogonalize a matrix.
HouseholderReflection(Matrix A, double epsilon)
          Construct an instance of the Householder reflection process to orthogonalize a matrix.
 
Method Summary
 PermutationMatrix P()
          Get a copy of the P pivoting matrix in the QR decomposition.
 Matrix Q()
          Get a copy of the Q matrix in the QR decomposition.
 UpperTriangularMatrix R()
          Get a copy of the upper triangular matrix R in the QR decomposition.
 int rank()
          Rank is computed by counting the number of non-zero rows in R.
 Matrix squareQ()
          Get a copy of the square Q matrix.
 Matrix tallR()
          Get a copy of the tall R matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nrows

public final int nrows
number of rows


ncols

public final int ncols
number of columns


epsilon

public final double epsilon
a precision parameter: when a number |x| ≤ ε, it is considered 0

Constructor Detail

HouseholderReflection

public HouseholderReflection(Matrix A,
                             double epsilon)
Construct an instance of the Householder reflection process to orthogonalize a matrix.

Parameters:
A - a matrix, where #rows >= #columns
epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
Throws:
java.lang.IllegalArgumentException - if #rows < #columns

HouseholderReflection

public HouseholderReflection(Matrix A)
Construct an instance of the Householder reflection process to orthogonalize a matrix.

Parameters:
A - a matrix, where #rows >= #columns
Method Detail

Q

public Matrix Q()
Get a copy of the Q matrix in the QR decomposition.
 Qn %*% ... %*% Q3 %*% Q2 %*% Q1 %*% A = R
 A = [Qn %*% ... %*% Q3 %*% Q2 %*% Q1]^-1 %*% R
 A = [Q1^-1 %*% Q2^-1 %*% ... %*% Qn^-1] %*% R
 A = [Q1 %*% Q2 %*% ... %*% Qn] %*% R, by the unitary property of Householder matrix
 So, Q = Q1 %*% Q2 %*% ... %*% Qn.
 

To compute Q, instead of explicitly doing this multiplication, we can improve the performance by applying Qi's repeatedly on an identity matrix.

Dimension of Q is nRows x nCols.

Specified by:
Q in interface QRDecomposition
Returns:
a copy of the Q matrix in the QR decomposition

R

public UpperTriangularMatrix R()
Description copied from interface: QRDecomposition
Get a copy of the upper triangular matrix R in the QR decomposition.
 A = QR
 

Dimension of R is ncols x ncols, a square matrix.

Specified by:
R in interface QRDecomposition
Returns:
a copy of the upper triangular matrix R in the QR decomposition

P

public PermutationMatrix P()
Get a copy of the P pivoting matrix in the QR decomposition.

Householder process needs no pivoting. Hence, P is always an identity matrix.

Specified by:
P in interface QRDecomposition
Returns:
an identity matrix

rank

public int rank()
Rank is computed by counting the number of non-zero rows in R.

Q may have more columns than the rank. The user is encouraged to interpret the result with caution.

Specified by:
rank in interface QRDecomposition
Returns:
the rank

squareQ

public Matrix squareQ()
Description copied from interface: QRDecomposition
Get a copy of the square Q matrix. This is an arbitrary orthogonal completion of the Q matrix in the QR decomposition. Dimension is nrows x nrows (square).
 A = square_Q %*% tall_R
 

Specified by:
squareQ in interface QRDecomposition
Returns:
a copy of the square Q matrix

tallR

public Matrix tallR()
Description copied from interface: QRDecomposition
Get a copy of the tall R matrix. This is completed by binding zero rows beneath the square upper triangular matrix R in the QR decomposition. Dimension is nrows x ncols. Note that this may no longer be square.
 A = square_Q %*% tall_R
 

Specified by:
tallR in interface QRDecomposition
Returns:
a copy of the tall R matrix

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.