Misunderstanding about prop_nodes

Hello,

I am trying to use prop_nodes but it doesn’t seem to do what I expect. I want to create a node feature based on predecessors features, recursively, basically:

node["h"] = node["c"] + \sum_{p: predecessor(node)} p["h"] * p["k"]

So, I am writing this:

order = dgl.topological_nodes_generator(g)
g.ndata["h"] = g.ndata["c"].clone()
msg_fn = lambda edges: {"m": edges.src["h"] * edges.src["k"]}
rdc_fn = lambda nodes: {"h": nodes.data["c"] + nodes.mailbox["m"].sum(1)}
g.prop_nodes(order[1:], msg_fn, rdc_fn)

But when I look at the feature “h” at the end, it is incorrect. I would appreciate any help.
PS: I am using dgl-cu102 0.5.2

Thanks!

What you described is actually collecting and aggregating messages from one-hop neighbors. Just use update_all should satisfy your need:

import dgl.function as fn
g = ...   # some graph
g.ndata['z'] = g.ndata['h'] * g.ndata['k']
g.update_all(fn.copy_u('z', 'm'), fn.sum('m', 'z_sum'))
g.ndata['h'] = g.ndata['c'] + g.ndata['z_sum']

prop_nodes and prop_edges internally calls multiple update_all to propagate messages along a path or other orders specified by the generator.

PS: Your DGL seems to be quite out-dated. Our latest version is 0.9. Please try it out.

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