-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CompressedColumnStorage<T>.Transpose
yields wrong result leading to sequential issues in Solver
s
#43
Comments
I haven't tested any of the code you provided, but the first issue I see is var aSparse = new CSparseMatrix(a.RowCount, a.ColumnCount) That would only be ok for a square matrix. If var aSparse = new CSparseMatrix(a.ColumnCount, a.RowCount) Can you please test this and report back. If the problems reside, I'll have a closer look. |
Hi @wo80! Thanks for the quick help, that was it! |
You need to understand how the matrix entries are stored (see for example https://www.smcm.iqfr.csic.es/docs/intel/mkl/mkl_manual/appendices/mkl_appA_SMSF.htm). MathNet uses CSR storage (matrix entries are stored row-wise) while CSparse uses CSC storarge (entries are stored column-wise). So if you take the CSR storage and just interpret it as CSC, it will represent the transposed matrix. This means, if your original matrix stored as CSR is
Yes, if you want to solve a least-squares problem, make sure that the CSparse CSparse.NET/CSparse/Double/Factorization/SparseQR.cs Lines 55 to 67 in 2fa5b20
|
I just looked up the documentation of the CSparse.NET/CSparse/Storage/CompressedColumnStorage.cs Lines 473 to 478 in 2fa5b20
Do you think changing the summary would be enough:
|
Thanks a ton for clarifying, seems that I really misunderstood a few things. I am actually thinking about rewriting most of my code to use CSparse directly, the performance is incredible!
Absolutely, that makes it very explicit.
is that one could interpret it as left multiplication, as right multiplication is quite uncommon. |
I think you are right. The CSparse.NET is a port of CSparse by Tim. Davis. If i remember right, CSparse.NET had reasonably good performance compared to original CSparse although the original one is in native C or C++. |
In case you were using the dense QR from MathNet (or even native MKL), the difference will be considerable. You can set up your matrix using the CSparse.NET
Alright, I will make sure to add a note that the matrix |
Please leave this issue open! I will close it with the next pull request. |
Thanks a ton, @wo80! |
CompressedColumnStorage<T>.Transpose
yields wrong result leading to sequential issues in Solve
rsCompressedColumnStorage<T>.Transpose
yields wrong result leading to sequential issues in Solver
s
Hi!
Issue
I have several issues, most of which stem from the first one here (let
SparseMatrix
be the one from Math.NET andCSparseMatrix
the one from Csparse.NET):CSparseMatrix
yields incorrect results.E.g. when transposing sparse matrix
a
aDash
to beHowever, I instead get
MatrixMarketWriter.WriteMatrix
).aSparse
is incorrectly dumped asValues
property is[1,2,3,4,5,6]
(with 3 rows and 2 columns).Is supposed
A = B*C
equivalent tovar A = B.ParallelMultiply(C)
orvar A = C.ParallelMultiply(B)
?When I execute
var aTilde = aDash.ParallelMultiply(aSparse);
I getvar aTilde = aSparse.ParallelMultiply(aDash);
I getMathematically,
aDash*aSparse
andaSparse*aDash
should beHere, I used the values for
aDash
andaSparse
that were computed by the library (i.e. the unexpected ones).Solve
rs.E.g.
var solver = SparseQR.Create(aTilde, ColumnOrdering.Natural);
yields incorrect factorization matrices and applying
Solve
(withColumnOrdering.Natural
) yields the wrong result.My original mathematical problem
I want to numerically solve the regularized l_2-minimization problem
|| Ax -b ||_2 + λ|| x ||_2
, whereA
is some noise operator,b
a noisy signal,x
the denoised signal that I want to find, andλ > 0
is an arbitrary regularization parameter.´x´ and ´b´ have the same number of entries.
This is equivalent to an l_2-minimization problem of the form
|| Cx_c - y ||_2
, withC in |R^mxn
being a sparse matrix dependent onλ
withm > n
.According to the documentation of
SparseQR.Solve
,which is exactly what I want there.
Unfortunately, this returns wrong values for my actual problem that I want to solve, where
m
is about 8000 andn
about 4000.So I heavily simplified the problem, which yields the results above.
Versions
The text was updated successfully, but these errors were encountered: