Before you start: review of the earlier sessions
The thread so far. Session 6 found the ceiling; session 7 is the first way around it, by feeding the network information that message passing cannot compute on its own. Session 8 is the second way.
What this session takes from earlier ones
Those sessions in one minute each
Lecture 6 · Theory of GNNs — How Expressive Are They?
A message-passing GNN is at most as powerful as the 1-WL test; it reaches that bound exactly when every aggregation is injective on multisets — which sum aggregation with MLPs (GIN) achieves and mean/max do not.
GIN layer. For graph classification, GIN reads out with a sum over nodes at every layer and concatenates them (the paper's readout).
Lecture 1 · Introduction — Machine Learning with Graphs
A graph model must work for any number of nodes and give the same answer no matter how the nodes are numbered — everything else is a design choice about what the nodes and edges mean.
A homogeneous graph is the special case \(|R| = |T| = 1\). Permutation: relabelling nodes with a permutation matrix \(P\) turns \(A\) into \(PAP^\top\); a graph-level model \(f\) must satisfy \(f(PAP^\top, PX) = f(A, X)\).
Warm-up: answer these before you read on
Why does the MLP in GIN matter? from Lecture 6
The universal-approximation theorem lets a one-hidden-layer MLP represent any injective multiset function; sum alone needs a well-chosen encoding of the inputs.
Why does a convolution on an image not transfer directly to a graph? from Lecture 1
A pixel has a fixed set of neighbours in a fixed order (a 3×3 window); a graph node has a variable number of neighbours and no canonical order, so a fixed filter cannot be slid over it.
Give a pair of graphs 1-WL cannot tell apart. from Lecture 6
Two disjoint triangles and a six-cycle: all nodes have degree two with degree-two neighbours at every iteration.
What is the difference between a directed and an undirected graph in the adjacency matrix? from Lecture 1
An undirected graph has a symmetric adjacency matrix; a directed graph does not.
More questions from every session you have reached, with spaced repetition: the cumulative review.
In short
A "perfect" GNN would satisfy two rules. Observation 1: same neighbourhood structure ⇒ same embedding. Observation 2: different structure ⇒ different embedding. Real MPNNs break Observation 2 (they can't tell a node on a triangle from one on a square — the WL ceiling). And some tasks want to break Observation 1 on purpose: two nodes with identical local structure but different positions (opposite corners of a grid) should get different embeddings.
The lecture's new lens is spectral. Write a GIN layer as a polynomial in \(A=V\Lambda V^\top\). With constant initial colours, the network only "sees" the eigenvectors that are not orthogonal to the all-ones vector; symmetric graphs hide the rest. The WL limitation is really a limitation of the initial node colours.
So the fixes are all feature augmentation: Laplacian eigenvectors (positional encodings), cycle counts and identity (ID-GNN), diagonals of \(A^k\) (closed-walk counts) for structure-aware tasks; distances to random anchor sets (P-GNN, inspired by Bourgain's theorem) for position-aware tasks.
The picture: two failures, two fixes
How to read it (hover a step)
- Observation 2 fails: \(v_1\) (on a triangle) and \(v_2\) (on a square) have different structures but every node has degree 2, so their computation trees are identical.
- Structure-aware fix: give each node \([\,(A^0)_{vv},(A^1)_{vv},\dots,(A^5)_{vv}]\) — the number of closed walks of each length. A triangle has closed walks of length 3; a square doesn't.
- Position-aware task: \(v_1\) and \(v_2\) are symmetric (mirror images), so even a perfect structural GNN must embed them equally — but a task may label them differently (e.g. "left side" vs "right side").
- Position fix: distance to a randomly chosen anchor breaks the symmetry. Many anchors (or anchor sets) act like coordinates.
1 · What would a perfect GNN do?
A \(K\)-layer GNN embeds a node from its \(K\)-hop neighbourhood. A perfect GNN is an injective map from neighbourhood structure (any number of hops) to embeddings. Failures appear at three levels — all for the same reason, "different inputs, same computation graph":
- Node level: triangle vs square node.
- Edge level: two edges A and B that share an endpoint \(v_0\); \(v_1,v_2\) are symmetric, so edge embeddings built from \((\mathbf{h}_{v_0},\mathbf{h}_{v_1})\) and \((\mathbf{h}_{v_0},\mathbf{h}_{v_2})\) collide even if only one closes a triangle.
- Graph level: two 3-regular graphs on 8 nodes (e.g. the cube vs a Möbius-ladder-like graph) — every node's tree is the same infinite 3-ary tree.
2 · A spectral perspective on message passing
Take a single-layer-MLP GIN: \(\mathbf{c}_v^{(l+1)}=\sigma\big(\mathbf{W}_0^{(l)}\mathbf{c}_v^{(l)}+\mathbf{W}_1^{(l)}\sum_{u\in N(v)}\mathbf{c}_u^{(l)}\big)\) — GraphSAGE with sum aggregation. Stack colours as rows of \(C^{(l)}\in\mathbb{R}^{N\times d}\). Neighbourhood sum is a sparse matrix product \(AC^{(l)}\), so
\[ C^{(l+1)}=\sigma\big(C^{(l)}W_0^{(l)}+AC^{(l)}W_1^{(l)}\big)=\sigma\Big(\sum_{k=0}^{1}A^kC^{(l)}W_k^{(l)}\Big). \]Now substitute the eigendecomposition \(A=V\Lambda V^\top\) (orthonormal eigenvectors \(V\), eigenvalues \(\Lambda\)):
The spectral decomposition is a complete description of the graph — e.g. \(\#\text{triangles at }v=\tfrac12\,(A^3)_{vv}=\tfrac12\sum_n\lambda_n^3\,v_n(v)^2\). But with constant initial colours \(C^{(0)}=\mathbf{1}\), the network only gets \(V^\top\mathbf{1}=[\langle v_1,\mathbf{1}\rangle,\dots,\langle v_n,\mathbf{1}\rangle]\). Any eigenvector orthogonal to \(\mathbf{1}\) is invisible. Graphs with symmetries have many such eigenvectors.
Why are eigenvectors of a symmetric graph often orthogonal to \(\mathbf{1}\)? Try a 4-cycle.
For \(C_4\), eigenvalues are \(2, 0, 0, -2\). The eigenvector for 2 is \(\mathbf{1}/2\). The others are orthogonal to it (orthonormal basis!) — e.g. \((1,-1,1,-1)/2\) for \(-2\). For a regular graph, \(\mathbf{1}\) is itself an eigenvector, so every other eigenvector is orthogonal to it: constant inputs reveal only the top eigenvalue (the degree). That's exactly why WL can't separate regular graphs with the same degree.
3 · Fix A: eigenvector positional encodings
If the problem is that inputs can't reach the eigenvectors, hand them over directly. Use the Laplacian \(L=D-A\) (variants normalise by degree). Its eigenvectors with small eigenvalues vary slowly over the graph (global structure, like low frequencies); large eigenvalues capture local oscillations/symmetries.
- Compute \(k\) eigenvectors \(v_1,\dots,v_k\).
- Stack into an \(n\times k\) matrix.
- Row \(i\) becomes extra features for node \(i\) (a "positional encoding", PE).
If \(v\) is an eigenvector, so is \(-v\) (sign ambiguity); with repeated eigenvalues any rotation within the eigenspace works (basis ambiguity). A network fed raw eigenvectors can give different outputs for the same graph. Lecture 8's readings (SignNet/BasisNet, PEARL) solve this.
4 · Fix B: structurally-aware features
Naïve fix: one-hot node IDs make every computation graph different — but need \(O(N)\) dimensions and aren't inductive. Better: features that are structural, so they generalise to unseen nodes/graphs.
- ID-GNN / cycle counts (You et al. AAAI 2021): count cycles starting at the node, per length, e.g. \(v_1\): [0,0,0,1,0,0] for "on a 3-cycle". ID-GNN-Fast uses per-level cycle counts; full ID-GNN colours the root node and uses different weights for it in message passing ("identity-aware" heterogeneous message passing).
- Closed loops (Kanatsoulis & Ribeiro, ICASSP 2024): \(C^{(0)}=[\mathrm{diag}(A^0),\mathrm{diag}(A^1),\dots,\mathrm{diag}(A^{D-1})]\). Counts closed walks of each length.
- Classics from Lecture 1: clustering coefficient, PageRank, centralities.
Theorem (Kanatsoulis & Ribeiro 2024): if two graphs' adjacency matrices have different eigenvalues, there exists a GNN with closed-loop initial node features that can always tell them apart.
Consequences: such GNNs separate almost all real-world graphs, and GIN with structural initial features is strictly more powerful than WL. Unlike one-hot IDs they remain inductive (you can count loops on any new graph); cost depends on what you count.
5 · Fix C: position-aware GNNs (anchors)
For position-aware tasks, structure alone can't help — symmetric nodes have identical structure by definition. Instead, give each node coordinates:
- Pick a random anchor node \(s_1\); describe \(v\) by \(d(v,s_1)\). Mirror nodes now differ.
- More anchors \(s_1,s_2,\dots\) = more coordinate axes, covering different regions.
- Anchor sets: distance to a set = min distance to its members. Large sets give coarse but cheap location; small sets give precision. Mixing sizes saves anchors.
Theory — Bourgain's theorem (1985): embed the graph metric \((V,d)\) into \(\mathbb{R}^k\) by
\[ f(v)=\big(d_{\min}(v,S_{1,1}),\dots,d_{\min}(v,S_{\log n,\,c\log n})\big)\in\mathbb{R}^{c\log^2 n}, \]where each \(S_{i,j}\) includes every node independently with probability \(1/2^i\). Then embedding distances approximate graph distances within an \(O(\log n)\) distortion. P-GNN samples \(O(\log^2 n)\) anchor sets accordingly, re-samples them every epoch (so it stays inductive), and at test time samples fresh sets for new graphs.
How to use the encoding: the simple way is to append it as node features (works well). But each dimension is tied to a random anchor set, so permuting the dimensions shouldn't change the meaning — a rigorous model needs a network that is permutation-equivariant over feature dimensions (P-GNN's design).
The mathematics, step by step
Lecture 6 ended with graphs a GNN cannot separate. This session repairs that from the side of linear algebra. The key move is to read a GNN layer as a polynomial in the adjacency matrix and then to decompose that matrix into eigenvalues and eigenvectors. Each card states one fact and checks it on a graph small enough to do by hand.
Symbols used in this session
| symbol | meaning | what kind of object |
|---|---|---|
| \(A\) | adjacency matrix (symmetric) | \(N\times N\) matrix |
| \(C^{(l)}\) | node features after layer \(l\) (the lecture's name for \(H^{(l)}\)); row \(v\) belongs to node \(v\) | \(N\times D\) matrix |
| \(W_0^{(l)},\ W_1^{(l)}\) | weights for the node's own features and for its neighbours' sum | matrices (parameters) |
| \(\lambda_i,\ \mathbf v_i\) | \(i\)-th eigenvalue and eigenvector of \(A\): \(A\mathbf v_i=\lambda_i\mathbf v_i\) | real number; unit vector in \(\mathbb R^N\) |
| \(V,\ \Lambda\) | matrix with the eigenvectors as columns; diagonal matrix of eigenvalues, so \(A=V\Lambda V^\top\) | \(N\times N\) matrices, \(V^\top V=I\) |
| \(\mathrm{diag}(M)\) | the vector of diagonal entries \(M_{vv}\) | vector in \(\mathbb R^N\) |
| \(L=D-A\) | graph Laplacian | \(N\times N\) symmetric matrix |
| \(S_{i,j}\) | random anchor sets of nodes; \(d_{\min}(v,S)\) is the distance from \(v\) to the nearest node of \(S\) | sets of nodes; whole number |
1A GNN layer is a polynomial in the adjacency matrix
In words. One layer adds two things: every node's own features, transformed, and the sum of its neighbours' features, transformed. Writing \(A^0=I\) shows both as powers of \(A\).
Why it has this form. Row \(v\) of \(AC\) is the sum of the rows of \(C\) over the neighbours of \(v\) (Lecture 3). The term with \(A^0\) is the self term. Stacking \(L\) layers composes these, and if the non-linearity is ignored the result contains \(A^0,A^1,\dots,A^L\) applied to the input features: a GNN processes its input through powers of \(A\). What it can compute is therefore governed by what powers of \(A\) can express.
Watch out. The sum uses the unnormalised \(A\) (sum aggregation), as GIN does; with \(D^{-1}A\) the same analysis runs with the eigenvectors of the normalised matrix.
2The spectral decomposition
In words. A symmetric matrix can be written with its eigenvectors and eigenvalues. Raising it to a power only raises the eigenvalues to that power. A layer therefore projects the features onto the eigenvectors, rescales each projection by \(\lambda_i^k\), and maps back.
Why it has this form. \(A^2=V\Lambda V^\top V\Lambda V^\top=V\Lambda^2V^\top\) because \(V^\top V=I\); repeat for any \(k\). \(V^\top C\) lists, for each eigenvector, how much of it the features contain (the projections). If the input features are the same on every node, \(C=\mathbf 1\), the projection onto any eigenvector perpendicular to \(\mathbf 1\) is zero, and no amount of rescaling brings it back: the GNN is blind to those eigenvectors. This is the spectral reason for the failures of Lecture 6.
Watch out. Eigenvectors are not unique: \(-\mathbf v_i\) is as good as \(\mathbf v_i\), and for a repeated eigenvalue any rotation inside its eigenspace is. Lecture 8 deals with the consequences.
3Closed-walk counts as input features
In words. Give node \(v\) as features the number of closed walks of length \(0,1,\dots,D-1\) that start and end at \(v\). These numbers are sums over all eigenvalues, weighted by the squared entry of each eigenvector at \(v\).
Why it has this form. \((A^k)_{vv}\) counts closed walks of length \(k\) (Lecture 1). From \(A^k=\sum_i\lambda_i^k\mathbf v_i\mathbf v_i^\top\), its \((v,v)\) entry is \(\sum_i\lambda_i^k(\mathbf v_i)_v^2\). These features differ between nodes whenever the spectrum does, they are unchanged by flipping the sign of an eigenvector (the entry is squared), and they are equivariant by construction. With them as input, a GNN can separate any two graphs whose adjacency matrices have different eigenvalues (the theorem in this session's key idea).
Watch out. Computing \(A^k\) for large \(k\) on a large graph is expensive and the counts explode; in practice \(D\) is small or the walks are replaced by random-walk return probabilities, \(\mathrm{diag}\big((D^{-1}A)^k\big)\).
4Laplacian eigenvectors as coordinates
In words. The Laplacian measures how much a signal on the nodes changes across edges. Its eigenvectors with small eigenvalues change slowly over the graph, so their entries can be used as coordinates that tell nodes in different regions apart.
Why it has this form. Expand \(\mathbf x^\top D\mathbf x-\mathbf x^\top A\mathbf x=\sum_id_ix_i^2-2\sum_{\{i,j\}\in E}x_ix_j\); each edge contributes \(x_i^2+x_j^2-2x_ix_j=(x_i-x_j)^2\). So \(\mathbf x^\top L\mathbf x\ge0\), and it is 0 for a constant vector: \(\mu_1=0\). The next eigenvector \(\mathbf u_2\) is the non-constant unit vector that varies least across edges; it tends to be positive on one side of the graph and negative on the other. On a path or a cycle the eigenvectors are sines and cosines, the same functions a transformer uses for positions in a sentence.
Watch out. Coordinates break the symmetry that makes a GNN permutation equivariant unless the model is built to ignore the arbitrary sign and basis; used naively, they hurt generalisation to new graphs.
5Position from distances to random anchor sets
In words. Pick \(c\log^2n\) random sets of nodes, of sizes \(n/2,n/4,\dots\). Describe each node by its shortest-path distance to the nearest member of each set.
Why it has this form. A single anchor node gives one distance, which many nodes share. Many anchor sets of different sizes pin a node down: large sets are near everybody and resolve small distances, small sets resolve large ones. Bourgain's theorem guarantees that with \(O(\log^2n)\) such sets the distances between the vectors \(f(v)\) approximate the true graph distances up to a factor \(O(\log n)\). The embedding is position-aware: two nodes with identical neighbourhoods but far apart get different vectors.
Watch out. The anchor sets are random and must be re-drawn or kept fixed consistently; the resulting features depend on that choice, so a model trained with them is tied to the graph it was trained on (transductive) unless anchors are re-sampled for every graph.
Check yourself
Questions from the lecture, in order. Answer each one in your head (or on paper) before you open it. If one stumps you, follow the link to the walkthrough block it comes from.
Check yourself: is "fails Observation 1 on purpose" a bug in the GNN? show answer
No. Observation 1 is a design goal for structure-aware tasks; for position-aware tasks we deliberately want to break it, so we must feed the model information that is not purely structural.
from What should a perfect GNN do?
Check yourself: why does the edge-level failure matter for link prediction in social networks? show answer
Two candidate friends of \(v_0\) that are structurally symmetric get the same score, even when one is a friend-of-a-friend and the other is not.
from Three levels of failure: same computation graph, different input
Check yourself: what would a layer that also mixes 2-hop neighbours look like? show answer
\(\sigma\big(\sum_{k=0}^{2}A^kC W_k\big)\). Note that \(A^2\) counts walks of length 2, not distinct 2-hop neighbours.
from Neighbourhood aggregation as matrix multiplication
Check yourself: the leading eigenvalue 2.303 appears in both graphs with the same projection 3.048. Why would you expect the leading (Perron) eigenvector never to be hidden? show answer
It has all positive entries in a connected graph, so its inner product with \(\mathbf{1}\) is positive.
from Spectral limitation of WL: a worked example
Check yourself: two graphs that are cospectral (same eigenvalues) are not covered by the theorem. Why can't you conclude that every pair of non-isomorphic graphs is separated? show answer
Non-isomorphic cospectral graphs exist; the theorem only uses eigenvalues.
from Closed loops diag(A^k) as features, and their power
Check yourself: why is using \(d_{\min}\) to a random set inductive while one-hot IDs are not? show answer
The function "distance to a random set sampled with probability \(1/2^i\)" is defined on any graph, and its distribution does not depend on node names.
Lecture walkthrough reference · slide by slide · opens on demand
The whole lecture in order, grouped by topic. Every drawing on the slides is redrawn here as a clean figure (click the step buttons where a figure has them), the heading of each block links to the matching pages of the official PDF, and the Review section after the walkthrough ties this session to the earlier ones. Read this and you do not need the deck.
- What should a perfect GNN do?
- Three levels of failure: same computation graph, different input
- WL colours inherit symmetry; GIN as a one-layer MLP
- Neighbourhood aggregation as matrix multiplication
- Spectral view: GIN as a function of eigenvectors
- Why constant initial colours hide eigenvectors
- Spectral limitation of WL: a worked example
- Eigenvector features (Laplacian positional encodings)
- The naive fix: one-hot node IDs
- Cycle counts and ID-GNN-Fast
- Closed loops diag(A^k) as features, and their power
- Structure-aware vs position-aware tasks
- Anchors and anchor-sets as coordinate axes
- Bourgain's theorem and P-GNN
What should a perfect GNN do? slides 3,5-9 ↗
Slide 3 recalls the full pipeline (dataset split → input graph → GNN → node embeddings → prediction head → predictions, compared with labels through the loss function and evaluation metrics). Today's question sits inside the "GNN" box: can we make GNN representations more expressive?
Slide 5 runs a thought experiment. A \(K\)-layer GNN embeds a node from its \(K\)-hop neighbourhood structure (the figure shows a node, its neighbourhood, and the computation tree unrolled from it). A perfect GNN would build an injective function from neighbourhood structure (of any number of hops) to node embeddings.
Slide 6 splits "injective and well defined" into two rules (ignoring node attributes, i.e. all nodes have the same feature):
- Observation 1: same neighbourhood structure ⇒ same embedding. The figure shows two nodes \(v_1,v_2\) on identical triangles: \(\mathbf{h}_{v_1}=\mathbf{h}_{v_2}\).
- Observation 2: different neighbourhood structure ⇒ different embeddings. The figure shows \(v_1\) on a triangle and \(v_3\) on a square: we want \(\mathbf{h}_{v_1}\neq\mathbf{h}_{v_3}\).
Slide 7: Observation 2 often cannot be satisfied. The GNNs so far are bounded above by the WL test (previous lecture). Example: message-passing GNNs cannot count cycle length. \(v_1\) lives on a cycle of length 3, \(v_2\) on a cycle of length 4. Every node has degree 2, so the computation graphs of \(v_1\) and \(v_2\) are the same infinite binary-branching tree (the figure shows the identical trees).
Slide 8: Observation 1 can also be a problem. Two nodes may have the same neighbourhood structure, yet a task may want different embeddings because the nodes sit in different positions in the graph. These are position-aware tasks. Even a perfect GNN fails here. Figures: a grid graph with \(v_1\) at the bottom-left corner and \(v_2\) at the top-right corner (locally identical corners), and a NYC road network where two intersections look alike locally but are far apart.
Slide 9 is the plan. Fix Observation 2 by building GNNs more expressive than WL (structurally-aware GNNs). Fix Observation 1 by creating embeddings from positions (position-aware GNNs).
Check yourself: is "fails Observation 1 on purpose" a bug in the GNN? show answer
No. Observation 1 is a design goal for structure-aware tasks; for position-aware tasks we deliberately want to break it, so we must feed the model information that is not purely structural.
Three levels of failure: same computation graph, different input slides 11-14 ↗
Slide 11: GNNs fail in structure-aware tasks at three levels — node, edge and graph. The cause is always the same: different inputs, but the same computational graph → the GNN fails.
- Node level (slide 12): node \(v_1\) on a triangle (label A) and node \(v_2\) on a square (label B). Their computation trees are equal (each node has two children, each child has two children, …), so any message-passing GNN gives them the same embedding.
- Edge level (slide 13): a path of six nodes, with \(v_1\) and \(v_2\) in the middle. We want to predict two candidate edges, A = \((v_0,v_1)\) and B = \((v_0,v_2)\), which share the endpoint \(v_0\). Edge predictions are built from the endpoint embeddings. Because \(v_1\) and \(v_2\) are symmetric in the path, their computation trees are equal, so edges A and B get the same score — although \(v_0\) is at distance 2 from \(v_1\) and distance 3 from \(v_2\).
- Graph level (slide 14): two different 8-node graphs A and B, drawn on an octagon with different chord patterns. Both are regular (every node has the same degree), so every node in both graphs has the same computation tree (the big radial trees in the figure). Pooling identical node embeddings gives identical graph embeddings.
Intuition: message passing only sees "how many neighbours of each colour", recursively. Regularity and symmetry make that information identical everywhere, so nothing distinguishes the inputs.
Check yourself: why does the edge-level failure matter for link prediction in social networks? show answer
Two candidate friends of \(v_0\) that are structurally symmetric get the same score, even when one is a friend-of-a-friend and the other is not.
WL colours inherit symmetry; GIN as a one-layer MLP slides 15-18 ↗
Slide 15 starts the spectral perspective. Two graphs:
- \(\mathcal{G}\): two hexagons sharing the edge E–F (10 nodes A…J).
- \(\hat{\mathcal{G}}\): two pentagons joined by the bridge E–F (also 10 nodes A…J).
The node colours are the WL colours. In both graphs E and F (degree 3) get the dark colour, C, D, G, H (neighbours of E/F) get a lighter colour, and A, B, I, J get white. The colourings are identical, so WL cannot tell the graphs apart. Two claims: WL colours inherit the graph symmetries, and symmetric colours are tied to limitations in the spectral decomposition of the graph.
Slides 16–18 recall the GIN update for colours (embeddings) \(\mathbf{c}_v\):
\[ \mathbf{c}_v^{(l+1)}=\mathrm{MLP}\Big((1+\epsilon)\,\mathbf{c}_v^{(l)}+\sum_{u\in N(v)}\mathbf{c}_u^{(l)}\Big). \]Take the MLP to be a single layer with pointwise activation \(\sigma\). Then (slide 16 keeps the \((1+\epsilon)\); slide 17 absorbs it into the weight):
\[ \mathbf{c}_v^{(l+1)}=\sigma\Big(\mathbf{W}_0^{(l)}\mathbf{c}_v^{(l)}+\mathbf{W}_1^{(l)}\sum_{u\in N(v)}\mathbf{c}_u^{(l)}\Big). \]Slide 18 points out two things: this is just GraphSAGE with sum aggregation, and the neighbour sum is a sparse matrix-vector multiplication. The next block makes that precise.
Why only one layer of MLP? Only the first linear layer touches the graph structure; later MLP layers act per node. So everything structural that the layer "knows" passes through this one linear map.
Neighbourhood aggregation as matrix multiplication slides 19-30 ↗
Slides 19–29 build one equation step by step on a 4-node path \(v_1 - v_2 - v_3 - v_4\). Its adjacency matrix (\(A[u,v]=1\) if \((u,v)\) is an edge, else 0) is
\[ A=\begin{pmatrix}0&1&0&0\\1&0&1&0\\0&1&0&1\\0&0&1&0\end{pmatrix}. \]Stack all colours as rows of a matrix: \(C^{(l)}\in\mathbb{R}^{N\times d}\), with \(C^{(l)}[v,:]=\mathbf{c}_v^{(l)}\) (slide 20). Now look at the product \(AC^{(l)}\) row by row (slides 23–29, with the relevant entries boxed in red):
- Row 1 of \(A\) is \((0,1,0,0)\), so \(AC^{(l)}[1,:]=\mathbf{c}_{v_2}^{(l)}\) — the sum over \(N(v_1)=\{v_2\}\).
- Row 2 is \((1,0,1,0)\): \(AC^{(l)}[2,:]=\mathbf{c}_{v_1}^{(l)}+\mathbf{c}_{v_3}^{(l)}\).
- Row 3 is \((0,1,0,1)\): \(AC^{(l)}[3,:]=\mathbf{c}_{v_2}^{(l)}+\mathbf{c}_{v_4}^{(l)}\).
- Row 4 is \((0,0,1,0)\): \(AC^{(l)}[4,:]=\mathbf{c}_{v_3}^{(l)}\).
So row \(v\) of \(AC^{(l)}\) is exactly \(\sum_{u\in N(v)}\mathbf{c}_u^{(l)}\). The whole layer, for all nodes at once (slides 28–30), is
\[ C^{(l+1)}=\sigma\big(C^{(l)}W_0^{(l)}+AC^{(l)}W_1^{(l)}\big)=\sigma\Big(\sum_{k=0}^{1}A^kC^{(l)}W_k^{(l)}\Big). \](Row vectors now multiply weights from the right, so \(W\) appears after \(C\).) The neat form \(\sum_k A^k C W_k\) says: one GIN layer is a degree-1 polynomial in \(A\) applied to the colours, followed by a pointwise non-linearity.
Check yourself: what would a layer that also mixes 2-hop neighbours look like? show answer
\(\sigma\big(\sum_{k=0}^{2}A^kC W_k\big)\). Note that \(A^2\) counts walks of length 2, not distinct 2-hop neighbours.
Spectral view: GIN as a function of eigenvectors slides 31-33 ↗
Slide 31: compute the eigendecomposition of the (symmetric) adjacency matrix:
\[ A=V\Lambda V^\top,\qquad V=[\mathbf{v}_1,\dots,\mathbf{v}_n]\ \text{orthonormal eigenvectors},\quad \Lambda=\mathrm{diag}(\lambda_1,\dots,\lambda_N). \]- The spectral decomposition is a universal characterisation of the graph: it determines \(A\), so it contains everything about the graph.
- Different graphs have different spectral decompositions (different \(V\) and/or \(\Lambda\)).
- The number of cycles can be written as a function of eigenvalues and eigenvectors. The slide's example:
where \(|\mathbf{v}_n|^2\) means the element-wise square. Entry \(v\) of \(\mathrm{diag}(A^3)\) counts closed walks of length 3 from \(v\); each triangle through \(v\) gives 2 such walks (two directions), so triangles at \(v\) = \(\tfrac12(A^3)_{vv}\).
Slides 32–33 substitute \(A^k=V\Lambda^kV^\top\) into the GIN layer:
\[ C^{(l+1)}=\sigma\Big(\sum_{k=0}^{1}A^kC^{(l)}W_k^{(l)}\Big)=\sigma\Big(\sum_{k=0}^{1}V\Lambda^k\,\boxed{V^\top C^{(l)}}\,W_k^{(l)}\Big). \]So the update depends on three things: the eigenvalues, the eigenvectors, and the dot products between the eigenvectors and the previous colours, \(V^\top C^{(l)}\) (boxed in red on slide 33). Intuition: the GNN first projects the colour signal onto each eigenvector ("frequency"), rescales each projection by \(\lambda_n^k\), and maps back.
Why constant initial colours hide eigenvectors slides 34-35 ↗
Slide 34 recalls colour refinement (WL) on two graphs. Both start with all colours 1. After one round each node's new colour is (own colour, multiset of neighbour colours): labels such as "1,1111" (degree 4), "1,111" (degree 3), "1,11" (degree 2) and "1,1" (degree 1). The two graphs produce the same multiset of new colours, so this round cannot separate them.
Slide 35 explains why, spectrally. With uniform initial colours, \(C^{(0)}=\mathbf{1}\) (the all-ones vector), so the boxed term is
\[ V^\top C^{(0)}=V^\top\mathbf{1}=\big[\langle\mathbf{v}_1,\mathbf{1}\rangle,\dots,\langle\mathbf{v}_n,\mathbf{1}\rangle\big]. \]- The new colours depend only on eigenvectors that are not orthogonal to \(\mathbf{1}\). If \(\langle\mathbf{v}_n,\mathbf{1}\rangle=0\), the pair \((\lambda_n,\mathbf{v}_n)\) drops out of the layer.
- Graphs with symmetries admit eigenvectors orthogonal to \(\mathbf{1}\). An automorphism that swaps two parts of the graph creates eigenvectors that are "antisymmetric" (+ on one side, − on the other), and those sum to 0.
Small example: the 4-cycle has eigenvalues \(2,0,0,-2\). The eigenvector for \(-2\) is \((1,-1,1,-1)\), which is orthogonal to \(\mathbf{1}\). A GNN started from constant colours never sees it.
Spectral limitation of WL: a worked example slides 36-39 ↗
| eigenvalues λₙ and projections ⟨vₙ, 1⟩ (slides 36–37) | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 𝒢 λₙ | 2.303 | 1.618 | 1.303 | 1 | 0.618 | −2.303 | −1.618 | −0.618 | −1 | −1.303 |
| ⟨vₙ,1⟩ | 3.048 | 0 | 0 | −0.816 | 0 | 0 | 0 | 0 | 0 | −0.210 |
| 𝒢̂ λ̂ₙ | 2.303 | 1.861 | 1 | 0.618 | 0.618 | 0.254 | −1.303 | −1.618 | −1.618 | −2.115 |
| ⟨v̂ₙ,1⟩ | 3.048 | 0 | −0.816 | 0 | 0 | 0 | −0.210 | 0 | 0 | 0 |
The spectra differ (𝒢̂ has 1.861, 𝒢 does not), but every eigenpair that differs has projection 0 on the all-ones vector, so with uniform colours WL and GIN only ever see the three visible eigenpairs, which are identical in both graphs.
Slides 36–37 return to \(\mathcal{G}\) (two hexagons sharing an edge) and \(\hat{\mathcal{G}}\) (two pentagons joined by a bridge). The table lists each eigenvalue \(\lambda_n\) and its projection \(\langle\mathbf{v}_n,\mathbf{1}\rangle\):
| \(\mathcal{G}\): \(\lambda_n\) | 2.303 | 1.618 | 1.303 | 1 | 0.618 | −2.303 | −1.618 | −0.618 | −1 | −1.303 |
|---|---|---|---|---|---|---|---|---|---|---|
| \(\langle\mathbf{v}_n,\mathbf{1}\rangle\) | 3.048 | 0 | 0 | −0.816 | 0 | 0 | 0 | 0 | 0 | −0.210 |
| \(\hat{\mathcal{G}}\): \(\hat\lambda_n\) | 2.303 | 1.861 | 1 | 0.618 | 0.618 | 0.254 | −1.303 | −1.618 | −1.618 | −2.115 |
| \(\langle\hat{\mathbf{v}}_n,\mathbf{1}\rangle\) | 3.048 | 0 | −0.816 | 0 | 0 | 0 | −0.210 | 0 | 0 | 0 |
Read it carefully. The spectra are different (e.g. \(\hat{\mathcal{G}}\) has 1.861, which slide 37 boxes in red; \(\mathcal{G}\) does not). So the graphs are different. But the eigenpairs with a nonzero projection on \(\mathbf{1}\) are the same in both: \((2.303, 3.048)\), \((1, -0.816)\), \((-1.303, -0.210)\). Every eigenpair that differs has projection 0. A GNN started from constant colours sees only the visible pairs, so it cannot distinguish \(\mathcal{G}\) from \(\hat{\mathcal{G}}\) — exactly what WL gives on slide 15.
Slide 38: the WL kernel also cannot count basic structures. Cycle counts, such as \(\mathrm{diag}(A^3)=\sum_n\lambda_n^3|\mathbf{v}_n|^2\), use all eigenpairs, including the hidden ones. Here \(\mathcal{G}\) has 6-cycles and \(\hat{\mathcal{G}}\) has 5-cycles, but that difference lives in the invisible part of the spectrum.
Slide 39 summarises:
- The limitations of WL are limitations of the initial node colour, and they are well understood in the spectral domain.
- Constant colourings are orthogonal to some adjacency eigenvectors, so critical spectral components (eigenvalues and eigenvectors) are omitted.
- At a high level, WL colours obey the same symmetries as the graph; these joint symmetries lock message passing into limited representations.
The conclusion points directly to the fix: change the input features so they are not orthogonal to the important eigenvectors.
Check yourself: the leading eigenvalue 2.303 appears in both graphs with the same projection 3.048. Why would you expect the leading (Perron) eigenvector never to be hidden? show answer
It has all positive entries in a connected graph, so its inner product with \(\mathbf{1}\) is positive.
Eigenvector features (Laplacian positional encodings) slides 41-44 ↗
Slide 41: what if we use eigenvectors as additional features? The key object is the Laplacian \(L = D - A\) (degree matrix minus adjacency). Each graph has its own Laplacian; it encodes the graph structure; several variants exist that add degree information differently (e.g. normalised Laplacians). For the 4-node path:
\[ L=\begin{pmatrix}1&0&0&0\\0&2&0&0\\0&0&2&0\\0&0&0&1\end{pmatrix}-\begin{pmatrix}0&1&0&0\\1&0&1&0\\0&1&0&1\\0&0&1&0\end{pmatrix}. \]Slide 42: the Laplacian captures structure, and its eigenvectors inherit this structure. Recall an eigenvector is \(\mathbf{v}\) with \(L\mathbf{v}=\lambda\mathbf{v}\) (\(L\) is \(n\times n\), \(\mathbf{v}\in\mathbb{R}^n\), \(\lambda\) a scalar). Small eigenvalues ↔ global structure; large eigenvalues ↔ local symmetries. The figure (from Kreuzer, Beaini et al. 2021) colours a molecule-like graph by eigenvector values: for \(\lambda_1=0.037\) and \(\lambda_2=0.1\) the colour changes slowly across the whole graph (one side green, other side purple); for \(\lambda_{10}=\lambda_{11}=1.0\) the pattern is local, alternating within small rings.
Slide 43: feature augmentation steps.
- Compute \(k\) eigenvectors \(\mathbf{v}_1,\dots,\mathbf{v}_k\) (the figure uses \(k=3\)).
- Stack them as columns of an \(n\times k\) matrix.
- Row \(i\) is a \(k\)-dimensional feature for node \(i\); append it to the node's input features.
Slide 44 tests this on a synthetic task: given a graph, predict YES if it has a cycle, NO otherwise. "PE" = augmented with Laplacian eigenvectors. Test accuracy (± s.d.), 4 layers:
| Model (#param) | 200 train | 500 | 1000 | 5000 |
|---|---|---|---|---|
| GIN (100774) | 70.585±0.636 | 74.995±1.226 | 78.083±1.083 | 86.130±1.140 |
| GIN-PE (102864) | 86.720±3.376 | 95.960±0.393 | 97.998±0.300 | 99.570±0.089 |
| GatedGCN (103933) | 50.000±0.000 | 50.000±0.000 | 50.000±0.000 | 50.000±0.000 |
| GatedGCN-PE (105263) | 95.082±0.346 | 96.700±0.381 | 98.230±0.473 | 99.725±0.027 |
GatedGCN without PE is at chance (50%) for every training size: it cannot detect cycles at all. With PE both models reach about 99.6–99.7% with 5000 samples, and are far better even with 200 samples, while adding only ~2% more parameters.
A caveat the slides do not dwell on: eigenvectors are defined only up to sign (and up to rotation inside a repeated eigenvalue, like \(\lambda_{10}=\lambda_{11}\) here). The same graph can give different PEs, so models usually randomly flip signs during training or use sign-invariant architectures.
The naive fix: one-hot node IDs slides 46-49 ↗
Slide 46 states the reasoning we use for all feature augmentations. Two different inputs (nodes, edges, graphs) are labelled differently. A "failed" model always assigns them the same embedding; a "successful" model assigns different embeddings. Embeddings are determined by computation graphs. Example: nodes \(v_1\) (triangle, label A) and \(v_2\) (square, label B) — goal: different embeddings.
Slide 47: one-hot encoding. Give each node a different ID (e.g. 1000, 0100, 0010, 0001). Then the computation graphs are clearly different: the leaves of \(v_1\)'s tree repeat \(v_1\)'s own ID at depth 3 (the walk closes around the triangle), which never happens in the square tree. So we can always tell nodes, edges and graphs apart.
Slide 48: the issues.
- Not scalable: needs \(O(N)\) feature dimensions (\(N\) = number of nodes).
- Not inductive: cannot generalise to new nodes or graphs (and IDs depend on an arbitrary node ordering).
Slide 49 compares constant and one-hot features:
| Constant feature | One-hot feature | |
|---|---|---|
| Expressive power | Medium: all nodes identical, but the GNN still learns from structure | High: each node has a unique ID, node-specific information can be stored |
| Inductive (unseen nodes) | High: give new nodes the constant feature and apply the GNN | Low: new nodes bring new IDs the GNN never saw |
| Computational cost | Low: 1-dimensional | High: high-dimensional, not for large graphs |
| Use cases | Any graph, inductive settings | Small graphs, transductive settings (no new nodes) |
The rest of the section looks for a middle ground: features that are structural (so they transfer to new graphs) but still break the WL symmetry.
Cycle counts and ID-GNN-Fast slides 50-51 ↗
Slide 50: certain structures are hard for GNNs to learn, so give them as features. Use cycle counts as augmented node features: a vector whose position \(i\) says whether the node lies on a cycle of length \(i\), starting from length 0.
- \(v_1\) on a triangle: \([0,0,0,1,0,0]\).
- \(v_1\) on a square: \([0,0,0,0,1,0]\).
Slide 51: ID-GNN-Fast (You, Gomes-Selman, Ying, Leskovec, AAAI 2021). Idea: count cycles originating from a given node and use them as initial features. The figure "colours" the root node \(v\) (orange) and unrolls the ID-GNN rooted subtree; at each depth, count how many tree nodes carry the root's identity. That gives a "cycle count at each level":
- \(v_1\) (triangle): \([1,0,2,2]\) — depth 3 has 2 copies of \(v_1\) ("length-3 cycles = 2": go around the triangle in either direction).
- \(v_2\) (square): \([1,0,2,0]\) — "length-3 cycles = 0".
The counts differ at level 3, so the rooted subtrees are now different (≠ in the figure). Two ways to see the idea: include identity information as an augmented node feature, and use cycle counts at each layer as augmented features. This works together with any GNN.
Notice: "number of times the root reappears at depth \(k\)" equals the number of closed walks of length \(k\), i.e. \((A^k)_{vv}\). This leads straight into the next block.
Closed loops diag(A^k) as features, and their power slides 52-55 ↗
Slide 52 (Kanatsoulis and Ribeiro, ICASSP 2024): use the diagonals of adjacency powers as augmented node features. \((A^k)_{vv}\) counts closed loops (closed walks) of length \(k\) through \(v\):
\[ C^{(0)}=\big[\mathrm{diag}(A^0),\ \mathrm{diag}(A^1),\ \mathrm{diag}(A^2),\ \mathrm{diag}(A^3),\dots,\mathrm{diag}(A^{D-1})\big]\in\mathbb{N}_0^{N\times D}. \]The slide's examples (\(D=6\)): \(v_1\) on a triangle gets \([1,0,2,2,6,8]\); \(v_1\) on a square gets \([1,0,2,0,8,0]\). The entry at \(k=3\) (2 vs 0, marked with an arrow) shows the triangle.
Slide typo: for the triangle the last entry should be 10, not 8. Closed walks of length \(k\) on \(K_3\) are \((2^k+2(-1)^k)/3\), giving \(1,0,2,2,6,10\). For the 4-cycle, \((2^k+(-2)^k)/4\) for \(k\ge1\) gives \(0,2,0,8,0\), matching the slide.
Why this works, spectrally: \(\mathrm{diag}(A^k)=\sum_n\lambda_n^k|\mathbf{v}_n|^2\) involves every eigenpair, so these features are not orthogonal to the hidden eigenvectors. Slide 53 states the results:
- Theorem: if two graphs have adjacency matrices with different eigenvalues, there exists a GNN with closed-loop initial node features that can always tell them apart.
- GNNs with structural initial node features can produce different representations for almost all real-world graphs.
- GIN with structural initial node features is strictly more powerful than the WL kernel.
Apply it to \(\mathcal{G}\) vs \(\hat{\mathcal{G}}\): their eigenvalues differ (1.618 vs 1.861 …), so closed-loop features separate them, while WL could not.
Slide 54: other common augmented features — clustering coefficient, PageRank, centrality, … Any feature from Lecture 1 can be used.
Slide 55 adds a structure-aware column to the earlier table:
| Constant | Structure-aware | |
|---|---|---|
| Expressive power | Medium | High: each node has a structure-aware ID, so node-specific information can be stored |
| Inductive | High | High: we can count triangles or closed loops in any graph |
| Computational cost | Low | Low/High, depending on the structures we count |
| Use cases | Any graph, inductive | Any graph, inductive |
Check yourself: two graphs that are cospectral (same eigenvalues) are not covered by the theorem. Why can't you conclude that every pair of non-isomorphic graphs is separated? show answer
Non-isomorphic cospectral graphs exist; the theorem only uses eigenvalues.
Structure-aware vs position-aware tasks slides 57-59 ↗
Slide 57 (You, Ying, Leskovec, ICML 2019) defines two task types on the same graph: two triangles joined by a bridge edge.
- Structure-aware task: nodes are labelled by their structural roles. The two bridge endpoints (degree 3) are B, the four other triangle nodes (degree 2) are A — on both sides.
- Position-aware task: nodes are labelled by their positions. Every node in the left triangle is A, every node in the right triangle is B.
Slide 58: for structure-aware tasks, GNNs work. \(v_1\) (degree 2) and \(v_2\) (bridge node) have different computation graphs, so they can be separated (feature augmentation handles harder cases like cycles).
Slide 59: GNNs always fail for position-aware tasks. A left-triangle node \(v_1\) and its mirror image \(v_2\) in the right triangle have the same computation graph, because of the graph's symmetry. No message-passing GNN, however powerful, can separate them. Question: can we define deep learning methods that are position-aware?
Link to SNA: "community membership" or "which side of a polarised network" is a position-aware label. A structural GNN with constant features sees two equally shaped echo chambers as the same.
Anchors and anchor-sets as coordinate axes slides 60-62 ↗
Slide 60: the power of an "anchor". Randomly pick a node \(s_1\) as an anchor. Represent \(v_1\) and \(v_2\) by their distances to \(s_1\). In the figure \(s_1\) is in the left triangle: \(d(v_1,s_1)=1\), \(d(v_2,s_1)=2\). The distances differ, so the symmetry is broken. An anchor works like a coordinate axis that locates nodes in the graph.
Slide 61: pick more anchors \(s_1, s_2\) (one in each triangle's bridge node). The relative-distance table is \(v_1: (1, 2)\), \(v_2: (2, 1)\). More anchors characterise position better in different regions of the graph: many anchors = many coordinate axes.
Slide 62: generalise an anchor from one node to a set of nodes. The distance to an anchor-set is the minimum distance to any node in the set. In the figure, \(v_3\) is another node in the left triangle; the size-2 anchor-set \(s_3=\{s_1, v_3\}\). Table:
| \(s_1\) | \(s_2\) | \(s_3\) | |
|---|---|---|---|
| \(v_1\) | 1 | 2 | 1 |
| \(v_3\) | 1 | 2 | 0 |
Single anchors \(s_1,s_2\) cannot separate \(v_1\) from \(v_3\) (both at distances 1 and 2), but the anchor-set \(s_3\) can. Observation: large anchor-sets can sometimes give a more precise position estimate, which lets us use fewer anchors in total.
Intuition: a small anchor-set tells you precisely about the neighbourhood of a few nodes; a large anchor-set tells you "how close you are to anything in a big random region". Mixing sizes gives coordinates at many scales.
Bourgain's theorem and P-GNN slides 63-68 ↗
Slide 63 states the goal: embed the graph's metric space \((V,d)\) into Euclidean space \(\mathbb{R}^k\) so that distances are preserved — for all \(u,v\in V\), \(\|\mathbf{z}_u-\mathbf{z}_v\|_2\) is close to \(d(u,v)\).
Slide 64: Bourgain's theorem (informal; Bourgain 1985). Define for each node \(v\)
\[ f(v)=\big(d_{\min}(v,S_{1,1}),\ d_{\min}(v,S_{1,2}),\ \dots,\ d_{\min}(v,S_{\log n,\,c\log n})\big)\in\mathbb{R}^{c\log^2 n}, \]- \(c\) is a constant;
- \(S_{i,j}\subset V\) is a random set that contains each node independently with probability \(1/2^i\) (\(i=1..\log n\) sets the scale, \(j=1..c\log n\) repeats);
- \(d_{\min}(v,S_{i,j})=\min_{u\in S_{i,j}} d(v,u)\).
Then the embedding distance produced by \(f\) is provably close to the original metric. (The precise statement: distortion \(O(\log n)\) with high probability.) Notice that the anchor-sets of the previous block are exactly the \(S_{i,j}\): small \(i\) → large sets, large \(i\) → small sets.
Slide 65: P-GNN follows the theorem. It samples \(O(\log^2 n)\) anchor-sets \(S_{i,j}\) and embeds each node via \(f(v)\in\mathbb{R}^{c\log^2 n}\). P-GNN stays inductive: anchor-sets are re-sampled every time during training, so the network learns to work with any anchor-sets; at test time, on a new unseen graph, new anchor-sets are sampled.
Slide 66 summarises position encoding for graphs: represent a node's position by its distances to randomly selected anchor-sets; each dimension is tied to one anchor-set (e.g. \(v_1\mapsto(1,2,1)\), \(v_3\mapsto(1,2,0)\)).
How to use it?
- Slide 67, the simple way: use the position encoding as an augmented node feature. It works well in practice. Issue: each dimension is tied to a random anchor-set, so the dimensions can be randomly permuted without changing the meaning. A normal NN is not invariant to permuting its input dimensions — its output would change.
- Slide 68, the rigorous way: a special NN that keeps the permutation-invariant property of the encoding: permuting input dimensions only permutes output dimensions, without changing the values. The figure (from the P-GNN paper) shows anchor-set selection \(S=\{S_1,S_2,S_3\}\) on a 5-node graph; for node \(v_1\), a function \(F\) combines \(v_1\)'s feature with each anchor-set's features into messages \(M_{v_1}[1],M_{v_1}[2],M_{v_1}[3]\) (one per anchor-set); \(\mathrm{AGG}_S\) aggregates them into \(\mathbf{h}_{v_1}\) for the next layer, and a projection \(\times\mathbf{w}\) maps the per-anchor-set messages to the output \(\mathbf{z}_{v_1}\in\mathbb{R}^3\), one coordinate per anchor-set.
Check yourself: why is using \(d_{\min}\) to a random set inductive while one-hot IDs are not? show answer
The function "distance to a random set sampled with probability \(1/2^i\)" is defined on any graph, and its distribution does not depend on node names.
Not shown (no new content): slides 1,2,4,10,40,45,56 — title page, announcements, section-divider pages.
Review: what to keep from this session
Carried forward. Lecture 8 uses the same positional encodings as the "tokens" of a graph transformer; Lecture 19 reports PReLU and sum aggregation as empirically best, consistent with the expressiveness argument; Lecture 21 reuses eigenvector-based encodings for geometric graphs.
Quick self-check
Why can a message-passing GNN with constant features not distinguish a node on a triangle from a node on a square?
Both see a degree-two neighbour at every iteration of colour refinement; the cycle length is never visible to 1-WL.
What is the sign ambiguity of Laplacian eigenvectors and why does it matter?
If v is an eigenvector so is −v; a model that reads the raw eigenvector would learn an arbitrary sign choice and fail on a graph where the solver flips it.
What makes an encoding "structural" rather than "positional"?
Structural encodings describe the local structure around a node (cycle counts, degrees) and are the same for structurally identical nodes; positional encodings locate the node in the graph and can differ for identical local structures.
Key idea
Message passing can only see what its initial features let it see: give nodes structural features (closed walks, cycles, eigenvectors) to go beyond WL on structure, and distances to random anchor sets to make embeddings position-aware.
\((A^k)_{vv}\) = number of closed walks of length \(k\) from \(v\). Since \(\mathrm{tr}(A^k)=\sum_n\lambda_n^k\), these features carry spectral information that constant inputs cannot reach.
Worked example: closed walks on \(K_3\) vs \(C_4\)
Compare a node of a triangle \(K_3\) (eigenvalues \(2,-1,-1\)) with a node of a square \(C_4\) (eigenvalues \(2,0,0,-2\)). By symmetry every node has \((A^k)_{vv}=\mathrm{tr}(A^k)/n\).
- \(K_3\): \(\mathrm{tr}(A^k)=2^k+2(-1)^k\). Divide by 3: \(k=0..5\): [1, 0, 2, 2, 6, 10].
- \(C_4\): \(\mathrm{tr}(A^k)=2^k+(-2)^k\) (zero eigenvalues add nothing for \(k\ge1\)). Divide by 4: [1, 0, 2, 0, 8, 0].
- They agree for \(k\le 2\) (degree 2 both), and first differ at \(k=3\): 2 closed walks of length 3 on a triangle (go round either way), none on a square (bipartite graphs have no odd closed walks).
- So a GIN fed these 6 numbers per node separates triangle-nodes from square-nodes after zero message-passing steps.
Strictly speaking: the slides' example vectors may differ slightly because their pictured graphs include extra nodes; the method is the same. Computing \(\mathrm{diag}(A^k)\) exactly costs matrix powers — for large sparse graphs use sparse products or random-probe estimators.
In code
import torch
from torch_geometric.utils import to_dense_adj
from torch_geometric.transforms import AddLaplacianEigenvectorPE, AddRandomWalkPE
A = to_dense_adj(edge_index)[0]
feats, P = [], torch.eye(A.size(0))
for k in range(6): # closed-walk counts diag(A^k)
feats.append(P.diagonal()); P = P @ A
x_struct = torch.stack(feats, 1)
data = AddLaplacianEigenvectorPE(k=8, attr_name='lap_pe')(data) # eigenvector PE
data = AddRandomWalkPE(walk_length=16, attr_name='rw_pe')(data) # diag of (D^-1 A)^k
Proof workshop: Closed walks count triangles
One problem in olympiad style. Give it fifteen minutes on paper before you open the first hint; the hints are graded, so open them one at a time.
Problem. Let \(A\) be the adjacency matrix of a simple graph. Prove that (a) \((A^k)_{vv}\) is the number of closed walks of length \(k\) at \(v\); (b) \((A^3)_{vv}=2t(v)\), where \(t(v)\) is the number of triangles through \(v\), and \(\mathrm{tr}(A^3)=6\,t(G)\); (c) \(G\) is bipartite if and only if \((A^k)_{vv}=0\) for every \(v\) and every odd \(k\). Then compute \(\mathrm{tr}(A^3)\) for \(C_6\) and for \(C_3\cup C_3\).
Hint 1
Hint 2
Solution
Why it matters. 1-WL cannot tell \(C_6\) from \(C_3\cup C_3\) (Lecture 6), but the closed-walk feature \((A^3)_{vv}\) separates them at once: 0 versus 2 at every node. This is exactly what random-walk structural encodings (RWSE) add, and why triangle counts remain worth computing as features on social graphs, where closure is the signal.
Sharper lens: exactly what the features add
Not on the slides. Three or four points where the lecture rounds something off: the exact statement, a second way to see it, and where it stops being true. Each is short and has a pointer for going further.
What constant inputs let a GNN see: the main eigenvalues
Section 2 says constant inputs hide the eigenvectors orthogonal to \(\mathbf 1\). The classical name for the visible ones is main eigenvalues (Cvetković 1970): those whose eigenspace is not orthogonal to \(\mathbf 1\). A linear GNN started from \(\mathbf 1\) produces the walk-count vectors \(\mathbf 1,A\mathbf 1,A^2\mathbf 1,\dots\), and their span has dimension equal to the number of main eigenvalues. A \(d\)-regular graph has exactly one, which is the whole proof of Lecture 6's "blind to regular graphs" in a line.
Non-linearities add more, but not without limit: every feature a message-passing GNN computes from constant inputs is constant on the classes of the coarsest equitable partition, which is the stable WL colouring. So the spectral story and the colour story of this lecture are one statement: the input lies in a symmetric subspace, and equivariant layers cannot leave it.
Closed-walk features stop at walk-regular graphs
The theorem in section 4 needs the two graphs to have different eigenvalues. Here is the standard pair where they do not. The 4×4 rook's graph (16 squares, adjacent when in the same row or column) and the Shrikhande graph are both strongly regular with parameters (16, 6, 2, 2): the same spectrum, and both are walk-regular, meaning \((A^k)_{vv}=\mathrm{tr}(A^k)/n\) at every node. Their closed-walk features, and their random-walk encodings, are identical at every node of both graphs. Even 3-WL cannot separate them.
What does separate them?
Every rung of expressivity has such a pair. The practical question, which the Frontier section raises, is whether your data contains them.
Why distances to anchors are a sound coordinate system
Show that for any set \(S\) of nodes, the coordinate \(f_S(v)=d(v,S)\) can never overstate a distance: \(|f_S(u)-f_S(v)|\le d(u,v)\).
Solution, and what it means for P-GNN
Lab: hands-on and practical tips
Try it live. In the Graph Explorer: read the Laplacian eigenvectors on the karate club, then feed them to a GCN as its only features. Each lesson has predict-then-check questions.
notebook · L07 powerful encoders works through the spectral view, closed-walk and random-walk encodings, Laplacian positional encodings with their sign ambiguity, and anchor-set positions.
AddRandomWalkPE(walk_length=8) gives the normalised variant.Readings & lookup guide
lecture notes CS224W course notes (Leni Aniva, Autumn 2024 — in your course folder)
Suggested order: ID-GNN (problem framing) → P-GNN (position) → Kanatsoulis & Ribeiro (spectral theory, closed loops) → counting substructures.
read first You, Gomes-Selman, Ying, Leskovec — Identity-aware Graph Neural Networks (AAAI 2021)
- Read: §3 (the node/edge/graph failure cases — Fig. 1 is the lecture's slides 12–14), §4 (ID-GNN: colour the centre node, heterogeneous message passing; ID-GNN-Fast with cycle counts).
- Key claim: strictly more expressive than 1-WL, and a drop-in extension of any MPNN.
core You, Ying, Leskovec — Position-aware Graph Neural Networks (ICML 2019)
- Read: §3 (structure- vs position-aware; Fig. 1), §4 (anchor-set sampling; the Bourgain-inspired distortion bound, Theorem 1), Fig. 2 (architecture).
- Lookup: Bourgain (1985) / Linial–London–Rabinovich (1995) for the metric-embedding background.
theory Kanatsoulis & Ribeiro — Graph Neural Networks are More Powerful than We Think (ICASSP 2024)
- Read: the spectral argument behind slides 31–39 and the closed-loop theorem. Matches this lecture's notation directly (the guest instructor is the first author).
theory Kanatsoulis & Ribeiro — Counting Graph Substructures with Graph Neural Networks (ICLR 2024)
- Read: which substructures (cycles, cliques, connected components) a GNN with suitable input features can count — and how. Compare with Chen et al. 2020 "Can GNNs count substructures?".
Homework & deadlines around this lecture
Homework 1 due Thu 10/15
Q1.1 and Q3 sit directly on the WL ceiling this lecture breaks. Try this extension for yourself: in Q1.1, how many layers would be needed if nodes carried closed-walk features?
Project proposal due Tue 10/20
If you're considering a "research implementation" project, positional/structural encodings (closed loops, RWPE, anchor sets) are well-scoped PyG contributions.
Homework 2 out Thu 10/15 · due Thu 10/29
Released with Lecture 8. Expect it to cover Lectures 5–9 material (training, expressiveness, beyond-WL features, transformers). Check the PDF when it's out; an overview will fit on the Lecture 8 page.
Self-check
A "position-aware" task is one where …
- nodes are labelled by their structural role
- structurally symmetric nodes may need different labels
- the graph has spatial coordinates
- only edges are labelled
E.g. mirror-image nodes in a symmetric graph; any purely structural GNN must give them the same embedding.
With constant initial features, a GIN can only use eigenvectors that …
- have the largest eigenvalues
- are sparse
- are orthogonal to 1
- are NOT orthogonal to 1
The input enters as \(V^\top\mathbf{1}\); orthogonal eigenvectors contribute 0.
\((A^3)_{vv}\) on a simple graph equals …
- the degree of v
- the number of triangles containing v
- twice the number of triangles containing v
- the number of 3-paths from v
Each triangle gives two closed walks of length 3 (two directions).
Why does P-GNN re-sample anchor sets every epoch?
- To stay inductive — it must work with any anchors, including on new graphs
- To reduce memory
- To implement dropout
- Because Bourgain's theorem requires it at test time only
The model learns to operate over arbitrary anchor sets rather than memorising fixed ones.
A known pitfall of Laplacian eigenvector PEs is …
- they're too cheap
- sign and basis ambiguity
- they're permutation invariant
- they only work on trees
\(v\) and \(-v\) are both eigenvectors; repeated eigenvalues allow rotations.
Flashcards (click to flip)
History & the bigger picture
- 1985 — Bourgain's embedding theorem: every finite metric embeds in Euclidean space with \(O(\log n)\) distortion. 1995 — Linial, London, Rabinovich make it algorithmic and bring it to TCS — a pure-math result turned into an algorithm, then into a GNN 25 years later.
- 2003 — Laplacian eigenmaps (Belkin & Niyogi): spectral coordinates for manifold learning — the ancestor of Laplacian PEs.
- 2019–2021 — the "beyond WL" boom: \(k\)-GNNs (Morris), P-GNN, ID-GNN, distance encoding (Li et al. 2020), subgraph GNNs (Bevilacqua et al. 2022).
- 2022–2024 — spectral rigor: SignNet/BasisNet, PEARL, and the closed-loop results (Kanatsoulis & Ribeiro) explain why random/structural features work.
Leibniz's principle of the identity of indiscernibles says two things with all the same properties are one thing. WL-bounded GNNs live in a Leibnizian world: structurally indiscernible nodes are treated as identical. Max Black's (1952) counter-example — two identical iron spheres in an otherwise empty universe — is exactly the mirror-node problem. Anchors are the philosopher's "this one here": an arbitrary choice of reference that breaks symmetry. Physics calls it spontaneous symmetry breaking.
Classic SNA bridge
| In this lecture | Classic SNA counterpart | What carried over, what changed |
|---|---|---|
| Laplacian eigenvectors as positional encodings | Spectral partitioning; the Fiedler vector as a polarisation axis; correspondence analysis of sociomatrices | SNA used the second eigenvector to split a network into two camps for decades. As a PE it injects "which side" into a GNN, with the sign ambiguity SNA never had to worry about because it only read the partition. |
| Closed-walk counts \(\mathrm{diag}(A^k)\) | Katz (1953) status index; subgraph centrality (Estrada & Rodríguez-Velázquez 2005) | Subgraph centrality is a weighted sum of exactly these closed-walk counts. The lecture's structural features are a classical centrality unbundled into its terms. |
| Anchor sets and distances (P-GNN) | Closeness centrality; distance-based positions; Freeman's "nested" ego-centred coordinates | SNA measured position as distance to everyone (closeness); P-GNN measures distance to random anchor sets, with Bourgain's theorem guaranteeing little is lost. Random anchors are a sampled closeness. |
| Identity-aware GNN (colour the centre node) | Ego-centred analysis: the ego is distinguished from alters | Ego-network measures always treated ego specially; message passing forgot to, and ID-GNN puts the ego back. |
| Structure-aware vs position-aware tasks | Role vs community (again); "positions" in blockmodels vs "cohesive subgroups" | The distinction Lecture 2 rediscovered as BFS vs DFS reappears as a property of the task, which is where SNA always located it. |
Compute the Fiedler vector of a retweet graph and use its sign as a "camp" feature alongside closed-walk counts as "role" features. Train two GNNs, one with each feature set, on stance and on bot detection. Expect the camp feature to help stance and the role features to help bot detection; a result in the other direction would be a genuinely interesting finding about your data.
Go deeper in the SNA course. The twelve-unit course on social network analysis in this repository gives the classic side of this lecture in full, with labs and real-data analyses: Unit 1 · Ties, triads & the roots of SNA (how structural features and subgraph counts are added back); Unit 6 · Communities & statistical network models (the Laplacian spectrum as positional encoding).
Connecting to your research
Running project. Section L06–L07 · rings that look normal of notebooks/project/retweet_thread.py applies this lecture to one synthetic X world with coordinated rings, the same graph across the whole course.
Research extension. experiments/rege-vs-wl (hypotheses written before running): counting (sum, WL) beats sets (max, regular equivalence) for finding rings in three different ring designs.
- Structure vs position = role vs community, again (Lecture 2). Structure-aware: "is this account a broadcaster/bridge?" Position-aware: "which camp is this account in?" Choose features accordingly: closed walks/triangles for roles, anchor distances or eigenvectors for camps.
- The Fiedler vector (Laplacian eigenvector of the second-smallest eigenvalue) is the classical polarisation signal — it splits a retweet graph into two camps. Using it as a PE is a principled way to inject "which side" information.
- Triangle counts relate to Coleman's social capital and Granovetter's closure; adding them as features gives your GNN sociologically meaningful inputs that 1-WL can't compute by itself.
From the experiments: results and datasets
Generated by scripts/sync_guides.py from the experiments' committed results and the dataset catalogue; rerun it (make sync-guides) after an experiment changes.
rege-vs-wl
Question. Regular equivalence (sets of neighbour roles) or WL (multisets): which separates rings? experiment folder ↗
Frontier 2025–26: what changed since the slides
Frontiers · four ways past 1-WL · a graph transformer is only as expressive as its encodings
Words & phrases
| Term | Simple meaning | Persian | In context |
|---|---|---|---|
| distortionn. | (metric embedding) how much an embedding stretches or shrinks distances, at worst | اعوجاج، میزان تحریف فاصله | "within an O(log n) distortion" |
| ambiguityn. | having more than one possible meaning or value | ابهام، چندمعنایی | "sign ambiguity" |
| eigenvectorn. | a vector that a matrix only stretches, Mv = λv | بردار ویژه | "Laplacian eigenvectors as positional encodings" |
| spectrumn. | the list of eigenvalues of a matrix | طیف | "graphs with a simple spectrum" |
| positional encodingn. | extra node features that say where a node sits in the graph | رمزگذاری موقعیتی | "random-walk positional encodings" |
| closed walkn. | a walk that ends where it started (vertices may repeat) | گشت بسته | "closed walks of length 3 count triangles" |
Go deeper
- Next: Lecture 8 — Graph Transformers, where positional encodings become the main way to tell the model about structure.
- Random features: Sato et al. (2021) and Abboud et al. (2021) — random node initialisation makes MPNNs universal (in probability). Why does randomness break symmetry so effectively?
- Open question: beyond-WL models are more expressive, but is expressiveness the bottleneck on real social graphs? Measure it: compute how many nodes in your Twitter graph share a 1-WL colour after 3 iterations.