Class RealUnitaryDecomposition
The base class for real matrix decompositions which proceed by using orthogonal transformations (specifically Householder reflectors) to bring a matrix into an upper triangular/Hessenburg matrix. Specifically, the QR and Hessenburg decompositions.
This class is provided because both the QR and Hessenburg decompositions proceed by very similar computations resulting in a substantial amount of overlap in the implementations of the two decompositions. This class serves to implement these common computations such that implementations of either decomposition may utilize them without the need of reimplementing them.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double
Scalar factor of the currently computed Householder reflector.protected double
To store norms of columns inUnitaryDecomposition.transformMatrix
.protected double
Stores the shifted value of the first entry in a Householder vector.Fields inherited from class org.flag4j.linalg.decompositions.unitary.UnitaryDecomposition
applyUpdate, householderVector, iHigh, iLow, inPlace, minAxisSize, numCols, numRows, qFactors, storeReflectors, subDiagonal, transformData, transformMatrix, workArray
Fields inherited from class org.flag4j.linalg.decompositions.Decomposition
hasDecomposed
-
Constructor Summary
ConstructorsConstructorDescriptionRealUnitaryDecomposition
(int subDiagonal) Creates a real unitary decomposer which will reduce the matrix to an upper triangular/Hessenburg matrix which is has zeros below the specified sub-diagonal.RealUnitaryDecomposition
(int subDiagonal, boolean storeReflectors) Creates a real unitary decomposer which will reduce the matrix to an upper triangular/Hessenburg matrix which has zeros below the specified sub-diagonal (must be 0 or 1).RealUnitaryDecomposition
(int subDiagonal, boolean storeReflectors, boolean inPlace) Creates a real unitary decomposer which will reduce the matrix to an upper triangular/Hessenburg matrix which has zeros below the specified sub-diagonal (must be 0 or 1). -
Method Summary
Modifier and TypeMethodDescriptionprotected void
computeHouseholder
(int j) Computes the Householder vector for the first column of the sub-matrix with upper left corner at(j, j)
.protected void
computePhasedNorm
(int j, double maxAbs) Computes the norm of columnj
below thej
th row of the matrix to be decomposed.protected double
findMaxAndInit
(int j) Finds the maximum value inUnitaryDecomposition.transformMatrix
at columnj
at or below thej
th row.getQ()
Gets the unitaryQ
matrix from the unitary decomposition.protected Matrix
Gets the upper triangular/Hessenburg matrix from the last decomposition.protected void
initWorkArrays
(int maxAxisSize) Initialized any work arrays to be used in computing the decomposition with the proper size.protected void
updateData
(int j) Updates theUnitaryDecomposition.transformMatrix
matrix using the computed Householder vector fromcomputeHouseholder(int)
.Methods inherited from class org.flag4j.linalg.decompositions.unitary.UnitaryDecomposition
decompose, decompose, getUpper, initQ, setUp
Methods inherited from class org.flag4j.linalg.decompositions.Decomposition
ensureHasDecomposed
-
Field Details
-
norm
protected double normTo store norms of columns inUnitaryDecomposition.transformMatrix
. -
currentFactor
protected double currentFactorScalar factor of the currently computed Householder reflector. -
shift
protected double shiftStores the shifted value of the first entry in a Householder vector.
-
-
Constructor Details
-
RealUnitaryDecomposition
public RealUnitaryDecomposition(int subDiagonal) Creates a real unitary decomposer which will reduce the matrix to an upper triangular/Hessenburg matrix which is has zeros below the specified sub-diagonal.- Parameters:
subDiagonal
- Sub-diagonal of the upper triangular/Hessenburg matrix. That is, the sub-diagonal for which all data below will be zero in the final upper quasi-triangular matrix. Must be Zero or one.subDiagonal = 0
: Matrix will be upper triangular.subDiagonal = 1
: Matrix will be upper Hessenburg.
- Throws:
IllegalArgumentException
- IfsubDiagonal < 0 || subDiagonal > 1
.
-
RealUnitaryDecomposition
public RealUnitaryDecomposition(int subDiagonal, boolean storeReflectors) Creates a real unitary decomposer which will reduce the matrix to an upper triangular/Hessenburg matrix which has zeros below the specified sub-diagonal (must be 0 or 1).Allows for specification if the reflectors used to bring matrix to upper triangular/Hessenburg form are to be stored or not.
If the
Q
matrix is needed, thenstoreReflectors
must betrue
. IfQ
is NOT needed, then not storing the reflectors may improve performance slightly by avoiding unneeded copies.It should be noted that if performance is improved, it will be a very slight improvement compared to the total time to compute the decomposition. This is because the computation of
Q
is only evaluated lazily oncegetQ()
is called, so this will only save on copy ops.- Parameters:
subDiagonal
- Sub-diagonal of the upper triangular/Hessenburg matrix. That is, the sub-diagonal for which all data below will be zero in the final upper quasi-triangular matrix. Must be Zero or one.subDiagonal = 0
: Matrix will be upper triangular.subDiagonal = 1
: Matrix will be upper Hessenburg.
storeReflectors
- Flag indicating if the reflectors used to bring the matrix to upper triangular/Hessenburg form should be stored.- Throws:
IllegalArgumentException
- IfsubDiagonal < 0 || subDiagonal > 1
.
-
RealUnitaryDecomposition
public RealUnitaryDecomposition(int subDiagonal, boolean storeReflectors, boolean inPlace) Creates a real unitary decomposer which will reduce the matrix to an upper triangular/Hessenburg matrix which has zeros below the specified sub-diagonal (must be 0 or 1).Allows for specification if the reflectors used to bring matrix to upper triangular/Hessenburg form are to be stored or not.
If the
Q
matrix is needed, thenstoreReflectors
must be true. IfQ
is NOT needed, then not storing the reflectors may improve performance slightly by avoiding unneeded copies.It should be noted that if performance is improved, it will be a very slight improvement compared to the total time to compute the decomposition. This is because the computation of
Q
is only evaluated lazily oncegetQ()
is called, so this will only save on copy ops.- Parameters:
subDiagonal
- Sub-diagonal of the upper triangular/Hessenburg matrix. That is, the sub-diagonal for which all data below will be zero in the final upper quasi-triangular matrix. Must be Zero or one.subDiagonal = 0
: Matrix will be upper triangular.subDiagonal = 1
: Matrix will be upper Hessenburg.
storeReflectors
- Flag indicating if the reflectors used to bring the matrix to upper triangular/Hessenburg form should be stored.inPlace
- Flag indicating if the decomposition should be done in-place.- If
true
, then the decomposition will be done in place. - If
false
, then the decomposition will be done out-of-place.
- If
- Throws:
IllegalArgumentException
- IfsubDiagonal < 0 || subDiagonal > 1
.
-
-
Method Details
-
getQ
Gets the unitary
Q
matrix from the unitary decomposition.Note, if the reflectors for this decomposition were not saved, then
Q
can not be computed and this method will benull
.- Specified by:
getQ
in classUnitaryDecomposition<Matrix,
double[]> - Returns:
- The
Q
matrix from the unitary decomposition. Note, if the reflectors for this decomposition were not saved, thenQ
can not be computed and this method will returnnull
.
-
getUpper
Gets the upper triangular/Hessenburg matrix from the last decomposition.- Specified by:
getUpper
in classUnitaryDecomposition<Matrix,
double[]> - Parameters:
H
- Storage for upper triangular/Hessenburg matrix. Assumed to be the zero matrix of an appropriate size.- Returns:
- The upper triangular/Hessenburg matrix from the last decomposition.
-
initWorkArrays
protected void initWorkArrays(int maxAxisSize) Initialized any work arrays to be used in computing the decomposition with the proper size.- Specified by:
initWorkArrays
in classUnitaryDecomposition<Matrix,
double[]> - Parameters:
maxAxisSize
- Length of the largest axis in the matrix to be decomposed. That is,max(numRows, numCols)
-
computeHouseholder
protected void computeHouseholder(int j) Computes the Householder vector for the first column of the sub-matrix with upper left corner at(j, j)
.- Specified by:
computeHouseholder
in classUnitaryDecomposition<Matrix,
double[]> - Parameters:
j
- Index of the upper left corner of the sub-matrix for which to compute the Householder vector for the first column. That is, a Householder vector will be computed for the portion of columnj
below rowj
.
-
computePhasedNorm
protected void computePhasedNorm(int j, double maxAbs) Computes the norm of columnj
below thej
th row of the matrix to be decomposed. The norm will have the same parity as the first entry in the sub-column.- Specified by:
computePhasedNorm
in classUnitaryDecomposition<Matrix,
double[]> - Parameters:
j
- Column to compute norm of below thej
th row.maxAbs
- Maximum absolute value in the column. Used for scaling norm to minimize potential overflow issues.
-
findMaxAndInit
protected double findMaxAndInit(int j) Finds the maximum value inUnitaryDecomposition.transformMatrix
at columnj
at or below thej
th row. This method also initializes the firstnumRows-j
data of the storage arrayUnitaryDecomposition.householderVector
to the data of this column.- Specified by:
findMaxAndInit
in classUnitaryDecomposition<Matrix,
double[]> - Parameters:
j
- Index of column (and starting row) to compute max of.- Returns:
- The maximum value in
UnitaryDecomposition.transformMatrix
at columnj
at or below thej
th row.
-
updateData
protected void updateData(int j) Updates theUnitaryDecomposition.transformMatrix
matrix using the computed Householder vector fromcomputeHouseholder(int)
.- Specified by:
updateData
in classUnitaryDecomposition<Matrix,
double[]> - Parameters:
j
- Index of sub-matrix for which the Householder reflector was computed for.
-