Aggregate information along a given path

Hi,

Thank you for this wonderful DGL! I would like to use DGL to implement a function that aggregates information from multi-hop neighbors along a given path. However, from my knowledge, DGL only aggregates information from 1-hop neighbors. After struggling for some time, I only find this link https://github.com/dmlc/dgl/issues/939 that is related to my issue. However, the mentioned function dgl.khop_graph does not fit my goal, since it just connects k-hop neighbor to the source node. By contrast, my goal is to aggregate information along a path, i.e., from n-hop neighbors to (n-1)-hop neighbors until n=1. I would truly appreciate it if anyone could help. Thank you so much.

Best,
Yongcheng

For “path”, if you just want to aggregate from n-hop neighbors to (n-1)-hop neighbors until n=1, then you can simply call g.update_all multiple times.

1 Like

Hi @mufeili

Thank you for the quick response! I really appreciate it. I’m sorry that I did not explain my objective concretely in my previous post. Let me take GAT as an example.

For each node, I would like to aggregate information from n-hop neighbors for a larger receptive field in each GAT layer. N-hop neighbors should also be involved in the computations of edge attention and then fed into the softmax function along with 1-hop neighbors. Also, since there should be multiple paths towards n-hop neighbors, I would like to select some of them, e.g., the shortest ones, to aggregate information in a more efficient manner.

Therefore, simply calling g.update_all may not completely solve my problem. May I ask if there is a way in DGL that could directly acquire n-hop neighbors for computations like 1-hop neighbors? Thank you so much.

Best,
Yongcheng

Perhaps the easiest way will be to simply augment the graph structures during data pre-processing. E.g., to aggregate information from n-hop neighbors for n > 1, simply call dgl.khop_graph for 2, …, n and add the edges to the original graph.

1 Like

Hi @mufeili

Thank you for the quick response! I will have a try by using dgl.khop_graph. By the way, may I ask if it is possible to directly acquire n-hop neighbors? Directly accessing n-hop neighbors might be more flexible for some further operations. Thanks!

Best,
Yongcheng

Besides dgl.khop_graph, another possibility is dgl.dataloading.neighbor. MultiLayerFullNeighborSampler.

1 Like

Hi @mufeili

Thank you for the suggestion! I truly appreciate it. I will try both methods. Thank you so much! Wish you all the best!

Best,
Yongcheng

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.