current_flow_betweenness#
- graph_tool.centrality.current_flow_betweenness(g, weight=None, vprop=None, eprop=None, norm=True, sources=None, targets=None, epsilon=None)[git][source]#
Compute the current-flow (random-walk) betweenness of the vertices and edges.
- Parameters:
- g
Graph Graph to be used. If it is directed, it is treated as undirected.
- weight
EdgePropertyMap(optional, default:None) Edge conductances. If not supplied, every edge has unit conductance.
- vprop
VertexPropertyMap(optional, default:None) Vertex property map to store the vertex betweenness values.
- eprop
EdgePropertyMap(optional, default:None) Edge property map to store the edge betweenness values.
- norm
bool(optional, default:True) Whether or not the betweenness values should be normalized.
- sourceslist or
numpy.ndarray(optional, default:None) If given, only the currents sent from these vertices are considered. If only
targetsis given, all vertices are sources.- targetslist or
numpy.ndarray(optional, default:None) If given, only the currents sent to these vertices are considered. If only
sourcesis given, all vertices are targets.- epsilon
float(optional, default:None) If given, the betweenness is estimated from a sample of random pairs of vertices, with an absolute error of the normalized values of at most
epsilonwith high probability. This cannot be combined withsourcesortargets.
- g
- Returns:
- vertex_betweenness
VertexPropertyMap Vertex property map with the vertex betweenness values.
- edge_betweenness
EdgePropertyMap Edge property map with the edge betweenness values.
- vertex_betweenness
See also
betweennessShortest-path betweenness centrality
current_flow_closenessCurrent-flow closeness centrality
communicability_betweennessWalk-based betweenness centrality
effective_resistanceEffective resistance between vertices
Notes
The current-flow betweenness [newman-measure-2005] [brandes-centrality-2005] counts the flow through each vertex and edge when a unit current is sent between every pair of vertices \(s,t\), with the edges as resistors of conductance \(w_e\). Unlike the shortest-path betweenness (see
betweenness()), it accounts for all paths, and is equivalent to counting the net passages of a random walk from \(s\) to \(t\). The edge betweenness is\[c_e = \sum_{s<t} |I_e^{(st)}|,\]where \(I_e^{(st)} = w_e(p^{(st)}_a - p^{(st)}_b)\) is the current along the edge \(e = \{a, b\}\) of conductance \(w_e\), given by the potentials \(\boldsymbol p^{(st)} = \boldsymbol L^{+}(\boldsymbol e_s - \boldsymbol e_t)\) (see
effective_resistance()for the Laplacian \(\boldsymbol L\)), so that parallel edges carry separate currents and self-loops carry none, and the vertex betweenness is\[c_v = \sum_{s<t,\, v\ne s,t} \frac{1}{2}\sum_{e\ni v} |I_e^{(st)}|.\]If
norm == True, the values are divided by the number of pairs involved, \((n-1)(n-2)/2\) for vertices and \(n(n-1)/2\) for edges, where \(n\) is the size of the component of the vertex or edge. Pairs in different components carry no current.The algorithm of [brandes-centrality-2005] is used: the currents follow from the inverse of the Laplacian (see
effective_resistance()), and the sum over pairs for each edge from sorting the potential differences, in time \(O(EV\log V)\) after the inversion, and \(O(V^2)\) memory.If
sourcesortargetsare given, the sums are restricted to the ordered pairs \((s,t)\) with \(s\) in the sources and \(t\) in the targets, and divided by two, so that both options together with all the vertices give the same values as without them; the normalization is also the same. The sums are computed by sorting the potential differences of the sources and targets of each edge, in time \(O(E(S+T)\log(S+T))\) after the inversion. The pairs in which the vertex is an endpoint are excluded from the vertex values, as for the other pairs.If
epsilonis given, the approximation of [brandes-centrality-2005] is used: the currents are computed for \(k=\lceil (c^*/\epsilon)^2\ln n\rceil\) random pairs of vertices of each component, where \(c^*=n/(n-2)\), and the betweenness values are estimated from their averages. This requires only the sparse LU factorization of the Laplacian and \(k\) solutions of linear systems, in time \(O(k(V + E))\) after the factorization (if its fill-in is small), instead of the full inverse. The random pairs are drawn from the random number generator of graph-tool (seeseed_rng()).References
[newman-measure-2005]M. E. J. Newman, “A measure of betweenness centrality based on random walks”, Social Networks 27, 39-54 (2005), DOI: 10.1016/j.socnet.2004.11.009 [sci-hub, @tor], arXiv: cond-mat/0309045
Examples
>>> g = gt.collection.data["karate"] >>> vb, eb = gt.current_flow_betweenness(g) >>> print(vb.a.argmax(), vb.a.max()) 0 0.486387208...
The betweenness can also be estimated from a sample of random pairs, or restricted to the currents between two groups of vertices, for example
>>> gt.seed_rng(42) >>> vb, eb = gt.current_flow_betweenness(g, epsilon=0.1) >>> print(vb.a.argmax(), vb.a.max()) 0 0.493141831... >>> vb, eb = gt.current_flow_betweenness(g, sources=[0, 1, 2], ... targets=[32, 33], norm=False) >>> print(vb.a.argmax(), vb.a.max()) 2 0.665614381...
The vertex and edge values of all pairs can be visualized by drawing the network with colors and sizes given by them:
>>> vb, eb = gt.current_flow_betweenness(g) >>> cmap = matplotlib.colors.LinearSegmentedColormap.from_list( ... "gray-blue", ["#d9d9d9", "#7dabd1"]) >>> ecmap = matplotlib.colors.LinearSegmentedColormap.from_list( ... "gray-blue", ["#d9d9d9", "#377eb8"]) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vb, vcmap=cmap, ... vertex_size=gt.prop_to_size(vb, mi=5, ma=15), ... edge_color=eb, ecmap=ecmap, ... edge_pen_width=gt.prop_to_size(eb, mi=0.5, ma=4), ... output="current_flow_betweenness-karate.pdf") <...>
Current-flow betweenness of the vertices and edges of Zachary’s karate club network. The vertex colors, from gray to blue, and the vertex sizes increase with the vertex values, and the edge colors and widths with the edge values.#