How to find measures after locating a community in igraph (R)?

I work with community discovery in graphs. I went through various community discovery algorithms implemented in igraph and built a community structure. Now, having received a community object for different algorithms, I want to compare algorithms based on various measurements, such as density, reduction ratio, and coverage. (I know that modularity is already implemented). I can get a subgraph and then calculate the density inside the cluster, but find the density between the clusters, I don’t know how to do it. This is the code I used to determine the density inside the cluster:

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 

In a similar way, I could act for each cluster and add all densities or take the average of all. My question is, 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 good way to extract the number of edges?

Please forgive me if this question has already been asked. I am new to igraph and R.

+6
source share
1 answer

Well, we can just adapt your code to a loop over various 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 to get boundaries between 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) 

You can also build communities to make sure it looks smart.

 plot.communities(wckarate, karate) 

enter image description here

+6
source

Source: https://habr.com/ru/post/971599/


All Articles