用这个工具盘一盘社交网络分析常用networks
❝
「graph_tool」是个专门用于「创建networks」的Python库,底层数据结构和算法使用C++实现,大量使用元编程,依赖于C++的Boost Graph库。 graph_tool背后会涉及到各种「复杂图形理论算法」(例如,graph isomorphism, subgraph isomormism, minimum spanning tree, connected components, dominator tree, maximum flow, etc),但本文不谈算法,只说如何创建networks。 graph_tool主要「运用领域」: ❝❞社交网络分析
❞
数据挖掘
家谱树
网络聚类和建模
......
graph_tool安装
conda create --name gt -c conda-forge graph-tool
conda activate gt
graph_tool丰富的subpackages
graph_tool有很多的subpackages,文档非常详细,可前往https://graph-tool.skewed.de/static/doc/py-modindex.html仔细研读:
❝❞
graph_tool.centrality
- 计算network的中心度相关的信息graph_tool.clustering
- 计算计算network的各种聚类系数graph_tool.collection
- 数据集graph_tool.correlations
- 计算相关度信息graph_tool.dynamics
- network中常研究的动态过程方法使用graph_tool.draw
- 一些常用的绘图算法graph_tool.flow
- Edmonds-Karp algorithm,push-relabel algorithm等graph_tool.generation
- 用于预先生成一些network,2D or 3D triangulation graph,circular graph等graph_tool.inference
- 推断图的社区结构graph_tool.search
- 搜索算法graph_tool.stats
- network简单统计graph_tool.topology
- 包装network的拓扑性质,比如最小生成树,拓扑排序等graph_tool.util
- 节点和边的查找方法
快速上手graph_tool
#创建包含两个顶点一个有向边的network图
from graph_tool.all import *
g = Graph()#实例化Graph类创建一个空图
ug = Graph(directed=False)#有向图
ug = Graph()
ug.set_directed(False)
assert ug.is_directed() == False
g1 = Graph()
g2 = Graph(g1)
#add_vertex()方法添加两个顶点
v1 = g.add_vertex()
v2 = g.add_vertex()
#add_edge()添加了从v1到v2的有向边
e = g.add_edge(v1, v2)
#graph_draw()函数创建network图
graph_draw(g, vertex_text=g.vertex_index, output="two-nodes.pdf")
graph_tool丰富demo
Simple blockmodel with 10 blocks
isomorphism
2D triangulation of random points
2D or 3D triangulation graph from a given point set
State of Axelrod’s model on a political blog network
a Price network
minimum spanning tree
K-core decomposition of a network of network scientists
Jaccard similarities to vertex 0
in a political books network
让graph-tool图动起来
graph-tool结合matplotlib
很方便的绘制子图~~
Reference
https://graph-tool.skewed.de
/https://en.wikipedia.org/wiki/Graph-tool
··· END ···
推荐阅读:
Python中的高效迭代库itertools,排列组合随便求
万字长文详解|Python库collections,让你击败99%的Pythoner
↓扫描关注本号↓
评论