graspologic-org / graspologic

Python package for graph statistics
https://graspologic-org.github.io/graspologic/
MIT License
780 stars 142 forks source link

Bug fix for SBM estimator with some size-one block and loops=False #1056

Closed bokveizen closed 4 months ago

bokveizen commented 8 months ago

Reference Issues/PRs

See Issue #1055

What does this implement/fix? Briefly explain your changes.

Expected Behavior

Any size-1 block should just have zero probability.

Actual Behavior

In sbm_estimators.py, _calculate_block_p calls _calculate_p, which divides zero when block.size = 0. This can happen when some block has size one and loops=False is used.

Adding

if block.size == 0:
    continue

before Line 519 of graspologic/graspologic/models/sbm_estimators.py should do the trick.

bdpedigo commented 6 months ago

thanks for this @bokveizen - right now some tests are failing due to unrelated reasons, once I have a fix for that I'll have a look at this. but at a glance, it seems perfect

bdpedigo commented 4 months ago

if you are still interested, you could merge dev into this branch, and i believe tests will pass now