-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in documentation of katz_centrality? #6279
Comments
I guess you are right! It's nice that you even found the probable origin of this. Since the |
Thanks for this! And for the detailed numerical analysis. So I see two possible fixes -- the suggest correction to the doc_string of \beta=1, or the correction \beta >= 0. We could also be more precise and say that this result holds in the limit as alpha -> 1/lambda_max. But I'm not sure that is causing any confusion. It is the incorrect value of beta=0 that is causing confusion. Also, the sentence doesn't say this is the only case where Katz Centrality matches Eigenvector Centrality, so I'm fine with the suggested language here (and in the @BrunoBaldissera PR). Thanks for the excuse to take a romp down the lane of linear algebra and infinite series. :) Let's fix the doc_string! |
Current Behavior
The docs for katz centrality state:
networkx/networkx/algorithms/centrality/katz.py
Lines 131 to 132 in f20ba5f
The value for
beta
here was changed from 1 to 0 a long time ago, in this commit:b33ebd4#diff-fd4d6088095ce7547e9e07adf7326d408cb55f6ef43d47aeba7f53d405b44b8dL259
Which I think may have been an incorrect response to issue #1247.
Expected Behavior
I believe that the previous note with
beta=1
was actually correct. For what it's worth, here are the relevant parts of the implementation in current master:networkx/networkx/algorithms/centrality/katz.py
Lines 153 to 166 in 6971d84
If we assume that
nstart
is left to the default ofNone
, we see thatx
starts out being all zeroes. But then, unlessbeta
is non-zero for at least some of the nodes, it is impossible for any element ofx
to ever become non-zero:networkx/networkx/algorithms/centrality/katz.py
Lines 168 to 177 in 6971d84
In other words, it looks to me like if
nstart=None
andbeta=0
then Katz centrality will always produce an array of zeroes. And in particular, even ifalpha
is (ever so slightly less than)1/lambda_max
it will not resemble the eigenvector centrality.Steps to Reproduce
(EDITED) Figured I should add an example, adapted from the example in the docs:
Environment
Python version: 3.11
NetworkX version: 3.0rc
The text was updated successfully, but these errors were encountered: