A local neighborhood gives a graph model a place to start when updating a node. For one-hop convolution, it consists of the starting node and the nodes connected to it by one edge. Unlike a patch of image pixels, it has no fixed shape or node order. section 3.4.1
A neighborhood-based update follows three practical steps:
- Find the central node’s immediate neighbors through the graph’s edges. section 3.4.1
- Gather their features and combine them with an aggregation such as a sum, mean, or maximum. The result must not depend on neighbor order. section 3.4.1 section 3.2.1
- Use the combined information to update the node’s representation; successive layers repeat this process. section 3.2.1 section 4.3.2
Figure 3.12 A comparison of convolution over grid data (left; e.g., a 2D image) and over a graph (right).
Compare the fixed grid patch with the differently shaped set of nodes reached by one graph edge. section 3.4.1
In PyTorch Geometric, `SAGEConv` accepts an `aggr` setting for the neighborhood operation; `GCNConv` uses a built-in weighted average. Choosing an operation changes how neighboring features contribute, not which nodes an edge connects. 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)
The GraphSAGE listing passes `agg_func` to each `SAGEConv` layer as its `aggr` parameter. section 3.2.1
A training mask selects which nodes contribute to the loss, but it does not remove their neighbors from message passing. A GCN still needs the graph structure during its forward pass to compute the local aggregations used for those predictions. section 4.3.2



