A batch of three graphs
shape▲▲△Exact.
STATEMENT
Put three graphs of different sizes into one batch, give the shape of every array, and find what goes wrong when the edge lists are not offset.
GIVEN
The paw graph ( nodes, edges , , , ), a path on nodes (, ) and a cycle on nodes (, , , , ), each numbered from . Node features have width . The readout sums node states per graph. For the check, every feature is and one round of sum aggregation is applied.
FIND
The total node count; the shapes of the batched features, the batch vector, the edge index and the readout; the offsets; the readouts with and without offsets.
STRATEGY
Stack the graphs’ nodes one after another. A batch is then one large graph whose adjacency matrix is block diagonal, provided every edge is shifted by the number of nodes before its graph.
SOLUTION
Shapes. There are nodes, so the features are . The batch vector, of length , records each node’s graph: . The undirected edges become directed entries, so the edge index is . The readout is , one row per graph.
Offsets. Graph ‘s node becomes node with , the running total of earlier sizes. The adjacency matrix of the batch is then block diagonal, and no message crosses between graphs. Since sum aggregation over a block-diagonal matrix acts on each block separately, batching changes no graph’s result.
The check. With all features , one round of sum aggregation gives each node its degree, and the per-graph sum of degrees is twice the edge count: , and .
Without offsets. All three edge lists then refer to nodes to . The path’s edges coincide with two of the paw’s and merge into them, and the cycle’s edges connect the paw’s nodes to one another and to node , which belongs to the path. The readouts become , and . The shapes are all still correct, so nothing fails until the numbers are compared.
Answer
nodes; features ; batch vector length ; edge index ; readout ; offsets . Readouts , , with offsets and , , without.
Check — sanity
Each correct readout equals twice that graph’s number of edges, , and , as the handshake count requires.
Where this breaks
A readout by mean needs each graph’s node count, , and , taken from the batch vector; dividing by would mix the graphs again. Graph libraries keep the batch vector for exactly this reason.
Variation
A dense alternative pads every graph to the largest size, , giving features of shape and three adjacency matrices. It wastes of node slots here, and far more when sizes vary widely.