|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.matrix.doubles.factorization.qr.GramSchmidt
public class GramSchmidt
The Gram–Schmidt process is a method for orthogonalizing a set of vectors in an inner product space. It does so by iteratively computing the vector orthogonal to the subspace spanned by previously found orthogonal vectors.
The orthogonal vector is the difference between a column vector and its projection on the subspace.
There is the problem of "loss of orthogonality" during the process,
which gives arise to the precision error or rounding error.
In general, the bigger the matrix is, e.g., dimension = 3500x3500,
the less precise the results are.
Also, the vectors in Q may not be as orthogonal.
A numerically stable Gram–Schmidt process with twice re-orthogonalization is implemented to alleviate the problem of rounding errors.
Numerical determination of rank requires a criterion to decide when a value should be treated as zero. This is a practical choice which depends on both the matrix and the application. For instance, for a matrix with a big first eigenvector, we should accordingly decrease the precision to compute the rank.
While the results for the orthogonal basis may match those of the Householder Reflection HouseholderReflection,
the results for the orthogonal complement may differ because the kernel basis is not unique.
| 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 | |
|---|---|
GramSchmidt(Matrix A)
Construct an instance of the Gram-Schmidt process to orthogonalize a matrix. |
|
GramSchmidt(Matrix A,
boolean pad0Cols,
double epsilon)
Construct an instance of the Gram-Schmidt process to orthogonalize a matrix. |
|
| Method Summary | |
|---|---|
PermutationMatrix |
P()
Get a copy of P, the pivoting matrix in the QR decomposition. |
Matrix |
Q()
Get a copy of the orthogonal Q matrix in the QR decomposition. |
UpperTriangularMatrix |
R()
Get a copy of the upper triangular matrix R in the QR decomposition. |
int |
rank()
Get the numerical rank of the matrix A as computed by the QR decomposition. |
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 |
|---|
public final int nrows
public final int ncols
public final double epsilon
| Constructor Detail |
|---|
public GramSchmidt(Matrix A,
boolean pad0Cols,
double epsilon)
A - the matrix to orthogonalizepad0Cols - when a column is linearly dependent on the previous columns, there is no orthogonal vector.
We pad the basis with a 0-vector.epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0public GramSchmidt(Matrix A)
A - a matrix| Method Detail |
|---|
public Matrix Q()
QRDecompositionQ matrix in the QR decomposition.
A = QR
Dimension of Q is nrows x ncols, same as A, the matrix to orthogonalize.
Q in interface QRDecompositionQ matrix in the QR decompositionpublic UpperTriangularMatrix R()
QRDecompositionR in the QR decomposition.
A = QR
Dimension of R is ncols x ncols, a square matrix.
R in interface QRDecompositionR in the QR decompositionpublic PermutationMatrix P()
QRDecompositionP, the pivoting matrix in the QR decomposition.
P in interface QRDecompositionP pivoting matrix in the QR decompositionpublic int rank()
QRDecomposition
Get the numerical rank of the matrix A as computed by the QR decomposition.
Numerical determination of rank requires a criterion to decide when a value should be treated as zero.
This is a practical choice which depends on both the matrix and the application. For instance, for a matrix with a big first eigenvector, we should accordingly decrease the precision to compute the rank.
You may need to change the precision parameter to accurately compute the rank. See the test cases for example.
rank in interface QRDecompositionApublic Matrix squareQ()
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
In this implementation, we extend Q by adding A's orthogonal complement at the end.
Suppose Q has the orthogonal basis for a subspace A.
To compute the orthogonal complement of A,
we can apply the Gram-Schmidt procedure to either
I - P = I - Q %*% Q.t(), or
{u1, u2, ... uk, e1, e2, ... en}
and keeping only the first n elements of the resulting basis of Rn.
The last n-k elements are the basis for the orthogonal complement.
k is the rank.
We implemented the second option.
squareQ in interface QRDecompositionpublic Matrix tallR()
QRDecompositionR 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
tallR in interface QRDecompositionR matrix
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||