You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A mistake about spectral clustering with amg solver #10715
I found a problem in the code of spectral clustering.
When using the amg solver and "n_nodes < 5 * n_components", it will firstly generate an embedding with arpack solver. However, this generated embedding would not be return. And the transformed laplacian matrix would be used to generate a new embedding with amg solver. Since the laplacian has been changed in the arpack part, the new embedding is wrong.
@jnothman I can only offer a simple fix for this problem. Since this is a small mistake if I'm right, maybe you can just accept my patch or take it as a reference.
I also missing insights and just try to connect the dots. From what I can see:
pyamg should be used with sparse matrix
amg is a preconditionner before to use lobcpg
lobcpg does not work with n_nodes < 5 and should default on eigh
when arpack failed, it should fallback to the lobcpg
lobcpg and arpack accepts both dense and sparse.
I have the impression that we should probably clean some of the logic there.
ifnotsparse.isparse(laplacian) andeigen_solver=='amg':
# warns to we switch to arpackeigen_solver='arpack'ifeigen_solver=='arpack':
# solve the problemtry:
...
exceptRuntimeError:
eigen_solver='lobcpg'# from that point eigen_solver will be either amg or lobcpg# check if we have enough n_nodesifn_nodes<5:
# use eighelse:
# check that we should preconditionifeigen_solver=='amg':
# preconditionne and get M# call lobcpg with M if available otherwise go for default
The idea behind @sky88088 patch looks correct and the logic of spectral embedding definitely looks like a good candidate for simplification. The selection of the eigen solver should probably be untangled from the execution as much as possible.
I feel that the whole logic of spectral_embedding needs a more complete test coverage before any changes take place. Otherwise we risk of coming back to this issue again and again, whenever any of the solvers crashes.
I feel that the whole logic of spectral_embedding needs a more complete test coverage before any changes take place. Otherwise we risk of coming back to this issue again and again, whenever any of the solvers crashes.
Yes the PR needs to come with some regression test for sure.
Activity
jnothman commentedon Feb 27, 2018
I'm not especially familiar with the algorithm. Would you be able to offer a fix, ideally with a test that illustrates what is currently broken?
sky88088 commentedon Feb 28, 2018
@jnothman I can only offer a simple fix for this problem. Since this is a small mistake if I'm right, maybe you can just accept my patch or take it as a reference.
lesteve commentedon Feb 28, 2018
@sky88088 what would be really good if you could one (or more) of these things:
cc @jmargeta and @glemaitre who have worked on this a little while ago IIRC and who may have some insights.
glemaitre commentedon Feb 28, 2018
I also missing insights and just try to connect the dots. From what I can see:
pyamgshould be used with sparse matrixamgis a preconditionner before to use lobcpglobcpgdoes not work withn_nodes < 5and should default oneigharpackfailed, it should fallback to thelobcpglobcpgandarpackaccepts both dense and sparse.I have the impression that we should probably clean some of the logic there.
glemaitre commentedon Feb 28, 2018
@lesteve @jnothman could you check if my guesses seem correct or not.
glemaitre commentedon Feb 28, 2018
Also currently we don't test pyamg with dense matrix so we never get into the error reported for sure.
sky88088 commentedon Mar 1, 2018
I hold the same idea with @glemaitre and my patch is adding the missing code in the arpack part:
Of course, the eigen solver type can also be resigned before the arpack part.
jmargeta commentedon Mar 1, 2018
The idea behind @sky88088 patch looks correct and the logic of spectral embedding definitely looks like a good candidate for simplification. The selection of the eigen solver should probably be untangled from the execution as much as possible.
After playing with that idea for a bit, it also revealed some places of potential code clean-up. https://gist.github.com/jmargeta/c393248ea7149b09e6ba5cfc6de8a16d (untested).
I feel that the whole logic of spectral_embedding needs a more complete test coverage before any changes take place. Otherwise we risk of coming back to this issue again and again, whenever any of the solvers crashes.
glemaitre commentedon Mar 2, 2018
Yes the PR needs to come with some regression test for sure.
amueller commentedon Aug 7, 2019
also see #10720 (comment)
amueller commentedon Aug 13, 2019
quite convinced that #14647 is the correct fix, also contains a regression test.