Heterograph get the number of neighbors with specific type

Hi I have a question regarding the dgl.heterograph

For example, I have a heterograph which is similar to the one in dgl tutorial:

  1. dic = {}
  2. dic[(‘user’, ‘follows’, ‘user’)] = [(0, 1), (1, 2)]
  3. dic[(‘user’, ‘plays’, ‘game’)] = [(0, 0), (1, 0), (1, 1), (2, 1)]
  4. dic[(‘developer’, ‘develops’, ‘game’)] = [(0, 0), (1, 1)]
  5. dic[(‘developer’, ‘follows’, ‘user’)] = [(0, 0)]
  6. dic[(‘user’, ‘develops’, ‘developer’)] = [(2, 1)]
  7. g = dgl.heterograph(dic)

The main differences are line 5 & 6. ‘follows’ edges are not necessarily used to connect ‘user’ & ‘user’ nodes. It can be used to connect ‘developer’ & ‘user’ nodes as well. It’s similar for ‘develops’ edges. My question is given this kind of heterograph, is it possible to (1) get the number of source nodes with ‘user’ of the ‘game’ node with node id 0 and (2) get the in_degree (with ‘plays’ edge type) of the ‘game’ node with node id 0? It seems that I cannot use existing function such as in_degrees or in_edges cannot solve my question. Thanks for your help!

You need to filter out matched canonical edge types from g.canonical_etypes first and then iterate over them with g.in_degrees.

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