Fix GRASP's dead similar-patient graph - #1194
Open
fbonc wants to merge 1 commit into
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
GRASPLayersetself.A_mat = Nonein__init__and never reassigned it, so theif self.A_mat is Nonebranch always won and the GCN was fed an identity adjacency mat. The kNN "similar-cluster" graph (which is the whole point of GRASP) was dead code.The kNN branch also hardcoded
n_neighbors=20while the graph has onlycluster_numnodes (default 2), so it would have raisedn_neighbors > n_sampleshad it ever run. The dead-code guard prevented the crash-prone call from ever executing.Fix
Build the kNN graph unconditionally, capping neighbors to the node count with
k = min(20, cluster_num - 1), and keep identity only as a genuine fallback when there are too few clusters (k < 1). Removed the unusedself.A_mat(the graph is rebuilt each forward from the current batch's cluster centers, so it can't be cached anyway).Tests
Added a regression test that looks at the adjacency passed to the GCN. it must be a real kNN graph (off-diagonal edges, no self-loops) for
cluster_num >= 2, and identity only forcluster_num == 1. Fails on the old identity-only behavior, passes on the fix.