second_order_centrality#
- graph_tool.centrality.second_order_centrality(g, weight=None, vprop=None)[git][source]#
Calculate the second-order centrality of each vertex.
- Parameters:
- g
Graph Graph to be used. It must be connected, and if it is directed, it is treated as undirected.
- weight
EdgePropertyMap(optional, default:None) Edge weights. If not supplied, every edge has unit weight.
- vprop
VertexPropertyMap(optional, default:None) Vertex property map to store the centrality values.
- g
- Returns:
- second_order
VertexPropertyMap A vertex property map with the second-order centrality values.
- second_order
See also
current_flow_betweennessRandom-walk betweenness centrality
kemeny_constantKemeny’s constant
Notes
The second-order centrality [kermarrec-second-2011] of a vertex is the standard deviation of the times between the successive visits of a random walk to it. The walk is made to have a uniform stationary distribution by adding to every vertex a self-loop with weight \(d_{\max}-d_v\), where \(d_v\) is its weighted degree (with the existing self-loops counted once) and \(d_{\max}\) the largest one, so that its transition matrix \(\boldsymbol P = (\boldsymbol A + d_{\max}\boldsymbol I - \boldsymbol D)/d_{\max}\), where \(A_{ij}\) is the total weight of the edges between \(i\) and \(j\) and \(\boldsymbol D\) the diagonal matrix of the \(d_v\), is doubly stochastic; the vertices that are visited less regularly, such as those that connect different modules, have larger values, i.e. they are more central.
The mean of the squared return times follows from the mean first passage times, and with the fundamental matrix \(\boldsymbol Z = (\boldsymbol I - \boldsymbol P + \boldsymbol 1\boldsymbol 1^\top/n)^{-1}\) of the walk the centrality is
\[SOC(v) = \sqrt{2n^2Z_{vv} - n(n+1)}.\]The matrix is inverted once, in time \(O(V^3)\) and with \(O(V^2)\) memory.
References
[kermarrec-second-2011]Anne-Marie Kermarrec, Erwan Le Merrer, Bruno Sericola, and Gilles Trédan, “Second order centrality: Distributed assessment of nodes criticity in complex networks”, Computer Communications 34, 619-628 (2011), DOI: 10.1016/j.comcom.2010.06.007 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["karate"] >>> soc = gt.second_order_centrality(g) >>> print(soc.a.argmin(), soc.a.min()) 33 49.209231728...
The values can be visualized by drawing the network with vertex colors and sizes given by them:
>>> cmap = matplotlib.colors.LinearSegmentedColormap.from_list( ... "gray-blue", ["#d9d9d9", "#7dabd1"]) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=soc, vcmap=cmap, ... vertex_size=gt.prop_to_size(soc, mi=5, ma=15), ... output="second_order_centrality-karate.pdf") <...>
Second-order centrality of the vertices of Zachary’s karate club network. The vertex colors, from gray to blue, and the vertex sizes increase with the value.#