How do you rewire a weighted network using igraph in R?

早过忘川 提交于 2019-12-13 10:15:05

问题


I have tried using 'rewire' in igraph in R, but it works only for unweighted networks. Any help???


回答1:


My version of igraph will happily rewire a weighted graph:

g <- graph.ring(10)
E(g)$weight <- seq_len(ecount(g))
E(g)$weight
# [1]  1  2  3  4  5  6  7  8  9 10
is.weighted(g)
# [1] TRUE
g2 <- rewire(g,niter=3)
plot(g2)
is.weighted(g2)
# [1] TRUE

Version is:

packageDescription("igraph")$Version
# [1] "0.6.6"



回答2:


Using version 1.0.1 of igraph, try the following:

# SAME EXAMPLE AS IN PREVIOUS ANSWER AND COMMENTS 
g <- graph.ring(10)
E(g)$weight <- seq_len(ecount(g))
E(g)$weight
# [1]  1  2  3  4  5  6  7  8  9 10
is.weighted(g)
# [1] TRUE
g2 <- rewire(g, with=each_edge(0.5)) #rewire vertices with constant probability
E(g2)$weight <- sample(E(g)$weight) #shuffle initial weights and assign them randomly to edges
plot(g2)
is.weighted(g2)
# [1] TRUE
E(g2)$weight
# [1]  3  6  2  4 10  1  9  8  7  5

Note that this approach might lead to multiedges or loops.



来源:https://stackoverflow.com/questions/21179746/how-do-you-rewire-a-weighted-network-using-igraph-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!