({{, (RefLink[GraphReciprocity, paclet:ref/GraphReciprocity])[g] 
gives the reciprocity of a graph g.}, {, (RefLink[GraphReciprocity, paclet:ref/GraphReciprocity])[{v->w,…}]
uses rules v->w to specify the graph g.}})

OpenersNotesSection(Spacer1)Details and Options

The reciprocity of a graph g is the fraction of reciprocal edges over all edges of g.

For a directed graph, the edges u->v and v->u are reciprocal and form a cycle of length 2.

For an undirected graph, all edges are reciprocal.

(RefLink[GraphReciprocity, paclet:ref/GraphReciprocity]) works with undirected graphs, directed graphs, and weighted graphs.

OpenersPrimaryExamplesSection(Spacer1)Examples  (14)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Compute the reciprocity of a directed graph:

GraphReciprocity[]

Distribution of graph reciprocity:

Histogram[GraphReciprocity/@RandomGraph[{10,20},99,DirectedEdges->True]]

OpenersExampleSection1(Spacer1)Scope  (6)

(RefLink[GraphReciprocity, paclet:ref/GraphReciprocity]) works with undirected graphs:

GraphReciprocity[]

Directed graphs:

GraphReciprocity[]

Weighted graphs:

GraphReciprocity[]

Multigraphs:

GraphReciprocity[]

Use rules to specify the graph:

GraphReciprocity[{1->2,1->3,2->3,2->4,3->1,3->4}]

(RefLink[GraphReciprocity, paclet:ref/GraphReciprocity]) works with large graphs:

g=RandomGraph[UniformGraphDistribution[10^4,10^5,DirectedEdges->True]];

Timing[GraphReciprocity[g]]

OpenersExampleSection3(Spacer1)Applications  (3)

(RefLink[GraphReciprocity, paclet:ref/GraphReciprocity]) measures the number of directed edges that are bidirectional:

g=CycleGraph[4,DirectedEdges->True];

Table[Labeled[g=EdgeAdd[g,i\[DirectedEdge]Mod[i-1,4,1]],N@GraphReciprocity[g]],{i,4}]

Test whether a square matrix is structurally symmetric:

m=SparseArray[{Band[{1,2}]->1,Band[{2,1}]->-1},{25,25}];

GraphReciprocity[AdjacencyGraph[Unitize[m]]]==1

Distribution of reciprocity in (RefLink[UniformGraphDistribution, paclet:ref/UniformGraphDistribution])[n,m,(RefLink[DirectedEdges, paclet:ref/DirectedEdges])->(RefLink[True, paclet:ref/True])]:

𝒢=UniformGraphDistribution[9,40,DirectedEdges->True];

data=GraphReciprocity/@RandomGraph[𝒢,1000];

Histogram[data]

The expected value is (m-1)/(n(n-1)-1):

N[{Mean[data],39/71}]

OpenersExampleSection4(Spacer1)Properties & Relations  (3)

The graph reciprocity is between 0 and 1:

RandomGraph[UniformGraphDistribution[5,10,DirectedEdges->True]]

N[GraphReciprocity[%]]

A bidirectional directed graph has reciprocity 1:

DirectedGraph[StarGraph[4]]

GraphReciprocity[%]

An undirected graph also has reciprocity 1:

StarGraph[8]

GraphReciprocity[%]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LocalClusteringCoefficient, paclet:ref/LocalClusteringCoefficient])  ▪  (RefLink[GlobalClusteringCoefficient, paclet:ref/GlobalClusteringCoefficient])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Social Network Analysis, paclet:guide/SocialNetworks])}, {▪(RefLinkPlain[Graph Measures & Metrics, paclet:guide/GraphMeasures])}, {▪(RefLinkPlain[Graph Properties & Measurements, paclet:guide/GraphPropertiesAndMeasurements])}})}})