莱顿算法中的社区数量

问题描述 投票:0回答:0

为了解决组合问题,我使用了 communities detection 并且需要预先选择社区的数量。这在 communities package

的 Louvain Method 中是可能的
# ! pip install communities

import numpy as np
from communities.algorithms import louvain_method

A = np.array([[1, 1, 0, 0, 0, 0, 1, 0], 
              [1, 0, 0, 1, 0, 0, 0, 0], 
              [0, 1, 1, 0, 0, 1, 0, 0],
              [0, 0, 1, 1, 0, 0, 0, 0],
              [0, 1, 0, 0, 0, 1, 0, 0], 
              [0, 0, 1, 0, 1, 0, 0, 0],
              [0, 1, 0, 1, 0, 0, 1, 0], 
              [0, 1, 0, 1, 1, 0, 1, 1], 
              [1, 0, 0, 0, 0, 0, 0, 1], 
              [0, 1, 0, 0, 1, 0, 0, 0]])

A_sq = np.matmul(A,A.transpose())

nbr_communities = 3
communities, _ = louvain_method(A_sq, nbr_communities)


print("len communities = ", len(communities), "nbr_communities=", nbr_communities)
print(communities,"\n")
for com in communities:
  print(A[list(com)], "\n")

我在 cdlibnetworkx 中找不到 Leiden 算法的此类参数。有没有 Leiden 的实现可以让我们选择它,或者有其他方法来实现这个?

python networkx cluster-computing graph-theory
© www.soinside.com 2019 - 2024. All rights reserved.