Beispiel #1
0
import pathlib

from infomap import Infomap

im = Infomap(silent=True)

name = "ninetriangles"
filename = f"../networks/{name}.net"

# You can read a network with the method read_file,
# which by default will accumulate to existing network data
im.read_file(filename, accumulate=False)

im.run(num_trials=5)

print(
    f"Found {im.max_depth} levels with {im.num_leaf_modules} leaf modules in {im.num_top_modules} top modules and codelength: {im.codelength:.8f} bits"
)
print(f"All codelengths: {im.codelengths}")

print("Tree:\n# path node_id module_id flow")
for node in im.nodes:
    print(f"{node.path} {node.node_id} {node.module_id} {node.flow:.8f}")

for module_level in range(1, im.max_depth):
    print(
        f"Modules at level {module_level}: {tuple(im.get_modules(module_level).values())}"
    )

print("\nModules at all levels:")
for node_id, modules in im.get_multilevel_modules().items():
Beispiel #2
0
from infomap import Infomap

im = Infomap(silent=True)
im.read_file("../networks/states.net")
im.run()

print("source target weight")
for source, target, weight in im.get_links():  # or im.links:
    print(source, target, weight)

print("source target flow")
for source, target, flow in im.get_links(data="flow"):  # or im.flow_links
    print(source, target, f"{flow:.4f}")