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

    Fields
    Modifier and Type
    Field
    Description
    protected final LinearMatrixSolver<T,U>
    Solver for system with an upper triangular coefficient matrix.
    protected T
    Q The Hermitian transpose of the orthonormal matrix from the QR decomposition.
    protected final UnitaryDecomposition<T,?>
    Decomposer to compute the QR decomposition for using the least-squares solver.
    protected T
    R The upper triangular matrix from the QR decomposition.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructs a least-squares solver with a specified decomposer to use in the QR decomposition.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Computes the QR decomposition for use in this solver.
    solve(T A, T B)
    Solves the set of linear system of equations given by A*X=B for the matrix X where A, B, and X are matrices.
    solve(T A, U b)
    Solves the linear system given by Ax=b in the least-squares sense.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • backSolver

      protected final LinearMatrixSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>> backSolver
      Solver for system with an upper triangular coefficient matrix.
    • qr

      protected final UnitaryDecomposition<T extends MatrixMixin<T,?,U,?>,?> qr
      Decomposer to compute the QR decomposition for using the least-squares solver.
    • Qh

      protected T extends MatrixMixin<T,?,U,?> Qh
      Q The Hermitian transpose of the orthonormal matrix from the QR decomposition.
    • R

      protected T extends MatrixMixin<T,?,U,?> R
      R The upper triangular matrix from the QR decomposition.
  • Constructor Details

    • LstsqSolver

      protected LstsqSolver(UnitaryDecomposition<T,?> qr, LinearMatrixSolver<T,U> backSolver)
      Constructs a least-squares solver with a specified decomposer to use in the QR decomposition.
      Parameters:
      qr - The QR decomposer to use in the solver.
      backSolver - The solver to solve the upper triangular system resulting from the QR decomposition which is equivalent to solving the normal equations
  • Method Details

    • solve

      public U solve(T A, U b)
      Solves the linear system given by Ax=b in the least-squares sense.
      Specified by:
      solve in interface LinearMatrixSolver<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 system Ax=b.
    • solve

      public T solve(T A, T B)
      Solves the set of linear system of equations given by A*X=B for the matrix X where A, B, and X are matrices.
      Specified by:
      solve in interface LinearMatrixSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>>
      Specified by:
      solve in interface LinearSolver<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 system A*X=B.
    • decompose

      protected void decompose(T A)
      Computes the QR decomposition for use in this solver.
      Parameters:
      A - Coefficient matrix in the linear system to solve.