[Paper Review] A fast algorithm for All-Pairs-Shortest-Paths suitable for neural networks
This paper proposes a novel, differentiable algorithm for computing all-pairs shortest paths (APSP) using matrix inversion of a weighted adjacency matrix, where the shortest path distances are derived from the logarithmic transformation of the resolvent matrix. The method enables fast, scalable, and neurally plausible computation of graph distances, particularly suitable for analog and neural network implementations, with provably accurate results under appropriate γ selection.
Given a directed graph of nodes and edges connecting them, a common problem is to find the shortest path between any two nodes. Here we show that the shortest path distances can be found by a simple matrix inversion: If the edges are given by the adjacency matrix <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>A</mml:mi> <mml:mrow><mml:mi>i</mml:mi> <mml:mi>j</mml:mi></mml:mrow> </mml:msub> </mml:math> then with a suitably small value of <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>γ</mml:mi></mml:math> the shortest path distances are <DispFormula> <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"> <mml:mrow><mml:msub><mml:mi>D</mml:mi> <mml:mrow><mml:mi>i</mml:mi> <mml:mi>j</mml:mi></mml:mrow> </mml:msub> <mml:mo>=</mml:mo> <mml:mtext>ceil</mml:mtext> <mml:mrow><mml:mo>(</mml:mo> <mml:mrow> <mml:msub><mml:mrow><mml:mi>log</mml:mi></mml:mrow> <mml:mi>γ</mml:mi></mml:msub> <mml:msub> <mml:mrow><mml:mrow><mml:mo>[</mml:mo> <mml:mrow> <mml:msup><mml:mrow><mml:mo>(</mml:mo> <mml:mstyle><mml:mi>I</mml:mi></mml:mstyle> <mml:mo>-</mml:mo> <mml:mi>γ</mml:mi> <mml:mstyle><mml:mi>A</mml:mi></mml:mstyle> <mml:mo>)</mml:mo></mml:mrow> <mml:mrow><mml:mo>-</mml:mo> <mml:mn>1</mml:mn></mml:mrow> </mml:msup> </mml:mrow> <mml:mo>]</mml:mo></mml:mrow> </mml:mrow> <mml:mrow><mml:mi>i</mml:mi> <mml:mi>j</mml:mi></mml:mrow> </mml:msub> </mml:mrow> <mml:mo>)</mml:mo></mml:mrow> </mml:mrow> </mml:math> </DispFormula> We derive several graph-theoretic bounds on the value of <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>γ</mml:mi></mml:math> , and explore its useful range with numerics on different graph types. Even when the distance function is not globally accurate across the entire graph, it still works locally to instruct pursuit of the shortest path. In this mode, it also extends to weighted graphs with positive edge weights. For a wide range of dense graphs this distance function is computationally faster than the best available alternative. Finally we show that this method leads naturally to a neural network solution of the all-pairs-shortest-path problem.
Motivation & Objective
- To develop a differentiable, fast, and scalable algorithm for all-pairs shortest path (APSP) computation suitable for neural network architectures.
- To demonstrate that matrix inversion of (I - γA)⁻¹ can yield accurate shortest path distances via logarithmic transformation, even for directed and weighted graphs.
- To show that the method is computationally faster than conventional APSP algorithms on dense graphs and suitable for analog or neuromorphic hardware.
- To establish a biologically plausible mechanism for pathfinding in brains using recurrent neural circuits that compute R-distances.
- To provide a practical framework for choosing γ to ensure local and global accuracy in distance estimation.
Proposed method
- The method computes distances using the R-distance formula: R_ij(γ) = log[(I - γA)⁻¹]_ij / log(γ), where A is the adjacency matrix and γ is a small positive scalar.
- For unweighted graphs, the R-distance rounds up to the true shortest path distance D_ij when γ is sufficiently small, satisfying γ < 1/N_ij^(k) for all paths.
- The approach generalizes to weighted graphs by replacing A with γ^W_ij, allowing positive integer weights to be encoded in the matrix exponentiation.
- The method leverages the power series expansion of the resolvent (I - γA)⁻¹ = I + γA + γ²A² + ..., which sums over all path counts weighted by γ^k.
- The algorithm is naturally suited for analog or neural network hardware, where matrix inversion and logarithmic operations can be implemented via continuous-time dynamics.
- The network is dynamically responsive: changing edge weights or input nodes instantly updates the output, enabling real-time pathfinding.

Experimental results
Research questions
- RQ1Can matrix inversion of a modified adjacency matrix yield accurate shortest path distances in directed and weighted graphs?
- RQ2What is the optimal range of γ to ensure both local and global accuracy in the R-distance approximation?
- RQ3How does the computational performance of this method compare to classical APSP algorithms like Floyd-Warshall on dense graphs?
- RQ4Can this method be implemented efficiently in analog or neural network hardware for real-time navigation?
- RQ5Does the R-distance function provide a biologically plausible mechanism for pathfinding in animal brains?
Key findings
- The R-distance formula R_ij(γ) = log[(I - γA)⁻¹]_ij / log(γ) yields the exact shortest path distance D_ij when γ is chosen such that γ < 1/N_ij^(k) for all paths, ensuring ceil(R_ij(γ)) = D_ij.
- For dense graphs with thousands of nodes, the method runs faster than naive implementations of Floyd-Warshall and other conventional APSP algorithms.
- The method remains accurate locally even when global accuracy breaks down due to machine precision limits, making it robust for dynamic environments.
- The approach generalizes to weighted graphs with positive integer weights by replacing A with γ^W_ij in the matrix exponentiation.
- The algorithm is naturally suited for analog and neuromorphic computing, with potential settling times in microseconds on hardware.
- The method provides a biologically plausible mechanism for pathfinding, as the underlying circuit motif matches recurrent neural circuits found in animal brains.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.