reciprocity

reciprocity(G, nodes=None)[source]

Compute the reciprocity in a directed graph.

The reciprocity of a directed graph is defined as the ratio of the number of edges pointing in both directions to the total number of edges in the graph. Formally, \(r = |{(u,v) \in G|(v,u) \in G}| / |{(u,v) \in G}|\).

The reciprocity of a single node u is defined similarly, it is the ratio of the number of edges in both directions to the total number of edges attached to node u.

Parameters
Ggraph

A networkx directed graph

nodescontainer of nodes, optional (default=whole graph)

Compute reciprocity for nodes in this container.

Returns
outdictionary

Reciprocity keyed by node label.

Notes

The reciprocity is not defined for isolated nodes. In such cases this function will return None.