liveBook · Manning

Neighborhood aggregation

As explained in Graph Neural Networks in Action

Neighborhood aggregation is a graph neural network technique that gathers and combines feature information from a node’s immediate neighbors.

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

How Graph Neural Networks in Action covers it

How deep it goes
Explains neighborhood features, mean-sum-max choices, and PyG layer parameters, while deferring advanced layer-wise aggregation.
Examples
Uses Amazon Products classification, GraphSAGE code, and mean, sum, and max comparisons.
What it assumes
Assumes basic graph nodes, edges, and features while defining neighborhoods and aggregation from their practical roles.
What you can do after
Apply neighborhood aggregation through PyG’s SAGEConv aggr parameter and compare aggregation choices for graph classification workflows.
How it connects
Connects node neighborhoods with graph convolution, message passing, convolutional GNNs, GCN, and GraphSAGE.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.