Class LstsqSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>>
java.lang.Object
org.flag4j.linalg.solvers.lstsq.LstsqSolver<T,U>
- All Implemented Interfaces:
LinearMatrixSolver<T,
,U> LinearSolver<T>
- Direct Known Subclasses:
ComplexLstsqSolver
,RealLstsqSolver
public abstract class LstsqSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>>
extends Object
implements LinearMatrixSolver<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 TAx=AT b.
This is done using a QR decomposition.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinearMatrixSolver
<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
ConstructorsModifierConstructorDescriptionprotected
LstsqSolver
(UnitaryDecomposition<T, ?> qr, LinearMatrixSolver<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
protected final LinearMatrixSolver<T extends MatrixMixin<T,?, backSolverU, ?>, U extends VectorMixin<U, T, ?, ?>> Solver for system with an upper triangular coefficient matrix. -
qr
Decomposer to compute theQR
decomposition for using the least-squares solver. -
Qh
Q
The Hermitian transpose of the orthonormal matrix from theQR
decomposition. -
R
R
The upper triangular matrix from theQR
decomposition.
-
-
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 interfaceLinearMatrixSolver<T extends MatrixMixin<T,
?, U, ?>, U extends VectorMixin<U, T, ?, ?>> - 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 interfaceLinearMatrixSolver<T extends MatrixMixin<T,
?, U, ?>, U extends VectorMixin<U, T, ?, ?>> - Specified by:
solve
in interfaceLinearSolver<T extends MatrixMixin<T,
?, U, ?>> - 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.
-