简体   繁体   English

根据iGraph中的常用参数折叠图[Python]

[英]collapsing graphs according to a common parameter in iGraph [Python]

I have an igraph network g where all edges' weights are 1 and where all vertices belong to on of 5 groups (noted with a vertex parameter called "group"). 我有一个igraph网络g,其中所有边的权重均为1,并且所有顶点都属于5个组中的一个(标注为“ group”的顶点参数)。

Now I want to make a new graph G where the vertices of g are collapsed, ore contracted, according to the group they belong to. 现在,我想根据其所属的组,创建一个新的图形G,其中g的顶点被折叠,矿石收缩。 So that the number of vertices of G is reduced to the number of different groups in g, and the edges between these new collapsed vertices have a weight equal to the summed up number of edges between the same groups in g. 因此,将G的顶点数量减少到g中不同组的数量,并且这些新的折叠顶点之间的边的权重等于g中相同组之间的边的总和。

I believe I could use contract_vertices(). 我相信我可以使用contract_vertices()。 But the edges' weights wouldn't be added, I'm guessing... Anyway, is there a way to accomplish this in igraph? 但是,我想,不会增加边缘的权重...无论如何,有没有办法在igraph中完成此任务?

Thanks! 谢谢!

Use contract_vertices() followed with simplify() , which can collapse the edges and sum the weights: 使用contract_vertices()后跟simplify() ,可以折叠边缘并求和权重:

g2 = g.copy()
g2.contract_vertices(membership)
g2.simplify(combine_edges={"weight": sum})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM