Affinity Propagation Clustering and Edge Filtering #2333
-
Hi, thank you for the amazing library :). I am trying to implement this paper Learning Physical Graph Representations from Visual Scenes, and they use the label propagation clustering algorithm, where each node is assigned a unique index and at each label propagation iteration its index is replaced with the most common index of its neighbors. This hard clustering algorithm is very simple, but I'm struggling to figure out how to implement it in a MessagePassing format. The node list is large (~4000), so I can't afford to keep a one-hot num-nodes-wide vector at each node and I'm not sure how to keep a list of the neighbors labels at each node in a batch-wise fashion. Is this possible to implement efficiently and if so do you have any ideas on how to do so? Also, they learn an affinity matrix to filter a grid's edges, which takes the form of concatenating every node pair on the grid, passing it through a function which yields a scalar and thresholding on that scalar to determine if the edge should exist. The way I'm doing this now is converting the graph to dense-node format, and getting every node pair as something like the following: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
What you may wanna try is to represent node indices as sparse matrices, and utilize sparse-sparse matrix multiplication, e.g.: from torch_sparse import SparseTensor
from torch_scatter import scatter_max
adj_t = SparseTensor(row=edge_index[0], col=edge_index[1], sparse_sizes=(N, N)).t()
x = SparseTensor.eye(N)
out = adj_t @ x
# Get the argmax of each row:
row, col, value = out.coo()
max, argmax = scatter_max(out[col], row, dim=0, dim_size=N)
# Assign most common label:
x = SparseTensor(row=torch.arange(N), col=argmax, sparse_sizes=(N, N)) Regarding your second question, this feels really similar to a classic link prediction problem, e.g.: row, col = edge_index
out = torch.cat([x[row], x[col]], dim=-1)
# Get a score for every edge, e.g.:
score = f(x)
mask = score > threshold
edge_index = edge_index[:, mask] |
Beta Was this translation helpful? Give feedback.
What you may wanna try is to represent node indices as sparse matrices, and utilize sparse-sparse matrix multiplication, e.g.:
Regarding your second question, this feels really similar to a classic link prediction problem, e.g.: