Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # code by Christopher G. Watson; [email protected]
- local.eff <- function(g) {
- if ('degree' %in% vertex_attr_names(g)) {
- degs <- V(g)$degree
- } else {
- degs <- degree(g)
- }
- eff <- numeric(length(degs))
- nodes <- which(degs > 1)
- eff[nodes] <- simplify2array(mclapply(nodes, function(x) {
- neighbs <- neighbors(g, v=x)
- g.sub <- induced.subgraph(g, neighbs)
- Nv <- vcount(g.sub)
- paths <- shortest.paths(g.sub, weights=NA)
- paths <- paths[upper.tri(paths)]
- 2 / Nv / (Nv - 1) * sum(1 / paths[paths != 0])
- }, mc.cores=detectCores())
- )
- eff
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement