5

I want to handle weighted undirected graphs in Pytorch Geometric. The node features are 50 dimensional. I found that this can be handled by the x attribute of the torch_geometric.data.data class. The weights of the edges are scalar values. We found out that edge_attr and edge_weight are the attributes to handle edges.

I think I should probably use edge_weight, is this correct?

Also, what is the difference between edge_attr and edge_weight?

I'm not very good at English, so I apologize for that. I hope I can get a good answer.

Thank you.

Sparky05
  • 4,692
  • 1
  • 10
  • 27
orangeman
  • 51
  • 1
  • 2
  • This answer might be useful https://ai.stackexchange.com/questions/16805/is-there-an-open-source-implementation-for-graph-convolution-networks-for-weight – RM- Oct 21 '21 at 14:37

2 Answers2

7

The difference between edge_weight and edge_attr is that edge_weight is always one-dimensional (one value per edge) and that edge_attribute can be multi-dimensional. You can check the cheatsheet for the support of the models.

Sparky05
  • 4,692
  • 1
  • 10
  • 27
  • No, the edge attribute contains features for the edges which can be used to calculate the message in a learnable way. The edge weights just scale the messages. – PascalIv Jul 19 '22 at 14:49
  • @PascalIv doesn't that implies also that edge weights have to be one-dimensional? I tested a forward pass of a GATConv layer and it works also if you pass an edge_weight tensor which has multiple dimensional so it is still not clear and the documentation does not help in any way – AleB May 26 '23 at 22:06
2

The difference between edge_weight and edge_attr is that edge_weight is the non-binary representation of the edge connecting two nodes, without edge_weight the edge connecting two nodes either exists or it doesn't(0 or 1) but with the weight the edge connecting the nodes can have arbitrary value.

Whereas edge_attr means the features of the edge connecting any two nodes. These feature can be multidimensional.