2014-01-17 68 views
-9

我曾尝试在R中使用igraph中的'rewire',但它仅适用于未加权的网络。任何帮助?如何在R中使用igraph重新加权加权网络?

+1

试图编辑以改善问题,但我的编辑被拒绝。看到OP下面的评论说,关键问题是在重新接线时产生NAs,即'使用wiehgts中的NA以上的例子是用 set.seed(1)g < - graph.ring(10)产生的。 E(g)$ weight < - seq_len(ecount(g)); E(克)重量$; #[1] 1 2 3 4 5 6 7 8 9 10; is.weighted(克); #[1] TRUE; g2 < - rewire(g,niter = 3); E(G2)$权重; #[1] 1 2 4 5 6 7 9 NA NA NA is.weighted(g2); #[1]使用igraph版本[1]为TRUE“0.7.1”' – user1320502

+1

@ user1320502编辑被拒绝的原因是因为您不会将文字放入OP的口中。问题不清楚,你应该要求OP改进它。你的猜测我不是很正确,所以我们应该把它留给OP。真正唯一的例外是从OP处收到评论并将其添加到问题中。 – NathanOliver

+0

@ user1320502此编辑[正在Meta上讨论](http://meta.stackoverflow.com/questions/332189/suggested-edit-deleting-the-question-in-its-entirety)。 –

回答

2

我的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" 
+1

这是真的。但我有一个图形编辑表格。前两列是节点,第三列是分配给每个边的权重。现在当我重新连接加权图(我使用read.graph(file.txt))时,这将重新绘制图形,但我不知道它是如何处理权重的。打印重新连线图的权重将打印具有一些NA条目的权重。我希望重量也会随着边缘洗牌。但这没有发生......这是我感兴趣的。??? – user3197361

+3

给我们一些示例代码,显示这一点并编辑您的问题。 – Spacedman

1

使用的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 

注这种做法可能会导致多重或循环。