Ejemplo n.º 1
0
            textcoords="offset points",
            horizontalalignment="center",
            verticalalignment="center",
            xytext=[0, 2],
            color=cmap_dark(communities[n]),
        )

    plt.axis("off")
    pathlib.Path("output").mkdir(exist_ok=True)
    print("Writing network figure to output/karate.png")
    plt.savefig("output/karate.png")
    # plt.show()


G = nx.karate_club_graph()

print("Building Infomap network from a NetworkX graph...")
im = Infomap(two_level=True, silent=True, num_trials=20)
im.add_networkx_graph(G)

print("Find communities with Infomap...")
im.run()

print(
    f"Found {im.num_top_modules} modules with codelength {im.codelength:.8f} bits"
)

nx.set_node_attributes(G, im.get_modules(), "community")

draw_network(G)
Ejemplo n.º 2
0
import networkx as nx
import numpy as np
from sklearn.model_selection import ParameterGrid

from infomap import Infomap

im = Infomap(two_level=True, silent=True, num_trials=10)
im.add_networkx_graph(nx.karate_club_graph())

grid = ParameterGrid({"markov_time": np.linspace(0.8, 2, 5)})

for params in grid:
    im.run(**params)
    print(
        f"markov_time={params['markov_time']:0.1f}: number of modules: {im.num_top_modules}"
    )