Leiden社区发现算法的学习和示例

Leiden是基于Louvain方法改进的社区检测算法,用于复杂网络分析,识别网络中紧密连接的社区,pip安装包leidenalg。

igraph是一个跨平台的图形库,leidenalg可直接基于igrap创建的图,运行复杂网络分析。

1 Leiden工具安装

pip install leidenalg

pip install python-louvain

pip install cairocffi

2 社区划分示例

以下是leiden社区划分的示例代码,整理自网络资料。

这里采用ModularityVertexPartition,基于模块度概念,通过优化模块度来寻找最佳的社区划分。

此外,还可以使用基于随机块模型的RBConfigurationVertexPartition,以及基于常数Potts模型的CPMVertexPartition。

复制代码
import igraph as ig
import leidenalg as la


vertices = ['Materials Science, Multidisciplinary', 'Physics, Applied', 'Chemistry, Physical', 'Nanoscience & Nanotechnology', 'Chemistry, Multidisciplinary', 'Physics, Condensed Matter', 'Metallurgy & Metallurgical Engineering', 'Engineering, Multidisciplinary', 'Energy & Fuels', 'Construction & Building Technology', 'Engineering, Civil', 'Engineering, Electrical & Electronic', 'Optics', 'Crystallography', 'Polymer Science', 'Mechanics', 'Electrochemistry', 'Engineering, Mechanical', 'Materials Science, Coatings & Films', 'Physics, Multidisciplinary', 'Engineering, Manufacturing', 'Engineering, Chemical', 'Physics, Atomic, Molecular & Chemical', 'Materials Science, Characterization & Testing', 'Mineralogy', 'Instruments & Instrumentation', 'Chemistry, Applied', 'Computer Science, Information Systems', 'Biochemistry & Molecular Biology', 'Mining & Mineral Processing', 'Nuclear Science & Technology', 'Materials Science, Ceramics', 'Green & Sustainable Science & Technology', 'Materials Science, Composites', 'Engineering, Industrial', 'Chemistry, Analytical', 'Spectroscopy', 'Geosciences, Multidisciplinary', 'Engineering, Geological', 'Thermodynamics', 'Archaeology', 'Art', 'Humanities, Multidisciplinary', 'Microscopy', 'Materials Science, Textiles', 'Mathematics, Interdisciplinary Applications', 'Chemistry, Inorganic & Nuclear', 'Quantum Science & Technology', 'Multidisciplinary Sciences', 'Biotechnology & Applied Microbiology', 'Imaging Science & Photographic Technology', 'Mathematics, Applied', 'Education, Scientific Disciplines', 'Acoustics']
edges = [('Physics, Applied', 'Materials Science, Multidisciplinary'), ('Chemistry, Physical', 'Materials Science, Multidisciplinary'), ('Nanoscience & Nanotechnology', 'Materials Science, Multidisciplinary'), ('Chemistry, Multidisciplinary', 'Materials Science, Multidisciplinary'), ('Physics, Condensed Matter', 'Materials Science, Multidisciplinary'), ('Metallurgy & Metallurgical Engineering', 'Materials Science, Multidisciplinary'), ('Engineering, Multidisciplinary', 'Materials Science, Multidisciplinary'), ('Energy & Fuels', 'Materials Science, Multidisciplinary'), ('Construction & Building Technology', 'Materials Science, Multidisciplinary'), ('Engineering, Civil', 'Materials Science, Multidisciplinary'), ('Engineering, Electrical & Electronic', 'Materials Science, Multidisciplinary'), ('Optics', 'Materials Science, Multidisciplinary'), ('Crystallography', 'Materials Science, Multidisciplinary'), ('Polymer Science', 'Materials Science, Multidisciplinary'), ('Mechanics', 'Materials Science, Multidisciplinary'), ('Electrochemistry', 'Materials Science, Multidisciplinary'), ('Engineering, Mechanical', 'Materials Science, Multidisciplinary'), ('Materials Science, Coatings & Films', 'Materials Science, Multidisciplinary'), ('Physics, Multidisciplinary', 'Materials Science, Multidisciplinary'), ('Engineering, Manufacturing', 'Materials Science, Multidisciplinary'), ('Engineering, Chemical', 'Materials Science, Multidisciplinary'), ('Physics, Atomic, Molecular & Chemical', 'Materials Science, Multidisciplinary'), ('Materials Science, Characterization & Testing', 'Materials Science, Multidisciplinary'), ('Mineralogy', 'Materials Science, Multidisciplinary'), ('Instruments & Instrumentation', 'Materials Science, Multidisciplinary'), ('Chemistry, Applied', 'Materials Science, Multidisciplinary'), ('Computer Science, Information Systems', 'Materials Science, Multidisciplinary'), ('Biochemistry & Molecular Biology', 'Materials Science, Multidisciplinary'), ('Mining & Mineral Processing', 'Materials Science, Multidisciplinary'), ('Nuclear Science & Technology', 'Materials Science, Multidisciplinary'), ('Materials Science, Ceramics', 'Materials Science, Multidisciplinary'), ('Green & Sustainable Science & Technology', 'Materials Science, Multidisciplinary'), ('Materials Science, Composites', 'Materials Science, Multidisciplinary'), ('Engineering, Industrial', 'Materials Science, Multidisciplinary'), ('Chemistry, Analytical', 'Materials Science, Multidisciplinary'), ('Spectroscopy', 'Materials Science, Multidisciplinary'), ('Geosciences, Multidisciplinary', 'Materials Science, Multidisciplinary'), ('Engineering, Geological', 'Materials Science, Multidisciplinary'), ('Thermodynamics', 'Materials Science, Multidisciplinary'), ('Archaeology', 'Materials Science, Multidisciplinary'), ('Art', 'Materials Science, Multidisciplinary'), ('Humanities, Multidisciplinary', 'Materials Science, Multidisciplinary'), ('Microscopy', 'Materials Science, Multidisciplinary'), ('Materials Science, Textiles', 'Materials Science, Multidisciplinary'), ('Mathematics, Interdisciplinary Applications', 'Materials Science, Multidisciplinary'), ('Chemistry, Inorganic & Nuclear', 'Materials Science, Multidisciplinary'), ('Quantum Science & Technology', 'Materials Science, Multidisciplinary'), ('Multidisciplinary Sciences', 'Materials Science, Multidisciplinary'), ('Biotechnology & Applied Microbiology', 'Materials Science, Multidisciplinary'), ('Imaging Science & Photographic Technology', 'Materials Science, Multidisciplinary'), ('Mathematics, Applied', 'Materials Science, Multidisciplinary'), ('Education, Scientific Disciplines', 'Materials Science, Multidisciplinary'), ('Acoustics', 'Materials Science, Multidisciplinary'), ('Materials Science, Multidisciplinary', 'Physics, Applied'), ('Chemistry, Physical', 'Physics, Applied'), ('Nanoscience & Nanotechnology', 'Physics, Applied'), ('Chemistry, Multidisciplinary', 'Physics, Applied'), ('Physics, Condensed Matter', 'Physics, Applied'), ('Metallurgy & Metallurgical Engineering', 'Physics, Applied'), ('Engineering, Multidisciplinary', 'Physics, Applied'), ('Energy & Fuels', 'Physics, Applied'), ('Engineering, Electrical & Electronic', 'Physics, Applied'), ('Optics', 'Physics, Applied'), ('Crystallography', 'Physics, Applied'), ('Polymer Science', 'Physics, Applied'), ('Mechanics', 'Physics, Applied'), ('Engineering, Mechanical', 'Physics, Applied'), ('Materials Science, Coatings & Films', 'Physics, Applied'), ('Engineering, Chemical', 'Physics, Applied'), ('Quantum Science & Technology', 'Physics, Applied'), ('Acoustics', 'Physics, Applied'), ('Materials Science, Multidisciplinary', 'Chemistry, Physical'), ('Physics, Applied', 'Chemistry, Physical'), ('Nanoscience & Nanotechnology', 'Chemistry, Physical'), ('Chemistry, Multidisciplinary', 'Chemistry, Physical'), ('Physics, Condensed Matter', 'Chemistry, Physical'), ('Metallurgy & Metallurgical Engineering', 'Chemistry, Physical'), ('Energy & Fuels', 'Chemistry, Physical'), ('Crystallography', 'Chemistry, Physical'), ('Polymer Science', 'Chemistry, Physical'), ('Electrochemistry', 'Chemistry, Physical'), ('Physics, Multidisciplinary', 'Chemistry, Physical'), ('Engineering, Chemical', 'Chemistry, Physical'), ('Physics, Atomic, Molecular & Chemical', 'Chemistry, Physical'), ('Mineralogy', 'Chemistry, Physical'), ('Chemistry, Applied', 'Chemistry, Physical'), ('Biochemistry & Molecular Biology', 'Chemistry, Physical'), ('Green & Sustainable Science & Technology', 'Chemistry, Physical'), ('Thermodynamics', 'Chemistry, Physical'), ('Chemistry, Inorganic & Nuclear', 'Chemistry, Physical'), ('Materials Science, Multidisciplinary', 'Nanoscience & Nanotechnology'), ('Physics, Applied', 'Nanoscience & Nanotechnology'), ('Chemistry, Physical', 'Nanoscience & Nanotechnology'), ('Chemistry, Multidisciplinary', 'Nanoscience & Nanotechnology'), ('Physics, Condensed Matter', 'Nanoscience & Nanotechnology'), ('Metallurgy & Metallurgical Engineering', 'Nanoscience & Nanotechnology'), ('Energy & Fuels', 'Nanoscience & Nanotechnology'), ('Engineering, Electrical & Electronic', 'Nanoscience & Nanotechnology'), ('Optics', 'Nanoscience & Nanotechnology'), ('Electrochemistry', 'Nanoscience & Nanotechnology'), ('Engineering, Chemical', 'Nanoscience & Nanotechnology'), ('Physics, Atomic, Molecular & Chemical', 'Nanoscience & Nanotechnology'), ('Chemistry, Applied', 'Nanoscience & Nanotechnology'), ('Biotechnology & Applied Microbiology', 'Nanoscience & Nanotechnology'), ('Materials Science, Multidisciplinary', 'Chemistry, Multidisciplinary'), ('Physics, Applied', 'Chemistry, Multidisciplinary'), ('Chemistry, Physical', 'Chemistry, Multidisciplinary'), ('Nanoscience & Nanotechnology', 'Chemistry, Multidisciplinary'), ('Physics, Condensed Matter', 'Chemistry, Multidisciplinary'), ('Engineering, Multidisciplinary', 'Chemistry, Multidisciplinary'), ('Energy & Fuels', 'Chemistry, Multidisciplinary'), ('Crystallography', 'Chemistry, Multidisciplinary'), ('Physics, Multidisciplinary', 'Chemistry, Multidisciplinary'), ('Green & Sustainable Science & Technology', 'Chemistry, Multidisciplinary'), ('Materials Science, Textiles', 'Chemistry, Multidisciplinary'), ('Materials Science, Multidisciplinary', 'Physics, Condensed Matter'), ('Physics, Applied', 'Physics, Condensed Matter'), ('Chemistry, Physical', 'Physics, Condensed Matter'), ('Nanoscience & Nanotechnology', 'Physics, Condensed Matter'), ('Chemistry, Multidisciplinary', 'Physics, Condensed Matter'), ('Metallurgy & Metallurgical Engineering', 'Physics, Condensed Matter'), ('Energy & Fuels', 'Physics, Condensed Matter'), ('Engineering, Electrical & Electronic', 'Physics, Condensed Matter'), ('Optics', 'Physics, Condensed Matter'), ('Polymer Science', 'Physics, Condensed Matter'), ('Mechanics', 'Physics, Condensed Matter'), ('Materials Science, Coatings & Films', 'Physics, Condensed Matter'), ('Quantum Science & Technology', 'Physics, Condensed Matter'), ('Materials Science, Multidisciplinary', 'Metallurgy & Metallurgical Engineering'), ('Physics, Applied', 'Metallurgy & Metallurgical Engineering'), ('Chemistry, Physical', 'Metallurgy & Metallurgical Engineering'), ('Nanoscience & Nanotechnology', 'Metallurgy & Metallurgical Engineering'), ('Physics, Condensed Matter', 'Metallurgy & Metallurgical Engineering'), ('Engineering, Electrical & Electronic', 'Metallurgy & Metallurgical Engineering'), ('Engineering, Manufacturing', 'Metallurgy & Metallurgical Engineering'), ('Materials Science, Characterization & Testing', 'Metallurgy & Metallurgical Engineering'), ('Mineralogy', 'Metallurgy & Metallurgical Engineering'), ('Mining & Mineral Processing', 'Metallurgy & Metallurgical Engineering'), ('Thermodynamics', 'Metallurgy & Metallurgical Engineering'), ('Materials Science, Multidisciplinary', 'Engineering, Multidisciplinary'), ('Physics, Applied', 'Engineering, Multidisciplinary'), ('Chemistry, Multidisciplinary', 'Engineering, Multidisciplinary'), ('Energy & Fuels', 'Engineering, Multidisciplinary'), ('Mechanics', 'Engineering, Multidisciplinary'), ('Engineering, Mechanical', 'Engineering, Multidisciplinary'), ('Engineering, Chemical', 'Engineering, Multidisciplinary'), ('Thermodynamics', 'Engineering, Multidisciplinary'), ('Materials Science, Multidisciplinary', 'Energy & Fuels'), ('Physics, Applied', 'Energy & Fuels'), ('Chemistry, Physical', 'Energy & Fuels'), ('Nanoscience & Nanotechnology', 'Energy & Fuels'), ('Chemistry, Multidisciplinary', 'Energy & Fuels'), ('Physics, Condensed Matter', 'Energy & Fuels'), ('Engineering, Multidisciplinary', 'Energy & Fuels'), ('Electrochemistry', 'Energy & Fuels'), ('Physics, Multidisciplinary', 'Energy & Fuels'), ('Engineering, Chemical', 'Energy & Fuels'), ('Green & Sustainable Science & Technology', 'Energy & Fuels'), ('Thermodynamics', 'Energy & Fuels'), ('Materials Science, Multidisciplinary', 'Construction & Building Technology'), ('Engineering, Civil', 'Construction & Building Technology'), ('Green & Sustainable Science & Technology', 'Construction & Building Technology'), ('Materials Science, Multidisciplinary', 'Engineering, Civil'), ('Construction & Building Technology', 'Engineering, Civil'), ('Engineering, Mechanical', 'Engineering, Civil'), ('Materials Science, Multidisciplinary', 'Engineering, Electrical & Electronic'), ('Physics, Applied', 'Engineering, Electrical & Electronic'), ('Nanoscience & Nanotechnology', 'Engineering, Electrical & Electronic'), ('Physics, Condensed Matter', 'Engineering, Electrical & Electronic'), ('Metallurgy & Metallurgical Engineering', 'Engineering, Electrical & Electronic'), ('Optics', 'Engineering, Electrical & Electronic'), ('Engineering, Manufacturing', 'Engineering, Electrical & Electronic'), ('Engineering, Chemical', 'Engineering, Electrical & Electronic'), ('Quantum Science & Technology', 'Engineering, Electrical & Electronic'), ('Materials Science, Multidisciplinary', 'Optics'), ('Physics, Applied', 'Optics'), ('Nanoscience & Nanotechnology', 'Optics'), ('Physics, Condensed Matter', 'Optics'), ('Engineering, Electrical & Electronic', 'Optics'), ('Materials Science, Multidisciplinary', 'Crystallography'), ('Physics, Applied', 'Crystallography'), ('Chemistry, Physical', 'Crystallography'), ('Chemistry, Multidisciplinary', 'Crystallography'), ('Materials Science, Multidisciplinary', 'Polymer Science'), ('Physics, Applied', 'Polymer Science'), ('Chemistry, Physical', 'Polymer Science'), ('Physics, Condensed Matter', 'Polymer Science'), ('Physics, Multidisciplinary', 'Polymer Science'), ('Engineering, Chemical', 'Polymer Science'), ('Biochemistry & Molecular Biology', 'Polymer Science'), ('Green & Sustainable Science & Technology', 'Polymer Science'), ('Materials Science, Multidisciplinary', 'Mechanics'), ('Physics, Applied', 'Mechanics'), ('Physics, Condensed Matter', 'Mechanics'), ('Engineering, Multidisciplinary', 'Mechanics'), ('Engineering, Mechanical', 'Mechanics'), ('Engineering, Chemical', 'Mechanics'), ('Materials Science, Characterization & Testing', 'Mechanics'), ('Materials Science, Composites', 'Mechanics'), ('Engineering, Geological', 'Mechanics'), ('Mathematics, Interdisciplinary Applications', 'Mechanics'), ('Imaging Science & Photographic Technology', 'Mechanics'), ('Mathematics, Applied', 'Mechanics'), ('Materials Science, Multidisciplinary', 'Electrochemistry'), ('Chemistry, Physical', 'Electrochemistry'), ('Nanoscience & Nanotechnology', 'Electrochemistry'), ('Energy & Fuels', 'Electrochemistry'), ('Materials Science, Multidisciplinary', 'Engineering, Mechanical'), ('Physics, Applied', 'Engineering, Mechanical'), ('Engineering, Multidisciplinary', 'Engineering, Mechanical'), ('Engineering, Civil', 'Engineering, Mechanical'), ('Mechanics', 'Engineering, Mechanical'), ('Materials Science, Coatings & Films', 'Engineering, Mechanical'), ('Engineering, Manufacturing', 'Engineering, Mechanical'), ('Engineering, Chemical', 'Engineering, Mechanical'), ('Instruments & Instrumentation', 'Engineering, Mechanical'), ('Mathematics, Interdisciplinary Applications', 'Engineering, Mechanical'), ('Acoustics', 'Engineering, Mechanical'), ('Materials Science, Multidisciplinary', 'Materials Science, Coatings & Films'), ('Physics, Applied', 'Materials Science, Coatings & Films'), ('Physics, Condensed Matter', 'Materials Science, Coatings & Films'), ('Engineering, Mechanical', 'Materials Science, Coatings & Films'), ('Materials Science, Multidisciplinary', 'Physics, Multidisciplinary'), ('Chemistry, Physical', 'Physics, Multidisciplinary'), ('Chemistry, Multidisciplinary', 'Physics, Multidisciplinary'), ('Energy & Fuels', 'Physics, Multidisciplinary'), ('Polymer Science', 'Physics, Multidisciplinary'), ('Materials Science, Multidisciplinary', 'Engineering, Manufacturing'), ('Metallurgy & Metallurgical Engineering', 'Engineering, Manufacturing'), ('Engineering, Electrical & Electronic', 'Engineering, Manufacturing'), ('Engineering, Mechanical', 'Engineering, Manufacturing'), ('Engineering, Industrial', 'Engineering, Manufacturing'), ('Materials Science, Multidisciplinary', 'Engineering, Chemical'), ('Physics, Applied', 'Engineering, Chemical'), ('Chemistry, Physical', 'Engineering, Chemical'), ('Nanoscience & Nanotechnology', 'Engineering, Chemical'), ('Engineering, Multidisciplinary', 'Engineering, Chemical'), ('Energy & Fuels', 'Engineering, Chemical'), ('Engineering, Electrical & Electronic', 'Engineering, Chemical'), ('Polymer Science', 'Engineering, Chemical'), ('Mechanics', 'Engineering, Chemical'), ('Engineering, Mechanical', 'Engineering, Chemical'), ('Chemistry, Applied', 'Engineering, Chemical'), ('Biochemistry & Molecular Biology', 'Engineering, Chemical'), ('Thermodynamics', 'Engineering, Chemical'), ('Materials Science, Multidisciplinary', 'Physics, Atomic, Molecular & Chemical'), ('Chemistry, Physical', 'Physics, Atomic, Molecular & Chemical'), ('Nanoscience & Nanotechnology', 'Physics, Atomic, Molecular & Chemical'), ('Materials Science, Multidisciplinary', 'Materials Science, Characterization & Testing'), ('Metallurgy & Metallurgical Engineering', 'Materials Science, Characterization & Testing'), ('Mechanics', 'Materials Science, Characterization & Testing'), ('Materials Science, Composites', 'Materials Science, Characterization & Testing'), ('Materials Science, Multidisciplinary', 'Mineralogy'), ('Chemistry, Physical', 'Mineralogy'), ('Metallurgy & Metallurgical Engineering', 'Mineralogy'), ('Mining & Mineral Processing', 'Mineralogy'), ('Materials Science, Multidisciplinary', 'Instruments & Instrumentation'), ('Engineering, Mechanical', 'Instruments & Instrumentation'), ('Materials Science, Multidisciplinary', 'Chemistry, Applied'), ('Chemistry, Physical', 'Chemistry, Applied'), ('Nanoscience & Nanotechnology', 'Chemistry, Applied'), ('Engineering, Chemical', 'Chemistry, Applied'), ('Materials Science, Multidisciplinary', 'Computer Science, Information Systems'), ('Materials Science, Multidisciplinary', 'Biochemistry & Molecular Biology'), ('Chemistry, Physical', 'Biochemistry & Molecular Biology'), ('Polymer Science', 'Biochemistry & Molecular Biology'), ('Engineering, Chemical', 'Biochemistry & Molecular Biology'), ('Materials Science, Multidisciplinary', 'Mining & Mineral Processing'), ('Metallurgy & Metallurgical Engineering', 'Mining & Mineral Processing'), ('Mineralogy', 'Mining & Mineral Processing'), ('Materials Science, Multidisciplinary', 'Nuclear Science & Technology'), ('Materials Science, Multidisciplinary', 'Materials Science, Ceramics'), ('Materials Science, Multidisciplinary', 'Green & Sustainable Science & Technology'), ('Chemistry, Physical', 'Green & Sustainable Science & Technology'), ('Chemistry, Multidisciplinary', 'Green & Sustainable Science & Technology'), ('Energy & Fuels', 'Green & Sustainable Science & Technology'), ('Construction & Building Technology', 'Green & Sustainable Science & Technology'), ('Polymer Science', 'Green & Sustainable Science & Technology'), ('Materials Science, Multidisciplinary', 'Materials Science, Composites'), ('Mechanics', 'Materials Science, Composites'), ('Materials Science, Characterization & Testing', 'Materials Science, Composites'), ('Materials Science, Multidisciplinary', 'Engineering, Industrial'), ('Engineering, Manufacturing', 'Engineering, Industrial'), ('Materials Science, Multidisciplinary', 'Chemistry, Analytical'), ('Spectroscopy', 'Chemistry, Analytical'), ('Geosciences, Multidisciplinary', 'Chemistry, Analytical'), ('Archaeology', 'Chemistry, Analytical'), ('Art', 'Chemistry, Analytical'), ('Humanities, Multidisciplinary', 'Chemistry, Analytical'), ('Materials Science, Multidisciplinary', 'Spectroscopy'), ('Chemistry, Analytical', 'Spectroscopy'), ('Geosciences, Multidisciplinary', 'Spectroscopy'), ('Archaeology', 'Spectroscopy'), ('Art', 'Spectroscopy'), ('Humanities, Multidisciplinary', 'Spectroscopy'), ('Materials Science, Multidisciplinary', 'Geosciences, Multidisciplinary'), ('Chemistry, Analytical', 'Geosciences, Multidisciplinary'), ('Spectroscopy', 'Geosciences, Multidisciplinary'), ('Engineering, Geological', 'Geosciences, Multidisciplinary'), ('Archaeology', 'Geosciences, Multidisciplinary'), ('Art', 'Geosciences, Multidisciplinary'), ('Materials Science, Multidisciplinary', 'Engineering, Geological'), ('Mechanics', 'Engineering, Geological'), ('Geosciences, Multidisciplinary', 'Engineering, Geological'), ('Materials Science, Multidisciplinary', 'Thermodynamics'), ('Chemistry, Physical', 'Thermodynamics'), ('Metallurgy & Metallurgical Engineering', 'Thermodynamics'), ('Engineering, Multidisciplinary', 'Thermodynamics'), ('Energy & Fuels', 'Thermodynamics'), ('Engineering, Chemical', 'Thermodynamics'), ('Materials Science, Multidisciplinary', 'Archaeology'), ('Chemistry, Analytical', 'Archaeology'), ('Spectroscopy', 'Archaeology'), ('Geosciences, Multidisciplinary', 'Archaeology'), ('Art', 'Archaeology'), ('Materials Science, Multidisciplinary', 'Art'), ('Chemistry, Analytical', 'Art'), ('Spectroscopy', 'Art'), ('Geosciences, Multidisciplinary', 'Art'), ('Archaeology', 'Art'), ('Materials Science, Multidisciplinary', 'Humanities, Multidisciplinary'), ('Chemistry, Analytical', 'Humanities, Multidisciplinary'), ('Spectroscopy', 'Humanities, Multidisciplinary'), ('Materials Science, Multidisciplinary', 'Microscopy'), ('Materials Science, Multidisciplinary', 'Materials Science, Textiles'), ('Chemistry, Multidisciplinary', 'Materials Science, Textiles'), ('Materials Science, Multidisciplinary', 'Mathematics, Interdisciplinary Applications'), ('Mechanics', 'Mathematics, Interdisciplinary Applications'), ('Engineering, Mechanical', 'Mathematics, Interdisciplinary Applications'), ('Materials Science, Multidisciplinary', 'Chemistry, Inorganic & Nuclear'), ('Chemistry, Physical', 'Chemistry, Inorganic & Nuclear'), ('Materials Science, Multidisciplinary', 'Quantum Science & Technology'), ('Physics, Applied', 'Quantum Science & Technology'), ('Physics, Condensed Matter', 'Quantum Science & Technology'), ('Engineering, Electrical & Electronic', 'Quantum Science & Technology'), ('Materials Science, Multidisciplinary', 'Multidisciplinary Sciences'), ('Materials Science, Multidisciplinary', 'Biotechnology & Applied Microbiology'), ('Nanoscience & Nanotechnology', 'Biotechnology & Applied Microbiology'), ('Materials Science, Multidisciplinary', 'Imaging Science & Photographic Technology'), ('Mechanics', 'Imaging Science & Photographic Technology'), ('Mathematics, Applied', 'Imaging Science & Photographic Technology'), ('Materials Science, Multidisciplinary', 'Mathematics, Applied'), ('Mechanics', 'Mathematics, Applied'), ('Imaging Science & Photographic Technology', 'Mathematics, Applied'), ('Materials Science, Multidisciplinary', 'Education, Scientific Disciplines'), ('Materials Science, Multidisciplinary', 'Acoustics'), ('Physics, Applied', 'Acoustics'), ('Engineering, Mechanical', 'Acoustics')]

# 创建图
g = ig.Graph(directed=False)
g.add_vertices(vertices)
g.add_edges(edges)

# 允许最大社区大小
_max_comm_size = 10

partition = la.find_partition(g, partition_type=la.ModularityVertexPartition,  max_comm_size=_max_comm_size, seed=5)

coordinates = {}
n_clusters_ = 0
# 输出社区结果
print("社区划分结果:", partition)
for index_arr in partition:
    for index in index_arr:
        key_name = vertices[index]
        coordinates[key_name] = n_clusters_
    n_clusters_ += 1
print("coordinates:", coordinates)

# 图谱可视化
pos = g.layout("kk")
coords = pos.coords
indices = g.vs.indices
ig.plot(partition, "./knowledge_map.png")

reference


leidenalg

https://github.com/vtraag/leidenalg

万物皆网络,万字长文详解社区发现算法Leiden

https://zhuanlan.zhihu.com/p/712714461

Python使用leidenalg和igraph生成知识图谱的x、y坐标和聚类(莱顿算法)

https://blog.csdn.net/weixin_42597632/article/details/139180324

相关推荐
语落心生16 分钟前
大宗供应链企业舆情指标系统设计(一)舆情指标设计
数据分析
越努力越幸运50840 分钟前
webpack的学习打包工具
前端·学习·webpack
语落心生1 小时前
餐饮供应链的数仓设计思考 (五) 系统稳定性与SLA保障体系
数据分析
语落心生1 小时前
餐饮供应链的数仓设计思考 (四) 餐饮连锁企业数据模型可解释性
数据分析
语落心生1 小时前
餐饮供应链的数仓设计思考 (三) 数据管道与核心系统API对接方案
数据分析
语落心生1 小时前
餐饮供应链的数仓设计思考 (二) 餐饮连锁企业深度业务模型分析
数据分析
韩曙亮1 小时前
【人工智能】AI 人工智能 技术 学习路径分析 ② ( 深度学习 -> 机器视觉 )
人工智能·深度学习·学习·ai·机器视觉
语落心生1 小时前
餐饮供应链的数仓设计思考 (一) 系统设计大纲
数据分析
九千七5261 小时前
sklearn学习(3)数据降维
人工智能·python·学习·机器学习·sklearn
写点什么呢2 小时前
使用PE安装Win10系统
学习