Course contentsShow
← Machine Learning and Deep Learning
Lesson 2503 of 3,53854. Graph Neural NetworksFree lesson

Aggregation Functions: Mean, Max, Sum

Compare different aggregation operators and understand their impact on expressiveness and learned representations.

Aggregation Functions: Mean, Max, Sum

You'll learn: How different aggregation operators in Graph Neural Networks affect what patterns they can capture and the representations they learn.

The Core Idea

In message passing, after collecting messages from neighbors, you need to aggregate them into a single vector. The choice of aggregation function—mean, max, or sum—fundamentally affects what your GNN can express and learn.

Think of polling friends for restaurant recommendations. Mean averaging gives everyone equal weight (democratic). Max picks the strongest opinion (spotting standouts). Sum accumulates all enthusiasm (sensitive to group size). Each tells you something different!

How They Differ

Mean aggregation (torch.mean()) normalizes by neighbor count, making it invariant to graph size. Great for smooth, averaged features but can blur distinct signals.

Max aggregation (torch.max()) selects the maximum value per feature dimension. Excellent at detecting critical features or outliers, but ignores the majority of neighbor information.

Sum aggregation (torch.sum()) accumulates all neighbor features. Most expressive—it can distinguish nodes with different numbers of neighbors (unlike mean). This sensitivity to graph structure makes GCN-style architectures powerful, but it can also amplify noise in dense graphs.

Expressiveness Trade-offs

Sum is theoretically most powerful because it preserves neighbor count information. Mean sacrifices this for stability. Max is selective but can miss distributed patterns.

In practice, mean works well for node classification when neighbor counts vary wildly. Max excels at detecting anomalies or salient features. Sum performs best when graph structure itself carries meaningful information.

Key Takeaway: Aggregation choice directly impacts what graph patterns your GNN can distinguish—sum is most expressive for structure, mean provides stability, and max highlights extremes.