gpt4 book ai didi

r - 警告消息已断开图形的巨型组件本身已断开连接

转载 作者:行者123 更新时间:2023-12-02 10:45:02 24 4
gpt4 key购买 nike

我在这里有点困惑,我使用以下代码提取了断开连接图的巨型组件。

function(graph) {
cl <- clusters(graph)
induced.subgraph(graph, which(cl$membership == which.max(cl$csize)))
}

但是在RStudio中运行这样的代码会给我带来频繁的错误,例如
is_connected(ngo.giant)
[1] TRUE
centr_clo(ngo.giant)$centralization
[1] 0.003214897
Warning message:
In centr_clo(ngo.giant) :
At centrality.c:2784 :closeness centrality is not well-defined for disconnected graphs
temp<-centr_eigen(ngo.giant,directed=T)
Warning message:
In centr_eigen(ngo.giant, directed = T) :
At centrality.c:344 :graph is directed and acyclic; eigenvector centralities will be zeros

是否有发生这种情况的原因?如果此代码过于含糊,我们深表歉意

最佳答案

我刚刚收到警告,我注意到这是由于我的图形是有向的,因此某些路径只能沿一个方向行走,而某些节点则与另一方向“分离”。

test <- data.frame(source=c('a', 'a'), target=c('b', 'c'), stringsAsFactors=FALSE)
g <- igraph::graph_from_data_frame(test, directed=TRUE)
igraph::closeness(g)

a b c
0.5000000 0.1666667 0.1666667
Warning message:
In igraph::closeness(g) :
At centrality.c:2784 :closeness centrality is not well-defined for disconnected graphs

同样,如果在 mehtod='all'中使用参数 closeness,则您的图形将被视为无向图。

关于r - 警告消息已断开图形的巨型组件本身已断开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56228986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com