Repository navigation
Update approx current_flow betweenness to use k directly - #8007
Conversation
| @@ -119,10 +124,13 @@ def approximate_current_flow_betweenness_centrality( | |||
| nb = (n - 1.0) * (n - 2.0) # normalization factor | |||
| cstar = n * (n - 1) / nb | |||
| l = 1 # parameter in approximation, adjustable | |||
There was a problem hiding this comment.
This l is also odd. Should we make it a parameter?
There was a problem hiding this comment.
If we do make it a parameter (and even if we don't) can we change this variable name? Even spelling el is easier to read than l which can look like a capital i or a 1 depending on font.
Would also be fine with me to remove that parameter. It currently has no effect and it is not clear what it is doing or how that affects things.
There was a problem hiding this comment.
Thanks for putting this together @mrecachinas - seeing the changes to the test suite make me less enthused about the "get rid of epsilon" approach. Given this, I'm leaning more towards docstring updates as the best way to resolve #6188: essentially improving the description for both epsilon and kmax and mentioning the relationship (as you had originally proposed @mrecachinas !). WDYT?
Also on an unrelated note - I see the old normalization factor (see L119) - pinging @eriknw for an extra set of eyes given the work to fix bc in #7908 . There's no endpoints in this case, but there is k!
Oh boy! I'll need to read up on this algorithm to have any degree of confidence. But, if this is similar to regular BC, the normalization might be something like Also, there may be nuance when |
| solver="full", | ||
| epsilon=0.5, | ||
| kmax=10000, | ||
| k=None, | ||
| seed=None, |
There was a problem hiding this comment.
Let's make the new keyword arg keyword only. And we should have seed keyword only also -- because it changes position in the function signature when we replace epsilon and kmax with k. So, anyone using position args will need to change their code -- and they should make the call use keywords.
So, I think something like this should work:
*,
k=None,
seed=None,
Also -- changing the argument structure will require that the random_state decorator get updated too.
@py_random_state("seed")|
I think this is different than the other BC function. First and most importantly, this doesn't have the |
|
Happy to remove my most recent changes (saw them after @dschult's review). I reverted the change to |
amcandio
left a comment
There was a problem hiding this comment.
Looks good to me. Many of the inputs such as n, sample size of epsilon could cause zero division errors. We might want to add some validations on the input so the error is clear for the user
|
Not sure why the label check is failing. Should it have been auto-added? |
|
Tha label has to be added manually by a core dev. (the name says "Labels / reviewer label?" which is not clear partly cuz it has a length restriction. But I think/hope that clicking on "view details" give a better message. :) Anyway, this just means one of us should look at your PR. :) |
|
@dschult How is this one looking? |
rossbar
left a comment
There was a problem hiding this comment.
This looks like the right approach to me. One comment about the kwarg-only specification but otherwise looks good!
Schefflera-Arboricola
left a comment
There was a problem hiding this comment.
Thanks @mrecachinas ! Consider adding tests for the new sample_weigh parameter and the error messages.
|
@dschult anything else remaining here? |
rossbar
left a comment
There was a problem hiding this comment.
LGTM, thanks @mrecachinas
I left a couple final docstring formatting nits. Normally I'd just push them up myself but it looks like you have the "maintainers may edit this branch" button disabled. Sorry for the nits!
Co-authored-by: Ross Barnowski <[email protected]>
dschult
left a comment
There was a problem hiding this comment.
This looks good. I've suggested a linting fix below. And I approve this PR once we get a green check. :)
* Update approx current_flow betweenness to use k directly Fix latex * Revert "Update approx current_flow betweenness to use k directly" This reverts commit 88acca7. * Update docstring for epsilon * Extract `l` to a param and rename to `sample_weight` * Address review feedback on param arrangement * Add some param validations * Move the kmax check below other checks * Reorder the kwarg-only delimiter * Add tests for sample_weight and errors * Make approximate_current_flow_betweenness_centrality match other centrality algorithms * Add tests for centrality edge cases * Apply suggestions from code review Co-authored-by: Ross Barnowski <[email protected]> * Update networkx/algorithms/centrality/current_flow_betweenness.py --------- Co-authored-by: Mridul Seth <[email protected]> Co-authored-by: Ross Barnowski <[email protected]> Co-authored-by: Dan Schult <[email protected]>
Rough pass at a fix for #6188.