kemeny_constant

kemeny_constant#

graph_tool.centrality.kemeny_constant(g, weight=None)[git][source]#

Return the Kemeny constant of the random walk on the graph.

Parameters:
gGraph

Connected undirected graph to be used.

weightEdgePropertyMap (optional, default: None)

Edge weights. If not given, every edge has unit weight.

Returns:
Kfloat

The Kemeny constant.

See also

kirchhoff_index

Sum of the effective resistances

second_order_centrality

Centrality based on random-walk return times

graph_tool.spectral.transition

Transition 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...