resource_allocation_index#

计算 ebunch 中所有节点对的资源分配指数。

节点 uv 的资源分配指数定义为

\[\sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{1}{|\Gamma(w)|}\]

其中 \(\Gamma(u)\) 表示节点 \(u\) 的邻居集合。

参数:
G

一个 NetworkX 无向图。

ebunch节点对的可迭代对象,可选 (默认 = None)

将为可迭代对象中给定的每对节点计算资源分配指数。节点对必须以 2 元组 (u, v) 的形式给出,其中 u 和 v 是图中的节点。如果 ebunch 为 None,则将使用图中的所有不存在的边。默认值: None。

返回:
piter迭代器

一个包含 3 元组 (u, v, p) 的迭代器,其中 (u, v) 是一对节点,p 是它们的资源分配指数。

抛出:
NetworkXNotImplemented

如果 GDiGraph, MultigraphMultiDiGraph

NodeNotFound

如果 ebunch 中包含不在 G 中的节点。

参考文献

[1]

T. Zhou, L. Lu, Y.-C. Zhang. Predicting missing links via local information. Eur. Phys. J. B 71 (2009) 623. https://arxiv.org/pdf/0901.0553.pdf

示例

>>> G = nx.complete_graph(5)
>>> preds = nx.resource_allocation_index(G, [(0, 1), (2, 3)])
>>> for u, v, p in preds:
...     print(f"({u}, {v}) -> {p:.8f}")
(0, 1) -> 0.75000000
(2, 3) -> 0.75000000