Repository navigation
Conversation
Serve load_centrality (newman_betweenness_centrality) and edge_load_centrality, which NetworkX computes with a Python walk from each source. Load splits what a node passes up equally among its predecessors rather than by their path counts, so the batched walk of betweenness carries each node's count of predecessors, and one multiply per level passes the shares back up. The cutoffs are NetworkX's: a count of levels as nx.predecessor stops, and the lengths Dijkstra keeps when weighted. A weighted call is served only where every edge weighs one positive value of one type, so that Dijkstra's predecessors are the levels', ties included. Other weights, nodes that may not compare when NetworkX sorts them, and a cutoff that is not a number are left to NetworkX. The name generator and the nxapi name check now accept a second name for a function, as NetworkX exports load_centrality.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 45-betweenness-k #154 +/- ##
====================================================
+ Coverage 92.94% 93.13% +0.19%
====================================================
Files 182 185 +3
Lines 11398 11790 +392
Branches 1301 1354 +53
====================================================
+ Hits 10594 10981 +387
- Misses 549 552 +3
- Partials 255 257 +2 🚀 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.
Add
load_centrality(dispatched asnewman_betweenness_centrality, the name NetworkX defines it under) andedge_load_centrality. NetworkX walks from each source in Python. Here a batch of sources walks the graph level by level, as betweenness does since #145, with each level holding its nodes' counts of predecessors; one multiply per level then passes the shares back up. Keys are NetworkX's exactly and values agree within a relative 1e-12. With the conversion counted, the backend took 1/16 to 1/150 of NetworkX's time on graphs where NetworkX took 0.9 to 62 s (Indicative).Load. From each source, a node passes up 1 plus what it got from below, split equally among its predecessors (its neighbours, or in-neighbours, a level up), not by path counts as betweenness splits it. A node on level 1 passes nothing, as in NetworkX, which stops at the source. The sum over sources is scaled by
1 / ((n - 1) * (n - 2))whennormalized, on undirected graphs too, and not at all for two nodes or fewer, as NetworkX does.vgiven. A float, 0.0 for a node that is not in the graph. Avthat is not hashable raises NetworkX's TypeError, except on the null graph, where NetworkX never looks it up.Edge load. The keys are
(u, v)and(v, u)for every edge, on directed graphs too, and each self-loop once, as NetworkX's. From each source every key gets 1, and an edge from a node to its successor a level below gets1 + U(w) / p(w)at both of its keys, wherewis the lower end,p(w)counts its predecessors andU(w)sums the same over the edges beloww. That is NetworkX's propagation written per level, so the values are symmetric. The pairs come by their first end in node order, then by their second, which may differ from NetworkX's order.Cutoff, unweighted.
nx.predecessorstops after the first level the cutoff is at most. So 2.5 walks 3 levels; any cutoff of 1 or less, negative ones and True included, walks one; and None, False, 0, NaN and inf walk them all.edge_load_centrality's defaultcutoff=Falsewalks them all.Weighted. NetworkX's Dijkstra predecessors follow its float sums and the order of its walk. They equal the levels', ties included, where every edge between two nodes weighs one positive, finite value, so that is what is served. All the weights must be of one type (int or NumPy int64, float or float64, or float32), each self-loop at least as heavy as an edge, and the lengths must keep rising to the cutoff. A length is the weight added once per level to the integer 0, as NetworkX adds it, and is kept when it is not past the cutoff. So with 0.7 on every edge a cutoff of 7 keeps ten levels (6.999999999999999). float32 weights add and compare as NumPy's float32 do. Left to NetworkX:
test_weighted_load;_adj;Int weights add as Python ints, which do not wrap past 2**63 where NetworkX's sums of NumPy int64s do; only a cutoff could tell.
Nodes that may not compare. NetworkX sorts each source's
(length, node)pairs, so it compares nodes at one length. A graph of three or more nodes is served only where the nodes are all numbers, all strings, or tuples holding one of these kinds at each index. Others, such as 0 beside "a", are left to NetworkX, which raises TypeError for some and answers others.edge_load_centralitysorts by length alone and serves any nodes.A cutoff that is not an int or float (Decimal, Fraction, str) is left to NetworkX.
Tolerance. Each value is a sum of positive terms. NetworkX adds them source by source in its walk's order, and this backend adds a batch at a time. NetworkX also adds 1 to each share a node passes up and takes it off at the end, which rounds off the last bits of a small share. The largest relative difference measured was:
The tests allow 1e-12.
Speed (Indicative, load 7 to 17; medians of three interleaved rounds). "cold" empties the conversion cache before each call. Every answer was checked against NetworkX's.
gnm_random_graph(1000, 5000)gnm_random_graph(3000, 15000)gnm_random_graph(2000, 10000)So the backend took 1/16 to 1/150 of NetworkX's time with the conversion. The grid gains least: it has up to 138 levels below a source, a multiply each. A second run on the commit, at load 19 to 28, gave 1/14 to 1/110. A process computing the edge load of the grid and of the 3000-node graph peaked at 0.73 GB.
Names. NetworkX exports
load_centrality, its second name fornewman_betweenness_centrality, and so doesnxapi. The generator (scripts/maketree.py) and the name check intest_match_nx.pynow accept a public name whose function is registered under another name.Tests.
normalizedboth ways, and 949 calls withv.backend_priority; batches of 1, 2 and 5 sources; direct calls of thenxapifunctions; and this backend's own graphs.NetworkX's
test_load_centrality.pythrough the backend: the same 18 tests pass before and after in dev, 3.7 and 3.6.1, with 24 load calls served in each and one left to NetworkX (test_weighted_load, whose weights differ).Not done.
chunksizekeyword, as betweenness has; the batch budget is betweenness's 256 MiB.should_run, which is not on this branch (50-spanning-trees adds it). At the sizes measured the backend was faster with the conversion counted; smaller graphs were not timed.Stacked on #145.