AI Wiki中文/EN

Equivariant networks: move the input, predict the matching move

等变神经网络

Prove and test rotation, translation and reflection equivariance, then separate it from scale symmetry and conservation.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Start with the problem

Rotate a molecule without deforming it. A scalar energy should stay the same, while a predicted displacement should rotate with the molecule. Those are different output requirements. An invariant representation discards the transformation at its output; an equivariant representation follows a specified transformation rule.

Cohen and Welling formalize structure-preserving maps between group representations. EGNN gives a geometric message-passing construction. We implement a small fixed-parameter member of the latter pattern and prove its properties before testing them.

Definitions and derivation

The definition allows input and output to transform differently:

F(Tgx)=Tg′F(x),Tgx=Qx+t,Q⊤Q=I.F(T_gx)=T'_gF(x),\qquad T_gx=Qx+t,\quad Q^\top Q=I.

For coordinates in Euclidean space, Q can be a rotation or reflection and t a translation. Scalar node features use the identity output action; coordinate outputs use Q and t. Setting every output action to identity gives invariance as a special case. A network’s weights need not be learned for its architecture to satisfy the equation.

Our N-node complete graph carries coordinates x and invariant scalar features h. Define symmetric scalar messages and update both kinds of features:

mij=0.1tanh⁡(hi+hj−0.2∥xi−xj∥2),mii=0,xi′=xi+1max⁡(N−1,1)∑j(xi−xj)mij,hi′=hi+tanh⁡ ⁣(∑jmij).m_{ij}=0.1\tanh(h_i+h_j-0.2\|x_i-x_j\|^2),\quad m_{ii}=0,\qquad x'_i=x_i+\frac1{\max(N-1,1)}\sum_j(x_i-x_j)m_{ij},\quad h'_i=h_i+\tanh\!\left(\sum_jm_{ij}\right).

The source paper permits richer, learned message and update functions. Here constants and a scalar tanh make every operation visible. The denominator is adapted to define the singleton case safely. All updates use old coordinates and features.

To prove equivariance, subtract two transformed coordinates: translation cancels and the difference becomes Q(xᵢ−xⱼ). Orthogonal Q preserves its squared norm, so each mᵢⱼ is unchanged. A weighted sum of relative vectors therefore rotates or reflects by Q; adding the transformed old coordinate restores translation t. Scalar outputs stay fixed because they use only invariant inputs. Relabeling nodes consistently merely relabels the sums, so permutation equivariance also holds.

This particular symmetric message additionally preserves the arithmetic centroid:

∑i(xi′−xi)=1max⁡(N−1,1)∑i<j[(xi−xj)mij+(xj−xi)mji]=0.\sum_i(x'_i-x_i)=\frac1{\max(N-1,1)}\sum_{i<j} \big[(x_i-x_j)m_{ij}+(x_j-x_i)m_{ji}\big]=0.

The pairwise cancellation uses mᵢⱼ=mⱼᵢ and equal normalization. General equivariant layers need not satisfy either condition. Centroid preservation here does not establish conservation of physical energy, momentum with arbitrary masses, or a valid dynamical model.

Scaling is not among the claimed transformations: doubling coordinates multiplies squared distances by four, changing messages. Reflection symmetry also has a cost: scalar distance-based readouts cannot distinguish mirror-related configurations with matching scalar features. A task sensitive to handedness may require a different symmetry group or additional features.

Computed coordinate updates: hollow circles are inputs, filled dots are outputs, and arrows use actual displacement lengths. Rotating and translating the input rotates and translates the output; the scalar features are held fixed.
Computed coordinate updates: hollow circles are inputs, filled dots are outputs, and arrows use actual displacement lengths. Rotating and translating the input rotates and translates the output; the scalar features are held fixed.

Run the calculation

Run Python 3.12 with NumPy 1.26.4:

import numpy as np


def layer(position,features):
    x,h = np.asarray(position,dtype=float),np.asarray(features,dtype=float)
    if x.ndim != 2 or not 1 <= len(x) <= 12 or not 1 <= x.shape[1] <= 3 or h.shape != (len(x),) or not np.isfinite(x).all() or not np.isfinite(h).all():
        raise ValueError('Use small finite coordinates and scalar node features.')
    delta=x[:,None,:]-x[None,:,:];d2=np.sum(delta**2,axis=2)
    message=.1*np.tanh(h[:,None]+h[None,:]-.2*d2);np.fill_diagonal(message,0)
    updated=x+np.sum(delta*message[:,:,None],axis=1)/max(len(x)-1,1)
    scalar=h+np.tanh(message.sum(axis=1))
    return updated,scalar


def example():return np.array([[0.,0],[1,0],[0,2]]),np.array([1.,.5,-.5])


if __name__ == '__main__':
    x,h=example();y,g=layer(x,h);print('coordinate update',y.round(9).tolist(),'scalar update',g.round(9).tolist())
    angle=.7;q=np.array([[np.cos(angle),-np.sin(angle)],[np.sin(angle),np.cos(angle)]]);shift=np.array([3.,-2.])
    ry,rg=layer(x@q.T+shift,h);print('rotation/translation errors',float(np.max(np.abs(ry-(y@q.T+shift)))),float(np.max(np.abs(rg-g))))
    sy,_=layer(2*x,h);print('scale-equivariance discrepancy',round(float(np.max(np.abs(sy-2*y))),9),'centroid drift',np.max(np.abs(y.mean(axis=0)-x.mean(axis=0))))

Actual output:

coordinate update [[-0.043086158, 0.029131261], [1.00500645, 0.076159416], [0.038079708, 1.894709323]] scalar update [1.056979271, 0.510012566, -0.604903306]
rotation/translation errors 1.1102230246251565e-16 0.0
scale-equivariance discrepancy 0.187485997 centroid drift 0.0

The coordinate transformation discrepancy is about 10⁻¹⁶, consistent with floating-point roundoff. Scalar outputs match. The scale discrepancy is 0.187485997, so the code supplies a counterexample to an unclaimed symmetry. Centroid drift is zero in this run. These tests check selected inputs; the algebraic proof establishes the general transformation property under the stated assumptions.

This dense implementation materializes N×N distances and messages, costing O(N²d) work and storage for d-dimensional coordinates. A sparse variant can scale with edges if its edge-construction rule respects the same transformations; axis-aligned binning or inconsistent pruning can break that promise.

When the method fails

Choose symmetry from the target, not from appearance alone. Gravity defines a preferred direction in many physical tasks, and images may include upright text whose orientation matters. Inputs such as velocities are vectors and must transform accordingly; feeding their raw components into an invariant scalar function would invalidate the proof.

Training with transformed examples can encourage approximate consistency but does not prove an architectural identity. Conversely, exact equivariance cannot repair poor labels or a wrong physical model. Numerical tolerances, coordinate magnitudes and graph construction should be included in deployment checks.

Exercises with answers

  1. Why does translation disappear from messages?

Answer 1: Messages use coordinate differences, so the same added translation cancels.

  1. Which output stays invariant here?

Answer 2: The scalar feature output h; coordinate output x instead transforms equivariantly.

  1. Does equivariance alone preserve the centroid?

Answer 3: No. Our additional symmetric pair coefficients and equal normalization cause cancellation.

  1. Why does scaling fail?

Answer 4: Squared distances change, so the scalar message coefficients change too.

Sources and next steps

Cohen–Welling physical page 2, Section 2 and Equation 1, defines equivariance between representation spaces. EGNN physical pages 2–3, Equations 3–6 and Section 3.1, give the coordinate/scalar construction and proof; page 4 compares related message rules. This chapter’s centroid and scaling calculations concern its explicit simplified model. See message passing for learned distance filters and orthogonal matrices for the norm identity.

Make a prediction, then check

Which operation generally breaks the example’s claimed identity if treated as an orthogonal transform?

Choose one answer

Learning objectives

  • Prove scalar invariance and coordinate equivariance.
  • Separate geometric symmetry from additional conservation laws.

Prerequisites & connections

Explore related knowledge →

References

  1. Group Equivariant Convolutional Networks
    Taco Cohen; Max Welling · 2016
  2. E(n) Equivariant Graph Neural Networks
    Víctor Garcia Satorras; Emiel Hoogeboom; Max Welling · 2021

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-AI-author technical check: primary-source scope, explicit assumptions, original calculations, independent mathematical references and bilingual tests; not independent human or second-agent review.

  • Single-AI-author technical check: bounded primary-source reading, explicit assumptions, original calculations, runnable examples and matching bilingual equations, code and exercises. Not an independent human or second-agent review.
  • Four focused CPython 3.12.4 tests passed per chapter, including independent finite differences, literal calculations, recurrence and convolution comparisons, permutation symmetry, closed-form limits and expressive counterexamples. All eight programs use NumPy 1.26.4. CPU teaching calculations, not framework or GPU benchmarks.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
  • Bilingual Matplotlib 3.9.1 SVGs use executed article functions for rigid coordinate updates, per-round routing allocations and reconstruction/label tradeoffs. Figures and sample data are hash-bound. Displacements are unscaled, rounds are not training steps, and diagnostic-table accuracy is not a held-out estimate.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.