Skip to content

Commit

Permalink
Fixed an error in the documentation of the katz centrality (networkx#…
Browse files Browse the repository at this point in the history
…6294)

* fixed a sentence in the documentation relating the parameter beta and the eigenvector centrality

* choose ev-cent docs wording, fix formula, remove comment

---------

Co-authored-by: Dan Schult <[email protected]>
  • Loading branch information
BrunoBaldissera and dschult authored Oct 31, 2023
1 parent 5146f98 commit 6ced50a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions networkx/algorithms/centrality/katz.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def katz_centrality(
beta : scalar or dictionary, optional (default=1.0)
Weight attributed to the immediate neighborhood. If not a scalar, the
dictionary must have an value for every node.
dictionary must have a value for every node.
max_iter : integer, optional (default=1000)
Maximum number of iterations in power method.
Expand Down Expand Up @@ -128,11 +128,11 @@ def katz_centrality(
The iteration will stop after ``max_iter`` iterations or an error tolerance of
``number_of_nodes(G) * tol`` has been reached.
When $\alpha = 1/\lambda_{\max}$ and $\beta=0$, Katz centrality is the same
as eigenvector centrality.
For strongly connected graphs, as $\alpha \to 1/\lambda_{\max}$, and $\beta > 0$,
Katz centrality approaches the results for eigenvector centrality.
For directed graphs this finds "left" eigenvectors which corresponds
to the in-edges in the graph. For out-edges Katz centrality
to the in-edges in the graph. For out-edges Katz centrality,
first reverse the graph with ``G.reverse()``.
References
Expand Down Expand Up @@ -183,7 +183,6 @@ def katz_centrality(
# normalize vector
try:
s = 1.0 / math.hypot(*x.values())
# this should never be zero?
except ZeroDivisionError:
s = 1.0
else:
Expand Down Expand Up @@ -289,11 +288,11 @@ def katz_centrality_numpy(G, alpha=0.1, beta=1.0, normalized=True, weight=None):
You can use ``max(nx.adjacency_spectrum(G))`` to get $\lambda_{\max}$ the largest
eigenvalue of the adjacency matrix.
When $\alpha = 1/\lambda_{\max}$ and $\beta=0$, Katz centrality is the same
as eigenvector centrality.
For strongly connected graphs, as $\alpha \to 1/\lambda_{\max}$, and $\beta > 0$,
Katz centrality approaches the results for eigenvector centrality.
For directed graphs this finds "left" eigenvectors which corresponds
to the in-edges in the graph. For out-edges Katz centrality
to the in-edges in the graph. For out-edges Katz centrality,
first reverse the graph with ``G.reverse()``.
References
Expand Down

0 comments on commit 6ced50a

Please sign in to comment.