jocpae / VesselGraph

MIT License
110 stars 9 forks source link

synthetic vessel graph numger of edges changing with different networkx configs #12

Closed FeynmanDNA closed 2 years ago

FeynmanDNA commented 2 years ago

Hi, I used the synthetic vessel graph and depending on before and after I convert it to networkx graph and whether it is set to_undirected=True, the number of edges change:

This is the vessel graph as PyG dataset:

link_dataset = LinkVesselGraph(root='./data/', 
                          name="synthetic_graph_3")

Then when I print the PyG dataset number of edges:

data = link_dataset[0]
print(f'Dataset: {link_dataset}:')
print('======================')
print(f'Number of graphs: {len(link_dataset)}')
print(f'Number of features: {link_dataset.num_features}')
print(f'Number of nodes: {data.num_nodes}')
print(f'Number of edges: {data.num_edges}')

"""
Dataset: LinkVesselGraph():
======================
Number of graphs: 1
Number of features: 5
Number of nodes: 3128
Number of edges: 6388
"""

The number of edges is 6388 vs when I convert it to networkx: image

#nodes, #edges =  3128 5112
#nodes, #edges =  3128 2556

Why is the number of edges keep changing?

jocpae commented 2 years ago

Hi Kay, So the number of edges is exactly double when you have a directed vs an undirected graph. This is expected. To understand the functionality of the inbuild PyG function please see: https://pytorch-geometric.readthedocs.io/en/latest/modules/utils.html?highlight=networkx#torch_geometric.utils.to_networkx

jqmcginnis commented 2 years ago

Hi @FeynmanDNA,

thank you very much for this question. The conventions are indeed a bit tricky and require some further explanation.

The pyg convention for link prediction tasks is to keep all training edges in data.edge_index. However, this also implies that if we convert the link dataset graph to networkx (using the pyg function), only the training edges will be present in the resulting networkx graph. I tried to clarify this by extending the test_link_graph.py script, and printing the dimensions, please see 4e14ed6.

Does this clarify it? Looking forward to your feedback!

Cheers, Julian

FeynmanDNA commented 2 years ago

Hi i think you comments in the code are very helpful! :)