momepy.betweenness_centrality¶
-
momepy.betweenness_centrality(graph, name=
'betweenness', mode='nodes', weight='mm_len', endpoints=True, radius=None, distance=None, normalized=False, verbose=True, **kwargs)[source]¶ Calculates the shortest-path betweenness centrality for nodes. Wrapper around
networkx.betweenness_centralityornetworkx.edge_betweenness_centrality. Betweenness centrality of a node v is the sum of the fraction of all-pairs shortest paths that pass through v\[c_B(v) =\sum_{s,t \in V} \frac{\sigma(s, t|v)}{\sigma(s, t)}\]where V is the set of nodes, \(\sigma(s, t)\) is the number of shortest \((s, t)\)-paths, and \(\sigma(s, t|v)\) is the number of those paths passing through some node v other than s, t. If s = t, \(\sigma(s, t) = 1\), and if v in {s, t}`, \(\sigma(s, t|v) = 0\). Betweenness centrality of an edge e is the sum of the fraction of all-pairs shortest paths that pass through e
\[c_B(e) =\sum_{s,t \in V} \frac{\sigma(s, t|e)}{\sigma(s, t)}\]where V is the set of nodes, \(\sigma(s, t)\) is the number of shortest \((s, t)\)-paths, and \(\sigma(s, t|e)\) is the number of those paths passing through edge e.
Adapted from [Porta et al., 2006].
- Parameters:¶
- graph : networkx.Graph¶
A Graph representing a street network. Ideally generated from GeoDataFrame using
momepy.gdf_to_nx().- name : str, optional¶
The calculated attribute name.
- mode : str, default 'nodes'¶
The mode of betweenness calculation.
'node'for node-based or'edges'for edge-based.- weight : str (default 'mm_len')¶
The attribute holding the weight of edge (e.g. length, angle).
- radius : int¶
Include all neighbors of distance <= radius from
n.- distance : str, optional¶
Use specified edge data key as distance. For example, setting
distance=’weight’will use the edgeweightto measure the distance from the nodenduringego_graphgeneration.- normalized : bool, optional¶
If
Truethe betweenness values are normalized by 2/((n-1)(n-2)), wherenis the number of nodes in a subgraph.- verbose : bool (default True)¶
If
True, shows progress bars in loops and indication of steps.- **kwargs : dict¶
Keyword argument for
networkx.betweenness_centralityornetworkx.edge_betweenness_centrality.
- Returns:¶
netx – A networkx.Graph object.
- Return type:¶
Graph
Examples
>>> network_graph = mm.betweenness_centrality(network_graph)Notes
In case of angular betweenness, implementation is based on “Tasos Implementation”.