-
Hi there, I've been doing Node embedding using GraphSAGE. Using the PyG library for Graph Neural Network, I decided to use the LSTM function for aggregate. The arguments it requires are as follows: Input 1: Node features (|V|, F_in) - Here I use Node coordinates x-y in 2D plane (V x 2) and already normalized into the range of [0, 1] e.g.
Input 2: Edge indices (2, |E|) - Adjacency matrix (V x V) but retrieves only the edge into (2, |E|) from the original adjacency matrix I have e.g.
Above we have a shape (V x V) with 6 edges in the graph. We had to transform it a bit to accommodate PyG's use of shape (2, |E|) and I'd like to call it
Output: Node features (|V|, F_out) - Similar to Node coordinates, but they are not in 2D anymore, they are in a new embedding dimension with F_out dimensions. My problem is that when using the LSTM aggregator it is forced to sort So I have to do sorting gives it with the following command: # inside def __init__()
self.GraphSageLayer = SAGEConv(in_channels=2, out_channels=hidden_dim, aggr='lstm')
# inside def forward()
sorted_edge_index, _ = torch.sort(edge_index, dim=1) # for LSTM
x = self.GraphSageLayer(coord.view(-1, 2), sorted_edge_index) # using GraphSAGE The
I noticed that in my full-mesh graph of 3 nodes connected when I sorted it, the edges could be reinterpreted as (0, 0), (0, 0), (1, 1), (1, 1), (2, 2), (2, 2) which made me curious. And my questions are the following 2 things.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Since graphs are unordered we need to sort the neighbors of a node to pass it to an LSTM.
Use |
Beta Was this translation helpful? Give feedback.
-
It wouldn't be strictly necessary to required sorted indices. Our current implementation expects it so in order to accelerate the aggregation. |
Beta Was this translation helpful? Give feedback.
Since graphs are unordered we need to sort the neighbors of a node to pass it to an LSTM.
Use
sort_edge_index
orData.sort()
to correctly sort edge indicies as described in the LSTM aggregation document