-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Fix for spectral clustering error when using 'amg' solver #13707
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @whitews
I'm not sure what chance it has to get into 0.21, but just in case:
Please add an entry to the change log at doc/whats_new/v0.21.rst
. Like the other entries there, please reference this pull request with :issue:
and credit yourself (and other contributors if applicable) with :user:
Updated the change log. Let me know if anything else is needed. |
Don't understand the codecov/patch failure, all local tests are passing for me. What does this failure mean? |
Codecov checks for lines of code that are never accessed during tests.
|
@jnothman This seems pretty clean now, everything is passing. |
I think that the mathematically proper fix is changing in sklearn/manifold/spectral_embedding_.py the present
into
so that the LOBPCG solver is still called on the unchanged Laplacian, but only the AMG preconditioner is fed with the shifted Laplacian. I have updated my #13393 to highlight this. I am unsure how the memory allocation would work in my suggestion above. May be to save memory one can do something like:
|
centers = np.eye(n_clusters, n_features) | ||
S, true_labels = make_blobs(n_samples=n_samples, centers=centers, | ||
cluster_std=1., random_state=42) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be check separately norm_laplacian = False and norm_laplacian = True . The latter is the default, the only option currently checked.
@whitews are you continuing with this? |
@jnothman Yes, I've updated the PR. Have the tests changed? Getting a 404 response for a deb package in the np_atlas Azure build. |
The tests haven't changed, but the world they operate in has. We will merge
a fix soon.
|
Yes, bit I've been low on time to review this and other pull requests. I hope one of us can get to it soon. |
@jnothman is there a plan trying to finish this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @whitews.
Btw, I've confirmed that the test fails on master, which is good.
Please merge the master from upstream to avoid the Circle CI failure. |
…into spec-clust-amg-fix
@jnothman I think this is ready. Are there any outstanding requests? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://scikit-learn.org/stable/modules/generated/sklearn.cluster.spectral_clustering.html, says that using amg eigen solver may lead to instabilities. This can be now removed, I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I pushed some cosmetic commits, will merge when CI is green.
Reference Issues/PRs
Fixes #13393. See also PR #12316
What does this implement/fix? Explain your changes.
Fixes LinAlgError when using spectral clustering with the
amg
solverAny other comments?
This PR is derived from the previous PR #12316 submitted by Andrew Knyazev (lobpcg). In that PR, Andrew fixed issue #13393 and also added a new label assignment option 'clusterQR'. It was requested that the PR be split to separate the fix and the new label assignment functionality. This PR contains Andrew's fix for the AMG bug.