2.5 异构图上的消息传递

(中文版)

异质图(1.5 异质图),简称异质图,是包含不同类型节点和边的图。不同类型的节点和边通常具有不同类型的属性,这些属性旨在捕捉每种节点和边类型的特征。在图神经网络的上下文中,根据其复杂性,某些节点和边类型可能需要用具有不同维度的表示来建模。

异构图上的消息传递可以分为两部分:

  1. 为每个关系 r 进行消息计算和聚合。

  2. 减少操作,合并每个节点类型的所有关系的聚合结果。

DGL 调用异构图消息传递的接口是 multi_update_all()multi_update_all() 接受一个包含 每个关系内 update_all() 参数的字典, 使用关系作为键,以及一个表示跨类型归约器的字符串。 归约器可以是 summinmaxmeanstack 之一。 以下是一个示例:

import dgl.function as fn

for c_etype in G.canonical_etypes:
    srctype, etype, dsttype = c_etype
    Wh = self.weight[etype](feat_dict[srctype])
    # Save it in graph for message passing
    G.nodes[srctype].data['Wh_%s' % etype] = Wh
    # Specify per-relation message passing functions: (message_func, reduce_func).
    # Note that the results are saved to the same destination feature 'h', which
    # hints the type wise reducer for aggregation.
    funcs[etype] = (fn.copy_u('Wh_%s' % etype, 'm'), fn.mean('m', 'h'))
# Trigger message passing of multiple types.
G.multi_update_all(funcs, 'sum')
# return the updated node feature dictionary
return {ntype : G.nodes[ntype].data['h'] for ntype in G.ntypes}