How to use infomap - 10 common examples

To help you get started, we’ve selected a few infomap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / example-networkx.py View on Github external
def findCommunities(G):
	"""
	Partition network with the Infomap algorithm.
	Annotates nodes with 'community' id and return number of communities found.
	"""
	conf = infomap.init("--two-level");
	# Input data
	network = infomap.Network(conf);
	# Output data
	tree = infomap.HierarchicalNetwork(conf)

	print("Building network...")
	for e in G.edges_iter():
		network.addLink(*e)

	network.finalizeAndCheckNetwork(True, nx.number_of_nodes(G));

	# Cluster network
	infomap.run(network, tree);

	print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))

	communities = {}
	clusterIndexLevel = 1 # 1, 2, ... or -1 for top, second, ... or lowest cluster level
	for node in tree.leafIter(clusterIndexLevel):
		communities[node.originalLeafIndex] = node.clusterIndex()
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / example-file-io.py View on Github external
#!/usr/bin/env python
import os.path
from infomap import infomap

conf = infomap.init("--silent -N5")
# Add output directory (and output name) to automatically write result to file
# conf = infomap.init("--silent -N5 . --out-name test")

filename = "../../ninetriangles.net"
name = os.path.splitext(os.path.basename(filename))[0]
print("Loading network from '%s'..." % filename)
network = infomap.Network(conf)
network.readInputData(filename)

print("Running Infomap...")
tree = infomap.HierarchicalNetwork(conf)
infomap.run(network, tree)

print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))

print("Writing top level clusters to %s_level1.clu..." % name)
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / example-networkx.py View on Github external
def findCommunities(G):
	"""
	Partition network with the Infomap algorithm.
	Annotates nodes with 'community' id and return number of communities found.
	"""
	conf = infomap.init("--two-level");
	# Input data
	network = infomap.Network(conf);
	# Output data
	tree = infomap.HierarchicalNetwork(conf)

	print("Building network...")
	for e in G.edges_iter():
		network.addLink(*e)

	network.finalizeAndCheckNetwork(True, nx.number_of_nodes(G));

	# Cluster network
	infomap.run(network, tree);

	print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / example-file-io.py View on Github external
#!/usr/bin/env python
import os.path
from infomap import infomap

conf = infomap.init("--silent -N5")
# Add output directory (and output name) to automatically write result to file
# conf = infomap.init("--silent -N5 . --out-name test")

filename = "../../ninetriangles.net"
name = os.path.splitext(os.path.basename(filename))[0]
print("Loading network from '%s'..." % filename)
network = infomap.Network(conf)
network.readInputData(filename)

print("Running Infomap...")
tree = infomap.HierarchicalNetwork(conf)
infomap.run(network, tree)

print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))

print("Writing top level clusters to %s_level1.clu..." % name)
tree.writeClu("%s_level1.clu" % name, 1)
print("Writing second level clusters to %s_level2.clu..." % name)
tree.writeClu("%s_level2.clu" % name, 2)

print("Writing tree to %s.tree..." % name)
tree.writeHumanReadableTree("%s.tree" % name)
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / example-file-io.py View on Github external
#!/usr/bin/env python
import os.path
from infomap import infomap

conf = infomap.init("--silent -N5")
# Add output directory (and output name) to automatically write result to file
# conf = infomap.init("--silent -N5 . --out-name test")

filename = "../../ninetriangles.net"
name = os.path.splitext(os.path.basename(filename))[0]
print("Loading network from '%s'..." % filename)
network = infomap.Network(conf)
network.readInputData(filename)

print("Running Infomap...")
tree = infomap.HierarchicalNetwork(conf)
infomap.run(network, tree)

print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))

print("Writing top level clusters to %s_level1.clu..." % name)
tree.writeClu("%s_level1.clu" % name, 1)
print("Writing second level clusters to %s_level2.clu..." % name)
tree.writeClu("%s_level2.clu" % name, 2)

print("Writing tree to %s.tree..." % name)
tree.writeHumanReadableTree("%s.tree" % name)

print("Done!")
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / Infomap.py View on Github external
#!/usr/bin/env python
# import os, sys
# sys.path.append(os.path.abspath('infomap'))

# from __future__ import print_function # Python 3 print function in Python 2
from infomap import infomap

conf = infomap.init("--two-level -v -N2")
# Add output directory (and output name) to automatically write result to file
# conf = infomap.init("--two-level -v -N2 . --out-name test")

print("Creating network...")
network = infomap.Network(conf)

names = list("ABCDEF")
network.addNodes(names)

network.addLink(0, 1)
network.addLink(0, 2)
network.addLink(0, 3)
network.addLink(1, 0)
network.addLink(1, 2)
network.addLink(2, 1)
network.addLink(2, 0)
network.addLink(3, 0)
network.addLink(3, 4)
network.addLink(3, 5)
network.addLink(4, 3)
network.addLink(4, 5)
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / example-networkx.py View on Github external
def findCommunities(G):
	"""
	Partition network with the Infomap algorithm.
	Annotates nodes with 'community' id and return number of communities found.
	"""
	conf = infomap.init("--two-level");
	# Input data
	network = infomap.Network(conf);
	# Output data
	tree = infomap.HierarchicalNetwork(conf)

	print("Building network...")
	for e in G.edges_iter():
		network.addLink(*e)

	network.finalizeAndCheckNetwork(True, nx.number_of_nodes(G));

	# Cluster network
	infomap.run(network, tree);

	print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))

	communities = {}
	clusterIndexLevel = 1 # 1, 2, ... or -1 for top, second, ... or lowest cluster level
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / Infomap.py View on Github external
#!/usr/bin/env python
# import os, sys
# sys.path.append(os.path.abspath('infomap'))

# from __future__ import print_function # Python 3 print function in Python 2
from infomap import infomap

conf = infomap.init("--two-level -v -N2")
# Add output directory (and output name) to automatically write result to file
# conf = infomap.init("--two-level -v -N2 . --out-name test")

print("Creating network...")
network = infomap.Network(conf)

names = list("ABCDEF")
network.addNodes(names)

network.addLink(0, 1)
network.addLink(0, 2)
network.addLink(0, 3)
network.addLink(1, 0)
network.addLink(1, 2)
network.addLink(2, 1)
network.addLink(2, 0)
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / example-networkx.py View on Github external
Annotates nodes with 'community' id and return number of communities found.
	"""
	conf = infomap.init("--two-level");
	# Input data
	network = infomap.Network(conf);
	# Output data
	tree = infomap.HierarchicalNetwork(conf)

	print("Building network...")
	for e in G.edges_iter():
		network.addLink(*e)

	network.finalizeAndCheckNetwork(True, nx.number_of_nodes(G));

	# Cluster network
	infomap.run(network, tree);

	print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))

	communities = {}
	clusterIndexLevel = 1 # 1, 2, ... or -1 for top, second, ... or lowest cluster level
	for node in tree.leafIter(clusterIndexLevel):
		communities[node.originalLeafIndex] = node.clusterIndex()

	nx.set_node_attributes(G, 'community', communities)
	return tree.numTopModules()
github YcheCourseProject / CommunityDetection / src / Compared_Algorithms / Infomap / Infomap / examples / python / example-file-io.py View on Github external
import os.path
from infomap import infomap

conf = infomap.init("--silent -N5")
# Add output directory (and output name) to automatically write result to file
# conf = infomap.init("--silent -N5 . --out-name test")

filename = "../../ninetriangles.net"
name = os.path.splitext(os.path.basename(filename))[0]
print("Loading network from '%s'..." % filename)
network = infomap.Network(conf)
network.readInputData(filename)

print("Running Infomap...")
tree = infomap.HierarchicalNetwork(conf)
infomap.run(network, tree)

print("Found %d top modules with codelength: %f" % (tree.numTopModules(), tree.codelength()))

print("Writing top level clusters to %s_level1.clu..." % name)
tree.writeClu("%s_level1.clu" % name, 1)
print("Writing second level clusters to %s_level2.clu..." % name)
tree.writeClu("%s_level2.clu" % name, 2)

print("Writing tree to %s.tree..." % name)
tree.writeHumanReadableTree("%s.tree" % name)

print("Done!")

infomap

Infomap network clustering algorithm

AGPL-3.0
Latest version published 12 months ago

Package Health Score

65 / 100
Full package analysis