Guest User

Untitled

a guest
Jan 7th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.54 KB | None | 0 0
  1. local.eff <- function(g) {
  2.   if ('degree' %in% vertex_attr_names(g)) {
  3.     degs <- V(g)$degree
  4.   } else {
  5.     degs <- degree(g)
  6.   }
  7.  
  8.   eff <- numeric(length(degs))
  9.   nodes <- which(degs > 1)
  10.  
  11.   eff[nodes] <- simplify2array(mclapply(nodes, function(x) {
  12.     neighbs <- neighbors(g, v=x)
  13.     g.sub <- induced.subgraph(g, neighbs)
  14.     Nv <- vcount(g.sub)
  15.    
  16.     paths <- shortest.paths(g.sub, weights=NA)
  17.     paths <- paths[upper.tri(paths)]
  18.     2 / Nv / (Nv - 1) * sum(1 / paths[paths != 0])
  19.     }, mc.cores=detectCores())
  20.   )
  21. eff
  22. }
Advertisement
Add Comment
Please, Sign In to add comment