Skip to content

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.

Advanced ~14 min8 steps

What runs in CodeSplash

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

Read first

01

Two kinds of symmetry

Read

Turn 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 RR and shift tt,

f(Rx+t)=f(x)(invariant),g(Rx+t)=R g(x)+t(equivariant, for positions).f(Rx + t) = f(x) \quad \text{(invariant)}, \qquad g(Rx + t) = R\,g(x) + t \quad \text{(equivariant, for positions)}.

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.

02

EGNN: messages that see distances only

Read

An 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 hih_i and coordinates xix_i. 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:

mij=ϕe(hi,hj,∥xi−xj∥2),hi′=ϕh(hi,∑jmij).m_{ij} = \phi_e\big(h_i, h_j, \lVert x_i - x_j\rVert^2\big), \qquad h_i' = \phi_h\Big(h_i, \sum_j m_{ij}\Big).

Coordinates move along the relative vectors, scaled by a number computed from each message:

xi′=xi+∑j(xi−xj) ϕx(mij).x_i' = x_i + \sum_j (x_i - x_j)\, \phi_x(m_{ij}).

Rotate the input and every xi−xjx_i - x_j 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?

16
How sure?

Graph

2

Normalization

1.2
  • Community separation
  • Mean cosine distance
  • Energy, share of input (dashed)
Aggregating the neighbor multisets {a, b} and {a, a, b, b} (a = 1, b = 2)
Aggregator{a, b}{a, a, b, b}Tells them apart
sum3.006.00yes
mean1.501.50no
max2.002.00no

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Reference · SPE010 · Needs a data type CodeSplash doesn't load yetE(n)-equivariant graph neural network (EGNN)EGNN models geometric systems with features and coordinates while respecting rotations, translations, reflections and node permutations under its specified update structure.
03

Check it by rotating

Explore

The reference uses a simplified update in which each node moves along its offsets, weighted by e−∥xi−xj∥2e^{-\lVert x_i - x_j\rVert^2}. 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).

Python
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))
R
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 (0.1,0)(0.1, 0), 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?

How sure?

Model

Four small networks with fixed random weights. Each gives one number (an energy) and one arrow per point.

6

How many points (atoms, say) the model sees.

90

Rotate every point by this angle about the origin before asking the model again.

Move every point by (1, −0.5) after rotating.

Input and the model's arrowsRotated input: new arrows vs rotated originals1234561234560Energy, rotated0Arrows, rotated0Energy, reordered0Arrows, reordered

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 first; the figure appears when you commit.

Make your prediction to see the result.

04

Where it breaks in practice

Predict

Predict first

You add each atom's raw x coordinate as one of its input features hih_i. Is the network still equivariant?

Still equivariantNo longer 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.

05

What symmetry doesn't buy

Read

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

06

What runs here

Read
07

Check: equivariance

Checkpoint

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

08

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