How to do one node inference?

Hello,

I’m quite new to DGL, I’ve played with the “karate club” tutorial : https://docs.dgl.ai/tutorials/basics/1_first.html

I’ve understood that this code snippet can compute all inferences at the same time.

net(G,G.ndata['h'])
and I got coherent results like this :

tensor([[ 1.7417, -2.1720],
            [ 1.0800, -1.4717],
            [ 0.0979, -0.3240],
            [ 1.7078, -2.1691],
            [ 2.1232, -2.5470],
            [ 2.1904, -2.5734],
    ....

But when I try to only run inference for one feature (the first one) :

g = G.subgraph(0)
x = G.ndata['h'][0].reshape(1,5)
net(g,x)

I got a different result …

tensor([[ 3.3179, -3.9537]], grad_fn=<AddmmBackward>)

I was expecting : [ 1.7417, -2.1720] which is the first line of the inference on all features/nodes

What is the difference ? What did I miss ?

Any help will be appreciated.

regards, H.

It’s a two-layer GCN. If you only did one layer GCN it should be the same. Please refer to stochastic training details for advanced sampling usage

As explained in the doc, with G.subgraph(0) you constructed a graph with node 0 and 0 edges. You ended up performing message passing on an empty graph for node 0. With net(G,G.ndata['h']), you performed message passing on the k-hop ego network of node 0. This is why you are getting different results.

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