Open ChenChengKuan opened 5 years ago
There are many ways to batch operations for multiple graphs. If all graphs are of the same size and not very large (and you don't care about sparsity), then stacking the adjacency matrices along a third axis might result in a simpler implementation (using batched matrix multiplications or tensor products). If you'd like to use sparse matrix multiplications, then you are confined to 2D matrices (as currently there are no sparse tensor ops for higher order tensors in PyTorch, or any other framework), and the blog-diagonal construction scheme is the most straightforward in this case. Lastly, you can represent graphs as edge lists and construct your own scatter/gather operations (using PyTorch's scatter
function). This gives you the highest flexibility in constructing GCNs/GNNs, but is a bit more tricky to implement.
Thanks for your suggestion for helping me understand these implementation details!
Hi
Thanks for providing this clean example of GCN in pytorch. I am new to graph machine learnig so I would like to ask is this work fit the following scenario (See the figure and text below)?
Given many small graphs (G1,G2,...Gn), each has node vector X (#node #features) and adjacent matrix A (#node #node), I just want to use GCN as an encoder to get the representation of each graph for the downstream task (The label is kind of sequential tags)
(There is only one GCN layers, All blue blocks are the same.)
In addition, after checking the batch operation issue (#1 ). In my scenario, I wonder whether it is possible to just stack multiple node vector X and its adjacent matrix A like below then apply the same batch operation as usual instead of creating a big block-diagonal matrix?