【问题标题】:How do you rewire a weighted network using igraph in R?如何在 R 中使用 igraph 重新连接加权网络?
【发布时间】:2014-02-06 10:05:12
【问题描述】:

我曾尝试在 R 的 igraph 中使用“rewire”,但它仅适用于未加权网络。有什么帮助???

【问题讨论】:

  • 尝试编辑以改进问题,但我的编辑被拒绝。看到 OP 下面的 cmets 说关键问题是重新布线时产生的 NA,即using the example above NA in the wiehgts are produced with set.seed(1) 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); E(g2)$weight; # [1] 1 2 4 5 6 7 9 NA NA NA is.weighted(g2); # [1] TRUE using igraph version [1] "0.7.1"
  • @user1320502 你的编辑被拒绝的原因是你没有把话放在OP的嘴里。问题不清楚,您应该要求 OP 改进它。你的猜测我不正确,所以我们应该把它留给 OP。真正唯一的例外是从 OP 中获取评论并将其添加到问题中。
  • @user1320502 此编辑是being discussed on Meta
  • 感谢@NathanOliver,但下面的 OP 声明“打印重新布线图的权重将打印带有一些 NA 条目的权重。我希望权重也将与边缘一起洗牌。但这不会发生.. .这是我感兴趣的。???”对 NA 编辑说得很清楚,并没有把话放在 OP 嘴里。不过谢谢,我会问一个新的单独问题。感谢 S.L Barth 的元链接

标签: r igraph


【解决方案1】:

我的igraph 版本很乐意重新连接加权图:

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

版本是:

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

【讨论】:

  • 这是真的。但我有一个 edglist 形式的图表。前两列是节点,第三列是分配给每条边的权重。现在,当我重新连接加权图(我使用 read.graph(file.txt) 制作的)时,这会重新连接图表,但我不知道它对权重做了什么。打印重新布线图的权重将打印带有一些 NA 条目的权重。我希望权重也将与边缘一起洗牌。但这并没有发生……这是我感兴趣的。???
  • 给我们一些显示这一点的示例代码并编辑您的问题。
【解决方案2】:

使用 igraph 的 1.0.1 版本,尝试以下操作:

# 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

请注意,这种方法可能会导致多重边或循环。

【讨论】:

    猜你喜欢
    • 2018-03-21
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多