diversity

Contents

diversity#

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

Calculate the diversity of the edge weights of each vertex.

Parameters:
gGraph

Graph to be used. If it is directed, it is treated as undirected.

weightEdgePropertyMap (optional, default: None)

Non-negative edge weights. If not supplied, every edge has unit weight.

vpropVertexPropertyMap (optional, default: None)

Vertex property map to store the values.

Returns:
diversityVertexPropertyMap

A vertex property map with the diversity values.

See also

burt_constraint

Burt’s constraint

Notes

The diversity [eagle-network-2010] of a vertex \(i\) is the normalized Shannon entropy of the weights of its edges,

\[D_i = -\frac{1}{\ln k_i}\sum_{j}p_{ij}\ln p_{ij}, \qquad p_{ij} = \frac{w_{ij}}{\sum_l w_{il}},\]

where \(k_i\) is the degree of \(i\), and the sums are over its edges. It is zero for vertices of degree one, and nan for isolated vertices. Parallel edges are counted separately. It takes time \(O(V + E)\).

References

[eagle-network-2010]

Nathan Eagle, Michael Macy, and Rob Claxton, “Network diversity and economic development”, Science 328, 1029-1031 (2010), DOI: 10.1126/science.1186605 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["lesmis"]
>>> d = gt.diversity(g, g.ep.value)
>>> print(d.a.mean())
0.719176144...

The values can be visualized by drawing the network with vertex colors and sizes given by them, and the edge widths given by the weights:

>>> 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=d, vcmap=cmap,
...               vertex_size=gt.prop_to_size(d, mi=5, ma=15),
...               edge_color=g.ep.value, ecmap=ecmap,
...               edge_pen_width=gt.prop_to_size(g.ep.value, mi=0.5, ma=4),
...               output="diversity-lesmis.pdf")
<...>
../_images/diversity-lesmis.png

Diversity of the vertices of the network of co-appearances of the characters of Les Misérables, with the numbers of co-appearances as edge weights. The vertex colors, from gray to blue, and the vertex sizes increase with the value. The edge colors, from gray to blue, and the edge widths increase with the weights.#