
Hi,
I have found a problem when using the thin QR to solve a LeastSquares problem. Here's my test code:
Public Shared Function MathNetQRSolve(xArray(,) As Double, yColumn() As Double, useFull As Boolean) As Double()
Dim QRType As LAGeneric.Factorization.QRMethod
If useFull Then
QRType = LAGeneric.Factorization.QRMethod.Full
Else
QRType = LAGeneric.Factorization.QRMethod.Thin
End If
Dim xMatrix As LAGeneric.Matrix(Of Double) = New DenseMatrix(xArray)
Dim yVector As LAGeneric.Vector(Of Double) = New DenseVector(yColumn)
Dim output As LAGeneric.Vector(Of Double)
Try
Dim tempQR As LAGeneric.Factorization.QR(Of Double) = xMatrix.QR(QRType)
output = tempQR.Solve(yVector)
Catch ex As Exception
output = New SparseVector(yColumn.Count)
MsgBox(ex.Message)
End Try
Return output.ToArray
End Function
If I use the thin QR factorization then it throws an error, "All vectors must have the same dimensionality". The factorization itself is fine, it's just the solve method that doesn't work.
Thanks,
Andrew


Feb 12, 2013 at 3:19 PM
Edited Feb 12, 2013 at 3:20 PM

Just having thought about it a little more, I think it's because for an M×N matrix:
Full QR Decomposition
Q is M×M
R is M×N
Thin QR Decomposition
Q is M×M
R is N×N (square matrix)
This means that when the solve method checks that the dimensions are the same then they won't be and that's where it throws the error.


Feb 13, 2013 at 5:53 AM
Edited Feb 14, 2013 at 5:42 AM

yep, in DenseQR we are checking
if (MatrixR.RowCount != input.RowCount)
but we we should be using the Q matrix not R.
Interesting that this passed the unit tests. I'll update the tests and check in a fix. [update: since we only tested square matrices when solving  doh!. Added tall matrix tests]



Chris as merged the fix into the main branch. Thanks for reporting the error.



No problem. Does this mean that the fix is available in the latest download or do I need to download the source code and compile it myself?
I assume that you caught this one in the same fix, but I think the GramSchmidt decomposition also had the same problem.



For the moment you'll need to compile it yourself.
It didn't occur to me to check GS. It looks there is an issue with it  thanks!


Coordinator
Feb 14, 2013 at 9:01 AM

(There have been quite a few fixes lately, so I'm considering a patch release soon, i.e. v2.4.1)



Hello there,
has this issue ever been solved? I am using the latest binaries but I get the same exception when trying to QR solve an MxN matrix (sparse or dense, full or thin method).
Thanks!


Coordinator
Mar 15, 2015 at 10:08 PM

Yes, this has been fixed roughly 2 years ago. Of course QR decompositions still require m >= n. Can you provide a repro?
Thanks,
Christoph

