-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG] clusterQR method added to spectral segmentation #12316
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
Closed
Closed
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
c8e8ff2
clusterQR method added to spectral segmentation
lobpcg 6f819e7
fix comment line too long
lobpcg 9902767
typo fixed in spectral.py
lobpcg 9fa6457
spectral.py trailing white space removed
lobpcg 44daccb
typos fixed
lobpcg 3ce05d0
Update doc/modules/clustering.rst
lobpcg 5789fb8
formatting/typo
lobpcg 9a0638b
spectral.py typo fixed
lobpcg b313306
Update sklearn/cluster/spectral.py
lobpcg 2146c81
Merge pull request #1 from scikit-learn/master
lobpcg 1a8a552
Merge pull request #2 from scikit-learn/master
lobpcg 33e34fe
Merge pull request #3 from lobpcg/master
lobpcg ac8445f
github.com/scikit-learn/scikit-learn/pull/12316#discussion_r251665191
lobpcg 06fba54
https://github.com/scikit-learn/scikit-learn/pull/12316#discussion_r2…
lobpcg 4b3f74b
Merge pull request #5 from scikit-learn/master
lobpcg b19eb7c
Merge pull request #6 from lobpcg/master
lobpcg 9426b4b
Merge pull request #8 from scikit-learn/master
lobpcg dfd9ed9
Merge pull request #9 from lobpcg/master
lobpcg e8b3b87
Update spectral.py
lobpcg 6b00bbb
removed redundant SVD
lobpcg 8cdcda2
testing new tol 1e-5 defaults and the laplacian shift in AMG
lobpcg 3b6844d
changed to eigen_solver='amg'
lobpcg e1fd3a0
eigen_solver='amg' is not installed in CircleCI so back to 'arpack'
lobpcg a11d94a
comment updated to include amg and lobpcg, now fixed
lobpcg 5b7afbc
AMG test on NOT fully connected graph
lobpcg 4189f7c
last changes reversed for error debugging
lobpcg 32e4d19
new AMG example, still connected graph
lobpcg 035d395
change n_neighbors=5 to 3 for graph to disconnect
lobpcg 5f79163
reversed changes to get back the original
lobpcg 4d3b7f9
added new AMG test NOT fully connected graph
lobpcg 1822016
flake8 line under-indented fixes
lobpcg abdb873
Merge pull request #11 from scikit-learn/master
lobpcg 8f9d659
Merge pull request #12 from lobpcg/master
lobpcg b75bd34
Merge pull request #14 from scikit-learn/master
lobpcg ea9ebdb
Merge branch 'clusterQR' into master
lobpcg 42d1414
Merge pull request #16 from lobpcg/master
lobpcg 1ceecd8
Merge branch 'master' into clusterQR
lobpcg be2018d
reverse changes that appear in a separate PR
lobpcg f962ed9
reverse changes that appear in a separate PR
lobpcg 3d20676
remove conj - complex numbers are not neeed
lobpcg f0d6f5c
reverse irrelevant change
lobpcg 6dfee88
reverse changes not relevant to this PR
lobpcg ba4a451
reverse irrelevant changes to this PR
lobpcg 6f9b305
typo fixed
lobpcg a9e9260
reverse changes irrelevant to this PR
lobpcg ced9b50
Merge pull request #18 from scikit-learn/master
lobpcg f2b1adc
Merge branch 'master' into clusterQR
lobpcg 13ea224
Merge pull request #21 from lobpcg/clusterQR
lobpcg 6924fa9
Merge pull request #22 from lobpcg/master
lobpcg 78a788a
trying to fix a conflict
lobpcg 5704634
Merge pull request #23 from scikit-learn/master
lobpcg 72d8d60
Merge pull request #24 from lobpcg/master
lobpcg 9556999
restore the edits
lobpcg 540f937
add imports
lobpcg 9bbd667
trying to fix rst warnings
lobpcg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,20 @@ | |
This procedure (spectral clustering on an image) is an efficient | ||
approximate solution for finding normalized graph cuts. | ||
|
||
There are two options to assign labels: | ||
There are three options to assign labels: | ||
|
||
* with 'kmeans' spectral clustering will cluster samples in the embedding space | ||
using a kmeans algorithm | ||
using a kmeans algorithm, | ||
* with 'clusterQR' will cluster samples in the embedding space | ||
using a clusterQR algorithm, | ||
lobpcg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* whereas 'discrete' will iteratively search for the closest partition | ||
space to the embedding space. | ||
|
||
""" | ||
print(__doc__) | ||
|
||
# Author: Gael Varoquaux <[email protected]>, Brian Cheung | ||
# Andrew Knyazev added clusterQR | ||
# License: BSD 3 clause | ||
|
||
import time | ||
|
@@ -62,28 +66,34 @@ | |
eps = 1e-6 | ||
graph.data = np.exp(-beta * graph.data / graph.data.std()) + eps | ||
|
||
# Apply spectral clustering (this step goes much faster if you have pyamg | ||
# installed) | ||
N_REGIONS = 25 | ||
# The actual number of regions in this example is 27: background and 26 coins | ||
N_REGIONS = 26 | ||
|
||
############################################################################# | ||
# Visualize the resulting regions | ||
# Compute and visualize the resulting regions | ||
|
||
# Any eigen_solver: 'arpack', 'lobpcg', 'amg' can be used. AMG is usually best | ||
# It often helps the spectral clustering to compute a few extra eigenvectors | ||
N_REGIONS_PLUS = 3 | ||
|
||
for assign_labels in ('kmeans', 'discretize'): | ||
for assign_labels in ('kmeans', 'discretize', 'clusterQR'): | ||
t0 = time.time() | ||
labels = spectral_clustering(graph, n_clusters=N_REGIONS, | ||
assign_labels=assign_labels, random_state=42) | ||
labels = spectral_clustering(graph, | ||
n_clusters=(N_REGIONS + N_REGIONS_PLUS), | ||
assign_labels=assign_labels, random_state=42, | ||
eigen_solver='arpack') | ||
t1 = time.time() | ||
labels = labels.reshape(rescaled_coins.shape) | ||
|
||
plt.figure(figsize=(5, 5)) | ||
plt.imshow(rescaled_coins, cmap=plt.cm.gray) | ||
for l in range(N_REGIONS): | ||
plt.contour(labels == l, | ||
colors=[plt.cm.nipy_spectral(l / float(N_REGIONS))]) | ||
plt.imshow(rescaled_coins, cmap=plt.get_cmap('gray')) | ||
plt.xticks(()) | ||
plt.yticks(()) | ||
title = 'Spectral clustering: %s, %.2fs' % (assign_labels, (t1 - t0)) | ||
print(title) | ||
plt.title(title) | ||
for l in range(N_REGIONS): | ||
plt.contour(labels == l, | ||
colors=[plt.cm.nipy_spectral((l+3) / float(N_REGIONS+3))]) | ||
plt.pause(0.5) | ||
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.