Neighborhood aggregation gathers and combines feature information from a node’s immediate neighbors. It enriches each node representation with local context, which helps convolutional graph neural networks learn patterns for tasks such as product category prediction. section 3.2.1 section 3.0
A typical aggregation pipeline works as follows:
- Identify the node’s directly connected neighborhood through the graph’s edges. section 3.2.1
- Gather neighbor feature vectors and combine them with an aggregation function. section 3.2 section 3.2.1
- Use the resulting contextual representation in convolutional GNN layers, with repeated layers supporting progressively broader local context. section 3.0
Common choices are mean, sum, and max. Mean averages neighbor features and can smooth anomalies; sum preserves an additive combination; max selects the largest feature value. GraphSAGE exposes this choice through SAGEConv’s aggr parameter, while GCN uses a built-in weighted average that requires a customized layer to modify. section 3.2 section 3.2.1
Choosing an aggregation in GraphSAGE
A GraphSAGE model can pass agg_func='mean', 'sum', or 'max' into two SAGEConv layers. On the Amazon Products classification task, the reported F1 scores were 0.7406 for mean, 0.7384 for sum, and 0.7449 for max.
Listing 3.5 GraphSAGE class with aggregation parameter
class GraphSAGE(torch.nn.Module):
def __init__(self, in_channels, \
hidden_channels, out_channels, agg_func='mean'): #1
super(GraphSAGE, self).__init__()
self.conv1 = SAGEConv(in_channels, \
hidden_channels, aggr=agg_func) #2
self.conv2 = SAGEConv(hidden_channels, \
out_channels, aggr=agg_func) #3
def forward(self, x, edge_index):
x = self.conv1(x, edge_index)
x = F.relu(x)
x = self.conv2(x, edge_index)
return F.log_softmax(x, dim=1)
Inspect the PyTorch Geometric GraphSAGE implementation to see where the aggregation function enters each SAGEConv layer. section 3.2.1
