Edges with 0 sampling probability are sampled by "sample_neighbors"

Hi,

Thank you very much for sharing and maintaining this amazing library.

I have a question related to the sampling probability in function sample_neighbors. My question is that why an edge with assign sampling probability being 0 can be sampled by the function.

Let’s first see the example in the official document (dgl.sampling.sample_neighbors — DGL 0.6.1 documentation),

g = dgl.graph(([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 2, 0]))

g.edata[‘prob’] = torch.FloatTensor([0., 1., 0., 1., 0., 1.])

sg = dgl.sampling.sample_neighbors(g, [0, 1], 1)

sg.edata[dgl.EID] # Returns tensor([2, 0])

Since the assigned probability of edge 2 is 0, it is not clear to me why this edge can be sampled by the function. Would you mind explaining a little bit more about how the function sample_neighbors works?

Thank you very much.

You need to pass in the name of the probability field:

sg = dgl.sampling.sample_neighbors(g, [0, 1], 1, prob='prob')
sg.edata[dgl.EID]
# tensor([5, 3])

Thank you very much for the reply. I got it.

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