Warning
This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
katz_centrality_numpy¶

katz_centrality_numpy
(G, alpha=0.1, beta=1.0, normalized=True, weight='weight')[source]¶ Compute the Katz centrality for the graph G.
Katz centrality is related to eigenvalue centrality and PageRank. The Katz centrality for node \(i\) is
\[x_i = \alpha \sum_{j} A_{ij} x_j + \beta,\]where \(A\) is the adjacency matrix of the graph G with eigenvalues \(\lambda\).
The parameter \(\beta\) controls the initial centrality and
\[\begin{split}\alpha < \frac{1}{\lambda_{max}}.\end{split}\]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 [R194] .
Parameters: G : graph
A NetworkX graph
alpha : float
Attenuation factor
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.
normalized : bool
If True normalize the resulting values.
weight : None or string, optional
If None, all edge weights are considered equal. Otherwise holds the name of the edge attribute used as weight.
Returns: nodes : dictionary
Dictionary of nodes with Katz centrality as the value.
See also
katz_centrality
,eigenvector_centrality_numpy
,eigenvector_centrality
,pagerank
,hits
Notes
This algorithm uses a direct linear solver to solve the above equation. The constant alpha should be strictly less than the inverse of largest eigenvalue of the adjacency matrix for there to be a solution. When \(\alpha = 1/\lambda_{max}\) and \(\beta=1\) Katz centrality is the same as eigenvector centrality.
For directed graphs this finds “left” eigenvectors which corresponds to the inedges in the graph. For outedges Katz centrality first reverse the graph with G.reverse().
References
[R194] (1, 2) M. Newman, Networks: An Introduction. Oxford University Press, USA, 2010, p. 720. Examples
>>> import math >>> G = nx.path_graph(4) >>> phi = (1+math.sqrt(5))/2.0 # largest eigenvalue of adj matrix >>> centrality = nx.katz_centrality_numpy(G,1/phi) >>> for n,c in sorted(centrality.items()): ... print("%d %0.2f"%(n,c)) 0 0.37 1 0.60 2 0.60 3 0.37