SHOW:
|
|
- or go back to the newest paste.
1 | # code by Christopher G. Watson; [email protected] | |
2 | ||
3 | local.eff <- function(g) { | |
4 | if ('degree' %in% vertex_attr_names(g)) { | |
5 | degs <- V(g)$degree | |
6 | } else { | |
7 | degs <- degree(g) | |
8 | } | |
9 | ||
10 | eff <- numeric(length(degs)) | |
11 | nodes <- which(degs > 1) | |
12 | ||
13 | eff[nodes] <- simplify2array(mclapply(nodes, function(x) { | |
14 | neighbs <- neighbors(g, v=x) | |
15 | g.sub <- induced.subgraph(g, neighbs) | |
16 | Nv <- vcount(g.sub) | |
17 | ||
18 | paths <- shortest.paths(g.sub, weights=NA) | |
19 | paths <- paths[upper.tri(paths)] | |
20 | 2 / Nv / (Nv - 1) * sum(1 / paths[paths != 0]) | |
21 | }, mc.cores=detectCores()) | |
22 | ) | |
23 | eff | |
24 | } |