Ejemplo n.º 1
0
def eval_map_equation(g, partitionobj):
    """Return the map equation score for a given partition."""
    g1 = nx.convert_node_labels_to_integers(g, label_attribute="name")
    scoremapeq = 0
    partition = partitionobj.communities
    part = dict()
    for i in range(len(partition)):
        for ind in partition[i]:
            part[ind] = i
    im = Infomap("--silent --no-infomap")  # Don't change the partition.
    for e in g1.edges():
        im.addLink(e[0], e[1])
    im.initial_partition = part
    im.run()
    scoremapeq = im.codelength
    return scoremapeq
Ejemplo n.º 2
0
}

# Only two modules, splitting the chain in the middle
partition2 = {
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 2,
    5: 2,
    6: 2,
    7: 2,
}

# Set initial partition on the Infomap instance to keep it during multiple runs
im.initial_partition = partition1

im.run(no_infomap=True)

print(
    f"Partition one with {im.num_top_modules} modules -> codelength: {im.codelength:.8f} bits"
)


# Set initial partition as run parameter to only use it for this run (will be restored to partition1 after)
im.run(initial_partition=partition2, no_infomap=True)

print(
    f"Partition two with {im.num_top_modules} modules -> codelength: {im.codelength:.8f} bits"
)