node_redundancy#
- node_redundancy(G, nodes=None)[source]#
计算二分图
G
中节点的节点冗余系数。节点
v
的冗余系数是节点v
的邻居对中,同时连接到其他节点的对所占的比例。在单模投影中,即使节点v
不存在,这些节点也可能相互连接。更正式地,对于任意顶点
v
,`v` 的冗余系数定义为\[rc(v) = \frac{|\{\{u, w\} \subseteq N(v), \: \exists v' \neq v,\: (v',u) \in E\: \text{且}\: (v',w) \in E\}|}{ \frac{|N(v)|(|N(v)|-1)}{2}},\]其中
N(v)
是节点v
在图G
中的邻居集合。- 参数:
- G图
二分图
- nodes列表或可迭代对象(可选)
计算这些节点的冗余度。默认为图 G 中的所有节点。
- 返回值:
- redundancy字典
一个以节点为键,节点冗余值为值的字典。
- 抛出:
- NetworkXError
如果图中的任何节点(或在指定了
nodes
的情况下,nodes
中的任何节点)的(出)度小于 2(根据冗余系数的定义,这会导致除以零)。
参考文献
[1]Latapy, Matthieu, Clémence Magnien, and Nathalie Del Vecchio (2008). Basic notions for the analysis of large two-mode networks. Social Networks 30(1), 31–48.
示例
计算图中每个节点的冗余系数
>>> from networkx.algorithms import bipartite >>> G = nx.cycle_graph(4) >>> rc = bipartite.node_redundancy(G) >>> rc[0] 1.0
计算图的平均冗余度
>>> from networkx.algorithms import bipartite >>> G = nx.cycle_graph(4) >>> rc = bipartite.node_redundancy(G) >>> sum(rc.values()) / len(G) 1.0
计算一组节点的平均冗余度
>>> from networkx.algorithms import bipartite >>> G = nx.cycle_graph(4) >>> rc = bipartite.node_redundancy(G) >>> nodes = [0, 2] >>> sum(rc[n] for n in nodes) / len(nodes) 1.0