Repository navigation
Fix sparse heuristic not applied to diagonal blocks in stochastic_block_model - #8557
Conversation
…ck_model The diagonal block (i==j) case consumed the edges iterator before the sparse/dense branching logic, so the sparse heuristic was never used for diagonal blocks. Remove the premature edge addition so diagonal blocks flow into the same sparse/dense logic as off-diagonal blocks.
855f99d to
0b48a4b
Compare
There was a problem hiding this comment.
Presumably the change in results is a result of the random state changing due to the removal of special handling of the i==j case. I think this is fine, though it's worth noting that this change will have an impact even outside of the sparse codepath as a result. Again this is probably fine, but just pointing it out so folks more familiar with the stochastic block model can take a look and double check!
rossbar
left a comment
There was a problem hiding this comment.
Also - it'd be nice to have a test that illustrates the original issue in the sparse branch (presumably that the sparsity algorithm wasn't being applied to the diagonal blocks) and illustrates the fix.
|
@rossbar use a single-block SBM so the only block is diagonal (i==j). Then run it with sparse=True and sparse=False using the same seed. Since sparse and dense use the RNG differently (geometric skip vs Bernoulli per edge), the edge sets should differ if the sparse heuristic is actually being applied. Before the fix they'd be identical, which is exactly the bug. |
|
Can you add the test you show in the comment to the test file? I think it'd be good to continue to check that. You could reference gh-8557 in a comment so people can find this discussion if needed. Thanks! |
…ck_model (networkx#8557) * Fix sparse heuristic not applied to diagonal blocks in stochastic_block_model The diagonal block (i==j) case consumed the edges iterator before the sparse/dense branching logic, so the sparse heuristic was never used for diagonal blocks. Remove the premature edge addition so diagonal blocks flow into the same sparse/dense logic as off-diagonal blocks. * add specific test that ensures dense and sparse paths differ --------- Co-authored-by: Dan Schult <[email protected]>
fixes #8536
Summary
i==j) case instochastic_block_modelconsumed theedgesiterator before the sparse/dense branching logic, so the sparse heuristic was never used for diagonal blocks.Test plan
test_community.pypass (22/22)test_stochastic_block_modelexpected edge count to match the corrected sparse heuristic behavior