Package org.flag4j.linalg.solvers.lstsq
Class LstsqSolver<T extends MatrixMixin<T,T,?,CMatrix,?,?,U,U>,U extends VectorMixin<U,U,?,CVector,?,T,T,CMatrix>>
java.lang.Object
org.flag4j.linalg.solvers.lstsq.LstsqSolver<T,U>
- All Implemented Interfaces:
LinearSolver<T,
U>
- Direct Known Subclasses:
ComplexLstsqSolver
,RealLstsqSolver
public abstract class LstsqSolver<T extends MatrixMixin<T,T,?,CMatrix,?,?,U,U>,U extends VectorMixin<U,U,?,CVector,?,T,T,CMatrix>>
extends Object
implements LinearSolver<T,U>
This class solves a linear system of equations
Ax=b
in a least-squares sense. That is,
minimizes ||Ax-b||
2 which is equivalent to solving the normal equations A
TAx=A
T
b
.
This is done using a QR decomposition
.-
Field Summary
Modifier and TypeFieldDescriptionprotected final LinearSolver
<T, U> Solver for system with an upper triangular coefficient matrix.protected T
Q
The hermitian transpose of the orthonormal matrix from theQR
decomposition.protected final UnitaryDecomposition
<T, ?> Decomposer to compute theQR
decomposition for using the least-squares solver.protected T
R
The upper triangular matrix from theQR
decomposition. -
Constructor Summary
ModifierConstructorDescriptionprotected
LstsqSolver
(UnitaryDecomposition<T, ?> qr, LinearSolver<T, U> backSolver) Constructs a least-squares solver with a specified decomposer to use in theQR
decomposition. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Computes theQR
decomposition for use in this solver.Solves the set of linear system of equations given byA*X=B
for the matrixX
whereA
,B
, andX
are matrices.Solves the linear system given byAx=b
in the least-squares sense.
-
Field Details
-
backSolver
-
qr
Decomposer to compute theQR
decomposition for using the least-squares solver. -
Qh
-
R
-
-
Constructor Details
-
LstsqSolver
Constructs a least-squares solver with a specified decomposer to use in theQR
decomposition.- Parameters:
qr
- TheQR
decomposer to use in the solver.backSolver
- The solver to solve the upper triangular system resulting from theQR
decomposition which is equivalent to solving the normal equations
-
-
Method Details
-
solve
Solves the linear system given byAx=b
in the least-squares sense.- Specified by:
solve
in interfaceLinearSolver<T extends MatrixMixin<T,
T, ?, CMatrix, ?, ?, U, U>, U extends VectorMixin<U, U, ?, CVector, ?, T, T, CMatrix>> - Parameters:
A
- Coefficient matrix in the linear system.b
- Vector of constants in the linear system.- Returns:
- The least squares solution to
x
in the linear systemAx=b
.
-
solve
Solves the set of linear system of equations given byA*X=B
for the matrixX
whereA
,B
, andX
are matrices.- Specified by:
solve
in interfaceLinearSolver<T extends MatrixMixin<T,
T, ?, CMatrix, ?, ?, U, U>, U extends VectorMixin<U, U, ?, CVector, ?, T, T, CMatrix>> - Parameters:
A
- Coefficient matrix in the linear system.B
- Matrix of constants in the linear system.- Returns:
- The solution to
X
in the linear systemA*X=B
.
-
decompose
Computes theQR
decomposition for use in this solver.- Parameters:
A
- Coefficient matrix in the linear system to solve.
-