在igraph(R)中进行社区检测后,如何找到对策? [英] How to find measures after community detection in igraph (R)?

查看:87
本文介绍了在igraph(R)中进行社区检测后,如何找到对策?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用图形中的社区检测.我经历了igraph中实现的各种社区检测算法,并绘制了社区结构图.现在,在获得针对不同算法的社区对象之后,我想根据密度,切割率,覆盖率等不同指标对算法进行比较. (我知道模块化已经实现).我可以获取一个子图,然后计算集群内部的密度,但是要找到集群内部的密度,我不知道如何进行.这是我用来查找集群内部密度的代码:

I am working with Community Detection in graphs. I have been through the different community detection algorithms implemented in igraph and plotting the community structures. Now after getting the communities object for different algorithms, I want to compare the algorithms based on different measures like density,cut ratio, coverage. (I know that modularity is already implemented). I can obtain a subgraph and then calculate the intra-cluster density but to find the inter-cluster density, I dont not know how to proceed. This is the code I have been using to find intra-cluster density:

karate <- graph.famous("Zachary")
wckarate <- walktrap.community(karate) #any algorithm
subg1<-induced.subgraph(karate, which(membership(wckarate)==1)) #membership id differs for each cluster
intradensity1 <- ecount(subg1)/ecount(karate) #for each cluster

类似地,我可以对每个群集进行处理,然后将所有密度相加或取所有平均值的平均值.我的问题是,如果社区的数量很大,那么如何进行?

Similarly I could proceed for each cluster and add all the densities or take the average of the all. My question is that if the number of communities is very large, then how to proceed?

如果我想提取不同社区之间的边缘数量,是否有一种不错的方法来提取边缘数量?

And if I want to extract the number of edges between different communities, is there a nice way to extract the number of edges?

如果已经问过这个问题,请原谅我.我是igraph和R的新手.

Please pardon me if this question is already asked. I am novice to igraph and R.

推荐答案

好吧,我们可以修改您的代码以遍历不同的子组

Well, we can just adapt your code to loop over the different subgroups

karate <- graph.famous("Zachary")
wckarate <- walktrap.community(karate) #any algorithm
sapply(unique(membership(wckarate)), function(g) {
    subg1<-induced.subgraph(karate, which(membership(wckarate)==g)) #membership id differs for each cluster
    ecount(subg1)/ecount(karate)
})

只要在社区之间取得优势,就可以做到

and as far as getting the edges between the communities, you could do

#get all combinations of communities
cs <- data.frame(combn(unique(membership(wckarate)),2))
cx <- sapply(cs, function(x) {
    es<-E(karate)[V(karate)[membership(wckarate)==x[1]] %--% 
              V(karate)[membership(wckarate)==x[2]]]    
    length(es)
})
cbind(t(cs),cx)

此外,您可以绘制社区以确保外观合理

Also you can plot the communities to make sure that looks reasonable

plot.communities(wckarate, karate)

这篇关于在igraph(R)中进行社区检测后,如何找到对策?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆