Registered Member
|
I have to calculate the full inverse of a sparse matrix, and ggael told me on IRC to take a look at test/sparse_solvers.cpp.
I did, and also read the API docs of SparseLU - which gives me .solve, but I found no .inverse method. So what's the easiest way to get the inverse of a sparse matrix? (FYI my matrices are about 7k X 7k, with perhaps 50k non-zero complex elements (neither hermitian nor tri-diagonal). The inverse is a full matrix. Currently boost/ublas takes about 11 hours for that task. Anything that's at last 1.5 times faster is worth switching to Eigen for me) |
Moderator
|
well, unfortunately, none of the supported libraries (SuperLU and UmfPack) provides a solve function (AX=B) with X and B sparse. Therefore there is no efficient way to extract the full inverse matrix. What you can still do is to use dense matrices for the solve step:
of course since your matrix is large, you should extract the inverse per column:
this should still be quite slow but much much faster than your current solution ! |
Registered Member
|
There's no need to actually construct the identity matrix, you can pass the Identity expression directly to solve():
[quote='ggael' pid='44563' dateline='1234372241'] of course since your matrix is large, you should extract the inverse per column:
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Moderator
|
well, superLU needs a plainmatrix, so yes, currently you need to pass an expression with DirectAccessBit flags (e.g., Matrix or Block)
thanks ! |
Registered Member
|
Oops, I didn't see that you were working with the SparseLU (now i see), as you said we could use a dense matrix for the solve step, i jumped to the "conclusion" that you were using a dense LU.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
[quote='bjacob' pid='44591' dateline='1234379370']
This doesn't compile in my brain ;) I think you meant this:
Any idea what might be wrong? (In my real application the matrix has more items set than the upper triangle, this was just to get a matrix that's surely invertible) |
Registered Member
|
Right
No, it's really < because you want to zero the smaller entries, not the bigger ones.
Did you use a fuzzy comparison? How far away from the identity are you?
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
[quote='bjacob' pid='44801' dateline='1234444490']
No, it's really " most elements are either (1, 0) or (2, 0) even though they should be zero, so it's very far away. |
Registered Member
|
Woooops ! Sure you're right, sorry! indeed it's >.
Try this actually (j instead of i) :
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Moderator
|
well, I had better to say that the code I wrote was just to give you an idea about how to do it, and indeed the comparison operator was wrong and the index as well, I did not expected you to simply copy paste it as it!
I think this one should be correct (with i for the row and j for the col => less trouble in mine mind
|
Registered Member
|
I'd be interested to know how long this takes compared to boost/ublas. If I remember correctly you could also compute inverses blockwise or by cholesky / lu, right? I don't remember in which situations you should do what, though.
'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett
'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger |
Registered Member
|
To me, some benchmark on factorization and creating inverse matrices of sparse matrices with different sparsity levels would be helpful as well. I guess, as time is approaching...
This is a little offtopic, but when using UMFPACK to create the inverse matrix I get a compilation error. In function `Eigen::SparseLU, 4>::~SparseLU()': (.text._ZN5Eigen8SparseLUINS_12SparseMatrixIdLi0EEELi4EED1Ev[Eigen::SparseLU, 4>::~SparseLU()]+0x15): undefined reference to `umfpack_di_free_numeric' Changing
in Eigen/Sparse does not seem to help... The same error goes to Cholmod. Using gcc 4.3.1 Any ideas? |
Moderator
|
that's very difficult because the number of options is really HUGE.
what is your umfpack version ? (here 5.2) perhaps you can check that the library really contains the symbol:
should return:
if not, then you have a problem with your umfpack library. |
Registered Member
|
True. But it would be interesting to understand the overhead by constructing the actual inverse...
True. Was compiled on another system. Thanks for letting me bugging you again! |
Registered Member
|
Thank you very much everyone, it now works as I want it. The execution time dropped from 11 hours to about half an hour, and I'm rather happy with that improvement
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]