Input: CPoints, i.e., the candidate points of the QTS Output: Ppoints, i.e., the period points used to split the QTS. 1. G ¼ getGraph(CPoints); // turns CPoints into graph G 2. COM ¼ convert(G); // concert G into communities COM 3. for each community in COM, denoted as COMi do 4. for each community in COM other than COMi, denoted as COMj do 5. tentatively move COMi into COMj 6. if the modularity of COM is not improved then 7. revoke the above move 8. end if 9. end for 10. end for 11. if some communities were successively moved then 12. go to line 3 to start other round of movement 13. end if 14. F ¼ getFeature(COM); // compute the features of each community 15. C’ ¼ k-means(COM,F); // cluster COM using k-means based on F 16. t ¼ getThreshold(C’); // compute the threshold t based on C’. 17. for each element of F, denoted as Fi do 18. if Fi < t then 19. remove COMi from COM, where Fi is derived from COMi 20. end if 21. end for 22. AMC ¼ getAMC(COM); // compute the AMC of each community 23. AMCmax ¼ getMAX(AMC); // get the maximum AMC 24. PPoints ¼ vertexes in the community corresponding to AMCmax;转换为python代码
时间: 2024-02-14 08:16:14 浏览: 143
以下是该算法的 Python 实现:
```python
from networkx.algorithms.community import greedy_modularity_communities
from sklearn.cluster import KMeans
def getGraph(CPoints):
# 将 CPoints 转换为 networkx 的图形式
pass
def convert(G):
# 将图 G 划分为社区
return list(greedy_modularity_communities(G))
def getFeature(COM):
# 计算每个社区的特征值
pass
def getThreshold(C):
# 根据聚类结果计算阈值
pass
def getAMC(COM):
# 计算每个社区的 AMC
pass
def getMAX(AMC):
# 找到 AMC 的最大值
pass
def splitQTS(CPoints):
G = getGraph(CPoints)
COM = convert(G)
while True:
flag = False
for i, COMi in enumerate(COM):
for j, COMj in enumerate(COM):
if i != j:
COM_new = COM.copy()
COM_new[j].update(COMi)
COM_new[i] = set()
modularity_new = modularity(G, COM_new)
if modularity_new > modularity(G, COM):
COM = COM_new
flag = True
break
if flag:
break
if not flag:
break
F = getFeature(COM)
C = KMeans(n_clusters=3).fit(COM, F).labels_
t = getThreshold(C)
for i, Fi in enumerate(F):
if Fi < t:
COM[i] = set()
AMC = getAMC(COM)
AMCmax = getMAX(AMC)
PPoints = [v for v in COM[AMC.index(AMCmax)]]
return PPoints
```
其中,`modularity` 是计算模块度的函数,需要根据具体情况实现。其他函数的实现方式也需要根据具体的要求来完成。
阅读全文