第142行: |
第142行: |
| </ref> | | </ref> |
| | | |
| + | ====代码实现==== |
| + | 利用网络科学工具包[NetworkX https://networkx.github.io/], 可以轻松调用GN算法实现社团检测。 |
| + | <source> |
| + | import networkx as nx |
| + | from networkx.algorithms import community |
| + | |
| + | from community.centrality import girvan_newman #导入GN算法包 |
| + | |
| + | G = nx.path_graph(10) #生成一个大小为10的path graph |
| + | comp = girvan_newman(G) |
| + | print(tuple(sorted(c) for c in next(comp))) |
| + | </source> |
| + | 结果: |
| + | <source>([0, 1, 2, 3, 4], [5, 6, 7, 8, 9]) # 输入Top-1的划分结果,为两个社团</source> |
| | | |
| ===模板度最大值=== | | ===模板度最大值=== |