infomap

infomapの概要と使い方

タグ infomap


概要

  • (双方向は問わない)グラフでクラスタ間の情報のやり取りを最小化するようにクラスタリングするアルゴリズム
  • クラスタの検出などを行える

インストール

$ python3 -m pip install infomap

具体例

from infomap import Infomap

# Command line flags can be added as a string to Infomap
im = Infomap("--two-level --directed")

# Add weight as optional third argument
im.add_link(0, 1)
im.add_link(0, 2)
im.add_link(0, 3)
im.add_link(1, 0)
im.add_link(1, 2)
im.add_link(2, 1)
im.add_link(2, 0)
im.add_link(3, 0)
im.add_link(3, 4)
im.add_link(3, 5)
im.add_link(4, 3)
im.add_link(4, 5)
im.add_link(5, 4)
im.add_link(5, 3)

# Run the Infomap search algorithm to find optimal modules
im.run()

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

print("Result")
print("\n#node module")
for node in im.tree:
    if node.is_leaf:
        print(node.node_id, node.module_id)
  • node_idが指定したnodeの数値
  • module_idがクラスタリングの結果

参考