How to sample neighbors from given hop?

Given a graph g and a hop range k, how to sample n nodes from each graph node’s k-hop neighbors with edge weights as prob? I found dgl.sampling.sample_neighbors(g, g.nodes(), n, prob="weight") api, but it can only sample from 1-hop neighbours.

@Yu-Qing-Wang, you have to do it iteratively.

Check the code I posted here: Subgraph sampling + position encoding

1 Like

Aside from @felipemello’s solution, if you only wish to sample instead of finding all neighbors, you can approximately do this with random walks by dgl.sampling.random_walk. I have a tutorial for this purpose, although it’s a work-in-progress: https://github.com/BarclayII/dgl/blob/new-tutorials/new-tutorial/L3_custom_sampler.ipynb (at the bottom).

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