Graph Neural Networks are Dynamic Programmers

Andrew Dudzik, Petar Veličković

Abstract

Recent advances in neural algorithmic reasoning with graph neural networks (GNNs) are propped up by the notion of algorithmic alignment. Broadly, a neural network will be better at learning to execute a reasoning task (in terms of sample complexity) if its individual components align well with the target algorithm. Specifically, GNNs are claimed to align with dynamic programming (DP), a general problem-solving strategy which expresses many polynomial-time algorithms. However, has this alignment truly been demonstrated and theoretically quantified? Here we show, using methods from category theory and abstract algebra, that there exists an intricate connection between GNNs and DP, going well beyond the initial observations over individual algorithms such as Bellman-Ford. Exposing this connection, we easily verify several prior findings in the literature, and hope it will serve as a foundation for building stronger algorithmically aligned GNNs.

Introduction

In the field of neural algorithmic reasoning, the primary objective is to train neural networks to execute classical algorithms—such as sorting, searching, or pathfinding—within a latent space. A central hypothesis in this field is that Graph Neural Networks (GNNs) are particularly effective because they "align" with Dynamic Programming (DP). Dynamic programming is a powerful algorithmic paradigm that solves complex problems by breaking them down into simpler subproblems, a structure that mirrors the iterative message-passing nature of GNNs.

However, until recently, this "alignment" was largely an intuitive notion based on loose analogies to specific algorithms like Bellman-Ford. Furthermore, GNNs and DP operate in fundamentally different mathematical universes: GNNs typically rely on linear algebra over real numbers, whereas DP often utilizes "tropical" mathematics, such as the min-plus semiring for shortest path problems. This paper bridges this gap by providing a rigorous categorical framework that explains why these systems align and how this knowledge can be used to engineer superior architectures.

Theoretical Framework: Category Theory and Integral Transforms

To establish a formal link, the authors turn to Category Theory—often called the "mathematics of mathematics"—to find a common language for GNNs and DP. They propose that both GNN message-passing and DP steps can be described as an "integral transform" over a "polynomial span."

The Integral Transform as a Three-Step Process

The core of the proposed framework is the decomposition of computation into three distinct categorical operations:

  1. Pullback: This step involves collecting input data from the graph's structure. In a GNN, this corresponds to a node looking at its neighbors' features.
  2. Argument Pushforward: This is the processing phase where inputs are transformed. In GNNs, this is the "message" or "scoring" function that determines the influence of one node on another.
  3. Message Pushforward: Finally, the processed results are aggregated. This corresponds to the "recombination" step in GNNs, such as a sum, mean, or max operation.
The integral transform visualized as graph operations: pullback, argument pushforward, and message pushforward.

Semiring Unification

By defining a latent space $R$ equipped with two operations—$\otimes$ for processing and $\oplus$ for aggregating—the authors show that GNNs and DP are instances of the same categorical structure. While standard GNNs use (multiplication, addition), DP algorithms might use (addition, minimum). This unification allows for the formal mapping of algorithmic alignment: if the "computational diagram" of a neural network matches the diagram of the target algorithm, the network will learn more efficiently and generalize better to unseen data.

Categorical diagram representing the unification of GNN message-passing and DP steps through semiring operations.

The $V^3$ Architecture: Correcting the Node-Centric Bias

A key insight from this categorical analysis is the "node-centric bias" of standard GNNs. Most GNNs are designed to update node or edge features ($V^2$ complexity). However, many complex DP algorithms are inherently edge-centric or involve higher-order interactions. For example, the Floyd-Warshall algorithm for all-pairs shortest paths considers triplets of nodes $(i, j, k)$.

By analyzing the categorical diagrams of these algorithms, the authors realized that standard GNNs are "misaligned" for such tasks because their internal "wiring" doesn't match the triplet-based logic of the algorithm. To address this, they derived the $V^3$ architecture, which explicitly materializes order-3 messages. This model creates a tighter algorithmic alignment by matching the computational "shape" of the target DP algorithms.

Experimental Results on the CLRS Benchmark

The researchers evaluated their theories using the CLRS Algorithmic Reasoning Benchmark, which contains 30 classical algorithms. This benchmark is specifically designed to test out-of-distribution (OOD) generalization, where models are trained on small graphs and tested on much larger ones.

The $V^3$ model, aligned via the categorical framework, significantly outperformed standard $V^2$ baselines:

  • Dijkstra’s Algorithm: Performance improved from 59.58% to 68.53%.
  • Insertion Sort: A massive leap from 15.39% to 24.67%.
  • Overall Impact: On edge-centric tasks, the $V^3$ variant provided an average improvement of 4.44%, and even showed slight gains on non-edge tasks (+1.01%).

These results confirm that "better alignment," as formally defined by the categorical framework, directly translates to superior performance in practical reasoning tasks.

Conclusion and Future Work

This research demonstrates that algorithmic alignment is not just a conceptual vibe but a quantifiable property that can be mapped using category theory. By exposing the intricate connection between GNNs and DP, the authors have provided a foundation for building more robust, algorithmically aligned models.

While the $V^3$ architecture is more computationally intensive due to its processing of node triplets, it sets a new standard for performance on complex reasoning tasks. Future work will explore scaling these higher-order models to larger graphs and extending the categorical framework to other domains, such as physics simulations or Fourier analysis, where integral transforms play a central role.

Summary updated

BibTeX
@inproceedings{dudzik2022graph,
  author = {Andrew Dudzik and Petar Veličković},
  title = {{Graph Neural Networks are Dynamic Programmers}},
  booktitle = {GTRL @ ICLR},
  year = {2022},
  url = {https://openreview.net/forum?id=rebfkS-yTx9},
}
Figure