I have a file containing the nodes of a graph and their respective communities using infomap community detection algorithm. I have read the file line by line and converted it into a 2D python list, where the list gives you all the nodes in the 0th community and so on. Now to compare this infomap algorithm with the one provided in igraph using the compare_communities (from igraph) I need both the community outputs in a vertexCluster object. How can I convert the 2D list to a vertexClustering Object?
You can simply initalise a new
VertexClustering object. The only thing is that you need to supply a membership list, instead of a list of a list of clusters.
Let us assume that
clusters is the list of clusters, such that
clusters[i] is a list of nodes that belong to cluster
graph contains the appropriate graph. One way to convert
clusters to a membership list is as follows
membership = [None]*graph.vcount() for c, cluster in enumerate(clusters): for v in cluster: membership[v] = c
you can then create a new
clustering = VertexClustering(graph, membership=membership)
If there are any nodes that are incorrectly labelled (i.e. not between
graph.vcount()-1), this should throw an error.