Repository navigation
Conversation
Each node's drop in Laplacian energy has a closed form, so the answer takes a few sparse products where NetworkX rebuilds and sums the dense Laplacian once per node. With d the Laplacian's diagonal (the weighted degree less any self-loop, as NetworkX builds it), the energy is the sum of d**2 and of the squared weights off the diagonal, and NetworkX's drop for node i is d[i]**2 + 2 * sum_j |w_ij| * d[j] + sum_j w_ij**2. Integer weights give NetworkX's values exactly while the energy is below 2**53; float weights agree to within the rounding of the energy, which NetworkX keeps by subtracting two energies. The checks come in NetworkX's order: the null graph, then weights that sum to 0 (ZeroDivisionError, or 0 for every node unnormalized), then the nodelist. The keys are the nodelist's items, in its order. Left to NetworkX: a directed graph, whose directed Laplacian is dense and built from an eigenvector found iteratively; a nodelist that is not a list of hashable nodes; a Laplacian energy that is not finite; float weights of both signs whose sum is so near 0 that NetworkX's order of summation decides whether it raises; and complex weights, which the sums here would read as their real parts, refused by the converted matrix's type.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 20-wiener-efficiency #159 +/- ##
========================================================
+ Coverage 92.88% 93.12% +0.24%
========================================================
Files 182 185 +3
Lines 11227 11623 +396
Branches 1274 1321 +47
========================================================
+ Hits 10428 10824 +396
Misses 546 546
Partials 253 253 🚀 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 laplacian_centrality. NetworkX builds the dense Laplacian and, for each node, copies it
without that node's row and column and sums its squares: O(n3) time and O(n2) memory. Here
each node's drop in energy comes from a closed form in a few sparse products, O(m).
dthe Laplacian's diagonal (the weighted degree less any self-loop, as NetworkX'slaplacian_matrixbuilds it), the energy issum(d**2)plus the squared weights off thediagonal. NetworkX removes node
iby taking|L[j, i]|off each other diagonal entry, sothe drop is
d[i]**2 + 2 * sum_j |w_ij| * d[j] + sum_j w_ij**2, the size of a negativeweight included. A self-loop changes nothing.
(the sums here are in float64). With float weights the values agree to within about
4e-16 of the whole energy, its rounding: NetworkX subtracts two energies, so a
node that drops little carries that rounding, and this answer is the nearer to the exact
one (on a random graph with weights of both signs, a relative error of 1e-13 against
NetworkX's 2e-11).
sum to 0 (ZeroDivisionError, or int 0 for every node of the graph when not normalized,
whatever the nodelist), then the nodelist (NetworkXError). When only self-loops carry
weight the energy is 0 and every value is NaN, NetworkX's 0 / 0. The keys are the
nodelist's items in its order, and
walk_typeandalphaare unused, as in NetworkX.eigenvector ARPACK finds from a random start (its own answer moves in the last bits from
call to call); a nodelist that is not a list of hashable nodes, which NetworkX meets with
errors of its own; a Laplacian energy that is not finite (a NaN or infinite weight, or a
square past the float range); float weights of both signs whose sum is so near 0 that
NetworkX's order of summation decides whether it raises; and complex weights, which the
sums here would read as their real parts. The weight sum is decided here when its order
cannot matter: weights of one sign, multiples of one power of 2 whose sum stays exact, or
an exact sum past the rounding a sum of that many terms can make. Complex weights are
refused by the converted matrix's type, with "Edge attribute 'weight' has complex values;
networkx serves the call", the words and rule 49 complex weights #149 uses for every name that reads weights.
Speed, Indicative (one shared machine at load 3.8 to 4.6; each call in a fresh process from a
NetworkX graph, conversion included; best of two interleaved rounds): about 760 to 3700 times
faster than NetworkX on graphs where NetworkX takes 1.7 to 16 s; the gap widens with n, as
NetworkX's time grows as n**3 and this one's with the edges.
Stacked on #121.