Class QRDecomposition


  • public class QRDecomposition
    extends Object
    QR with pivoting. See http://www.netlib.org/lapack/lug/node42.html and http://www.netlib.org/lapack/lug/node27.html, and Golub and VanLoan, section 5.5.6+. Designed to mimic the way R does this by default.
    Author:
    paul
    • Constructor Summary

      Constructors 
      Constructor Description
      QRDecomposition​(cern.colt.matrix.DoubleMatrix2D A)  
      QRDecomposition​(cern.colt.matrix.DoubleMatrix2D A, boolean pivoting)
      Construct the QR decomposition of A.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      cern.colt.matrix.DoubleMatrix2D chol2inv()
      Used for computing standard errors of parameter estimates for least squares; copies functionality of R chol2inv.
      protected String diagnose()  
      cern.colt.matrix.DoubleMatrix1D effects​(cern.colt.matrix.DoubleMatrix1D y)
      Compute effects matrix Q'y (as in Rb = Q'y).
      cern.colt.matrix.DoubleMatrix2D effects​(cern.colt.matrix.DoubleMatrix2D y)
      Compute effects matrix Q'y (as in Rb = Q'y)
      cern.colt.list.IntArrayList getPivotOrder()  
      cern.colt.matrix.DoubleMatrix2D getQ()
      Generates and returns the (economy-sized - first p columns only) orthogonal factor Q.
      protected cern.colt.matrix.DoubleMatrix2D getQR()
      For testing.
      cern.colt.matrix.DoubleMatrix1D getQraux()  
      cern.colt.matrix.DoubleMatrix2D getR()
      Returns the upper triangular factor, R.
      int getRank()  
      double getTolerance()  
      boolean hasFullRank()
      Returns whether the matrix A has full rank.
      boolean isPivoting()  
      cern.colt.matrix.DoubleMatrix2D solve​(cern.colt.matrix.DoubleMatrix2D y)
      Least squares solution of A*X = y; returns X using the stored QR decomposition of A.
      String toString()
      Returns a String with (propertyName, propertyValue) pairs.
    • Constructor Detail

      • QRDecomposition

        public QRDecomposition​(cern.colt.matrix.DoubleMatrix2D A)
        Parameters:
        A - the matrix to decompose, pivoting will be used.
      • QRDecomposition

        public QRDecomposition​(cern.colt.matrix.DoubleMatrix2D A,
                               boolean pivoting)
        Construct the QR decomposition of A. With pivoting = true, this reproduces quite closely the behaviour of R qr().
        Parameters:
        A - the matrix to decompose
        pivoting - set to false to obtain standard QR behaviour.
    • Method Detail

      • chol2inv

        public cern.colt.matrix.DoubleMatrix2D chol2inv()
        Used for computing standard errors of parameter estimates for least squares; copies functionality of R chol2inv.
        Returns:
      • effects

        public cern.colt.matrix.DoubleMatrix1D effects​(cern.colt.matrix.DoubleMatrix1D y)
        Compute effects matrix Q'y (as in Rb = Q'y).

        "Tthe effects are the uncorrelated single-degree-of-freedom values obtained by projecting the data onto the successive orthogonal subspaces generated by the QR decomposition during the fitting process. The first r (the rank of the model) are associated with coefficients and the remainder span the space of residuals (but are not associated with particular residuals)."

        Parameters:
        y - vector Missing values are ignored, otherwise assumed to be of the right size
        Returns:
        vector of effects - these are the projections of y into Q column space
      • effects

        public cern.colt.matrix.DoubleMatrix2D effects​(cern.colt.matrix.DoubleMatrix2D y)
        Compute effects matrix Q'y (as in Rb = Q'y)
        Parameters:
        y - matrix of data, assumed to be of right size, missing values are not supported
        Returns:
        matrix of effects - these are the projections of y's columns into Q column subspace associated with the parameters, so values are "effects" each basis vector on the data
      • getPivotOrder

        public cern.colt.list.IntArrayList getPivotOrder()
        Returns:
      • getQ

        public cern.colt.matrix.DoubleMatrix2D getQ()
        Generates and returns the (economy-sized - first p columns only) orthogonal factor Q.
        Returns:
        first p columns of Q
      • getQraux

        public cern.colt.matrix.DoubleMatrix1D getQraux()
        Returns:
      • getR

        public cern.colt.matrix.DoubleMatrix2D getR()
        Returns the upper triangular factor, R.
        Returns:
        R
      • getRank

        public int getRank()
        Returns:
        rank
      • getTolerance

        public double getTolerance()
      • hasFullRank

        public boolean hasFullRank()
        Returns whether the matrix A has full rank.
        Returns:
        true if R, and hence A, has full rank.
      • isPivoting

        public boolean isPivoting()
        Returns:
        true if pivoting was used (just whether it was set; not whether any actual pivoting happened)
      • solve

        public cern.colt.matrix.DoubleMatrix2D solve​(cern.colt.matrix.DoubleMatrix2D y)
        Least squares solution of A*X = y; returns X using the stored QR decomposition of A.
        Parameters:
        y - A matrix with as many rows as A and any number of columns. Least squares is fit for each column of y.
        Returns:
        X that minimizes the two norm of Q*R*X - B.
        Throws:
        IllegalArgumentException - if y.rows() != A.rows().
        IllegalArgumentException - if !this.hasFullRank() (A is rank deficient). However, rank-deficient cases are handled by pivoting, so if you are using pivoting you should not see this happening.
      • toString

        public String toString()
        Returns a String with (propertyName, propertyValue) pairs. Useful for debugging or to quickly get the rough picture.
        Overrides:
        toString in class Object
      • diagnose

        protected String diagnose()
      • getQR

        protected cern.colt.matrix.DoubleMatrix2D getQR()
        For testing.
        Returns: