Efficient Soft-KNN Graph Construction #6368
-
Hi all! For my research, I want to create a differentiable graph construction method. Basically what I want to achieve is a differentiable version of radius_graph or knn_graph. One naive implementation I thought about is to just have a fully connected graph with the inverse distance (low distance = high weight). The problem I have is that I am unsure what is the most efficient way to get the distances between each combination of points. That is the code:
For now, I am wondering how I can skip the creation of stacked_x altogether. It would be even better if there is a concise, differentiable way to arrive from x at edge_index / edge_weight. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
edge_index = knn_graph(x, batch)
dist = (x[edge_index[0]] - x[edge_index[1]]).norm(dim=-1) Let me know if this helps you. |
Beta Was this translation helpful? Give feedback.
-
Thank you, this is definitely helpful! I need to test if it has the desired effect (your solution is definitely efficient since it restricts the number of numbers). |
Beta Was this translation helpful? Give feedback.
radius_graph
andknn_graph
are discrete operators, so gradients can only go through edge weights, distances. So what you can do isLet me know if this helps you.