Skip to content

13 distance measures - #112

Open
eriknw wants to merge 2 commits into
python-graphblas:12-componentsfrom
eriknw:13-distance-measures
Open

eriknw wants to merge 2 commits into
python-graphblas:12-componentsfrom
eriknw:13-distance-measures

Conversation

@eriknw

@eriknw eriknw commented Dec 2, 2026

Copy link
Copy Markdown
Member

Add the distance measures, computed as reductions over batches of shortest-path lengths.

  • eccentricity, diameter, radius, center, periphery (with usebounds on an undirected graph with integer lengths they walk from as few nodes as the bounds allow)
  • harmonic_diameter, average_shortest_path_length (Floyd-Warshall methods and a precomputed sp are declined)
  • eccentricity, diameter, radius, center and periphery raise OverflowError where integer lengths could pass 2**63
  • Lengths are Bellman-Ford's, so a negative edge without a negative cycle is answered; the null graph is left to NetworkX

Stacked on #111.

Each is a reduction over shortest-path lengths found for a batch of
sources at a time, the walk harmonic_centrality and
closeness_centrality use: the greatest length in a source's row is its
eccentricity, and the other four take the least or the greatest of
those. Memory is bounded by the batch rather than by the number of
node pairs.

With `usebounds` on an undirected graph whose lengths are integers,
the four walk from as few nodes as the Takes and Kosters bounds allow,
in batches that double, so a long thin graph costs a few batches
rather than a walk from every node. Elsewhere every node is walked
from; the message a disconnected graph raises follows `usebounds`
either way, as NetworkX's does.

Integer weights raise OverflowError where n times the heaviest
absolute weight reaches 2**62, as in the bellman_ford names, since a
length, or the sum of two that the bounds take, could pass 2**63.

A precomputed `sp` and the null graph, whose answer differs between
NetworkX releases, are left to NetworkX. A given `e` is read as
NetworkX reads it.
Both sum over the batches of shortest-path lengths that eccentricity
reads: harmonic_diameter the reciprocals of the nonzero lengths (the
sum harmonic_centrality takes per node), average_shortest_path_length
the lengths themselves, once it has checked that every node reaches
every node, which NetworkX checks first. The lengths are found and
summed in floats, as both answers are: integer lengths, and their sums,
can pass 2**63.

average_shortest_path_length answers `method` None, "unweighted",
"dijkstra" and "bellman-ford". The Floyd-Warshall methods, which
answer a negative cycle with a number where this walk raises, and any
other value are left to NetworkX, as is harmonic_diameter's `sp`.
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.82747% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.14%. Comparing base (56fafb6) to head (2700338).

Additional details and impacted files
@@                Coverage Diff                @@
##           12-components     #112      +/-   ##
=================================================
+ Coverage          90.52%   91.14%   +0.62%     
=================================================
  Files                156      159       +3     
  Lines               8460     9053     +593     
  Branches            1065     1112      +47     
=================================================
+ Hits                7658     8251     +593     
+ Misses               557      553       -4     
- Partials             245      249       +4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant