A Short History of GCN and GraphSAGE
Images and sequences come with a regular notion of “nearby.” Graphs do not: every node can have a different number of neighbors, and vertex labels carry no spatial meaning. Modern graph neural networks emerged by turning spectral graph filters into localized, reusable neighborhood operations.
The Message-Passing Lens
Forget matrices for a moment. At layer $\ell$, every node owns a vector $h_v^{(\ell)}$. A message-passing layer performs three conceptual moves:
Collect
Read representations from neighbors $u\in\mathcal N(v)$, optionally including $v$ itself.
Aggregate
Compress a variable-size, unordered multiset of neighbor vectors into one fixed-size summary $m_v^{(\ell)}$.
Update
Combine the summary with the node's current state, apply trainable weights and a nonlinearity, and obtain $h_v^{(\ell+1)}$.
$$m_v^{(\ell)}=\operatorname{AGG}_{\ell}\!\left(\{h_u^{(\ell)}:u\in\mathcal N(v)\}\right),\qquad h_v^{(\ell+1)}=\operatorname{UPDATE}_{\ell}\!\left(h_v^{(\ell)},m_v^{(\ell)}\right).$$
Graph Convolutional Networks (GCN)
Kipf and Welling begin from spectral graph convolution, use a localized first-order approximation, and apply a “renormalization trick.” The resulting layer is compact:
$$H^{(l+1)} = \sigma \left( \tilde{D}^{-\frac{1}{2}} \tilde{A} \tilde{D}^{-\frac{1}{2}} H^{(l)} W^{(l)} \right)$$
- $\tilde A=A+I$: self-loops preserve each node's own state while neighbor information arrives.
- $\tilde D_{ii}=\sum_j\tilde A_{ij}$: degree after self-loops are added.
- $S=\tilde D^{-1/2}\tilde A\tilde D^{-1/2}$: fixed, symmetric propagation weights determined by graph structure.
- $H^{(\ell)}\in\mathbb R^{n\times d_\ell}$: node representations, with $H^{(0)}=X$.
- $W^{(\ell)}\in\mathbb R^{d_\ell\times d_{\ell+1}}$: learned feature transformation shared by every node.
Node-Level Interpretation
GCN forms a degree-normalized weighted sum over the closed neighborhood, then applies the shared projection and activation:
$$h_v^{(l+1)} = \sigma \left( \sum_{u \in \mathcal{N}(v) \cup \{v\}} \frac{1}{\sqrt{\tilde{d}_v \tilde{d}_u}} h_u^{(l)} W^{(l)} \right)$$
Why GCN Adds Self-Loops and Normalizes
A raw sum gives hubs a much larger magnitude simply because they have more neighbors. Symmetric normalization scales an edge contribution using degrees at both endpoints. This keeps the propagation operator balanced across irregular neighborhoods; it is not the same as an unweighted arithmetic mean.
The matrix order is associative: implementations may compute $SHW$ or $S(HW)$. On sparse graphs, multiplying by $S$ should use sparse edge operations—materializing a dense $n\times n$ matrix defeats the method's edge-linear scaling.
GraphSAGE: Inductive Learning
GraphSAGE learns a function for producing embeddings, not a lookup table containing one learned vector per training node. At inference time, the same parameters can embed an unseen node—or a new compatible graph—from its features and local neighborhood.
For layer $k$:
$$h_{\mathcal{N}(v)}^{(k)} = \text{AGGREGATE}_k \left( \left\{ h_u^{(k-1)}, \forall u \in \mathcal{N}(v) \right\} \right)$$
$$h_v^{(k)} = \sigma \left( W^{(k)} \cdot \text{CONCAT} \left( h_v^{(k-1)}, h_{\mathcal{N}(v)}^{(k)} \right) \right)$$
Mean
Element-wise average. Fast and permutation invariant, but distinct multisets can share the same mean.
Pooling
Apply an MLP to each neighbor, then element-wise max-pool. The final max operation is symmetric.
LSTM
More expressive sequential processing, but not inherently permutation invariant; the original method uses random neighbor permutations.
GCN-style mean
Mean over self and neighbors followed by a shared transform. This variant does not keep self and neighbor summaries separate.
Sampling & Receptive Fields
Without sampling, an $L$-layer mini-batch may need almost the whole graph: every seed requests neighbors, then neighbors of neighbors. GraphSAGE caps this expansion with a fanout $S_k$ at each layer.
Sampling Is a Modeling Choice
Small fanouts reduce cost but may miss rare, informative neighbors and add variance. Importance sampling, biased random walks, or domain-aware sampling can outperform uniform selection when neighbor relevance is highly uneven.
GCN vs. GraphSAGE
| Dimension | GCN layer | GraphSAGE |
|---|---|---|
| Neighbor weighting | fixed symmetric degree normalization | chosen learned aggregator; often a sampled mean or pool |
| Self information | included through self-loops | commonly concatenated or transformed separately |
| Training unit | often full graph in the original setup | seed mini-batches with sampled computation graphs |
| Unseen nodes | possible with compatible features and graph preprocessing | an explicit design goal of the architecture |
| Main tradeoff | simple, stable propagation versus full-graph cost | bounded batches versus sampling variance |
Worked Examples
A Three-Node GCN Pass
Let node 0 connect to nodes 1 and 2. After adding self-loops, adjusted degrees are $(3,2,2)$ and
$$S=\tilde D^{-1/2}\tilde A\tilde D^{-1/2}=\begin{bmatrix}1/3&1/\sqrt6&1/\sqrt6\\1/\sqrt6&1/2&0\\1/\sqrt6&0&1/2\end{bmatrix}.$$
Use $H=\begin{bmatrix}1&0\\0&1\\1&1\end{bmatrix}$ and $W=\begin{bmatrix}0.5&-0.5\\1&0.5\end{bmatrix}$. First transform features, then propagate:
| Node | Transformed feature $(HW)_v$ | Normalized pre-activation $(SHW)_v$ | After ReLU |
|---|---|---|---|
| 0 | $(0.5,-0.5)$ | $\approx(1.187,0.037)$ | $(1.187,0.037)$ |
| 1 | $(1,0.5)$ | $\approx(0.704,0.046)$ | $(0.704,0.046)$ |
| 2 | $(1.5,0)$ | $\approx(0.954,-0.204)$ | $(0.954,0)$ |
The values differ even though nodes 1 and 2 have the same degree: their own features differ, and the self-loop preserves that distinction.
A GraphSAGE Mean Input
For target 0, suppose the sampled neighbors are 1 and 2. Their mean is $((0,1)+(1,1))/2=(0.5,1)$. Mean GraphSAGE concatenates the target's own vector $(1,0)$ with that summary, producing $(1,0,0.5,1)$ before the learned linear map. The parameters—not a stored node ID embedding—decide how much self versus neighbor information to keep.
Complexity Analysis
Let $n=|V|$, $m=|E|$, input width $d$, output width $d'$, batch size $B$, depth $L$, and fanout $S_\ell$ at layer $\ell$.
| Architecture | Approximate work | Working memory | Scaling lever |
|---|---|---|---|
| Full-Batch GCN | $O(md+n dd')$ per layer | $O(m+nd)$ excluding parameters | sparse adjacency operations |
| GraphSAGE (Sampled) | proportional to sampled nodes/edges and their feature transforms | $O\!\left(Bd\sum_{k=0}^{L}\prod_{\ell=1}^{k}S_\ell\right)$ worst-case tree expansion | fanouts, depth, deduplication, batch size |
Neighborhood overlap often reduces the actual sampled-node count below the tree bound. Conversely, high feature dimensions and storing activations for backpropagation can dominate memory even after sampling controls topology.
PyTorch & NumPy Implementations
The NumPy routine exposes every GCN matrix step. The PyTorch layer consumes an explicit sampled-neighbor list so the implementation matches GraphSAGE's bounded-fanout description. Production libraries replace the teaching loops with sparse kernels and batched index operations.
Real-World Applications
GCN and GraphSAGE are architectural templates. The prediction head and loss determine whether the model classifies nodes, scores edges, or summarizes an entire graph.
Recommendation
Users, items, boards, or sessions become nodes. PinSage used importance-based neighborhood sampling to learn item embeddings on Pinterest's web-scale graph.
Molecular prediction
Atoms provide node features and bonds provide topology. A pooling head converts node representations into a molecule-level prediction; edge-aware variants are often needed for bond types.
Fraud and abuse
Accounts, devices, payments, and shared identifiers form heterogeneous interaction graphs. Neighborhood features can expose coordinated patterns missed by isolated records.
Citation and content graphs
Document features combine with link structure for node classification. This is the semi-supervised setting used in the original GCN experiments.
Exercises
1. Recompute the normalization
Add an edge $(1,2)$ to the worked graph. Recalculate $\tilde D$ and $S$, then explain why every existing normalized edge weight changes.
2. Separate self from neighbors
Remove $I$ from the GCN equation and find a graph where a node loses its distinctive feature after one layer. Compare this with GraphSAGE concatenation.
3. Audit permutation invariance
Permute one node's neighbor list. Show that mean and max-pool aggregation are unchanged. Construct an LSTM example whose output changes with order.
4. Measure sampling variance
For a high-degree node, repeatedly estimate the full neighbor mean with fanouts 2, 5, and 20. Plot estimation error against fanout.
5. Build two layers
Implement recursive two-hop sampling for a seed batch. Count requested nodes before and after deduplicating overlapping neighborhoods.
Limitations & Over-Smoothing
The Over-Smoothing Problem
Repeated neighborhood mixing can make node representations increasingly difficult to distinguish. The harmful depth is graph-, task-, and architecture-dependent—there is no universal four-layer threshold. Residual or initial-feature connections, jumping knowledge, normalization, and controlled propagation can help.
Over-squashing
Information from an exponentially growing neighborhood is compressed into a fixed-width vector, so distant signals can become bottlenecked.
Homophily assumptions
Simple averaging works best when connected nodes should be similar. Heterophilous graphs may need signed, directional, relational, or higher-order designs.
Sampling variance
GraphSAGE reduces memory by observing only part of a neighborhood. Predictions can vary with the sample, especially at small fanouts.
Structural expressivity
Basic message passing can map different local structures to the same representation when their aggregated feature multisets are indistinguishable.
Also watch for train–test feature drift, disconnected or featureless nodes, information leakage through graph construction, and evaluation splits that place near-duplicate neighborhoods on both sides of the test boundary.