Graph neural networks through a tiny power grid
All five chapters, static comparisons and worked answers. This edition loads no JavaScript.
01
A grid, before the network
Five buses. Five connections. One question: what can each node learn from its neighbors?
Keep the relations in view
Suppose five buses in a small power-grid sketch each carry a feature. You want a model that can combine a bus's own information with information from connected buses. A table can store the features, but the table's row order does not say who is connected to whom. The graph supplies that missing relation.
We will use the shape of a grid to make message passing inspectable. The values are invented, dimensionless features. They are not voltage, power, fault probabilities, or calibrated stress readings. No electrical equation runs underneath the picture.
TOY INPUT · initial features
| Node | Neighbors | Count |
|---|---|---|
| A | B, C | 2 |
| B | A, C | 2 |
| C | A, B, D | 3 |
| D | C, E | 2 |
| E | D | 1 |
The triangle meets a two-edge branch at C. E can reach A through D and C, but has no direct edge to A.
A graph is a set of nodes and a set of edges. Here the nodes are A, B, C, D and E. The five undirected edges are AB, AC, BC, CD and DE. Undirected means that our model permits messages in both directions along each listed connection. It says nothing about the direction of electrical flow.
A's neighbors are B and C. C's neighbors are A, B and D. E has only D. Move the circles around on the page and those neighbor sets stay the same: a graph's drawn position is different from its connectivity.
A number attached to a node
A feature is a recorded input attached to an entity. Write the input at node as . In A–E order, our input is:
The superscript indicates a column: five rows, one feature per node. A richer input could give each node a vector—an ordered list of several features. We start with a scalar, one number, so every operation fits on paper.
A hidden state is the representation carried between layers. We write it as , where counts layers. At the start, set . The network will change states while the input remains the original record.
Edges can also carry features. We assign each edge a synthetic gate . Later we will halve the C–D gate. This multiplier scales a model message; it is not a measured property of an electrical line.
CL-007 · Toy assumption: all five values, edge gates and the graph itself were chosen for this lesson.
A representation is a starting point
So far, we have a graph and features. We have not specified what to predict, what counts as a good prediction, or how to learn parameters. Those are separate modeling choices.
The immediate task is smaller: compute a new state for every node using the same local rule. If you can explain what C receives, you can reconstruct the main mechanism of a message-passing layer. Then we can ask how far a local change travels.
CL-014 · Model boundary: topology chooses communication paths. This toy contains no physical power-balance or conservation equation.
02
One round of messages
Freeze the old states. Gather neighbor information. Apply the same update everywhere.
Start with C
C begins at 1. Its neighbors A, B and D begin at 2, 0 and 3. Imagine that each neighbor sends its current value along the connecting edge. With all gates equal to one, C receives three messages: 2, 0 and 3.
Our toy rule keeps half of C's own value and adds half of the mean incoming message. The mean is the sum divided by the number of neighbors:
Three messages → mean 5/3 → half self plus half mean → new C=4/3.
| Node | Input h⁽⁰⁾ | New h⁽¹⁾ |
|---|---|---|
| A | 2.000 | 1.250 |
| B | 0.000 | 0.750 |
| C | 1.000 | 1.333 |
| D | 3.000 | 1.750 |
| E | 0.000 | 1.500 |
The arithmetic at every other node follows the same rule. D uses old C=1 and old E=0, so D's neighbor mean is 1/2 and its new state is 7/4. D does not read the newly computed C=4/3 in this round.
This is a synchronous update: everyone reads the same old snapshot, then all new states replace it together. Updating an array in place as you walk through the nodes would make later nodes read earlier results and create a different computation.
CL-009 · Derived from the toy rule. Fractions are exact; tables round only for display.
Give the operations names
Let be the neighbor set of node , and let be its degree, the count of neighbors. The index runs through that set. The gate multiplies the sender's state.
The first line aggregates messages into . The second combines the aggregate with the node's own state. We stipulate for every node and every round. An isolated node has no neighbors; our declared convention sets its aggregate to zero, giving .
Degree counts present edges, even if a gate reduces a message. It does not sum the gate values. That detail will matter when we edit C–D. Self information is carried by the term; there are no self-edges in our edge list.
CL-008 · Toy assumption: this exact averaging rule and isolated-node convention are choices for an inspectable model.
Where the neural part enters
A learned message-passing network replaces these simple operations with parameterized functions. A message function can use the receiver's state, sender's state and edge attributes. An update function combines the aggregate with the receiver. The symbol denotes the learnable parameters at layer .
AGG means an aggregation such as sum or mean. Our toy uses , a mean aggregate, and . Practical functions can transform vectors and use nonlinearities. The small arithmetic example exposes the same message–aggregate–update structure.
The functions are shared across nodes within a layer. C and E use the same parameters but receive different inputs. General networks may use different parameters in different layers; we additionally tie our two coefficients across rounds.
CL-002 · Gilmer et al., §2, equations (1)–(3)
Nothing in this guide fits those coefficients. A forward pass computes states with supplied parameters. Training would require an objective and an optimizer to change parameters. Advancing the layer control is another stage of the forward computation, not another training step.
CL-015 · Derived distinction: the canonical lab contains no loss, gradient calculation or parameter update.
03
How far can a change travel?
Connected does not mean immediately visible. Each local layer extends the dependency path.
Can E notice A?
Keep the graph and weights fixed. Raise only A's initial feature from 2 to 4. Before trying the lab, predict: can E's state change after one layer? After two?
In the first layer, B and C read A directly. A also retains part of its own change. D reads C's old state, which is still 1 in both runs. E reads D's old state, which is still 3. Neither D nor E can notice A yet.
In the second layer, D can receive C's changed state from layer one. E still reads D's unchanged layer-one state. The earliest path from A to E is A–C–D–E: three edges, hence three local layers.
CL-004 · Battaglia et al., §4.3 and Figure 7: local propagation without a global channel
Trace the two forward passes
The lab compares a baseline A=2 with your selected A value. Both runs use the same selected connection setting and the same weights. This isolates the effect of A's feature. Double rings and signed differences mark a numerical change; a connected node may still have zero difference at the current layer.
Follow the changed feature
Toy values · fixed a=b=½ · no training or electrical solver
Layer 1, A=4, C–D present. Within 1 hops of A: A, B, C. Observed nonzero differences: A, B, C. E has no path short enough to respond yet.
Selected-A run. Double ring = nonzero difference. Δ means selected minus baseline.
| Node | A=2 run | Selected A | Difference |
|---|---|---|---|
| A | 1.250 | 2.250 | +1.000 |
| B | 0.750 | 1.250 | +0.500 |
| C | 1.333 | 1.667 | +0.333 |
| D | 1.750 | 1.750 | 0.000 |
| E | 1.500 | 1.500 | 0.000 |
C at layer 1 reads layer 0. A: 4.000 × gate 1 = 4.000; B: 0.000 × gate 1 = 0.000; D: 3.000 × gate 1 = 3.000.
Message sum 7.000 ÷ degree 3 = 2.333. New C = ½ × own 1.000 + ½ × mean 2.333 = 1.667.
Isolate the edge intervention
This separate comparison holds your A input fixed and changes only C–D relative to the full graph.
| Node | Full C–D | Selected C–D | Difference |
|---|---|---|---|
| A | 2.250 | 2.250 | 0.000 |
| B | 1.250 | 1.250 | 0.000 |
| C | 1.667 | 1.667 | 0.000 |
| D | 1.750 | 1.750 | 0.000 |
| E | 1.500 | 1.500 | 0.000 |
The range is 0–4 layers and A is 0–6. Reset returns A=4, layer 1, full C–D. Computation uses full precision; display rounds to 3 decimals. Degree counts retained edges. Nothing here is an electrical quantity.
| Layer | Changed nodes | E difference |
|---|---|---|
| 0 | A | 0.000 |
| 1 | A, B, C | 0.000 |
| 2 | A, B, C, D | 0.000 |
| 3 | A, B, C, D, E | +0.042 |
At layer 1, A/B/C respond. At layer 2, D joins them. At layer 3, E first responds. Self retention keeps earlier effects present. These are deterministic outputs of the shared model.
Try A=4 at layers 0, 1, 2 and 3. Then return A to 2: every difference vanishes, even though paths still exist. The graph gives a set of possible dependencies. An actual change also requires a different input and a computation that responds to it.
For this positive linear toy and a nonzero change at A, every node within the selected number of hops responds. For a general learned GNN, zero weights, cancellation or a nonlinearity can suppress a reachable input. “Within k hops” is a dependency bound, not a promise that every reachable feature changes every output.
CL-010 · Derived for the stipulated positive self and neighbor coefficients. Displayed differences use a 10−12 threshold; computation uses full precision.
An edge edit changes the rule locally
Reset, then remove C–D. A's change can now reach only A, B and C, however many local layers you apply. The graph has split into two connected components. D and E still update their own states; they simply have no computational path from A.
Removing C–D also changes the neighbor count at its endpoints. At the original input, C now averages A=2 and B=0: the mean is 1, and the new C is 1. D now averages only E=0, so its new state is 3/2.
Now keep C–D but halve its gate. C still has three neighbors and D still has two; their messages across this edge are multiplied by 1/2. C's new value becomes 13/12 and D's becomes 13/8. A weaker message and a missing edge are different interventions in this model.
| C–D mode | Degree C | New C | New D |
|---|---|---|---|
| present | 3 | 1.333 | 1.750 |
| half | 3 | 1.083 | 1.625 |
| removed | 2 | 1.000 | 1.500 |
The lesson is not that a particular normalization is correct for a grid. It is that you must inspect the normalization actually used. Here a half gate attenuates a message without renormalizing the mean. It does not simulate an electrical line change.
CL-011 · Derived. The table holds A at its original value 2 to isolate the edge intervention. Later effects can spread from both edited endpoints.
04
Same graph, different order
A node’s answer should follow its identity, not its row number.
Reorder everything consistently
Our arrays use A, B, C, D, E. Another program might store E, C, A, D, B. If the features and edge references move consistently with their nodes, this is the same graph in a different storage order.
| Node ID | Original row | New row | New state |
|---|---|---|---|
| E | 5 | 1 | 1.500 |
| C | 3 | 2 | 1.333 |
| A | 1 | 3 | 1.250 |
| D | 4 | 4 | 1.750 |
| B | 2 | 5 | 0.750 |
Original output order: A 1.250, B 0.750, C 1.333, D 1.750, E 1.500. New order: E 1.500, C 1.333, A 1.250, D 1.750, B 0.750.
The output attached to C remains 4/3. It simply occupies a different array row. This is permutation equivariance: permuting the input representation permutes the node outputs in the same way.
That is different from invariance, where an output stays exactly the same under a permutation. A sum of incoming messages is invariant to their list order. The collection of per-node outputs is equivariant to reordering the nodes. Neither property says that all nodes must have equal states.
CL-003 · Battaglia et al., §3.2.2–3.2.4: shared functions and invariant aggregation
Why the update follows the node
C still receives the same three values on the same three edges. A sum or mean does not care whether those messages are listed as A, B, D or D, A, B. The update uses the same coefficients at every receiver. Therefore C gets the same answer.
For a compact statement, let mean a consistent reordering, and let mean one update on graph . If is the graph with node records and edge references reordered together, then:
Read the equality as: reorder then compute, or compute then reorder—the result agrees. This is a derivation from shared functions and an order-independent reducer. Floating-point summation order may introduce tiny rounding differences in an implementation; our tests compare with an explicit absolute tolerance.
Shuffling only the feature values is a different experiment. Giving A the old value of E while leaving the edges fixed changes which entity has which input. Equivariance does not require that change to leave predictions alone.
CL-012 · Derived equivariance. A node ID is a stable reference here, not a special learned parameter or an extra numerical input.
A state still needs a job
A readout maps the resulting states to a desired output. A shared node head could produce one output for each node. A graph head might first sum node states and then produce one output for the whole graph. A graph-level output can be invariant to node order while node-level outputs remain equivariant.
Here is the last layer, is a parameterized node readout, and is a proposed prediction. A supervised objective would compare those predictions with targets and adjust and . The symbols locate where learning would happen; the toy has no fitted readout.
CL-016 · Gilmer et al., §2, equation (3) and output-level examples
For document intelligence, nodes could represent text regions and edges could represent a chosen spatial relation. For a grid study, nodes could represent buses with suitably defined features. Those are possible problem formulations, not evidence of useful accuracy. The graph construction, target, loss and held-out evaluation would need their own justification.
A useful local aggregation can also discard a distinction that the target needs. The next chapter examines a case where repeated mixing erases almost everything that distinguishes our five starting values.
05
When mixing stops helping
More context is useful only if the representation keeps the distinctions the task needs.
Repeat this exact average
Return to the original connected graph, all gates 1 and . Each new state is a convex average: nonnegative coefficients sum to one. It stays between the previous smallest and largest values. The overall range therefore cannot increase under this exact rule.
Keep applying the same operator. The node values approach a common value. The bars below show a deterministic computation from the original input; they are not a training curve and report no prediction accuracy.
DETERMINISTIC TOY OUTPUT · bars share a 0–3 scale
Layer 0
Layer 1
Layer 4
Layer 20
Layer 100
All gates 1, a=b=½, original connected graph. The limiting value is 1.300. Rounded values may look equal before exact convergence.
Why 1.3? This neighbor-mean rule preserves a degree-weighted average. A and B each have degree 2, C degree 3, D degree 2, E degree 1. Thus the limit is:
The ordinary mean is 6/5, a different number. The denominator used in the update determines which weighted quantity is preserved. On this finite connected undirected graph, the self term makes the averaging walk lazy, avoiding an alternating two-cycle. Repeated application converges to its unique degree-weighted consensus.
Why degree weighting is preserved
Multiply each node update by its degree and sum over nodes. The self term contributes half of the previous degree-weighted sum. In the neighbor term, each node's old value appears once for each of its incident edges, so it contributes the other half. The total stays fixed. Connectivity and positive self retention make all nodes approach one value, which must equal that preserved sum divided by total degree.
CL-013 · Derived for this fixed, connected, undirected, unit-gate toy. Removing C–D gives separate limits 1 on ABC and 1.5 on DE. Halving a gate while retaining the old degree breaks the convex-average premise.
What this says about oversmoothing
Initially, A=2 and E=0 were easy to distinguish by their state. At consensus they both carry 1.3. A downstream head that sees only this scalar has lost the distinction. This illustrates a mechanism behind oversmoothing: repeated neighborhood mixing can make node representations less discriminative.
The scope matters. Li, Han and Wu analyze smoothing in graph convolutional networks; Oono and Suzuki give conditions under which particular GNNs approach a restricted representation subspace. These analyses do not establish that every deep GNN makes every vector identical or that an extra layer always reduces task accuracy.
CL-006 · Li, Han & Wu: “When GCNs Fail,” Figure 2 and Theorem 1
CL-006 · Oono & Suzuki, §3.3 and §4: conditions on expressive-power loss
Nor is our update the exact Kipf–Welling GCN layer. That layer uses added self-connections, symmetric degree normalization, a trainable matrix and a nonlinearity. Our neighbor mean and separate half-self term are deliberately simpler. Do not transfer the number 1.3, or our scalar consensus shape, to another normalization.
CL-005 · Kipf & Welling, §2, equation (2)
A second limitation is already visible at one layer: a mean of messages [0,2] equals a mean of [1,1]. This toy cannot recover which pair produced that aggregate if all other inputs agree. Aggregation is a modeling decision about which distinctions to retain.
Derived counterexample from CL-008: equal means do not imply equal neighbor multisets. This is a limitation of the chosen mean, not every possible GNN.
Try a graph that is not a grid
A document relation graph has five text regions P, Q, R, S, T. Its undirected edges are PQ, QR, QS and ST. Imagine the same positive self-plus-neighbor rule and unit gates. Increase only R's initial scalar feature by 2.
Which regions must change after two synchronous rounds? Can T change yet? If Q–S is removed, can R's change ever reach T?
You do not need an OCR model to answer. Use the relation graph and the computation, not the apparent closeness or meaning of the text regions.
Reveal the worked reasoning
From R, the distances are R=0, Q=1, P=2, S=2 and T=3. Positive coefficients and a positive single-source change make R, Q, P and S change after two rounds. T is unchanged until round three. Removing Q–S separates P/Q/R from S/T, so R's change never reaches T through these local layers.
If the message coefficient were zero, paths would still exist but neighbor changes would have no effect. This is why the general claim is “can depend on”; the exact changed set needs the positive toy assumptions.
Back at the grid, the same discipline applies. Choose what nodes and edges mean, define message and update functions, locate any learned parameters, and check the output against the intended task. A graph-shaped model supplies a pattern of information access. Physical validity comes only from additional modeling and evidence that this toy does not provide.
CL-014 · No physical simulation or real-grid recommendation. The transfer answer is derived from CL-004/010's local-dependency argument.
Glossary
- Node / edge
- An entity / a chosen relation between entities. Our edges are undirected.
- Feature x / hidden state h
- The observed input / the intermediate representation. Each has one dimension in this toy.
- Neighbor set N(i) / degree dᵢ
- The nodes adjacent to i / their count. Degree counts present edges, not gate strength.
- Message / aggregate / update
- A transformed neighbor contribution / their order-independent combination / the new receiver state.
- Layer ℓ / parameters θ
- A stage of computation / coefficients fitted during training in a learned model. Our coefficients are stipulated.
- Receptive field
- The input region a state can depend on. For our local synchronous model at L layers, it is bounded by L hops.
- Equivariant / invariant
- Outputs reorder with inputs / an output stays unchanged under that reordering.
- Gate eᵢⱼ
- A synthetic multiplier on a message. Neither an electrical parameter nor a normalized attention score.
Primary sources
- Gilmer et al. · Neural Message Passing for Quantum Chemistry (2017)
§2, equations 1–3: message/update functions, attributed graphs and readout. CL-001,002,015,016.
- Battaglia et al. · Relational inductive biases, deep learning, and graph networks (2018)
§3.2: graph representation, shared functions and invariant aggregation. §4.3/Figure 7: locality without global channels. CL-003,004.
- Kipf & Welling · Semi-Supervised Classification with Graph Convolutional Networks (2017)
§2, equation 2: a specific symmetric-normalized GCN. This is not our implemented scalar mean. CL-005.
- Li, Han & Wu · Deeper Insights into Graph Convolutional Networks for Semi-Supervised Learning (2018)
“Laplacian Smoothing” and “When GCNs Fail,” Figure 2/Theorem 1. Scope matters. CL-006.
- Oono & Suzuki · Graph Neural Networks Exponentially Lose Expressive Power for Node Classification (2020)
§3.3 Corollary 2; §4 Theorem 2: architectural and spectral/weight conditions. CL-006.
Reproduce the computation
The canonical model module (local copy) is shared by the page, the static figures and the command-line lab. Read its numerical checks (local copy). In the project folder, run:
node code-lab/run.mjs
node code-lab/run.mjs --check
cd site
npm run build
npm testThe lab records deterministic outputs in code-lab/outputs.json. It uses JavaScript numbers, no random source, no dataset, no network and no training. Full-precision calculations drive the display; tables round to three decimals. The longer averaging run repeats the same fixed operator and is not a sequence of training updates.
Build-time KaTeX supplies local HTML and MathML; no math CDN is needed. The complete reading edition includes all explanations, comparisons and worked answers with zero scripts.