DGL Nodes merging

I have two graph denoted as

G = dgl.graph((torch.tensor([0, 0, 1, 2, 2]), torch.tensor([1, 2, 2, 3, 4]))).

I would like to merge the srcNode 2 with the dstNode 3 and 4, and replacing the neighborhood dependancies, which will give:

Gmerged = dgl.graph((torch.tensor([0, 0, 0, 1, 1]), torch.tensor([1, 3, 4, 3, 4]))).

Someone knows an efficient way of doing this ? Which will not be time computing as i have to execute this in training. Let’s see this as a Zoom-IN implementation.

I found dgl.merge but it doesn’t seem to do what i want.

Thanks for your help :pray:

I do not understand the problem here. It sounds like you relabeled the nodes in a graph rather than merged two graphs. How did you relabel the nodes?

Thanks for your answer. The second graph (Gmerged) corresponds to the first graph, where i remove the node 2 and update the in/out edges from 2 and its neighbors with the node 3 and 4. All the neighbors of 2 are now connected to 3 and 4, and 3 / 4 are connected to the same neighborhood of 2.
I am looking to do this with DGl in an efficient way to use it in a GCN training loop (so have to be fast with 1 000 000 edges’ graph).

Hope i am clear ?

If your graph is relatively large, perhaps you can first extract subgraphs and then perturb subgraphs. You might also want to try directly perturbing the adjacency matrix of the subgraphs and see if it will be faster and easier.

It could be a solution, but do we have a function in DGL like dgl_merge which could merge two nodes in a graph, defined as dgl.merge_nodes(G, torch.tensor([2]), torch.tensor([3, 4])) ?


No, we don’t have that.

Ok thanks Mufeili, i will try to do something with your previous message :slight_smile:

1 Like

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