eigenvector_centrality#
- eigenvector_centrality(G, max_iter=100, tol=1e-06, nstart=None, weight=None)[source]#
Compute the eigenvector centrality for the graph
G
.Eigenvector centrality computes the centrality for a node based on the centrality of its neighbors. The eigenvector centrality for node \(i\) is the \(i\)-th element of the vector \(x\) defined by the equation
\[Ax = \lambda x\]where \(A\) is the adjacency matrix of the graph
G
with eigenvalue \(\lambda\). By virtue of the Perron–Frobenius theorem, there is a unique solution \(x\), all of whose entries are positive, if \(\lambda\) is the largest eigenvalue of the adjacency matrix \(A\) ([2]).- Parameters:
- Ggraph
A networkx graph
- max_iterinteger, optional (default=100)
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 (default=None)
Starting value of eigenvector iteration for each node.
- 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 eigenvector centrality as the value.
- Raises:
- NetworkXPointlessConcept
If the graph
G
is the null graph.- NetworkXError
If each value in
nstart
is zero.- 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
The measure was introduced by [1] and is discussed in [2].
The power iteration method is used to compute the eigenvector and convergence is not guaranteed. Our method stops after
max_iter
iterations or when the change in the computed vector between two iterations is smaller than an error tolerance ofG.number_of_nodes() * tol
. This implementation uses (\(A + I\)) rather than the adjacency matrix \(A\) because it shifts the spectrum to enable discerning the correct eigenvector even for networks with multiple dominant eigenvalues.For directed graphs this is “left” eigenvector centrality which corresponds to the in-edges in the graph. For out-edges eigenvector centrality first reverse the graph with
G.reverse()
.References
[1]Phillip Bonacich. “Power and Centrality: A Family of Measures.” American Journal of Sociology 92(5):1170–1182, 1986 <http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf>
Examples
>>> G = nx.path_graph(4) >>> centrality = nx.eigenvector_centrality(G) >>> sorted((v, f"{c:0.2f}") for v, c in centrality.items()) [(0, '0.37'), (1, '0.60'), (2, '0.60'), (3, '0.37')]