Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def return_infomap_communities(network):
infomapWrapper = infomap.Infomap("--two-level --silent")
# Add link weight as an optional third argument
for e in network.edges():
infomapWrapper.addLink(e[0], e[1])
infomapWrapper.run()
tree = infomapWrapper.tree
print("Found %d modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))
print("\n#node module")
part = defaultdict(list)
for node in tree.leafIter():
part[node.moduleIndex()].append(node.physIndex)
return list(part.values())
from infomap import infomap
infomapWrapper = infomap.Infomap("--two-level")
# Set the start index for bipartite nodes
infomapWrapper.setBipartiteNodesFrom(5)
# Add weight as an optional third argument
infomapWrapper.addLink(5, 0)
infomapWrapper.addLink(5, 1)
infomapWrapper.addLink(5, 2)
infomapWrapper.addLink(6, 2)
infomapWrapper.addLink(6, 3)
infomapWrapper.addLink(6, 4)
infomapWrapper.run()
tree = infomapWrapper.tree
print("Found %d modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))
def return_infomap_communities(network):
infomapWrapper = infomap.Infomap("--two-level --silent")
# Add link weight as an optional third argument
for e in network.edges():
infomapWrapper.addLink(e[0], e[1])
infomapWrapper.run()
tree = infomapWrapper.tree
print("Found %d modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))
print("\n#node module")
part = defaultdict(list)
for node in tree.leafIter():
part[node.moduleIndex()].append(node.physIndex)
return list(part.values())
from infomap import infomap
infomapWrapper = infomap.Infomap("--two-level")
# Add weight as an optional third argument
infomapWrapper.addLink(0, 1)
infomapWrapper.addLink(0, 2)
infomapWrapper.addLink(0, 3)
infomapWrapper.addLink(1, 0)
infomapWrapper.addLink(1, 2)
infomapWrapper.addLink(2, 1)
infomapWrapper.addLink(2, 0)
infomapWrapper.addLink(3, 0)
infomapWrapper.addLink(3, 4)
infomapWrapper.addLink(3, 5)
infomapWrapper.addLink(4, 3)
infomapWrapper.addLink(4, 5)
infomapWrapper.addLink(5, 4)
infomapWrapper.addLink(5, 3)
def findCommunities(G):
"""
Partition network with the Infomap algorithm.
Annotates nodes with 'community' id and return number of communities found.
"""
infomapWrapper = infomap.Infomap("--two-level")
print("Building Infomap network from a NetworkX graph...")
for e in G.edges():
infomapWrapper.addLink(*e)
print("Find communities with Infomap...")
infomapWrapper.run();
tree = infomapWrapper.tree
print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))
communities = {}
for node in tree.leafIter():
communities[node.originalLeafIndex] = node.moduleIndex()