kemeny_constant#
- graph_tool.centrality.kemeny_constant(g, weight=None)[git][source]#
Return the Kemeny constant of the random walk on the graph.
- Parameters:
- g
Graph Connected undirected graph to be used.
- weight
EdgePropertyMap(optional, default:None) Edge weights. If not given, every edge has unit weight.
- g
- Returns:
- K
float The Kemeny constant.
- K
See also
kirchhoff_indexSum of the effective resistances
second_order_centralityCentrality based on random-walk return times
graph_tool.spectral.transitionTransition matrix
Notes
The Kemeny constant [kemeny-finite-1960] is the expected number of steps a random walk takes to reach a target vertex drawn from the stationary distribution, which does not depend on the starting vertex. It is given by
\[K = \sum_{k=2}^{V}\frac{1}{1-\lambda_k},\]where \(\lambda_k\) are the eigenvalues of the transition matrix \(P = D^{-1}A\) other than \(\lambda_1 = 1\), which are those of the symmetric matrix \(D^{-1/2}AD^{-1/2}\). Here \(A_{ij}\) is the total weight of the edges between \(i\) and \(j\) (with self-loops counted twice in \(A_{ii}\), see
adjacency()), and \(D\) is the diagonal matrix of the weighted degrees \(d_i = \sum_jA_{ij}\), which must be positive. They are computed with a dense eigensolver, in time \(O(V^3)\).References
[kemeny-finite-1960]John G. Kemeny and J. Laurie Snell, “Finite Markov Chains”, Van Nostrand (1960).
Examples
>>> g = gt.collection.data["karate"] >>> print(gt.kemeny_constant(g)) 42.8866827...