
Message passing — each node aggregates transformed messages from its neighbours to update its state.
Graph Neural Networks (GNNs) operate on graph-structured data — nodes joined by edges — through message passing. Each node updates its state by aggregating transformed messages from its neighbours. Stacking these steps propagates local information across the graph, making GNNs a natural fit for meshes, molecules, and other relational data.
1. Edge Update
$$ \mathbf{h}_{ij}^{(k)} = \phi_e\!\left(\mathbf{h}_i^{(k-1)}, \mathbf{h}j^{(k-1)}, \mathbf{h}{ij}^{(k-1)}\right) $$
2. Message Aggregation
$$ \mathbf{m}i^{(k)} = \bigoplus{j\in\mathcal{N}(i)} \psi\!\left(\mathbf{h}_i^{(k-1)}, \mathbf{h}j^{(k-1)}, \mathbf{h}{ij}^{(k)}\right) $$
3. Node Update
$$ \mathbf{h}_i^{(k)} = \phi_h\!\left(\mathbf{h}_i^{(k-1)}, \mathbf{m}_i^{(k)}\right) $$

Prediction heads — node, edge, and graph-level outputs read off the learned latents.
| Prediction Task | Prediction Head |
|---|---|
| Node Prediction | $\hat{\mathbf{y}}_i = \text{MLP}\!\left(\mathbf{h}_i\right)$ |
| Edge Prediction | $\hat{\mathbf{y}}_{ij} = \text{MLP}\!\left(\begin{bmatrix}\mathbf{h}_i \\ \mathbf{h}_j\end{bmatrix}\right)$ |
| Graph Prediction | $\hat{\mathbf{y}}{\mathcal{G}} = \text{MLP}\!\left(\bigoplus{i\in\mathcal{G}} \mathbf{h}_i\right)$ |