1

I'm not able to find a good documentation to use PLP and PLM algoritms. I need to detect community in a graph using networkit's libraries. I've found only this link: https://networkit.iti.kit.edu/api/community.html but I don't understand what kind of function can give me the community's structure and how I can run the algorithm. I need some explaination like this: https://networkit.iti.kit.edu/api/doxyhtml/class_networ_kit_1_1_p_l_p.html#abeb42305639e48a3160a45aee354783a (C++) where is clear that I can run the algorithm and then use toString() to see the structure. I need a Graph G, I think, but I don't know what to do next.

1 Answers1

2

As many classes in NetworKit, both PLP and PLM include a run() method that executes the algorithm and you need to invoke it before getting the result. Also, there is no need to use the toString() method to get the community structure; you can use the getPartition() method (included in both PLP and PLM, see the documentation) which returns a Partition object that represents the community structure (you can find the documentation of Partition here).

See below for a simple example:

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()

Each community is associated with a unique integer id, and each node is associated to a community id. plpCommunityIDs is a set that contains all the community ids, while plpCommunities is a vector of size n (number of nodes of the graph) that contains the community id of each node (for example, use c = plpCommunities[v] to store in c the community id of node v).

angriman
  • 345
  • 1
  • 10