Class QRDecomposition

  • All Implemented Interfaces:
    java.io.Serializable

    public class QRDecomposition
    extends java.lang.Object
    implements java.io.Serializable
    QR Decomposition. 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.
    Since:
    0.1
    Author:
    Arthur Zimek
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String ERR_MATRIX_RANK_DEFICIENT
      When a matrix is rank deficient.
      private int m
      Row and column dimensions.
      private int n
      Row and column dimensions.
      private double[][] QR
      Array for internal storage of decomposition.
      private double[] Rdiag
      Array for internal storage of diagonal of R.
      private static long serialVersionUID
      Serial version
    • Constructor Summary

      Constructors 
      Constructor Description
      QRDecomposition​(double[][] A)
      QR Decomposition, computed by Householder reflections.
      QRDecomposition​(double[][] A, int m, int n)
      QR Decomposition, computed by Householder reflections.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double[][] getH()
      Return the Householder vectors
      double[][] getQ()
      Generate and return the (economy-sized, m by n) orthogonal factor
      double[][] getR()
      Return the upper triangular factor
      double[][] inverse()
      Find the inverse matrix.
      boolean isFullRank()
      Is the matrix full rank?
      int rank​(double t)
      Get the matrix rank?
      double[] solve​(double[] b)
      Least squares solution of A*X = b
      double[][] solve​(double[][] B)
      Least squares solution of A*X = B
      double[] solveInplace​(double[] b)
      Least squares solution of A*X = b
      private double[][] solveInplace​(double[][] B)
      Least squares solution of A*X = B
      • Methods inherited from class java.lang.Object

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

      • ERR_MATRIX_RANK_DEFICIENT

        protected static final java.lang.String ERR_MATRIX_RANK_DEFICIENT
        When a matrix is rank deficient.
        See Also:
        Constant Field Values
      • serialVersionUID

        private static final long serialVersionUID
        Serial version
        See Also:
        Constant Field Values
      • QR

        private double[][] QR
        Array for internal storage of decomposition.
      • m

        private int m
        Row and column dimensions.
      • n

        private int n
        Row and column dimensions.
      • Rdiag

        private double[] Rdiag
        Array for internal storage of diagonal of R.
    • Constructor Detail

      • QRDecomposition

        public QRDecomposition​(double[][] A)
        QR Decomposition, computed by Householder reflections.
        Parameters:
        A - Rectangular matrix
      • QRDecomposition

        public QRDecomposition​(double[][] A,
                               int m,
                               int n)
        QR Decomposition, computed by Householder reflections.
        Parameters:
        A - Rectangular matrix
        m - row dimensionality
        n - column dimensionality
    • Method Detail

      • isFullRank

        public boolean isFullRank()
        Is the matrix full rank?
        Returns:
        true if R, and hence A, has full rank.
      • rank

        public int rank​(double t)
        Get the matrix rank?
        Parameters:
        t - Tolerance threshold
        Returns:
        Rank of R
      • getH

        public double[][] getH()
        Return the Householder vectors
        Returns:
        Lower trapezoidal matrix whose columns define the reflections
      • getR

        public double[][] getR()
        Return the upper triangular factor
        Returns:
        R
      • getQ

        public double[][] getQ()
        Generate and return the (economy-sized, m by n) orthogonal factor
        Returns:
        Q
      • solve

        public double[][] solve​(double[][] B)
        Least squares solution of A*X = B
        Parameters:
        B - The matrix B with as many rows as A and any number of columns.
        Returns:
        X that minimizes the two norm of Q*R*X-B.
        Throws:
        java.lang.IllegalArgumentException - Matrix row dimensions must agree.
        java.lang.ArithmeticException - Matrix is rank deficient.
      • solveInplace

        private double[][] solveInplace​(double[][] B)
        Least squares solution of A*X = B
        Parameters:
        B - The matrix B with as many rows as A and any number of columns (will be overwritten).
        Returns:
        X that minimizes the two norm of Q*R*X-B.
        Throws:
        java.lang.IllegalArgumentException - Matrix row dimensions must agree.
        java.lang.ArithmeticException - Matrix is rank deficient.
      • solve

        public double[] solve​(double[] b)
        Least squares solution of A*X = b
        Parameters:
        b - A column vector with as many rows as A.
        Returns:
        X that minimizes the two norm of Q*R*X-b.
        Throws:
        java.lang.IllegalArgumentException - Matrix row dimensions must agree.
        java.lang.ArithmeticException - Matrix is rank deficient.
      • solveInplace

        public double[] solveInplace​(double[] b)
        Least squares solution of A*X = b
        Parameters:
        b - A column vector b with as many rows as A.
        Returns:
        X that minimizes the two norm of Q*R*X-b.
        Throws:
        java.lang.IllegalArgumentException - Matrix row dimensions must agree.
        java.lang.ArithmeticException - Matrix is rank deficient.
      • inverse

        public double[][] inverse()
        Find the inverse matrix.
        Returns:
        Inverse matrix
        Throws:
        java.lang.ArithmeticException - Matrix is rank deficient.