[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] igraph R code to Python
From: |
Simone Gabbriellini |
Subject: |
Re: [igraph] igraph R code to Python |
Date: |
Wed, 19 Jan 2011 12:06:40 +0100 |
Tamas,
thanks a lot, lcc.vs is fine for me! ;)
I have uploaded some R code for bipartite networks on the igraph wiki R
recipes. I am now trying to write a Python version of it, either for my
research needs and for sake of completing my wiki entry (btw, is there a Python
recipes page?).
After retrieving the largest connected component (lcc), I would like to find
the average shortest paths for top and bottom nodes in it. Is there something
like:
mean(shortest.paths(lcc, v=V(lcc)[type==FALSE], to=V(lcc)[type==FALSE], mode =
'all'))
mean(shortest.paths(lcc, v=V(lcc)[type==TRUE], to=V(lcc)[type==TRUE], mode =
'all'))
I know it is much to ask, but I have also to translate a clustering function
that Gabor wrote in order to reproduce in python all the clustering measures of
Latapy, Magnien and Del Vecchio, Social Networks 30 (2008):
ccBip <- function(g) {
if (! "name" %in% list.vertex.attributes(g)) {
V(g)$name <- seq_len(vcount(g))
}
neib <- get.adjlist(g)
names(neib) <- V(g)$name
proj <- bipartite.projection(g)
lapply(proj, function(x) {
el <- get.edgelist(x)
sapply(V(x)$name, function(v) {
subs <- el[,1]==v | el[,2]==v
f <- function(un, vn) length(union(un, vn))
vals <- E(x)[subs]$weight / unlist(mapply(f, neib[el[subs,1]],
neib[el[subs,2]]))
mean(vals)
})
})
}
any help is more than welcome!
best,
Simone