Class RawQR
- java.lang.Object
-
- org.ojalgo.matrix.decomposition.AbstractDecomposition<java.lang.Double>
-
- org.ojalgo.matrix.decomposition.RawDecomposition
-
- org.ojalgo.matrix.decomposition.RawQR
-
- All Implemented Interfaces:
MatrixDecomposition<java.lang.Double>
,MatrixDecomposition.Determinant<java.lang.Double>
,MatrixDecomposition.EconomySize<java.lang.Double>
,MatrixDecomposition.Ordered<java.lang.Double>
,MatrixDecomposition.RankRevealing<java.lang.Double>
,MatrixDecomposition.Solver<java.lang.Double>
,QR<java.lang.Double>
,Provider2D
,Provider2D.Determinant<java.lang.Double>
,Provider2D.Inverse<java.util.Optional<MatrixStore<java.lang.Double>>>
,Provider2D.Rank
,Provider2D.Solution<java.util.Optional<MatrixStore<java.lang.Double>>>
,DeterminantTask<java.lang.Double>
,InverterTask<java.lang.Double>
,MatrixTask<java.lang.Double>
,SolverTask<java.lang.Double>
,InvertibleFactor<java.lang.Double>
,Structure1D
,Structure2D
final class RawQR extends RawDecomposition implements QR<java.lang.Double>
For an m-by-n matrix A with m >= n, the QR decomposition is an m-by-n orthogonal matrix Q and an n-by-n upper triangular matrix R so that A = Q*R.
The QR decompostion always exists, even if the matrix does not have full rank, so the constructor will never fail. The primary use of the QR decomposition is in the least squares solution of nonsquare systems of simultaneous linear equations. This will fail if isFullRank() returns false.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.ojalgo.matrix.transformation.InvertibleFactor
InvertibleFactor.IdentityFactor<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition
MatrixDecomposition.Determinant<N extends java.lang.Comparable<N>>, MatrixDecomposition.EconomySize<N extends java.lang.Comparable<N>>, MatrixDecomposition.Factory<D extends MatrixDecomposition<?>>, MatrixDecomposition.Hermitian<N extends java.lang.Comparable<N>>, MatrixDecomposition.Ordered<N extends java.lang.Comparable<N>>, MatrixDecomposition.Pivoting<N extends java.lang.Comparable<N>>, MatrixDecomposition.RankRevealing<N extends java.lang.Comparable<N>>, MatrixDecomposition.Solver<N extends java.lang.Comparable<N>>, MatrixDecomposition.Values<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.matrix.Provider2D
Provider2D.Condition, Provider2D.Determinant<N extends java.lang.Comparable<N>>, Provider2D.Eigenpairs, Provider2D.Hermitian, Provider2D.Inverse<M>, Provider2D.Rank, Provider2D.Solution<M>, Provider2D.Symmetric, Provider2D.Trace<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.matrix.decomposition.QR
QR.Factory<N extends java.lang.Comparable<N>>
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.LongIndex, Structure1D.LoopCallback
-
Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure2D
Structure2D.IntRowColumn, Structure2D.Logical<S extends Structure2D,B extends Structure2D.Logical<S,B>>, Structure2D.LongRowColumn, Structure2D.ReducibleTo1D<R extends Structure1D>, Structure2D.Reshapable, Structure2D.RowColumnKey<R,C>, Structure2D.RowColumnMapper<R,C>
-
-
Field Summary
Fields Modifier and Type Field Description private double[]
myDiagonalR
Array for internal storage of diagonal of R.private int
myNumberOfHouseholderTransformations
-
Fields inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition
TYPICAL
-
-
Constructor Summary
Constructors Constructor Description RawQR()
Not recommended to use this constructor directly.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
btran(PhysicalStore<java.lang.Double> arg)
Backwards-transformationjava.lang.Double
calculateDeterminant(Access2D<?> matrix)
protected boolean
checkSolvability()
int
countSignificant(double threshold)
boolean
decompose(Access2D.Collectable<java.lang.Double,? super PhysicalStore<java.lang.Double>> matrix)
QR Decomposition, computed by Householder reflections.private boolean
doDecompose(double[][] data)
private MatrixStore<java.lang.Double>
doGetInverse(R064Store preallocated)
Makes no use ofpreallocated
at all.private MatrixStore<java.lang.Double>
doSolve(R064Store preallocated)
java.lang.Double
getDeterminant()
A matrix' determinant is the product of its eigenvalues.MatrixStore<java.lang.Double>
getInverse()
The output must be a "right inverse" and a "generalised inverse".MatrixStore<java.lang.Double>
getInverse(PhysicalStore<java.lang.Double> preallocated)
Implementing this method is optional.RawStore
getQ()
Generate and return the (economy-sized) orthogonal factorMatrixStore<java.lang.Double>
getR()
Return the upper triangular factordouble
getRankThreshold()
MatrixStore<java.lang.Double>
getSolution(Access2D.Collectable<java.lang.Double,? super PhysicalStore<java.lang.Double>> rhs)
[A][X]=[B] or [this][return]=[rhs]MatrixStore<java.lang.Double>
getSolution(Access2D.Collectable<java.lang.Double,? super PhysicalStore<java.lang.Double>> rhs, PhysicalStore<java.lang.Double> preallocated)
Implementing this method is optional.MatrixStore<java.lang.Double>
invert(Access2D<?> original, PhysicalStore<java.lang.Double> preallocated)
Exactly how (if at all) a specific implementation makes use ofpreallocated
is not specified by this interface.boolean
isFullSize()
boolean
isSolvable()
Please note that producing a pseudoinverse and/or a least squares solution is ok! The return value, of this method, is not an indication of if the decomposed matrix is square, has full rank, is postive definite or whatever.PhysicalStore<java.lang.Double>
preallocate(Structure2D template)
Will create a PhysicalStore instance suitable for use withInverterTask.invert(Access2D, PhysicalStore)
.PhysicalStore<java.lang.Double>
preallocate(Structure2D templateBody, Structure2D templateRHS)
Will create a PhysicalStore instance suitable for use withSolverTask.solve(Access2D, Access2D, PhysicalStore)
.void
reset()
Delete computed results, and resets attributes to default valuesMatrixStore<java.lang.Double>
solve(Access2D<?> body, Access2D<?> rhs)
[A][X]=[B] or [body][return]=[rhs]MatrixStore<java.lang.Double>
solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<java.lang.Double> preallocated)
Exactly how (if at all) a specific implementation makes use ofpreallocated
is not specified by this interface.-
Methods inherited from class org.ojalgo.matrix.decomposition.RawDecomposition
allocate, checkSymmetry, collect, function, getColDim, getInternalData, getInternalStore, getRowDim, make, makeDiagonal, newRawStore, reset, scalar, wrap, wrap
-
Methods inherited from class org.ojalgo.matrix.decomposition.AbstractDecomposition
computed, countColumns, countRows, getDimensionalEpsilon, isAspectRatioNormal, isComputed
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ojalgo.matrix.task.InverterTask
invert, preallocate
-
Methods inherited from interface org.ojalgo.matrix.transformation.InvertibleFactor
btran
-
Methods inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition
isComputed
-
Methods inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition.Determinant
toDeterminantProvider
-
Methods inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition.RankRevealing
getRank, isFullRank
-
Methods inherited from interface org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver
compute, ftran, ftran, invert, solve, toInverseProvider, toSolutionProvider
-
Methods inherited from interface org.ojalgo.matrix.decomposition.QR
isOrdered, reconstruct
-
Methods inherited from interface org.ojalgo.matrix.task.SolverTask
preallocate
-
Methods inherited from interface org.ojalgo.structure.Structure2D
count, countColumns, countRows, firstInColumn, firstInRow, getColDim, getMaxDim, getMinDim, getRowDim, isEmpty, isFat, isScalar, isSquare, isTall, isVector, limitOfColumn, limitOfRow, size
-
-
-
-
Method Detail
-
btran
public void btran(PhysicalStore<java.lang.Double> arg)
Description copied from interface:InvertibleFactor
Backwards-transformationSolve [x]T[A] = [b]T (equivalent to [A]T[x] = [b]) by transforming [b] into [x] in-place.
- Specified by:
btran
in interfaceInvertibleFactor<java.lang.Double>
- Parameters:
arg
- [b] transformed into [x]
-
calculateDeterminant
public java.lang.Double calculateDeterminant(Access2D<?> matrix)
- Specified by:
calculateDeterminant
in interfaceDeterminantTask<java.lang.Double>
-
countSignificant
public int countSignificant(double threshold)
- Specified by:
countSignificant
in interfaceMatrixDecomposition.RankRevealing<java.lang.Double>
- Parameters:
threshold
- Significance limit- Returns:
- The number of elements in the diagonal matrix that are greater than the threshold
-
decompose
public boolean decompose(Access2D.Collectable<java.lang.Double,? super PhysicalStore<java.lang.Double>> matrix)
QR Decomposition, computed by Householder reflections. Structure to access R and the Householder vectors and compute Q.- Specified by:
decompose
in interfaceMatrixDecomposition<java.lang.Double>
- Parameters:
matrix
- Rectangular matrix- Returns:
- true if decomposition suceeded; false if not
-
getDeterminant
public java.lang.Double getDeterminant()
Description copied from interface:MatrixDecomposition.Determinant
A matrix' determinant is the product of its eigenvalues.
- Specified by:
getDeterminant
in interfaceMatrixDecomposition.Determinant<java.lang.Double>
- Specified by:
getDeterminant
in interfaceProvider2D.Determinant<java.lang.Double>
- Returns:
- The matrix' determinant
-
getInverse
public MatrixStore<java.lang.Double> getInverse()
Description copied from interface:MatrixDecomposition.Solver
The output must be a "right inverse" and a "generalised inverse".- Specified by:
getInverse
in interfaceMatrixDecomposition.Solver<java.lang.Double>
-
getInverse
public MatrixStore<java.lang.Double> getInverse(PhysicalStore<java.lang.Double> preallocated)
Description copied from interface:MatrixDecomposition.Solver
Implementing this method is optional.
Exactly how a specific implementation makes use of
preallocated
is not specified by this interface. It must be documented for each implementation.Should produce the same results as calling
MatrixDecomposition.Solver.getInverse()
.- Specified by:
getInverse
in interfaceMatrixDecomposition.Solver<java.lang.Double>
- Parameters:
preallocated
- Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/final/correct solution. UseInverterTask.preallocate(int, int)
orInverterTask.preallocate(Structure2D)
to get a suitable instance.- Returns:
- The inverse, this is where you get the solution
-
getQ
public RawStore getQ()
Generate and return the (economy-sized) orthogonal factor
-
getR
public MatrixStore<java.lang.Double> getR()
Return the upper triangular factor
-
getRankThreshold
public double getRankThreshold()
- Specified by:
getRankThreshold
in interfaceMatrixDecomposition.RankRevealing<java.lang.Double>
-
getSolution
public MatrixStore<java.lang.Double> getSolution(Access2D.Collectable<java.lang.Double,? super PhysicalStore<java.lang.Double>> rhs)
Description copied from interface:MatrixDecomposition.Solver
[A][X]=[B] or [this][return]=[rhs]- Specified by:
getSolution
in interfaceMatrixDecomposition.Solver<java.lang.Double>
-
getSolution
public MatrixStore<java.lang.Double> getSolution(Access2D.Collectable<java.lang.Double,? super PhysicalStore<java.lang.Double>> rhs, PhysicalStore<java.lang.Double> preallocated)
Description copied from interface:MatrixDecomposition.Solver
Implementing this method is optional.
Exactly how a specific implementation makes use of
preallocated
is not specified by this interface. It must be documented for each implementation.Should produce the same results as calling
MatrixDecomposition.Solver.getSolution(Collectable)
.- Specified by:
getSolution
in interfaceMatrixDecomposition.Solver<java.lang.Double>
- Parameters:
rhs
- The Right Hand Side, wont be modfiedpreallocated
- Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/final/correct solution. UseSolverTask.preallocate(int, int, int)
orSolverTask.preallocate(Structure2D, Structure2D)
to get a suitable instance.- Returns:
- The solution
-
invert
public MatrixStore<java.lang.Double> invert(Access2D<?> original, PhysicalStore<java.lang.Double> preallocated) throws RecoverableCondition
Description copied from interface:InverterTask
Exactly how (if at all) a specific implementation makes use of
preallocated
is not specified by this interface. It must be documented for each implementation.Should produce the same results as calling
InverterTask.invert(Access2D)
.Use
InverterTask.preallocate(Structure2D)
to obtain a suitbalepreallocated
.- Specified by:
invert
in interfaceInverterTask<java.lang.Double>
preallocated
- Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/ /correct solution.- Returns:
- The inverse
- Throws:
RecoverableCondition
- TODO
-
isFullSize
public boolean isFullSize()
- Specified by:
isFullSize
in interfaceMatrixDecomposition.EconomySize<java.lang.Double>
- Returns:
- True if it will generate a full sized decomposition.
-
isSolvable
public boolean isSolvable()
Description copied from interface:MatrixDecomposition.Solver
Please note that producing a pseudoinverse and/or a least squares solution is ok! The return value, of this method, is not an indication of if the decomposed matrix is square, has full rank, is postive definite or whatever. It's that in combination with the specific decomposition algorithm's capabilities.- Specified by:
isSolvable
in interfaceMatrixDecomposition.Solver<java.lang.Double>
- Overrides:
isSolvable
in classAbstractDecomposition<java.lang.Double>
- Returns:
- true if this matrix decomposition is in a state to be able to deliver an inverse or an equation system solution (with some degree of numerical stability).
-
preallocate
public PhysicalStore<java.lang.Double> preallocate(Structure2D template)
Description copied from interface:InverterTask
Will create a PhysicalStore instance suitable for use with
InverterTask.invert(Access2D, PhysicalStore)
.When inverting a matrix (mxn) the preallocated memory/matrix will typically be nxm (and of course most of the time A is square).
- Specified by:
preallocate
in interfaceInverterTask<java.lang.Double>
-
preallocate
public PhysicalStore<java.lang.Double> preallocate(Structure2D templateBody, Structure2D templateRHS)
Description copied from interface:SolverTask
Will create a PhysicalStore instance suitable for use with
SolverTask.solve(Access2D, Access2D, PhysicalStore)
. The dimensions of the returned instance is not specified by this interface - it is specified by the behaviour/requirements of each implementation.When solving an equation system [A][X]=[B] ([mxn][nxb]=[mxb]) the preallocated memory/matrix will typically be either mxb or nxb.
- Specified by:
preallocate
in interfaceSolverTask<java.lang.Double>
-
reset
public void reset()
Description copied from interface:MatrixDecomposition
Delete computed results, and resets attributes to default values- Specified by:
reset
in interfaceMatrixDecomposition<java.lang.Double>
- Overrides:
reset
in classAbstractDecomposition<java.lang.Double>
-
solve
public MatrixStore<java.lang.Double> solve(Access2D<?> body, Access2D<?> rhs) throws RecoverableCondition
Description copied from interface:SolverTask
[A][X]=[B] or [body][return]=[rhs]- Specified by:
solve
in interfaceSolverTask<java.lang.Double>
- Throws:
RecoverableCondition
-
solve
public MatrixStore<java.lang.Double> solve(Access2D<?> body, Access2D<?> rhs, PhysicalStore<java.lang.Double> preallocated) throws RecoverableCondition
Description copied from interface:SolverTask
Exactly how (if at all) a specific implementation makes use of
preallocated
is not specified by this interface. It must be documented for each implementation.Should produce the same results as calling
SolverTask.solve(Access2D, Access2D)
.Use
SolverTask.preallocate(Structure2D, Structure2D)
to obtain a suitbalepreallocated
.- Specified by:
solve
in interfaceSolverTask<java.lang.Double>
rhs
- The Right Hand Side, wont be modfiedpreallocated
- Preallocated memory for the results, possibly some intermediate results. You must assume this is modified, but you cannot assume it will contain the full/ /correct solution.- Returns:
- The solution
- Throws:
RecoverableCondition
-
doDecompose
private boolean doDecompose(double[][] data)
-
doGetInverse
private MatrixStore<java.lang.Double> doGetInverse(R064Store preallocated)
Makes no use ofpreallocated
at all. Simply delegates togetInverse()
.
-
doSolve
private MatrixStore<java.lang.Double> doSolve(R064Store preallocated)
-
checkSolvability
protected boolean checkSolvability()
- Overrides:
checkSolvability
in classAbstractDecomposition<java.lang.Double>
-
-