Heterogeneous edges

Hi all,

I’m trying to create a graph with heterogeneous edges (different features and labels for different edge types). The idea is to have different types of messages in training and depending on the type of the message (controlled by the edge type), assign a sign during concatenation.

Any ideas how I can achieve this?

See if the example below makes sense to you.

import dgl
import dgl.function as fn
import torch

g = dgl.heterograph({('A', '+', 'A'): ([0, 1], [1, 2]), 
                     ('A', '-', 'A'): ([1, 3], [2, 3])})
g.ndata['h'] = torch.randn((g.num_nodes(), 2))
for cetype in g.canonical_etypes:
    srctype, etype, dsttype = cetype
    g.update_all(fn.copy_u('h', 'm'), fn.sum('m', 'h_{}'.format(cetype)), etype=cetype)
out = g.ndata["h_('A', '+', 'A')"] - g.ndata["h_('A', '-', 'A')"]

Thanks a lot! That’s what I was looking for!

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