Class Schur<T extends MatrixMixin<T,?,?,?,?,?,?,?>,U>
- Type Parameters:
T
- The type of matrix to be decomposed.U
- The type for the internal storage datastructure of the matrix to be decomposed.
- All Implemented Interfaces:
Decomposition<T>
- Direct Known Subclasses:
ComplexSchur
,RealSchur
The base class for Schur decompositions.
The Schur decomposition decompose a square matrix A
into A=UTU<sup>H</sup>
where U
is a unitary
matrix and T
is a quasi-upper triangular matrix called the Schur form of A
. T
is upper triangular
except for possibly 2x2 blocks along the diagonal. T
is similar to A
meaning they share the same eigenvalues.
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Flag indicating if a check should be made during the decomposition that the working matrix contains only finite values.protected final boolean
Flag indicating if the orthogonal matrixU
in the Schur decomposition should be computed.protected final int
Default number of iterations to apply before doing an exceptional shift.protected final int
Default factor for computing the maximum number of iterations to perform.protected int
Number of iterations to run without deflation before an exceptional shift is done.protected UnitaryDecomposition
<T, U> Decomposer to compute the Hessenburg decomposition as a setup step for the implicit double step QR algorithm.protected U
Stores the vectorv
in the Householder reflectorP = I -
invalid input: '&alpha'vv
T.protected int
Maximum number of iterations to run QR algorithm for.protected int
Factor for computing the maximum number of iterations to run theQR
algorithm for.protected int
The total number of exceptional shifts that have been used during the decomposition.protected int
Stores the number of rows in the matrix being decomposed.protected final RandomCNumber
Random number generator to be used when computing a random exceptional shift.protected U
Stores the non-zero entries of the first column of the shifted matrix(A-
invalid input: '&rho'1I)(A-
invalid input: '&rho'2I)
where invalid input: '&rho'1 and invalid input: '&rho'2 are the two shifts.protected int
The number of iterations run in the QR algorithm without deflating or performing an exceptional shift.protected T
For storing the (possibly block) upper triangular matrixT
in the Schur decomposition.protected U
Array for holding temporary values when computing the shifts.protected T
For storing the unitaryU
matrix in the Schur decomposition.protected U
An array for storing temporary values along the colum of a matrix when applying Householder reflectors. -
Constructor Summary
ConstructorDescriptionSchur
(boolean computeU, RandomCNumber rng, UnitaryDecomposition<T, U> hess) Creates a decomposer to compute the Schur decomposition for a real dense matrix. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
checkConvergence
(int workingSize) Checks for convergence of lower 2x2 sub-matrix within working matrix to upper triangular or block upper triangular form.void
decomposeBase
(T src) Computes the Schur decomposition of the input matrix.getT()
Gets the upper, or possibly block-upper, triangular Schur matrixT
from the Schur decompositiongetU()
Gets the unitary matrixU
from the Schur decomposition containing the Schur vectors as its columns.protected abstract void
performDoubleShift
(int workingSize) Performs a full iteration of the Francis implicit double shiftedQR
algorithm (this includes the bulge chase).protected abstract void
performExceptionalShift
(int workingSize) Performs a full iteration of the single shiftedQR
algorithm (this includes the bulge chase) where the shift is chosen to be a random value with the same magnitude as the lower right element of the working matrix.setExceptionalThreshold
(int exceptionalThreshold) Sets the number of iterations of theQR
algorithm to perform without deflation before performing a random shift.setMaxIterationFactor
(int maxIterationFactor) Specify maximum iteration factor for computing the total number of iterations to run theQR
algorithm for when computing the decomposition.protected void
Performs basic setup and initializes data structures to be used in the decomposition.protected abstract void
Initializes temporary work arrays to be used in the decomposition.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.flag4j.linalg.decompositions.Decomposition
decompose
-
Field Details
-
rng
Random number generator to be used when computing a random exceptional shift. -
DEFAULT_EXCEPTIONAL_ITERS
protected final int DEFAULT_EXCEPTIONAL_ITERSDefault number of iterations to apply before doing an exceptional shift.- See Also:
-
DEFAULT_MAX_ITERS_FACTOR
protected final int DEFAULT_MAX_ITERS_FACTORDefault factor for computing the maximum number of iterations to perform.- See Also:
-
T
For storing the (possibly block) upper triangular matrixT
in the Schur decomposition. -
U
For storing the unitaryU
matrix in the Schur decomposition. -
hess
Decomposer to compute the Hessenburg decomposition as a setup step for the implicit double step QR algorithm. -
numRows
protected int numRowsStores the number of rows in the matrix being decomposed. -
householderVector
Stores the vectorv
in the Householder reflectorP = I -
invalid input: '&alpha'vv
T. -
shiftCol
Stores the non-zero entries of the first column of the shifted matrix(A-
invalid input: '&rho'1I)(A-
invalid input: '&rho'2I)
where invalid input: '&rho'1 and invalid input: '&rho'2 are the two shifts. -
workArray
An array for storing temporary values along the colum of a matrix when applying Householder reflectors. This can help improve cache performance when applying the reflector. -
temp
Array for holding temporary values when computing the shifts. -
maxIterationsFactor
protected int maxIterationsFactorFactor for computing the maximum number of iterations to run theQR
algorithm for. -
maxIterations
protected int maxIterationsMaximum number of iterations to run QR algorithm for. -
exceptionalThreshold
protected int exceptionalThresholdNumber of iterations to run without deflation before an exceptional shift is done. -
sinceLastExceptional
protected int sinceLastExceptionalThe number of iterations run in the QR algorithm without deflating or performing an exceptional shift. -
numExceptional
protected int numExceptionalThe total number of exceptional shifts that have been used during the decomposition. -
checkFinite
protected boolean checkFiniteFlag indicating if a check should be made during the decomposition that the working matrix contains only finite values. If true, an explicit check will be made and an exception will be thrown ifnon-finite
values are found. If false, no check will be made and the floating point arithmetic will carry on withinfinities
,negative-infinities
, andNaNs
present. -
computeU
protected final boolean computeUFlag indicating if the orthogonal matrixU
in the Schur decomposition should be computed. If false,U
will not be computed. This may provide performance improvements for large matrices whenU
is not required (for instance: in eigenvalue computations where eigenvectors are not needed).
-
-
Constructor Details
-
Schur
Creates a decomposer to compute the Schur decomposition for a real dense matrix.
If the
U
matrix is not needed, passingcomputeU = false
may provide a performance improvement.- Parameters:
computeU
- Flag indicating if the unitaryU
matrix should be computed for the Schur decomposition. If true,U
will be computed. If false,U
will not be computed.rng
- Random number generator to use when performing random exceptional shifts.hess
- Decomposer to compute the Hessenburg decomposition as a setup step for theQR
algorithm.
-
-
Method Details
-
setExceptionalThreshold
Sets the number of iterations of the
QR
algorithm to perform without deflation before performing a random shift.That is, if
exceptionalThreshold = 10
, then at most 10 iterationsQR
algorithm iterations will be performed. If, by the 10th iteration, no convergence has been detected which allows for deflation, then aQR
algorithm iteration will be performed with a random (i.e. exceptional) shift.By default, the threshold is set to
DEFAULT_EXCEPTIONAL_ITERS
- Parameters:
exceptionalThreshold
- The new exceptional shift threshold. i.e. the number of iterations to perform without deflation before performing an iteration with random shifts.- Returns:
- A reference to this decomposer.
- Throws:
IllegalArgumentException
- IfexceptionalThreshold
is not positive.
-
setMaxIterationFactor
Specify maximum iteration factor for computing the total number of iterations to run the
QR
algorithm for when computing the decomposition. The maximum number of iterations is computed asmaxIteration = maxIterationFactor * src.numRows;
By default, this is computed as
maxIterations =
DEFAULT_MAX_ITERS_FACTOR
* src.numRows;
src
is the matrix being decomposed.- Parameters:
maxIterationFactor
- maximum iteration factor for use in computing the total maximum number of iterations to run theQR
algorithm for.- Throws:
IllegalArgumentException
- IfmaxIterationFactor
is not positive.
-
getT
Gets the upper, or possibly block-upper, triangular Schur matrixT
from the Schur decomposition- Returns:
- The T matrix from the Schur decomposition
A=UTU
H
-
getU
Gets the unitary matrixU
from the Schur decomposition containing the Schur vectors as its columns.- Returns:
A=UTU
H
-
decomposeBase
Computes the Schur decomposition of the input matrix.
- Parameters:
src
- The source matrix to decompose.- Throws:
LinearAlgebraException
- If the decomposition does not converge within the specified number of max iterations. See invalid input: '{@link /*missing*/}'
-
setUp
Performs basic setup and initializes data structures to be used in the decomposition.- Parameters:
src
- The matrix to be decomposed.
-
setUpArrays
protected abstract void setUpArrays()Initializes temporary work arrays to be used in the decomposition. -
performExceptionalShift
protected abstract void performExceptionalShift(int workingSize) Performs a full iteration of the single shiftedQR
algorithm (this includes the bulge chase) where the shift is chosen to be a random value with the same magnitude as the lower right element of the working matrix. This can help theQR
converge for certain pathological cases where the double shift algorithm oscillates or fails to converge for repeated eigenvalues.- Parameters:
workingSize
- The current working size for the decomposition. I.e. all entries below this row have converged to an upper or possible 2x2 block upper triangular form.
-
performDoubleShift
protected abstract void performDoubleShift(int workingSize) Performs a full iteration of the Francis implicit double shiftedQR
algorithm (this includes the bulge chase).- Parameters:
workingSize
- The current working size for the decomposition. I.e. all entries below this row have converged to an upper or possible 2x2 block upper triangular form.
-
checkConvergence
protected abstract int checkConvergence(int workingSize) Checks for convergence of lower 2x2 sub-matrix within working matrix to upper triangular or block upper triangular form. If convergence is found, this will also zero out the values which have converged to near zero.- Parameters:
workingSize
- Size of current working matrix.- Returns:
- Returns the amount the working matrix size should be deflated. Will be zero if no convergence is detected, one if convergence to upper triangular form is detected and two if convergence to block upper triangular form is detected.
-