edge_reciprocity

edge_reciprocity#

graph_tool.structure.edge_reciprocity(g, weight=None, self_loops=False, kind='graph')[git][source]#

Calculate the edge reciprocity of the graph.

Parameters:
gGraph

Graph to be used.

weightEdgePropertyMap (optional, default: None)

Edge weights.

self_loopsbool (optional, default: False)

Whether self-loops should be considered.

kindstr (optional, default: "graph")

If "graph", the reciprocity of the whole graph is returned; if "vertex" or "edge", that of every vertex or edge.

Returns:
reciprocityfloat, VertexPropertyMap, or EdgePropertyMap

The reciprocity value, or the values of the vertices or edges.

See also

graph_tool.clustering.dyad_census

Counts of the dyad types

graph_tool.clustering.triad_census

Counts of the triad types

graph_tool.correlations.assortativity

Degree assortativity coefficient

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 counts.

If weights are provided, the number of edges is replaced by the sum of edge weights.

With \(W_{uv}\) the total weight of the edges from \(u\) to \(v\), the reciprocity of a vertex \(v\) (kind == "vertex") is

\[r_v = \frac{2\sum_u \min(W_{vu}, W_{uv})}{\sum_u W_{vu} + \sum_u W_{uv}},\]

which for unweighted graphs without parallel edges is the fraction of the in- and out-neighbors of \(v\) connected to it in both directions, and that of an edge \((u, v)\) (kind == "edge") is \(\min(W_{uv}, W_{vu})/W_{uv}\), so that the reciprocity of the graph is the weighted average of the edge values. Vertices without edges, and excluded self-loops, get the value nan.

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...
>>> r = gt.edge_reciprocity(g, kind="vertex")
>>> print(np.nanmean(r.fa))
0.705471920296...