How to deal with different types of nodes with different feature dimensions

The graph I want to deal with has different types of nodes with different feature dimensions. Each kind of nodes has a specific update function. I wonder how can I do message passing in this case?

I try this way:

For example, there are two kinds of nodes in the graph. One kind of nodes has feature1, the other kind of nodes has feature2. Define all nodes with both two features and set the feature which doesn’t belong to this node to zero.

This is kinda stupid and I don’t know if it really works.

def msg_func(self, edges):
    weight_feature1_type = self.weight_feature1[edges.data['type']]
    weight_feature2_type = self.weight_feature2[edges.data['type']]

    msg_feature1 = torch.matmul(edges.src['feature2'], weight_feature1_type)
    msg_feature2 = torch.matmul(edges.src['feature1'], weight_feature2_type)

    return {'msg_feature1': msg_feature1, 'msg_feature2': msg_feature2}



def red_func(self, nodes):
    return {'feature1': torch.sum(nodes.mailbox['msg_feature1'], dim=1),
            'feature2': torch.sum(nodes.mailbox['msg_feature2'], dim=1)}
1 Like

You can use send_and_recv or pull/push to do partial update on graph, for example, each time for one type of node.
And you can write the logic as you did, independently for each send_and_recv call or other message passing function.

Thank you for raising this problem. It seems you are dealing with heterogeneous graphs with different node types. We are actively discussing APIs for heterogeneous graphs. Hopefully, we’ll have a version of the heterogeneous graph API very soon. I’ll keep you updated.

Thank you so much!! I will have a try.

Thank you for answering me. Looking forward to the new version!

I use the first dimensions to encode the node type (using a one-hot representation) and then append the different features (providing the corresponding value if applicable, or zeros if the particular type doesn’t have such feature).

I understand that the approach doesn’t scale with the number of different types, but for a moderately low number I’m having good results.