Skip to content

57 reaching centrality - #155

Open
eriknw wants to merge 1 commit into
python-graphblas:20-wiener-efficiencyfrom
eriknw:57-reaching
Open

eriknw wants to merge 1 commit into
python-graphblas:20-wiener-efficiencyfrom
eriknw:57-reaching

Conversation

@eriknw

@eriknw eriknw commented Dec 3, 2026

Copy link
Copy Markdown
Member

This adds global_reaching_centrality and local_reaching_centrality, unweighted. On a directed graph a node's local reaching centrality is the share of the other nodes it reaches. On an undirected graph NetworkX's code goes on to average the weights along each path with every edge counting 1, so a node at length d adds 1/d. The global value is the mean shortfall from the largest local value, so it needs every node's: the nodes are walked in blocks, one breadth-first search from all the sources of a block at once.

  • Directed values are ratios of counts, and the global value sums the shortfalls in node order with Python's sum, as NetworkX does, so they are NetworkX's to the bit. An undirected local value sums NetworkX's terms in its order, so it is NetworkX's to the bit too. The undirected global value adds each level's count over its length, so its last bits can differ: on 400 random graphs, 186 of the 200 undirected global values were equal and the rest within a relative 9e-16, in NetworkX 3.6.1, 3.7 and dev.
  • A weight is left to NetworkX. It averages the weights along the one shortest path its Dijkstra finds first, and shortest paths of equal length can average differently. On the directed edges 0-1 (weight 2), 1-3 (6), 0-2 (3) and 2-3 (3), both paths from 0 to 3 have length 28/3 under NetworkX's lengths, the total weight over each weight, with average weights 4 and 3. The local value of 0 is 0.7619 with the path NetworkX finds and 0.8571 with the other, so matching it means replaying its heap order. Given paths are left to NetworkX as well.
  • Errors are NetworkX's, in its order: a single node with a self-loop, then a graph with no edges, then a node v not in the graph (NodeNotFound, an unhashable v too). A v of None is left to NetworkX, which reads it as every source and then raises TypeError (directed) or AttributeError (undirected) on the generator it gets back.
  • Speed (Indicative, load 7 to 12, conversion included, random graphs with 4 edges per node): global_reaching_centrality at 5,000 nodes took 0.15 s directed and 0.12 s undirected, against NetworkX's 11.0 s and 15.9 s, with a peak memory of 0.28 GB against 3.9 GB. At 1,500 nodes it took 0.017 s against 0.97 s and 1.16 s. local_reaching_centrality is one walk, so the conversion dominates a single call: at 1,000,000 nodes it took 2.8 s directed and 4.8 s undirected against NetworkX's 2.0 s and 3.9 s, and 0.012 s and 0.032 s once the conversion is cached. Over a loop of 100 calls on one graph, the first conversion included (random graphs with 4 edges per node), it is 31x to 52x faster from 100,000 nodes: 0.84 s against NetworkX's 29.7 s directed and 1.21 s against 37.2 s undirected at 100,000 nodes, and 1.70 s against 88.3 s and 2.88 s against 114.6 s at 300,000. At 1,000 nodes the loop took 0.11 s against 0.08 s directed and 0.05 s against 0.15 s undirected.

Stacked on #121.

On a directed graph a node's local reaching centrality is the share of
the other nodes it reaches; on an undirected one each node at length d
counts 1/d. The global value needs it for every node, so the nodes are
walked in blocks, one breadth-first search from every source of a block
at once.

A directed value is a ratio of counts, and the global value sums the
shortfalls in node order with Python's sum, as NetworkX does, so both
are NetworkX's to the bit. An undirected local value sums NetworkX's
terms in its order, so it matches to the bit too. The undirected global
value adds each level's count over its length, so it can differ from
NetworkX's in the last bits.

A weight is left to NetworkX: it averages the weights along the path
its Dijkstra picks, and paths of equal length can average differently.
Given paths are left to it as well, and so is a v of None, which
NetworkX reads as every source before raising on the result. Errors
are NetworkX's, in its order.
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.48718% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.99%. Comparing base (5b54ace) to head (8f200a0).

Additional details and impacted files
@@                   Coverage Diff                    @@
##           20-wiener-efficiency     #155      +/-   ##
========================================================
+ Coverage                 92.88%   92.99%   +0.11%     
========================================================
  Files                       182      185       +3     
  Lines                     11227    11422     +195     
  Branches                   1274     1294      +20     
========================================================
+ Hits                      10428    10622     +194     
  Misses                      546      546              
- Partials                    253      254       +1     
🚀 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