Equivariance: networks that rotate with their input
Physical systems don't care how you orient them. An invariant output stays put under rotation; an equivariant one rotates along. EGNN builds this in by letting messages see only distances. Check it numerically.
What runs in CodeSplash
- SPE010E(n)-equivariant graph neural network (EGNN) Needs a data type CodeSplash doesn't load yet
You will be able to
- Tell invariance from equivariance with an example of each
- Write EGNN's message and coordinate updates and say why they respect rotations and shifts
- Check equivariance numerically by rotating inputs and comparing outputs
- Say what symmetry does not guarantee
Two kinds of symmetry
ReadTurn a molecule around. Its energy doesn't change: energy is invariantInvarianceAn output that stays the same when the input is transformed in a stated way, like a label under rotation.. The forces on its atoms turn with it: forces are equivariantEquivarianceAn output that transforms in step with the input, like predicted forces rotating when the molecule rotates.. In symbols, for a rotation and shift ,
A network that gets this wrong has to learn every orientation from data. One that has it built in needs fewer examples and can't make orientation-dependent mistakes.
EGNN: messages that see distances only
ReadAn E(n)-equivariant graph networkE(n)-equivariant graph networkA graph network on points with coordinates whose messages use only distances, so rotating or shifting the input moves the output alike. stores, for each node, features and coordinates . Each layer computes messagesMessage passingEach node collects messages from its neighbors (functions of both nodes and the edge), sums them and updates its state. from features and squared distances, which don't change under rotations, shifts or reflections:
Coordinates move along the relative vectors, scaled by a number computed from each message:
Rotate the input and every rotates while the scalars stay the same, so the output rotates too.
Without coordinates this is plain message passing: see how features spread, and blur, over several layers.
DExplorable · Message passing and oversmoothing
Why does a graph network get better with a few layers and worse with many?
Each layer averages over neighbors. At which depth (0–32) will the communities be best separated?
Graph
Normalization
- Community separation
- Mean cosine distance
- Energy, share of input (dashed)
| Aggregator | {a, b} | {a, a, b, b} | Tells them apart |
|---|---|---|---|
| sum | 3.00 | 6.00 | yes |
| mean | 1.50 | 1.50 | no |
| max | 2.00 | 2.00 | no |
Commit your prediction above to see the result
Make your prediction to see the result.
Check it by rotating
ExploreThe reference uses a simplified update in which each node moves along its offsets, weighted by . It rotates the input by 90°, shifts it, and confirms that updating then rotating gives the same answer as rotating then updating. The first node moves to (−0.049, −0.041).
import numpy as np
X = np.array([[0., 0.], [1., 0.], [.2, .7]])
def update(P):
d = P[:, None, :] - P[None, :, :]; w = np.exp(-(d * d).sum(-1))
return P + .1 * (d * w[:, :, None]).sum(axis=1)
R = np.array([[0., -1.], [1., 0.]]); t = np.array([2., -3.])
print(update(X)); print(np.allclose(update(X @ R.T + t), update(X) @ R.T + t))X <- rbind(c(0, 0), c(1, 0), c(.2, .7))
update <- function(P) {
out <- P
for (i in seq_len(nrow(P))) for (j in seq_len(nrow(P))) {
d <- P[i, ] - P[j, ]; out[i, ] <- out[i, ] + .1 * d * exp(-sum(d^2))
}
out
}
R <- rbind(c(0, -1), c(1, 0)); t <- c(2, -3)
print(update(X)); print(isTRUE(all.equal(update(sweep(X %*% t(R), 2, t, "+")), sweep(update(X) %*% t(R), 2, t, "+"))))Change the update so it adds a fixed vector, say , to every node, and the check fails: a fixed direction doesn't rotate.
DExplorable · Equivariance: rotate the input, check the output
Does a model's answer turn with its input, as physics says it must?
Rotate the input. Will this model's energy stay exactly the same?
Model
Four small networks with fixed random weights. Each gives one number (an energy) and one arrow per point.
How many points (atoms, say) the model sees.
Rotate every point by this angle about the origin before asking the model again.
Move every point by (1, −0.5) after rotating.
Red bars fail the check. Differences below 10⁻¹² are rounding and show as 0.
Commit your prediction above to see the result
Make your prediction to see the result.
Where it breaks in practice
PredictPredict first
You add each atom's raw x coordinate as one of its input features . Is the network still equivariant?
Reveal
No. A raw coordinate changes under rotation, so it is not a valid invariant feature. The messages now depend on orientation. The same happens with orientation-dependent preprocessing, a hard distance cutoff applied inconsistently, or a fixed lab frame. Test rotated and shifted copies of real inputs within a numerical tolerance.
What symmetry doesn't buy
ReadEquivariance removes one kind of error. It doesn't make forces correct, conserve energy along a simulation, capture long-range interactions beyond the graph's cutoff, or extrapolate to structures unlike the training data. Large coordinate steps can still make a stack of layers unstable.
So evaluate the way the reference asks: hold out whole systems or trajectories, compare against simpler baselines, and measure the errors you care about (forces, energies, rollouts), not only the training loss.
What runs here
ReadCheck: equivariance
CheckpointCheck yourself
A model predicts a molecule's energy and the forces on its atoms. Under rotation, which should be invariant and which equivariant?
Show the answer
Answer: a
A scalar like energy doesn't change. Vectors like forces rotate with the molecule.
Check yourself
Why do EGNN's messages respect rotations and shifts?
Show the answer
Answer: b
Distances are invariant; relative vectors rotate. Scalars times relative vectors give an equivariant update.
Check yourself
How do you check an implementation's equivariance?
Show the answer
Answer: a
A direct numerical test catches broken preprocessing, cutoffs or frames that the architecture proof doesn't cover.
Check yourself
Your equivariant model is exact to rounding error. What has that established?
Show the answer
Answer: c
Symmetry is one constraint. Accuracy, conservation, long-range effects and transfer need their own evaluation.
Recap
Recap- Invariant outputs stay put under rotation; equivariant outputs rotate along.
- EGNN builds messages from distances and moves coordinates along relative vectors.
- Test equivariance numerically: preprocessing and features can break it.
- Symmetry isn't accuracy. EGNN needs geometric graphs, a data type CodeSplash doesn't load yet.
Concepts in this lesson