Class RealLstsqSolver
- All Implemented Interfaces:
LinearMatrixSolver<Matrix,
,Vector> LinearSolver<Matrix>
Instances of this class solve real linear systems of the form \( Ax = b \) or \( AX = B \) in a least-squares sense. The system may be under-, well-, or over-determined. Specifically, this solver minimizes the sum of squared residuals:
- \( ||Ax - b||_{2}^{2} \) for vector-based problems, or
- \( ||AX - B||_{F}^{2} \) for matrix-based where problems
Usage:
A single system may be solved by calling either LstsqSolver.solve(MatrixMixin, VectorMixin)
or
LstsqSolver.solve(MatrixMixin, VectorMixin)
.
Instances of this solver may also be used to efficiently solve many systems of the form \( Ax = b \) or \( AX = B \) for the same coefficient matrix \( A \) but numerous constant vectors/matrices \( b \) or \( B \). To do this, the workflow would be as follows:
- Create an instance of
RealLstsqSolver
. - Call
decompse(A)
once on the coefficient matrix \( A \). - Call
solve(b)
orsolve(B)
as many times as needed to solve each system for with the various \( b \) vectors and/or \( B \) matrices.
decompse(A)
will override the coefficient matrix set that call:
Implementation Notes:
Minimizing the sum of squared residuals is achieved by computing a QR decomposition of the coefficient matrix \( A \): \[ A = QR \] where \( Q \) is a orthonormal matrix and \( R \) is an upper triangular matrix. The normal equations then reduces to: \[ \begin{alignat*}{6} & &A^TAx &= A^Tb &&\; \text{ or }\; &A^TAX &= A^TB \\ &\implies &(QR)^TQRx &= (QR)^Tb &&\; \text{ or }\; &(QR)^TQRX &= (QR)^TB \\ &\implies &R^TQ^TQRx &= R^TQ^Tb &&\; \text{ or }\; &R^TQ^TQRX &= R^TQ^TB \\ &\implies &R^TRx &= R^TQ^Tb &&\; \text{ or }\; &R^TRX &= R^TQ^TB \quad \text{ since } Q \text{ is orthonormal.} \\ &\implies &Rx &= Q^Tb &&\; \text{ or }\; & RX &= Q^TB \end{alignat*} \] which is easily solved by back-substitution on \( R \).
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.linalg.solvers.lstsq.LstsqSolver
backSolver, Qh, qr, R
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a solver for solving real linear systems of the form \( Ax = b \) or \( AX = B \) in a least-squares sense. -
Method Summary
-
Constructor Details
-
RealLstsqSolver
public RealLstsqSolver()Creates a solver for solving real linear systems of the form \( Ax = b \) or \( AX = B \) in a least-squares sense. The system may be under-, well-, or over-determined. The solution is computed by minimizing the sum of squared residuals:- \( ||Ax - b||_{2}^{2} \) for vector-based problems, or
- \( ||AX - B||_{F}^{2} \) for matrix-based where problems
-