katz_centrality#
- katz_centrality(G, alpha=0.1, beta=1.0, max_iter=1000, tol=1e-06, nstart=None, normalized=True, weight=None)[source]#
Compute the Katz centrality for the nodes of the graph G.
Katz centrality computes the centrality for a node based on the centrality of its neighbors. It is a generalization of the eigenvector centrality. The Katz centrality for node \(i\) is
\[x_i = \alpha \sum_{j} A_{ij} x_j + \beta,\]where \(A\) is the adjacency matrix of graph G with eigenvalues \(\lambda\).
The parameter \(\beta\) controls the initial centrality and
\[\alpha < \frac{1}{\lambda_{\max}}.\]Katz centrality computes the relative influence of a node within a network by measuring the number of the immediate neighbors (first degree nodes) and also all other nodes in the network that connect to the node under consideration through these immediate neighbors.
Extra weight can be provided to immediate neighbors through the parameter \(\beta\). Connections made with distant neighbors are, however, penalized by an attenuation factor \(\alpha\) which should be strictly less than the inverse largest eigenvalue of the adjacency matrix in order for the Katz centrality to be computed correctly. More information is provided in [1].
- Parameters:
- Ggraph
A NetworkX graph.
- alphafloat, optional (default=0.1)
Attenuation factor
- betascalar or dictionary, optional (default=1.0)
Weight attributed to the immediate neighborhood. If not a scalar, the dictionary must have a value for every node.
- max_iterinteger, optional (default=1000)
Maximum number of iterations in power method.
- tolfloat, optional (default=1.0e-6)
Error tolerance used to check convergence in power method iteration.
- nstartdictionary, optional
Starting value of Katz iteration for each node.
- normalizedbool, optional (default=True)
If True normalize the resulting values.
- weightNone or string, optional (default=None)
If None, all edge weights are considered equal. Otherwise holds the name of the edge attribute used as weight. In this measure the weight is interpreted as the connection strength.
- Returns:
- nodesdictionary
Dictionary of nodes with Katz centrality as the value.
- Raises:
- NetworkXError
If the parameter
beta
is not a scalar but lacks a value for at least one node- PowerIterationFailedConvergence
If the algorithm fails to converge to the specified tolerance within the specified number of iterations of the power iteration method.
See also
Notes
Katz centrality was introduced by [2].
This algorithm it uses the power method to find the eigenvector corresponding to the largest eigenvalue of the adjacency matrix of
G
. The parameteralpha
should be strictly less than the inverse of largest eigenvalue of the adjacency matrix for the algorithm to converge. You can usemax(nx.adjacency_spectrum(G))
to get \(\lambda_{\max}\) the largest eigenvalue of the adjacency matrix. The iteration will stop aftermax_iter
iterations or an error tolerance ofnumber_of_nodes(G) * tol
has been reached.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, first reverse the graph with
G.reverse()
.References
[1]Mark E. J. Newman: Networks: An Introduction. Oxford University Press, USA, 2010, p. 720.
[2]Leo Katz: A New Status Index Derived from Sociometric Index. Psychometrika 18(1):39–43, 1953 https://link.springer.com/content/pdf/10.1007/BF02289026.pdf
Examples
>>> import math >>> G = nx.path_graph(4) >>> phi = (1 + math.sqrt(5)) / 2.0 # largest eigenvalue of adj matrix >>> centrality = nx.katz_centrality(G, 1 / phi - 0.01) >>> for n, c in sorted(centrality.items()): ... print(f"{n} {c:.2f}") 0 0.37 1 0.60 2 0.60 3 0.37 ----
Additional backends implement this function
- cugraphGPU-accelerated backend.
nstart
isn’t used (but is checked), andnormalized=False
is not supported.- Additional parameters:
- dtypedtype or None, optional
The data type (np.float32, np.float64, or None) to use for the edge weights in the algorithm. If None, then dtype is determined by the edge values.
graphblas : OpenMP-enabled sparse linear algebra backend.