org.ejml.alg.dense.decomposition.qr
Class QRDecompositionHouseholder

java.lang.Object
  extended by org.ejml.alg.dense.decomposition.qr.QRDecompositionHouseholder
All Implemented Interfaces:
DecompositionInterface<DenseMatrix64F>, QRDecomposition<DenseMatrix64F>

public class QRDecompositionHouseholder
extends Object
implements QRDecomposition<DenseMatrix64F>

This variation of QR decomposition uses reflections to compute the Q matrix. Each reflection uses a householder operations, hence its name. To provide a meaningful solution the original matrix must have full rank. This is intended for processing of small to medium matrices.

Both Q and R are stored in the same m by n matrix. Q is not stored directly, instead the u from Qk=(I-γ*u*uT) is stored. Decomposition requires about 2n*m2-2m2/3 flops.

See the QR reflections algorithm described in:
David S. Watkins, "Fundamentals of Matrix Computations" 2nd Edition, 2002

For the most part this is a straight forward implementation. To improve performance on large matrices a column is writen to an array and the order of some of the loops has been changed. This will degrade performance noticeably on small matrices. Since it is unlikely that the QR decomposition would be a bottle neck when small matrices are involved only one implementation is provided.

Author:
Peter Abeles

Field Summary
protected  double[] dataQR
           
protected  boolean error
           
protected  double gamma
           
protected  double[] gammas
           
protected  int minLength
           
protected  int numCols
           
protected  int numRows
           
protected  DenseMatrix64F QR
          Where the Q and R matrices are stored.
protected  double tau
           
protected  double[] u
           
protected  double[] v
           
 
Constructor Summary
QRDecompositionHouseholder()
           
 
Method Summary
protected  void commonSetup(DenseMatrix64F A)
          This function performs sanity check on the input for decompose and sets up the QR matrix.
 boolean decompose(DenseMatrix64F A)
           In order to decompose the matrix 'A' it must have full rank.
 double[] getGammas()
           
 DenseMatrix64F getQ(DenseMatrix64F Q, boolean compact)
          Computes the Q matrix from the imformation stored in the QR matrix.
 DenseMatrix64F getQR()
          Returns a single matrix which contains the combined values of Q and R.
 DenseMatrix64F getR(DenseMatrix64F R, boolean compact)
          Returns an upper triangular matrix which is the R in the QR decomposition.
protected  void householder(int j)
           Computes the householder vector "u" for the first column of submatrix j.
 boolean inputModified()
          Is the input matrix to DecompositionInterface.decompose(org.ejml.data.Matrix64F) is modified during the decomposition process.
 void setExpectedMaxSize(int numRows, int numCols)
           
protected  void updateA(int w)
           Takes the results from the householder computation and updates the 'A' matrix.

A = (I - γ*u*uT)A
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QR

protected DenseMatrix64F QR
Where the Q and R matrices are stored. R is stored in the upper triangular portion and Q on the lower bit. Lower columns are where u is stored. Q_k = (I - gamma_k*u_k*u_k^T).


u

protected double[] u

v

protected double[] v

numCols

protected int numCols

numRows

protected int numRows

minLength

protected int minLength

dataQR

protected double[] dataQR

gammas

protected double[] gammas

gamma

protected double gamma

tau

protected double tau

error

protected boolean error
Constructor Detail

QRDecompositionHouseholder

public QRDecompositionHouseholder()
Method Detail

setExpectedMaxSize

public void setExpectedMaxSize(int numRows,
                               int numCols)

getQR

public DenseMatrix64F getQR()
Returns a single matrix which contains the combined values of Q and R. This is possible since Q is symmetric and R is upper triangular.

Returns:
The combined Q R matrix.

getQ

public DenseMatrix64F getQ(DenseMatrix64F Q,
                           boolean compact)
Computes the Q matrix from the imformation stored in the QR matrix. This operation requires about 4(m2n-mn2+n3/3) flops.

Specified by:
getQ in interface QRDecomposition<DenseMatrix64F>
Parameters:
Q - The orthogonal Q matrix.
compact - If true an m by n matrix is created, otherwise n by n.
Returns:
The Q matrix.

getR

public DenseMatrix64F getR(DenseMatrix64F R,
                           boolean compact)
Returns an upper triangular matrix which is the R in the QR decomposition.

Specified by:
getR in interface QRDecomposition<DenseMatrix64F>
Parameters:
R - An upper triangular matrix.
compact -
Returns:
The R matrix.

decompose

public boolean decompose(DenseMatrix64F A)

In order to decompose the matrix 'A' it must have full rank. 'A' is a 'm' by 'n' matrix. It requires about 2n*m2-2m2/3 flops.

The matrix provided here can be of different dimension than the one specified in the constructor. It just has to be smaller than or equal to it.

Specified by:
decompose in interface DecompositionInterface<DenseMatrix64F>
Parameters:
A - The matrix which is being decomposed. Modification is implementation dependent.
Returns:
Returns if it was able to decompose the matrix.

inputModified

public boolean inputModified()
Description copied from interface: DecompositionInterface
Is the input matrix to DecompositionInterface.decompose(org.ejml.data.Matrix64F) is modified during the decomposition process.

Specified by:
inputModified in interface DecompositionInterface<DenseMatrix64F>
Returns:
true if the input matrix to decompose() is modified.

householder

protected void householder(int j)

Computes the householder vector "u" for the first column of submatrix j. Note this is a specialized householder for this problem. There is some protection against overflow and underflow.

Q = I - γuuT

This function finds the values of 'u' and 'γ'.

Parameters:
j - Which submatrix to work off of.

updateA

protected void updateA(int w)

Takes the results from the householder computation and updates the 'A' matrix.

A = (I - γ*u*uT)A

Parameters:
w - The submatrix.

commonSetup

protected void commonSetup(DenseMatrix64F A)
This function performs sanity check on the input for decompose and sets up the QR matrix.

Parameters:
A -

getGammas

public double[] getGammas()


Copyright © 2012. All Rights Reserved.