2
"""Node redundancy for bipartite graphs."""
3
# Copyright (C) 2011 by
4
# Jordi Torrents <jtorrents@milnou.net>
5
# Aric Hagberg <hagberg@lanl.gov>
8
from itertools import combinations
11
__author__ = """\n""".join(['Jordi Torrents <jtorrents@milnou.net>',
12
'Aric Hagberg (hagberg@lanl.gov)'])
13
__all__ = ['node_redundancy']
15
def node_redundancy(G, nodes=None):
16
r"""Compute bipartite node redundancy coefficient.
18
The redundancy coefficient of a node `v` is the fraction of pairs of
19
neighbors of `v` that are both linked to other nodes. In a one-mode
20
projection these nodes would be linked together even if `v` were
25
rc(v) = \frac{|\{\{u,w\} \subseteq N(v),
26
\: \exists v' \neq v,\: (v',u) \in E\:
27
\mathrm{and}\: (v',w) \in E\}|}{ \frac{|N(v)|(|N(v)|-1)}{2}}
29
where `N(v)` are the neighbors of `v` in `G`.
36
nodes : list or iterable (optional)
37
Compute redundancy for these nodes. The default is all nodes in G.
41
redundancy : dictionary
42
A dictionary keyed by node with the node redundancy value.
46
>>> from networkx.algorithms import bipartite
47
>>> G = nx.cycle_graph(4)
48
>>> rc = bipartite.node_redundancy(G)
52
Compute the average redundancy for the graph:
54
>>> sum(rc.values())/len(G)
57
Compute the average redundancy for a set of nodes:
60
>>> sum(rc[n] for n in nodes)/len(nodes)
65
.. [1] Latapy, Matthieu, Clémence Magnien, and Nathalie Del Vecchio (2008).
66
Basic notions for the analysis of large two-mode networks.
67
Social Networks 30(1), 31--48.
74
for u, w in combinations(G[v], 2):
75
if len((set(G[u]) & set(G[w])) - set([v])) > 0: