liveBook · Manning

SAGEConv

As explained in Graph Neural Networks in Action

A PyTorch Geometric neural-network layer that computes GraphSAGE neighborhood aggregation using a configurable aggregation function.

SAGEConv is a PyTorch Geometric layer for GraphSAGE neighborhood aggregation. It updates each node by combining information from nearby nodes, making localized sampling practical for large graphs. section 3.1.2 section 3.2.1

A typical SAGEConv-based GraphSAGE layer follows this pipeline:

  • Aggregate neighbor embeddings with a selected function such as mean, sum, max, or LSTM. section 3.2.1
  • Combine the aggregated neighbor representation with the central node’s representation. section 3.4.7
  • Transform the combined representation with learned weights, then optionally normalize it. section 3.4.7
  • Stack layers with nonlinearities such as ReLU to produce embeddings or classification outputs. section 3.1.2

Configuring aggregation

A GraphSAGE model can pass an aggregation choice into both layers: SAGEConv(in_channels, hidden_channels, aggr='mean') and SAGEConv(hidden_channels, out_channels, aggr='mean'). Replacing mean with sum or max changes how neighbor signals are combined; reported results differ across these settings. section 3.2.1

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 complete configurable GraphSAGE class, including the aggregation argument and its use in both SAGEConv layers. section 3.2.1

Table 3.10 Mapping key computational operations in the GCN embedding formula
Operation
Function/Method
Aggregate the embeddings of the neighbors (sum, mean, or other).
SAGEConv.message_and_aggregate
Concatenate neighbor embeddings with that of the central node.
SAGEConv.forward
Matrix multiply that concatenation with the Weights matrix.
SAGEConv.message_and_aggregate
Apply an activation function.
If the project parameter is set to True, done in SAGEConv.forward
Apply a normalization.
SAGEConv.forward

Trace the layer’s computational mapping from neighbor aggregation through combination, transformation, activation, and normalization. section 3.4.7

How Graph Neural Networks in Action covers it

How deep it goes
Explains configurable aggregation, stacked-layer usage, and internal propagation, transformation, residual, and normalization operations.
Examples
Uses two-layer PyTorch models, configurable mean/sum/max aggregation, an implementation listing, and comparative F1 and log-loss results.
What it assumes
Assumes node features and edge_index inputs, while demonstrating the layer and GraphSAGE model structure directly in PyTorch Geometric.
What you can do after
Build it from scratch by defining stacked SAGEConv layers, selecting aggr, applying nonlinearities, and returning embeddings or predictions.
How it connects
Connects neighborhood aggregation, GraphSAGE, GCN, message passing, node embeddings, activation functions, and normalization.

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.