[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] Using external software for community detection in R
From: |
Fabio Daolio |
Subject: |
[igraph] Using external software for community detection in R |
Date: |
Wed, 20 Oct 2010 20:05:24 +0200 |
First of all, thanks again for the great work on the library.
I'd like to share with you what I'm doing: possibly there's a
better way to do it, maybe this could be useful to somebody
else.
I need to use the MCL algorithm, and I'd also like to try the
InfoMap algorithm in the near future, using the R interface.
Let's say that my network is stored in the variable "df", that
I'd like to pass it to MCL as a list of weighed edge, and that,
finally, I'd like to assign a membership value to its vertices
as a result of the community detection.
Here's what I came up with:
outfile<-"tmp.txt"
cmd<-paste("mcl - --abc -o - >",outfile,sep="")
pw<-pipe(cmd,open="wb")
write.graph(df,file=pw,format="ncol")
close(pw)
pr<-pipe(paste("cat ",outfile,sep=""),open="r")
lines<-readLines(pr)
comms<-strsplit(split="\t", lines)
close(pr)
for(i in 1:length(comms)){
for(n in comms[[i]]){
V(df)[which(V(df)$name==n)-1]$memb<-i-1
}
}
modularity(df,V(df)$memb)
Basically I set up a pipe for writing the network to MCL,
whose output is redirected to a temporary file, from which
I read through another pipe. It works.
Is there a way to avoid even the creation of that tmp file?
And is there a quicker way to assign memberships?
Sincerely,
--
Fabio Daolio
-----------------------------------------------------------------------------
PhD Student
Research & Teaching Assistant
UNIL University of Lausanne
HEC École des Hautes Études Commerciales
ISI Institut des Systèmes d'Information
Quartier UNIL-Dorigny, Internef 135
CH-1015 Lausanne, Switzerland
Phone: +41 (0)21 692 35 83
Fax: +41 (0)21 692 35 85
Skype: fabiodaolio
-----------------------------------------------------------------------------
- [igraph] Using external software for community detection in R,
Fabio Daolio <=