betweenness

Contents

betweenness#

graph_tool.centrality.betweenness(g, pivots=None, vprop=None, eprop=None, weight=None, norm=True, cutoff=None, sources=None, targets=None)[git][source]#

Calculate the betweenness centrality for each vertex and edge.

Parameters:
gGraph

Graph to be used.

pivotslist or numpy.ndarray (optional, default: None)

If provided, the betweenness will be estimated using the vertices in this list as pivots. If the list contains all nodes (the default) the algorithm will be exact, and if the vertices are randomly chosen the result will be an unbiased estimator.

vpropVertexPropertyMap (optional, default: None)

Vertex property map to store the vertex betweenness values.

epropEdgePropertyMap (optional, default: None)

Edge property map to store the edge betweenness values.

weightEdgePropertyMap (optional, default: None)

Edge property map corresponding to the weight value of each edge.

normbool (optional, default: True)

Whether or not the betweenness values should be normalized.

cutofffloat (optional, default: None)

If given, only the shortest paths of length at most cutoff are considered (range-limited betweenness).

sourceslist or numpy.ndarray (optional, default: None)

If given, only the shortest paths that start at these vertices are considered. If only targets is given, all vertices are sources.

targetslist or numpy.ndarray (optional, default: None)

If given, only the shortest paths that end at these vertices are considered. If only sources is given, all vertices are targets.

Returns:
vertex_betweennessVertexPropertyMap

A vertex property map with the vertex betweenness values.

edge_betweennessEdgePropertyMap

An edge property map with the edge betweenness values.

See also

central_point_dominance

Central point dominance of the graph

pagerank

PageRank centrality

eigentrust

Eigentrust centrality

eigenvector

Eigenvector centrality

hits

Authority and hub centralities

trust_transitivity

Pervasive trust transitivity

load_centrality

Load centrality

current_flow_betweenness

Random-walk betweenness centrality

group_betweenness

Betweenness of a group of vertices

Notes

Betweenness centrality of a vertex \(C_B(v)\) is defined as,

\[C_B(v)= \sum_{s \neq v \neq t \in V \atop s \neq t} \frac{\sigma_{st}(v)}{\sigma_{st}}\]

where \(\sigma_{st}\) is the number of shortest paths from s to t, and \(\sigma_{st}(v)\) is the number of shortest paths from s to t that pass through a vertex \(v\). This may be normalised by dividing through the number of pairs of vertices not including v, which is \((n-1)(n-2)/2\), for undirected graphs, or \((n-1)(n-2)\) for directed ones.

The algorithm used here is defined in [brandes-faster-2001], and has a complexity of \(O(VE)\) for unweighted graphs and \(O(VE + V(V+E)\log V)\) for weighted graphs. The space complexity is \(O(V+E)\).

If the pivots parameter is given, the complexity will be instead \(O(PE)\) for unweighted graphs and \(O(PE + P(V+E)\log V)\) for weighted graphs, where \(P\) is the number of pivot vertices.

If cutoff is given, only the pairs \(s, t\) at a distance of at most cutoff contribute to the sum [brandes-variants-2008], and every search stops at this distance, so that the running time depends only on the sizes of the neighborhoods of that radius. The normalization is the same as without the cutoff.

If sources or targets are given, the sum is restricted to the pairs with \(s\) in the sources and \(t\) in the targets [brandes-variants-2008], and for edges the endpoints are included, i.e. the paths from \(s\) to \(t\) contribute to their first and last edges. For undirected graphs, the sum over these ordered pairs is divided by two, so that both options together with all the vertices give the same values as without them, and the normalization is also the same as without them (for the edges, \(n(n-1)\) for directed graphs and \(n(n-1)/2\) for undirected ones). They cannot be combined with pivots, and the complexity is \(O(SE)\) for unweighted graphs and \(O(SE + S(V+E)\log V)\) for weighted graphs, where \(S\) is the number of sources.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

References

[brandes-faster-2001]

U. Brandes, “A faster algorithm for betweenness centrality”, Journal of Mathematical Sociology, 2001, DOI: 10.1080/0022250X.2001.9990249 [sci-hub, @tor]

[brandes-centrality-2007]

U. Brandes, C. Pich, “Centrality estimation in large networks”, Int. J. Bifurcation Chaos 17, 2303 (2007). DOI: 10.1142/S0218127407018403 [sci-hub, @tor]

[brandes-variants-2008] (1,2)

Ulrik Brandes, “On variants of shortest-path betweenness centrality and their generic computation”, Social Networks 30, 136-145 (2008), DOI: 10.1016/j.socnet.2007.11.001 [sci-hub, @tor]

[adamic-polblogs]

L. A. Adamic and N. Glance, “The political blogosphere and the 2004 US Election”, in Proceedings of the WWW-2005 Workshop on the Weblogging Ecosystem (2005). DOI: 10.1145/1134271.1134277 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["polblogs"]
>>> g = gt.GraphView(g, vfilt=gt.label_largest_component(g))
>>> vp, ep = gt.betweenness(g)
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=vp,
...               vertex_size=gt.prop_to_size(vp, mi=5, ma=15),
...               edge_pen_width=gt.prop_to_size(ep, mi=0.5, ma=5),
...               vcmap=matplotlib.cm.gist_heat,
...               vorder=vp, output="polblogs_betweenness.pdf")
<...>
../_images/polblogs_betweenness.png

Betweenness values of a political blogs network of [adamic-polblogs].#