within_inter_cluster#

计算 ebunch 中所有节点对的簇内和簇间共同邻居的比率。

对于两个节点 uv,如果一个共同邻居 w 与它们属于同一社区,则 w 被视为 uv 的簇内共同邻居。否则,它被视为 uv 的簇间共同邻居。簇内共同邻居集合的大小与簇间共同邻居集合的大小之间的比率定义为 WIC 度量。[1]

参数
Ggraph(图)

一个 NetworkX 无向图。

ebunchiterable of node pairs(节点对的可迭代对象),可选 (默认 = None)

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

deltafloat(浮点数),可选 (默认 = 0.001)

用于防止两个节点之间没有簇间共同邻居时发生除以零的错误。详情请参阅 [1]。默认值:0.001。

communitystring(字符串),可选 (默认 = ‘community’)

包含社区信息的节点属性名称。G[u][community] 指示节点 u 属于哪个社区。每个节点最多属于一个社区。默认值:‘community’。

返回
piteriterator(迭代器)

一个由 3-元组 (u, v, p) 组成的迭代器,其中 (u, v) 是一个节点对,p 是它们的 WIC 度量。

抛出
NetworkXNotImplemented

如果 GDiGraphMultigraphMultiDiGraph

NetworkXAlgorithmError
  • 如果 delta 小于或等于零。

  • 如果在 ebunch 中或在 G 中(如果 ebunchNone)没有节点提供社区信息。

NodeNotFound

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

参考文献

[1] (1,2)

Jorge Carlos Valverde-Rebaza and Alneu de Andrade Lopes. Link prediction in complex networks based on cluster information. In Proceedings of the 21st Brazilian conference on Advances in Artificial Intelligence (SBIA’12) https://doi.org/10.1007/978-3-642-34459-6_10

示例

>>> G = nx.Graph()
>>> G.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 4), (2, 4), (3, 4)])
>>> G.nodes[0]["community"] = 0
>>> G.nodes[1]["community"] = 1
>>> G.nodes[2]["community"] = 0
>>> G.nodes[3]["community"] = 0
>>> G.nodes[4]["community"] = 0
>>> preds = nx.within_inter_cluster(G, [(0, 4)])
>>> for u, v, p in preds:
...     print(f"({u}, {v}) -> {p:.8f}")
(0, 4) -> 1.99800200
>>> preds = nx.within_inter_cluster(G, [(0, 4)], delta=0.5)
>>> for u, v, p in preds:
...     print(f"({u}, {v}) -> {p:.8f}")
(0, 4) -> 1.33333333