Repository navigation
79 self edges - #177
Open
eriknw wants to merge 1 commit into
Open
79 self edges#177eriknw wants to merge 1 commit into
eriknw wants to merge 1 commit into
Conversation
A DiGraph's has_self_edges, given only "total_degrees+" in the cache, said there were self-loops if those degrees summed to more than twice the number of edges. They never do: a self-loop counts once in its row and once in its column, as any other edge does. So a DiGraph with a self-loop that had been asked for its degree centrality then said it had none, took the matrix itself as its off-diagonal part, and gave a reciprocity of 0.5 where NetworkX gives 1/3. That case now reads the diagonal. The cases for the row and column degrees looked under "row_degrees" and "column_degrees", which are only aliases: the cache keeps them as "count_rowwise" and "count_columnwise", so those cases never ran. They now read the keys the cache holds.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #177 +/- ##
==========================================
+ Coverage 76.82% 81.35% +4.53%
==========================================
Files 118 121 +3
Lines 4271 4553 +282
Branches 818 750 -68
==========================================
+ Hits 3281 3704 +423
+ Misses 751 657 -94
+ Partials 239 192 -47 🚀 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.
A
DiGraphwhose cache heldtotal_degrees+said it had no self-loops when it had one. Given that key alone,has_self_edgesasked whether the total degrees sum to more than twice the number of edges, which they never do: a self-loop counts once in its row and once in its column, as any other edge does. TheFalsethen spread, as it is meant to when true:offdiagbecameAitself and each-property its+. Onnx.DiGraph([(0, 1), (1, 2), (2, 0), (2, 2), (0, 3), (3, 0)]),nx.degree_centralityand thennx.reciprocitythrough the backend gave 0.5 where NetworkX gives 1/3 (in dev and 3.6.1; 1/3 now in dev, 3.7 and 3.6.1). It has been so since #8.total_degrees+alone, the answer now comes from the diagonal, as it does when the cache holds nothing that tells. The cases for the row and column degrees looked underrow_degrees+/-andcolumn_degrees+/-, namesget_propertyresolves tocount_rowwise+/-andcount_columnwise+/-before the cache is read, so they never ran; they now look under the names the cache keeps, and answer without reading the diagonal. Every other inference in the function holds, as doesGraph's, which reads onlyL+/-,U+/-,offdiagand a negative diagonal, and so do those in the getters that settlehas_self_edgeson the way (L+/-andU+/-, the degree getters and the reductions).Graphand 19 for aDiGraph, each value from a graph of its own:has_self_edgesandoffdiagare right when asked directly, and after any of those properties is then asked, which must also be right. ADiGraph's row, column and total degrees answer without reading the diagonal. Afterdegree_centrality,has_self_edgesandoffdiagare right on both classes, andreciprocity, overall and per node, is NetworkX's. Random orders of 24 properties anddegree_centralityon aGraph, and of 35 properties and 5 algorithms on aDiGraph, each on 300 random graphs of up to 6 nodes, with and without loops, give a fresh graph's answer at every step. On main, 43 of the 79 cases fail in dev, 3.7 and 3.6.1, every one on aDiGraph.DiGraphthat differ from a fresh graph's on main and none after; on aGraph, none either way. In dev, on three 3000-node graphs with a loop in one, 3000 orders find 290 on aDiGraphon main and 61 after; the 61 arerecip_degrees+built fromrecip_degrees-and the diagonal as FP64 where a fresh graph has INT64, with the same values. Compared by value, 236 on main and none after.Graph's, and of the getters that sethas_self_edges, 40 fail these tests in dev, 3.7 and 3.6.1, among them the oldtotal_degrees+case and one that takestotal_degrees+alone for a loop, the row or column degrees alone under the old names, each degree case with its comparison loosened or turned around, and each getter's comparison loosened. The other two are equivalent: the row and the column pair looked up under the old names, where the single-key case below them gives the same answer, also without the diagonal.count_element+/-read from a cachedcount_rowwise+/-counts the rows, not the edges;iso_valueraisesKeyErrorafteris_isois cached asFalse;has_negative_diagonaltakes a missingmin_element-for 0, so a negative weight off the diagonal can make it, and with ithas_self_edges,True; and a-scalar reduction read from cachedL-andU-callsMatrix.reduce, which does not exist. Also, the clustering of a single node looks fordegrees+/-in the cache, which keeps them ascount_rowwise+/-, so it never reuses them; that costs time, not answers.