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
