ra_index_soundarajan_hopcroft#
- ra_index_soundarajan_hopcroft(G, ebunch=None, community='community')[源码]#
使用社区信息计算 ebunch 中所有节点对的资源分配指数。
对于两个节点 \(u\) 和 \(v\),此函数仅考虑与 \(u\) 和 \(v\) 属于同一社区的共同邻居来计算资源分配指数。数学上,
\[\sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{f(w)}{|\Gamma(w)|}\]其中如果 \(w\) 与 \(u\) 和 \(v\) 属于同一社区,则 \(f(w)\) 等于 1,否则等于 0,且 \(\Gamma(u)\) 表示 \(u\) 的邻居集合。
- 参数:
- G图
一个 NetworkX 无向图。
- ebunch节点对的可迭代对象,可选 (默认 = None)
将为可迭代对象中给定的每一对节点计算分数。节点对必须以 2 元组 (u, v) 的形式给出,其中 u 和 v 是图中的节点。如果 ebunch 为 None,则将使用图中所有不存在的边。默认值:None。
- community字符串,可选 (默认 = ‘community’)
包含社区信息的节点属性名称。G[u][community] 用于识别 u 属于哪个社区。每个节点至多属于一个社区。默认值:‘community’。
- 返回:
- piter迭代器
一个包含 3 元组 (u, v, p) 的迭代器,其中 (u, v) 是一对节点,p 是它们的分数。
- 引发:
- NetworkXNotImplemented
如果
G
是DiGraph
、Multigraph
或MultiDiGraph
。- NetworkXAlgorithmError
如果在
ebunch
或G
中(如果ebunch
是None
)有节点没有可用的社区信息。- NodeNotFound
如果
ebunch
包含不在G
中的节点。
参考文献
[1]Sucheta Soundarajan 和 John Hopcroft。利用社区信息提高链接预测方法的精度。刊于:Proceedings of the 21st international conference companion on World Wide Web (WWW ‘12 Companion)。ACM 出版,地点:New York, NY, USA,页码:607-608。http://doi.acm.org/10.1145/2187980.2188150
示例
>>> G = nx.Graph() >>> G.add_edges_from([(0, 1), (0, 2), (1, 3), (2, 3)]) >>> G.nodes[0]["community"] = 0 >>> G.nodes[1]["community"] = 0 >>> G.nodes[2]["community"] = 1 >>> G.nodes[3]["community"] = 0 >>> preds = nx.ra_index_soundarajan_hopcroft(G, [(0, 3)]) >>> for u, v, p in preds: ... print(f"({u}, {v}) -> {p:.8f}") (0, 3) -> 0.50000000