Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-1053

QRDecomposition.getSolver() should be able to find pseudo-inverse of non-square matrices



    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.2
    • 3.3
    • None
    • None


      I don't have a complete solution to this, so don't commit this as-is, but posting in case someone can get it over the line.

      If you process a tall m x n matrix (non-square, m>n) with QRDecomposition and then call getSolver().getInverse(), you will get DimensionMismatchException. There's not a good reason the QR decomposition can't compute the least-squares solution here.

      The issue is that it tries to invert A by solving AX = I. The dimension of I has to match the row dimension of A, or m. However it's using the length of the diagonal of R, which is min(m,n), which is n when m>n.

      That patch is simple and is part of the attached patch. It also includes a test case for a tall matrix.

      However it doesn't work for a fat matrix (m<n). There's a test case for that too. It returns an n x m value but the rows for i >= m are 0 and are not computed. I'm not sure enough about the shape of the computation to be able to fix it, but it is where it's solving the triangular system Rx = y.


        1. MATH-1053.patch
          3 kB
          Sean R. Owen



            Unassigned Unassigned
            srowen Sean R. Owen
            0 Vote for this issue
            3 Start watching this issue