liveBook · Manning

Max aggregator

As explained in Graph Neural Networks in Action

Max aggregation combines neighbor features by selecting the maximum value in each feature dimension.

Max aggregation combines neighbor features by selecting the largest value independently in each feature dimension. It is useful when the strongest neighborhood signal matters more than an average, such as a prominent feature that could be diluted by other neighbors. section 3.2.1

Configure max aggregation in a GraphSAGE message-passing pipeline as follows:

  • Pass aggr='max' to each SAGEConv layer. section 3.2.1
  • For every feature dimension, compare the corresponding values from neighboring nodes and retain the maximum. section 3.2.1
  • Compare max with mean, sum, or other aggregators because the best choice depends on graph characteristics and prediction goals. section 3.2.1
  • Treat benchmark results cautiously when training uses a small or arbitrarily selected node subset or imbalanced classes. section 3.3.3
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)

Shows a GraphSAGE class that exposes aggregation as a constructor parameter and passes it to both convolution layers. section 3.2.1

GraphSAGE classification comparison

A two-layer GraphSAGE model using max aggregation with 50% dropout achieved an F1 score of 0.8674 and log loss of 0.594, compared with 0.7406 and 2.1214 for the mean baseline. A mixed ['max', 'sum', 'mean'] configuration achieved the highest reported F1 score, 0.8876. section 3.3.3

How Graph Neural Networks in Action covers it

How deep it goes
Defines per-dimension selection and demonstrates layer configuration, but does not descend into aggregation internals.
Examples
Uses configurable GraphSAGE code, aggregation-performance tables, and a confusion matrix from a max-aggregation classifier.
What you can do after
Apply it via SAGEConv by setting aggr='max', then compare classification metrics against alternative aggregators.
How it connects
Connects GraphSAGE and SAGEConv with neighborhood aggregation, mean aggregation, and sum aggregation.

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.