Repository navigation
Conversation
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 Report❌ Patch coverage is 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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds
global_reaching_centralityandlocal_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 lengthdadds1/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.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.weightis 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. Givenpathsare left to NetworkX as well.vnot in the graph (NodeNotFound, an unhashablevtoo). Avof 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.global_reaching_centralityat 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_centralityis 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.