naive_greedy_modularity_communities#

naive_greedy_modularity_communities(G, resolution=1, weight=None)[源代码]#

使用贪婪模块度最大化方法在 G 中查找社区。

此实现的时间复杂度为 O(n^4),比其他替代方法慢得多,但作为一个易于理解的参考实现提供。

贪婪模块度最大化方法首先将每个节点视为一个独立的社区,然后合并最能增加模块度的社区对,直到不存在这样的社区对。

此函数最大化广义模块度,其中 resolution 是分辨率参数,通常表示为 \(\gamma\)。参阅 modularity()

参数:
GNetworkX 图

图必须是简单无向图。

resolution浮点数 (默认值=1)

如果 resolution 小于 1,模块度偏向更大的社区。大于 1 则偏向更小的社区。

weight字符串或 None,可选 (默认值=None)

用于表示权重的边属性名称。如果为 None,则每条边的权重为 1。节点的度是与其相邻的边权重的总和。

返回:
列表

由节点集合组成的列表,每个集合代表一个社区。按长度排序,最大的社区在前。

另请参阅

greedy_modularity_communities
modularity

示例

>>> G = nx.karate_club_graph()
>>> c = nx.community.naive_greedy_modularity_communities(G)
>>> sorted(c[0])
[8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]