dgl.DGLGraph.prop_edges

DGLGraph.prop_edges(edges_generator, message_func, reduce_func, apply_node_func=None, etype=None)[source]

通过顺序触发边上的send_and_recv(),使用图遍历传播消息。

遍历顺序由edges_generator指定。它生成边缘前沿。边缘前沿应为有效边缘类型。更多详情请参见send()

同一前沿中的边将一起触发,而不同前沿中的边将根据生成顺序触发。

Parameters:
  • edges_generator (generator) – 边缘前沿的生成器。

  • message_func (dgl.function.BuiltinFunction or callable) – The message function to generate messages along the edges. It must be either a DGL Built-in Function or a User-defined Functions.

  • reduce_func (dgl.function.BuiltinFunction or callable) – The reduce function to aggregate the messages. It must be either a DGL Built-in Function or a User-defined Functions.

  • apply_node_func (callable, optional) – An optional apply function to further update the node features after the message reduction. It must be a User-defined Functions.

  • etype (str or (str, str, str), optional) –

    The type name of the edges. The allowed type name formats are:

    • (str, str, str) for source node type, edge type and destination node type.

    • or one str edge type name if the name can uniquely identify a triplet format in the graph.

    Can be omitted if the graph has only one type of edges.

示例

>>> import torch
>>> import dgl
>>> import dgl.function as fn

实例化一个异构图并执行多轮消息传递。

>>> g = dgl.heterograph({('user', 'follows', 'user'): ([0, 1, 2, 3], [2, 3, 4, 4])})
>>> g.nodes['user'].data['h'] = torch.tensor([[1.], [2.], [3.], [4.], [5.]])
>>> g['follows'].prop_edges([[0, 1], [2, 3]], fn.copy_u('h', 'm'),
...                         fn.sum('m', 'h'), etype='follows')
>>> g.nodes['user'].data['h']
tensor([[1.],
        [2.],
        [1.],
        [2.],
        [3.]])

另请参阅

prop_nodes