Guest
Sign in to keep your graphs and progress.
Select an algorithm and generate steps to begin visualization
Every vertex averages its neighbours, layer after layer
One GCN layer replaces each vertex's features by a normalised sum over itself and its neighbours. Stacking layers spreads labels, too many layers blur them (oversmoothing)
Select an algorithm and generate steps to begin visualization
A graph convolutional network (GCN) is the simplest and most widely used graph neural network. Kipf and Welling introduced it in 2017 for node classification, where a few vertices carry labels and the rest must be guessed. Each layer replaces every vertex's feature vector by a weighted sum over itself and its neighbours, the message passing step, then applies a learned weight matrix and a nonlinearity. The weights are 1 / √(d̃(u) d̃(v)), with degrees counted including a self-loop, so a vertex with many neighbours does not drown out the rest. Stacking k layers lets information travel k edges. This page shows the message passing at the heart of it, without the learned weights, so you can see where the labels go.
Choose two labelled vertices: one starts with the vector (1, 0) for class 1 and the other with (0, 1) for class 2, every other vertex with (0, 0). Each layer, every vertex sends its vector to its neighbours and to itself, scaled by 1 / √(d̃(u) d̃(v)), and adds what it receives. The visualizer shows each message in the first layer, then the vectors after layers 2, 4, 8, 16 and 32, colours every vertex by the class it leans to and writes in its badge how strongly it leans. On the example, two groups of five joined by one edge with A and J labelled, the first layer reaches 6 vertices, and after two layers every vertex in A's group leans to class 1 and every vertex in J's group to class 2. After 32 layers the shares only range from 38% to 62%: the classes blur.
GCNs and their descendants classify users and accounts in social and financial networks, flag fraud rings whose members look normal one by one, recommend items from user and item graphs as PinSage did at Pinterest, predict properties of molecules from their atoms and bonds, and label papers in citation networks such as Cora, the standard benchmark. The same normalized averaging appears in GraphSAGE, graph attention networks and the message passing networks used in chemistry. Oversmoothing, which this page shows, is the main reason real GCNs use only two or three layers, or add skip connections, normalization or attention to keep vertices distinguishable.
k layers of normalized message passing. The visualizer leaves out the learned weights.
GCN(G, X, k):
A~ = A + I // self-loops
d~(v) = degree of v in A~
H = X
repeat k times:
for each vertex v:
H2(v) = sum over u in N(v) and v itself of H(u) / sqrt(d~(u) d~(v))
H = sigma(H2 W) // learned W, nonlinearity
return H // one vector per vertexIn matrix form a layer is H ← σ(D̃^(−1/2) Ã D̃^(−1/2) H W). The page drops W and σ so that only the mixing shows. A trained GCN learns W from the labelled vertices, but the way information spreads, one hop per layer and averaged, is exactly what is drawn.
The ten-vertex example loaded on this page.
Example graph: Two groups of five, A to E and F to J, each with 7 edges, joined by the single edge E–F. A is labelled class 1, J class 2.
A two-layer GCN predicts class 1 for A, B, C, D, E and class 2 for F, G, H, I, J. 32 layers keep the same split here but almost erase the difference: oversmoothing.
Time: O(E · f) per layer, O(k · E · f) for k layers · Space: O(V · f)
With f features, a layer sends one f-vector along each edge and each self-loop, O((E + V) · f), then multiplies by W, O(V · f · f′). Stored sparsely, Â is never a dense V × V matrix. Training adds a backward pass of the same cost. Full-batch training keeps the activations of every layer, which is why large graphs use sampled neighbourhoods, as in GraphSAGE.
Other ways to label vertices from a few known ones.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Label propagation | There are no features to learn from. It repeats the same kind of averaging until it settles, with no weights. | O(E) per round |
| node2vec embeddings | Vectors should be learned without labels first, then fed to any classifier. | O(r · l · n) for the walks, plus training |
| Graph attention network (GAT) | Neighbours should count differently, with weights learned per edge instead of fixed by degree. | O(E · f) per layer, larger constant |
Read the full article: Graph Neural Networks (GNN) Explained
Read the full article: Spectral Graph Theory in Machine Learning
Related algorithms: node2vec and DeepWalk (Node Embeddings), Weisfeiler-Lehman Test (Colour Refinement), Label Propagation, Personalized PageRank, Spectral Partitioning (Fiedler Vector)
Built by Mohammed Islam Hadjoudj · Work with me