Fix GRASP's dead similar-patient graph - #1194
Conversation
|
The kNN graph now runs, but the adjacency passed to the GCN is missing the self-connections from GRASP. The paper augments the graph as |
|
@fbonc pls address Daryl's comment. |
Fixed. implementation now adds the identity matrix to the kNN adjacency before it is passed to both GCN layers. also updated the regression test to assert self-connections on the diagonal while retaining the check that neighbor edges are present. |
|
Looks good now. The kNN graph includes the self-connections required by the paper. |
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.