pyg-team / pytorch_geometric

Graph Neural Network Library for PyTorch
https://pyg.org
MIT License
21.35k stars 3.66k forks source link

Documentation: Be clear about direction of the edges in message() #1040

Open jaromiru opened 4 years ago

jaromiru commented 4 years ago

The documentation about edge orientation is inconsistent. In the Creating Message Passing Networks tutorial, the main expression says that e𝑖,𝑗 denotes (optional) edge features from node 𝑖 to node 𝑗., the attached expression also suggests it. However, in documentation to MessagePassing.message(), the documentation says Constructs messages from node 𝑗 to node 𝑖 (this is actually true).

I mean, when an user implement message(), it is unclear what is the orientation:

def message(self, x_i, x_j):
    # it is actually x_j -> x_i
    # with flow='source_to_target'

This is misleading and unclear. I had to create a small test program to actually see what is the direction of information flow. It should be made more consistent and clear. I would also suggest to add a example with directed edges in Introduction section (currently, there is an example with undirected edges).

rusty1s commented 4 years ago

Thanks for this issue. I agree and fixed the typo. An introduction with directed edges seems like a good idea. I will try to work on that.

douglasrizzo commented 4 years ago

I have a similar question which I believe might also benefit if detailed in the documentation. If I want node 0 to aggregate messages from nodes 1, 2 and 3 and flow='source_to_target', is the correct edge_index tensor:

[[0,0,0],
 [1,2,3]]

or

[[1,2,3],
 [0,0,0]]

?


I believe this is a nice bit of information to explicitly detail somewhere in the documentation, as I've found many issues detailing similar confusion (#126 #219 #806).

By the answers I found https://github.com/rusty1s/pytorch_geometric/issues/126#issue-420188693 https://github.com/rusty1s/pytorch_geometric/issues/126#issuecomment-486717794, it looks like the correct is option 1. Thank you in advance.

rusty1s commented 4 years ago
[[1,2,3],
 [0,0,0]]

Messages are sent from source (1, 2, 3) to target (0, 0, 0).

douglasrizzo commented 4 years ago

Oh boy.