question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NeighborSampler for k-hop sampling

See original GitHub issue

❓ Questions & Help

I have a hard time understanding NeighborSampler even with small examples. It doesn’t make sense in most cases.

l = np.array([[0, 1], [1, 4], [1, 5], [1, 6], [0, 2], [2, 7], [0, 3], [3, 8], [3, 9], [3, 10], [3, 11]]).transpose()
r = np.array([l[1, :], l[0, :]])
edge_index = torch.from_numpy(r)

train_loader = NeighborSampler(edge_index,
                               sizes=[2, 2], batch_size=1)

for batch_size, n_id, adjs in train_loader:
    print("###")
    for edge_ind, e_id, size in adjs:
        print(e_id)

gives me:

tensor([ 4,  0, 10,  8,  3,  1])
tensor([6, 0])

It looks like it jumps over edges?

How can I use it for k-hop sampling?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, Jul 1, 2020

The NeighborSampler example looks correct to me. It samples two edges in the last layer for node 0: to nodes 1 and 3. in the first layer, it samples 6 edges for nodes 0, 1 and 3: to nodes 1, 4, 6, 2, 9, 11.

Regarding your second issue: You pass in two edges, but 3 edge features. So that‘s an expected crash and isn‘t related to symmetric adjacencies.

0reactions
rusty1scommented, Sep 23, 2020

Edge 0 and Edge 4 are sampled for node 0 in layer 1. The NeighborSampler will recursively sample neighbors/edges for all nodes encountered in all previous layers, e.g., for applying skip-connections.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NeighborSampler — DGL 0.9.1post1 documentation
Sampler that builds computational dependency of node representations via neighbor sampling for multilayer GNN. This sampler will make every node gather messages ...
Read more >
torch_geometric.loader — pytorch_geometric documentation
A data loader that performs mini-batch sampling from node information, ... The neighbor sampler from the "Inductive Representation Learning on Large Graphs" ...
Read more >
NeighborSampler for k-hop sampling · Issue #1391 - GitHub
The NeighborSampler example looks correct to me. It samples two edges in the last layer for node 0: to nodes 1 and 3....
Read more >
How to use the dgl.contrib.sampling.NeighborSampler ... - Snyk
To help you get started, we've selected a few dgl.contrib.sampling.NeighborSampler examples, based on popular ways it is used in public projects.
Read more >
Region or Global? A Principle for Negative Sampling in Graph ...
Neighbor Sampler S. It is necessary to sample neigh- bors for the central node to apply GNN for ... and the items outside...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found