learngraphtheory.org

Guest

Sign in to keep your graphs and progress.

Algorithm Selection

Select an algorithm and generate steps to begin visualization

GCN Visualizer

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)

Time: O(k · E · f) for k layers
Space: O(V · f)
Use Case: Node classification, recommendation, molecules and proteins, fraud detection, the base of graph neural networks
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Graph Convolutional Network (Message Passing)

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.

How it works

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.

Applications

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.

Pseudocode

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 vertex

In 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.

Worked example, step by step

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.

  1. Start. A holds (1, 0), J holds (0, 1) and the other 8 vertices (0, 0).
  2. Layer 1. A sends to itself and to B and C. With d̃(A) = 3, d̃(B) = 4 and d̃(C) = 5, A gets 1 / 3 ≈ 0.33, B 1 / √12 ≈ 0.29 and C 1 / √15 ≈ 0.26. J does the same for H, I and itself: 6 vertices carry a signal.
  3. Layer 2. Every vertex has now heard from everything within two edges. All of A's group leans to class 1 and all of J's group to class 2, and the share of class 1 still ranges from 0% to 100%.
  4. Deeper layers. After 8 layers the share of class 1 ranges from 5% to 95%, after 16 from 21% to 79%, after 32 only from 38% to 62%.

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.

Complexity, and where it comes from

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.

When to use Graph Convolutional Network (Message Passing), and when not to

Other ways to label vertices from a few known ones.

AlternativePrefer it whenCost
Label propagationThere are no features to learn from. It repeats the same kind of averaging until it settles, with no weights.O(E) per round
node2vec embeddingsVectors 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

Common pitfalls

  • Stacking too many layers. Each layer averages again, so after many layers all vectors point the same way. Here the spread of the shares shrinks from 0% to 100% down to 38% to 62% after 32 layers. Two or three layers are usual, deeper stacks need skip connections or normalization.
  • Forgetting the self-loops. Without A + I a vertex's new vector ignores its own old one, and on a bipartite graph the signal flips sides at every layer. The self-loop keeps each vertex in its own average.
  • Normalizing by one degree only. Dividing by d̃(v) alone gives a plain mean, by d̃(u) alone a random walk step. The symmetric 1 / √(d̃(u) d̃(v)) keeps the eigenvalues of the operator between −1 and 1, which keeps deep stacks numerically stable.

Frequently asked questions

Why is it called a convolution?
In spectral graph theory a filter on a graph signal is a function of the Laplacian's eigenvalues. Kipf and Welling reduced a first-order polynomial filter to the normalized adjacency, so a layer is a cheap local filter, like a 3 × 3 convolution on an image.
What does a GCN learn?
Only the weight matrices W, shared by all vertices. The graph decides who talks to whom, W decides which feature combinations matter. That is why a GCN trained on the labelled part of a graph can classify the rest.
Can a GCN tell any two graphs apart?
No. Message passing networks are at most as strong as the Weisfeiler–Lehman colour refinement test, so graphs it cannot distinguish get the same outputs. GIN reaches that bound, higher-order networks go beyond it.

Related algorithms: node2vec and DeepWalk (Node Embeddings), Weisfeiler-Lehman Test (Colour Refinement), Label Propagation, Personalized PageRank, Spectral Partitioning (Fiedler Vector)

Built by Mohammed Islam HadjoudjWork with me

An example graph: you can change it, or start blank.

Zoom Controls

30%
Nodes: 10
Edges: 15