Commons Math
  1. Commons Math
  2. MATH-1053

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


    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2
    • Fix Version/s: 3.3
    • Labels:


      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.


        Luc Maisonobe made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Luc Maisonobe made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 3.3 [ 12324600 ]
        Resolution Fixed [ 1 ]
        Thomas Neidhart made changes -
        Issue Type Bug [ 1 ] Improvement [ 4 ]
        Sean Owen made changes -
        Field Original Value New Value
        Attachment MATH-1053.patch [ 12611757 ]
        Sean Owen created issue -


          • Assignee:
            Sean Owen
          • Votes:
            0 Vote for this issue
            3 Start watching this issue


            • Created: