使用节点数和平均度参数创建网络 [英] Create networks with parameter number of nodes and mean degree

查看:20
本文介绍了使用节点数和平均度参数创建网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个随机网络(和无标度网络),其中N个节点,<k>个平均度。我如何才能做到这一点?

NetLogoNW扩展的nw: generate-random(和nw:generate-preferential-attachment)方法似乎不允许处理平均节点度。

我错了吗?小费? 谢谢。

推荐答案

确实,nw:generate-randomnw:generate-preferential-attachment都不允许您指定准确的平均程度。然而,在nw:generate-random的情况下,平均度数将大约为connection-probability * num-nodes。例如:

observer> repeat 10 [ ca nw:generate-random turtles links 1000 0.1 print 2 * count links / count turtles ]
99.902
100.358
100.522
99.674
100.338
100.272
99.772
100.24
100.24
100.412

也就是说,如果您确实想指定准确的平均程度,您可以使用以下命令:

to generate-random [ num-nodes avg-degree ]
  crt num-nodes
  while [ 2 * count links < avg-degree * count turtles ] [
    ask one-of turtles [
      create-link-with one-of other turtles
    ]
  ]
end

请注意,该代码故意不会执行类似create-link-with one-of other turtles with [ not link-neighbor? myself ]的操作,因为这将最终创建更多的海龟,其度数将超过其应有的度数(即,平均度数将是正确的,但度数分布将是不对称的)。

优先依恋要稍微复杂一些。我们必须让足够多的海龟播种,这样才能让到来的海龟有足够的海龟附着在上面:

to generate-preferential-attachment [ num-nodes avg-degree ]
  crt avg-degree + 1 [
    create-links-with other turtles
  ]
  repeat (num-nodes - (avg-degree + 1)) [
    crt 1 [
      while [ 2 * count links < avg-degree * count turtles ] [
        create-link-with one-of other [ both-ends ] of one-of links
      ]
    ]
  ]
end

此代码使用与Models库中的优先附件模型相同的优先附件机制。从该模式:

;; This code is the heart of the "preferential attachment" mechanism, and acts like
;; a lottery where each node gets a ticket for every connection it already has.
;; While the basic idea is the same as in the Lottery Example (in the Code Examples
;; section of the Models Library), things are made simpler here by the fact that we
;; can just use the links as if they were the "tickets": we first pick a random link,
;; and than we pick one of the two ends of that link.
在大多数情况下,我只是在我的模型中使用NW过程来生成,但当我真的需要控制准确的平均度数时,我会在上面使用变体。再说一次,为了防止学位分布中的偏见悄悄进入,它们比你预期的要复杂一些。

这两个过程都假定没有预先存在的海龟。如果你的模型不是这样,请让我知道,我会修改的。否则会使代码变得不必要地复杂(因为您必须跟踪您创建了哪些海龟)。

编辑是对评论中的问题的回应:

while [ 2 * count links < avg-degree * count turtles ] [ ... ]将导致...反复运行,直到平均度数等于avg-degree。回想一下,平均学位等于2 * count links / count turtles

因此,在生成随机网络的情况下,我们尝试添加一个链接,检查是否有足够的链接,如果没有,则继续进行,直到足够为止。之所以在这里使用while而不是repeat,是因为外观的主体可能实际上没有创建链接(如果海龟试图链接到它已经链接的海龟)。这样写是为了防止学位分布中的偏见:海龟拥有的链接越多,它获得新墨水的可能性就越小。

在优先连接的情况下,我们一次添加一个节点,然后向该节点添加链接,直到我们的平均度数正确为止。这比总是让海龟带着avg-degree / 2链接进来更可取,因为它在奇数度数下玩得更好。

这篇关于使用节点数和平均度参数创建网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆