gpt4 book ai didi

随机生成指定聚类系数的网络

转载 作者:行者123 更新时间:2023-12-04 10:19:12 26 4
gpt4 key购买 nike

过去我用过 igraph生成具有指定重新布线概率的小世界网络 p ,这特别容易,因为它是 sample_smallworld 中的一个参数功能。例如:

myNetwork <- sample_smallworld(dim = 1, size = 10, nei = 2, p = 0.25)
plot(myNetwork, layout = layout_in_circle)



我现在想生成具有指定聚类系数的小世界网络。我是新来的 igraph这似乎是它应该拥有的功能,但经过一番搜索后,我只找到了从预先存在的网络计算系数的方法,而不是将其用作生成网络本身的参数的方法。

生成具有指定聚类系数的网络的最佳方法是什么?

最佳答案

如果你对一些条件没问题,那么可以使用 sna::rguman() 获得一种近似的近似值。 .条件是:(1)使用全局传递性(也许你可以使用它并修改); (2) 使用无向图; (3) 如果使用较小的传递性值,则使用大尺寸的图,或者对于小尺寸的图使用较大的传递性值。还有,放弃sample_smallworld()算法。如果没问题,这可能会让你到达你想去的地方:

library(sna)
library(igraph)

sample_cluster <- function(nv = 150, clustering_coef = 0.5, thres = 0.05) {
g <- sna::rguman(1, nv, mut = clustering_coef, asym = 0, null = 1 - clustering_coef) %>%
graph_from_adjacency_matrix(mode = "undirected")

while (!(transitivity(g) >= clustering_coef-thres & transitivity(g) <= clustering_coef+thres)) {
g <- sna::rguman(1, nv, mut = clustering_coef, asym = 0, null = 1 - clustering_coef) %>%
graph_from_adjacency_matrix(mode = "undirected")
}

return(g)

}


sample_cluster(15, clustering_coef = 0.2, thres = 0.001) %>% transitivity()
#> [1] 0.2

sample_cluster(200, clustering_coef = 0.01, thres = 0.001) %>% transitivity()
#> [1] 0.009009009

sample_cluster(200, clustering_coef = 0.2, thres = 0.001) %>% transitivity()
#> [1] 0.2007628

sample_cluster(20, clustering_coef = 0.7, thres = 0.001) %>% transitivity()
#> [1] 0.7007168

创建于 2020-03-31 由 reprex package (v0.3.0)

不花哨,不复杂,但可能会成功!

关于随机生成指定聚类系数的网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60946344/

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