Neighborhood aggregation

Also known as: aggregation function

On this page 7

Neighborhood aggregation is the operation in a graph neural network that combines the feature vectors of a node’s neighbors into a single summary vector, which is then used to update that node’s representation. In graph learning, it is the core mechanism of the message passing framework and the reason a node’s embedding comes to reflect both its own attributes and the structure of its surroundings.

The component that performs this step is often called the aggregation function. Because graphs have no fixed ordering of neighbors and nodes have varying degrees, the aggregator must be permutation invariant and must accept inputs of any size. Its choice strongly influences what a model can distinguish, how stable its training is and how well it scales to graphs with millions of nodes.

How neighborhood aggregation works

Neighborhood aggregation works in three steps inside each graph neural network layer: message computation, aggregation and update. First, each neighbor produces a message, typically a learned linear transformation of its current features, sometimes combined with edge features. Second, the aggregator merges all incoming messages into one vector. Third, an update function combines this vector with the node’s own previous state, often through concatenation or addition followed by a nonlinearity.

Stacking layers expands the receptive field: after k layers, each node has received information from nodes up to k hops away. Most practical models use two to four layers, because deeper stacks tend to blur node representations together, a problem known as over-smoothing.

The table below lists the components of a single aggregation layer and their typical implementations.

ComponentRoleTypical implementation
Message functionTransforms neighbor featuresLinear layer or small MLP
Aggregation functionMerges messages into one vectorSum, mean, max or attention
Update functionCombines summary with own stateConcatenation plus MLP, GRU cell
NormalizationControls scale across node degreesDegree normalization, layer norm
Self-loopKeeps the node’s own informationAdding the node to its neighborhood
Components of one message passing layer

Common aggregation functions

The most widely used aggregators are sum, mean, max and attention-weighted sum, and each one preserves a different kind of information about the neighborhood. Choosing among them is a trade-off between expressive power, numerical stability and robustness to degree variation.

AggregatorWhat it preservesMain limitationRepresentative model
SumFull multiset, including neighbor countsScale grows with node degreeGraph isomorphism network
MeanDistribution of neighbor featuresCannot count neighborsGraph convolutional network
MaxMost salient feature per dimensionIgnores multiplicity and distributionGraphSAGE pooling variant
AttentionLearned importance of each neighborHigher cost, possible instabilityGraph attention network
Multiple combinedSeveral statistics at onceMore parameters and memoryPNA model
Comparison of standard aggregation functions

The graph convolutional network uses a symmetrically degree-normalized sum, which behaves like a weighted mean. GraphSAGE introduced mean, LSTM and pooling aggregators over sampled neighborhoods, while graph attention networks compute attention coefficients for each edge and often use multiple attention heads to stabilize learning.

Expressive power and the Weisfeiler-Lehman connection

The expressive power of neighborhood aggregation is bounded by the one-dimensional Weisfeiler-Lehman test, a classical graph isomorphism heuristic that iteratively refines node colors from the multiset of neighbor colors. A message passing network can distinguish two graphs only if this test can distinguish them.

Reaching that upper bound requires an injective aggregation over multisets. Sum aggregation followed by a sufficiently expressive MLP satisfies this condition, which is why the graph isomorphism network uses sum. Mean and max are not injective: mean cannot tell a node with two identical neighbors from one with a single neighbor, and max cannot tell either from a node with ten identical neighbors.

The following table shows how aggregators behave on simple neighborhood multisets with scalar features.

Neighbor featuresSumMeanMax
{1, 1}211
{1}111
{1, 1, 1, 1}411
{0, 2}212
Aggregator outputs on example neighborhoods

Only sum separates all four cases here, although sum alone still confuses {1, 1} with {0, 2}, which is why learned transformations before aggregation matter in practice.

Scaling, sampling and structural limits

On large graphs, full neighborhood aggregation becomes expensive because the number of nodes involved grows exponentially with depth. A node with an average degree of 50 can reach hundreds of thousands of nodes within three hops, a problem often called neighborhood explosion.

Several techniques control this cost. Neighbor sampling, popularized by GraphSAGE, aggregates over a fixed number of randomly sampled neighbors per layer, for example 25 and then 10. Cluster-GCN partitions the graph and aggregates within subgraphs, and personalized PageRank propagation decouples feature transformation from aggregation.

Aggregation also has structural limits. Over-smoothing makes node representations converge as depth grows, and over-squashing compresses exponentially many distant messages into fixed-size vectors through bottleneck edges. On heterophilous graphs, where connected nodes tend to differ, averaging neighbors can erase useful signals.

ProblemCauseCommon remedy
Over-smoothingRepeated averaging over many layersResidual connections, fewer layers
Over-squashingBottleneck edges in the graphGraph rewiring, virtual node
HeterophilyNeighbors carry dissimilar labelsSeparate ego and neighbor embeddings
High-degree hubsUnbounded sum magnitudeDegree normalization or sampling
Problems and common remedies

Choosing an aggregator in practice

The right aggregator depends on the task and the graph. Sum is preferred for graph classification and for tasks where counts matter, such as molecular property prediction. Mean is a robust default for node classification on graphs with highly variable degrees, such as social and citation networks.

  • Use attention when neighbors differ strongly in relevance and the graph is moderately sized.
  • Combine several aggregators with degree scalers when expressiveness matters more than cost.
  • Add edge features to messages when relations carry types or weights, as in heterogeneous graphs.
  • Validate depth empirically, because the best number of layers depends on graph diameter and homophily.

In everyday language

Picture a town where each person wants to understand their local area. Each day, they ask their direct neighbors what they know. They then blend those answers with their own view. After two days, they also know what their neighbors’ neighbors said.

Neighborhood aggregation does the same thing for points in a network. Each point collects information from its connections and summarizes it. The way it summarizes matters. Adding everything up keeps track of how many neighbors there are. Averaging shows only the typical neighbor.

Seen in the real world

A payment provider builds a fraud detection model on a graph of about 20 million accounts connected by transactions, shared devices and shared addresses. Each account starts with features such as account age, transaction volume and chargeback history.

The team trains a two-layer GraphSAGE model with mean aggregation and samples 15 neighbors in the first layer and 10 in the second, which keeps each training batch within GPU memory. A second variant uses sum aggregation for the device edges, because the number of accounts sharing one device is itself a strong fraud signal.

Compared with a gradient-boosting model that uses only per-account features, the graph model flags coordinated fraud rings earlier, because suspicious behavior spreads through aggregated neighbor information. Analysts review fewer false alarms at the same detection rate.