我找不到一个好的文档来使用PLP和PLM算法。我需要使用networkit的库来检测图中的社区。我只找到了这个链接:https://networkit.iti.kit.edu/api/community.html,但我不知道什么样的函数可以给我社区的结构,以及我如何运行算法。我需要这样的解释:https://networkit.iti.kit.edu/api/doxyhtml/class_networ_kit_1_1_p_l_p.html#abeb42305639e48a3160a45aee354783a (C++),很明显,我可以运行算法,然后使用toString()来查看结构。我想我需要一个Graph G,但我不知道下一步该做什么。
发布于 2018-09-01 20:46:26
与NetworKit中的许多类一样,PLP和PLM都包含一个执行算法的run()方法,您需要在获得结果之前调用它。此外,不需要使用toString()方法来获取社区结构;您可以使用getPartition()方法(包含在PLP和PLM中,请参阅documentation),该方法返回一个表示社区结构的Partition对象(您可以找到Partition here的文档)。
下面是一个简单的例子:
from networkit import *
# In this example I generate a graph with a random community structure.
# In your code use your own graph.
g = generators.ClusteredRandomGraphGenerator(100, 10, 0.5, 0.01).generate()
# Creating an instance of PLP and running the algorithm.
# Use community.PLM(g) to run the PLM algorithm.
plp = community.PLP(g).run()
# Getting the Partition object.
plpPartition = plp.getPartition()
# Getting the community IDs.
plpCommunityIDs = plpPartition.getSubsetIds()
# Getting the community ID of each node of the graph g.
plpCommunities = plpPartition.getVector()每个社区都与一个唯一的整数id相关联,每个节点都与一个社区id相关联。plpCommunityIDs是一个包含所有社区id的集合,而plpCommunities是一个大小为n(图的节点数)的向量,它包含每个节点的社区id (例如,使用c = plpCommunities[v]在c中存储节点v的社区id)。
https://stackoverflow.com/questions/52113140
复制相似问题