Heterograph instantiation may be wrong

I am instantiating my DGL heterograph for two objects (streets and buildings) that possess two different relations (intersects and within) as follows:
dgl_heterograph = dgl.heterograph(
{
("building", "within", "street"): within_tuple_list,
("street", "intersects", "building"): intersects_tuple_list,
}
)
Where within_tuple_list and intersects_tuple_list are list of tuples denoting the edges between the objects.

When I print the graph_object, I get:

Graph(num_nodes={'building': 18233, 'street': 19630}, num_edges={('building', 'within', 'street'): 1391319, ('street', 'intersects', 'building'): 29}, metagraph=[('building', 'street', 'within'), ('street', 'building', 'intersects')])

The number of buildings is 18233 and streets is 29 but this does not correspond to what is instantiated ( see num_nodes). I am doing something wrong, any help will be greatly appreciated. Thanks in advance.

What’s the version of DGL? As of DGL 0.5, DGL requires a 2-tuple of tensors/lists/arrays for within_tuple_list and intersects_tuple_list.

If this is already the case, what’s the maximum id of street in within_tuple_list and intersects_tuple_list?

Thanks for your response. I am using version DGL 0.5.3. The maximum street ID in the within_tuple_list is 19229 and 19558 in the intersects_tuple_list. However, source nodes for the street-intersects-building path is 29 street nodes. The rest come from the target nodes of the building-within-street path. Thank you for your help.

The number of nodes of a type is at least the maximum ID of the corresponding type plus 1. If the maximum street ID is 19558, the number of street nodes in the whole heterogeneous graph need to be at lest 19559.

Thanks @mufeili. That is correct, the number of street nodes is 19559 (the tiny disparity is because the data is downloaded from a live server).

When I attempt to replicate the HAN Hetero code to classify building nodes, I get this error: dgl._ffi.base.DGLError: Expect number of features to match number of nodes (len(u)). Got 18233 and 19559 instead. Please recall that the number of buildings is 18233 and streets is 19559. I have also checked that the number of features (buildings) is actually 18233. Any suggestions will be highly appreciated. Thank you!

It sounds like you by accident you assigned the features of buildings to the street nodes. If I remember correctly, the original HAN deals with graphs of a single node type and multiple edge types (metapaths). To adapt HAN to your case, you may need to modify the code.

Thanks @mufelli, the DGL repo I referenced also has an implementation HAN for graphs of multiple node types and that is the one I am using.

Ok. Then just do a double check to make sure you assign the correct features to the correct nodes.

1 Like

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