Question about User-defined Functions

Hi, Thank you very much for reading my question, this is a truly wonderful community !
I am new to graph nn sorry if I am not making sense. I was reading a paper :

Skeleton-Based Action Recognition with Directed Graph Neural Networks

in which model skeleton as : bones as edges and joints as nodes.

there is one line in the paper :

the model can extract the angle information of a joint (node), which
needs only the information of one joint and its two connected bones (edges?).

I am wondering in

def f_edge(edges): 
    return {'cc': edges.src['h']}
g.apply_edges(f_edge)

how can I get the [ last edge(s) ] that an edge's source node connected from ? I read other posts and found out about in_edges and out_edges but dont quite know how to use it in User-defined Functions. Thank you very much

import dgl
import torch
import dgl.function as fn

g= dgl.graph(([0,1,2,3],[2,2,1,2]))
g.ndata['h'] = torch.ones(g.num_nodes(), 2)
g.edata['w'] = torch.ones(g.num_edges(), 2)
def udf(nodes):
    return {'hh' : nodes.data['h'] + nodes.mailbox['ww'].sum(1)}
g.update_all(fn.copy_e('w', 'ww'), udf)
print(g.ndata['hh'])
1 Like

Thank you very much for your prompt reply ! that is very helpful !

Hi, thank you very much again for your time, but may I please ask further with providing a scenario:

g= dgl.graph(([0,1,2],[2,2,3]))
g.ndata['h'] = torch.ones(g.num_nodes(), 2)
g.edata['w'] = torch.ones(g.num_edges(), 2)

would it be possible to : before summing the nodes.mailbox['ww'].sum(1)
be able to retain it and multiple edge C by edge B and edge A separately ?

ie . edge C = ( C/B + C/A ) / 2

like to save mailbox data from previous function , without summing itself individually , to be used in another message function.

Thank you very much for your time and effort in reading and responding to my question

You could use the line graph (i.e. the edges become nodes in the new graph, and two nodes are connected iff the corresponding edges in the original graph are connected) and do message passing on the line graph. You can use dgl.line_graph for that purpose.

1 Like

thanks for your reply , very appreciated for your help !

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