Node classification in multiple graphs

Hello dears,
I have multiple graphs and want to classify their nodes. Until now, all the examples regarding node classification consist one graph not multiple graphs. Can anybody give me a suggestion?
Thanks

2 Likes

Hi @mkh

Let’s say you have multiple DGL graph objects g_{1}, g_{2}, g_{3} with # nodes n_{1}, n_{2}, and n_{3}. Using DGL, you can create a batch graph (think block-diagonal matrix), using the dgl.batch function:

graph = dgl.batch([g1, g2, g3])

Similarly, you would need to stack the node feature matrices (assuming the feature matrices are of the same size) as

feat = th.stack([feat_1, feat_2, feat_3], axis=2)
feat = feat.view(feat.shape[0]*feat.shape[-1], in_feats)

otherwise, you could use Numpy

feats = th.tensor(np.row_stack([feat_1, feat_2, feat_3])).float()

This creates a large graph, with no edges shared between sub-graphs – as such, no information is convolved across graphs, and a large feature matrix. You can plug graph and feat directly into your model for both training and testing-purposes.

5 Likes

Very cool answer.
Forgiving me I am a beginner, trying many times still fails to implement this function.

Can you share some code of this function?

Thanks in advance.

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