SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.doubles.operation
Class Householder

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.doubles.operation.Householder

public class Householder
extends java.lang.Object

A Householder transformation in the 3-dimensional space is the reflection of a vector in a plane. The plane, containing the origin, is uniquely defined by a unit vector, called the generator, orthogonal to the plane.

The reflection Hx can be computed without explicitly expanding H.

 H = I - 2vv'
 Hx = (I - 2vv')x = Ix - 2vv'x = x - 2v<v,x>, where x is a column vector

 yH = (H'y')' = (Hy')', where y is a row vector
 

When H is applied to a set of column vectors, it transforms each vector individually, as in block matrix multiplication.

 H %*% A = H %*% [A1 A2 ... An] = [H %*% A1 H %*% A2 ... H %*% An]
 

When H is applied to a set of row vectors, it transforms each vector individually, as in block matrix multiplication.

           | (H %*% A1')' |
           | (H %*% A2')' |
 A %*% H = | (H %*% A3')' |
           | (H %*% A4')' |
           | (H %*% A5')' |
 

See Also:

Nested Class Summary
static class Householder.Context
          Context information about a Householder transformation.
 
Constructor Summary
Householder(Vector generator)
          Construct a Householder matrix from a vector that defines a hyperplane orthogonal to the vector.
 
Method Summary
 Vector generator()
          Get a copy of the Householder generating vector.
static Householder.Context getContext(Vector x)
          Generate the getContext information from a vector x.
 Matrix H()
          Get a copy of the Householder matrix H.
static Matrix product(Householder[] Hs, int from, int to)
          Given Householder matrix {Qi}, compute Q, where Q = Q1 %*% Q2 %*% ... %*% Qn %*% I To compute Q, instead of explicitly doing this multiplication, we can improve the performance by applying Qi's repeatedly on the Identity matrix.
static Matrix product(Householder[] hhs, int from, int to, int nRows, int nCols)
          Given Householder matrices {Qi}, compute Q.
 Matrix reflect(Matrix A)
          Apply the Householder matrix, H, to a matrix (a set of column vectors), A.
 Vector reflect(Vector x)
          Apply the Householder matrix, H, to a column vector, x.
 Matrix reflectRows(Matrix A)
          Apply the Householder matrix, H, to a matrix (a set of row vectors), A.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Householder

public Householder(Vector generator)
Construct a Householder matrix from a vector that defines a hyperplane orthogonal to the vector. If the generator is a 0-vector, the Householder matrix is the Identity matrix.

Parameters:
generator - the orthogonal defining vector
Method Detail

generator

public Vector generator()
Get a copy of the Householder generating vector.

Returns:
a copy of the Householder generating vector

reflect

public Vector reflect(Vector x)
Apply the Householder matrix, H, to a column vector, x.
 Hx = x - 2 * <v,x> * v
 

Parameters:
x - the vector to apply H to
Returns:
Hx

reflect

public Matrix reflect(Matrix A)
Apply the Householder matrix, H, to a matrix (a set of column vectors), A.
 H %*% A = [H*A1, H*A2, ... H*An]
 

Parameters:
A - the matrix to apply H to
Returns:
H %*% A

reflectRows

public Matrix reflectRows(Matrix A)
Apply the Householder matrix, H, to a matrix (a set of row vectors), A.
           | (H %*% A1')' |
           | (H %*% A2')' |
 A %*% H = | (H %*% A3')' |
           | (H %*% A4')' |
           | (H %*% A5')' |
 

Parameters:
A - the matrix to apply H to
Returns:
A %*% H

H

public Matrix H()
Get a copy of the Householder matrix H.
 H = I - 2 * v * v'
 

If you are to compute H %*% v, do not use this function. Use reflect(Vector) instead.

Returns:
a copy of the Householder matrix

product

public static Matrix product(Householder[] hhs,
                             int from,
                             int to,
                             int nRows,
                             int nCols)
Given Householder matrices {Qi}, compute Q.
 Q = Q1 %*% Q2 %*% ... %*% Qn %*% I
 

The Identity matrix, I, can have more rows than columns. The bottom rows are padded with zeros.

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

Parameters:
hhs - an array of Householders
from - the beginning index of Hs; Q1 is Q_from
to - the ending index of Hs; Qn is Q_to
nRows - number of rows of I
nCols - number of columns of I
Returns:
the product of an array of Householder matrices, from Hs[from] to Hs[to]

product

public static Matrix product(Householder[] Hs,
                             int from,
                             int to)
Given Householder matrix {Qi}, compute Q, where
 Q = Q1 %*% Q2 %*% ... %*% Qn %*% I
 
To compute Q, instead of explicitly doing this multiplication, we can improve the performance by applying Qi's repeatedly on the Identity matrix.

Parameters:
Hs - an array of Householders
from - the beginning index of Hs
to - the ending index of Hs
Returns:
the product of an array of Householder matrices, from Hs[from] to Hs[to]

getContext

public static Householder.Context getContext(Vector x)
Generate the getContext information from a vector x.

We implemented a modified version of

 Algorithm 1.1 in
 Matrix Algorithms, Volume 1 by
 G. W. Steward
 

Given a vector x, return a vector generator, such that

 Hx = ±||x|| * e1
 

That is,

 H.reflect(x) == new Vector(new double[]{±x.norm(), 0, ...})
 

Parameters:
x - a vector
Returns:
the getContext information for constructing a Householder object

SuanShu, a Java numerical and statistical library

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