pgl.message

The Message Implement for recv function

class pgl.message.Message(msg, segment_ids)[source]

Bases: object

This implement Message for graph.recv.

Parameters
  • msg – A dictionary provided by send function.

  • segment_ids – The id that the message belongs to.

edge_expand(msg)[source]

This is the inverse method for reduce.

Parameters

feature (paddle.Tensor) – A reduced message.

Returns

Returns a paddle.Tensor with the first dim the same as the num_edges.

Examples

import numpy as np
import pgl
import paddle

num_nodes = 5
edges = [ (0, 1), (1, 2), (3, 4)]
feature = np.random.randn(5, 100)
edge_feature = np.random.randn(3, 100)
graph = pgl.Graph(num_nodes=num_nodes,
        edges=edges,
        node_feat={
            "feature": feature
        },
        edge_feat={
            "edge_feature": edge_feature
        })
graph.tensor()

def send_func(src_feat, dst_feat, edge_feat):
    return { "out": src_feat["feature"] }

message = graph.send(send_func, src_feat={"feature": graph.node_feat["feature"]})

def recv_func(msg):
    value = msg["out"]
    max_value = msg.reduce_max(value)
    # We want to subscribe the max_value correspond to the destination node.
    max_value = msg.edge_expand(max_value)
    value = value - max_value
    return msg.reduce_sum(value)

out = graph.recv(recv_func, message)
reduce(msg, pool_type='sum')[source]

This method reduce message by given pool_type.

Now, this method only supports default reduce function, with (‘sum’, ‘mean’, ‘max’, ‘min’).

Parameters
  • feature (paddle.Tensor) – feature with first dim as num_edges.

  • pool_type (str) – ‘sum’, ‘mean’, ‘max’, ‘min’ built-in receive function.

Returns

Returns a paddle.Tensor with the first dim the same as the largest segment_id.

reduce_max(msg)[source]

This method reduce message by max.

Parameters

feature (paddle.Tensor) – feature with first dim as num_edges.

Returns

Returns a paddle.Tensor with the first dim the same as the largest segment_id.

reduce_mean(msg)[source]

This method reduce message by mean.

Parameters

feature (paddle.Tensor) – feature with first dim as num_edges.

Returns

Returns a paddle.Tensor with the first dim the same as the largest segment_id.

reduce_min(msg)[source]

This method reduce message by min.

Parameters

feature (paddle.Tensor) – feature with first dim as num_edges.

Returns

Returns a paddle.Tensor with the first dim the same as the largest segment_id.

reduce_softmax(msg)[source]

This method reduce message by softmax.

Parameters

feature (paddle.Tensor) – feature with first dim as num_edges.

Returns

Returns a paddle.Tensor with the first dim the same as the largest segment_id.

reduce_sum(msg)[source]

This method reduce message by sum.

Parameters

feature (paddle.Tensor) – feature with first dim as num_edges.

Returns

Returns a paddle.Tensor with the first dim the same as the largest segment_id.