edge_reciprocity#
- graph_tool.topology.edge_reciprocity(g, weight=None, self_loops=False)[source]#
Calculate the edge reciprocity of the graph.
- Parameters:
- g
Graph Graph to be used edges.
- weight
EdgePropertyMap(optional, default:None) Edge weights.
- self_loops
bool(optional, default:False) Whether self-loops should be considered.
- g
- Returns:
- reciprocityfloat
The reciprocity value.
Notes
The edge [reciprocity] is defined as \(E^\leftrightarrow/E\), where \(E^\leftrightarrow\) and \(E\) are the number of bidirectional and all edges in the graph, respectively. If
self_loops is False, self-loops are not considered in these counds.If weights are provided, the number of edges is replaced by the sum of edge weights.
The algorithm runs with complexity \(O(E + V)\).
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
[reciprocity]S. Wasserman and K. Faust, “Social Network Analysis”. (Cambridge University Press, Cambridge, 1994)
[lopez-reciprocity-2007]Gorka Zamora-López, Vinko Zlatić, Changsong Zhou, Hrvoje Štefančić, and Jürgen Kurths “Reciprocity of networks with degree correlations and arbitrary degree sequences”, Phys. Rev. E 77, 016106 (2008) DOI: 10.1103/PhysRevE.77.016106 [sci-hub, @tor], arXiv: 0706.3372
Examples
>>> g = gt.Graph() >>> g.add_vertex(2) <...> >>> g.add_edge(g.vertex(0), g.vertex(1)) <...> >>> gt.edge_reciprocity(g) 0.0 >>> g.add_edge(g.vertex(1), g.vertex(0)) <...> >>> gt.edge_reciprocity(g) 1.0 >>> g = gt.collection.data["pgp-strong-2009"] >>> gt.edge_reciprocity(g) 0.692196963163...