如何根据节点的入度创建链接?
How to create links based on the node's in-degree?
我在创建两个不同品种(人类和僵尸)的链接时遇到了一些困难。
这些链接应该以这样的方式创建,即来自第一个品种(人类)的海龟具有更多链接(入度)有更高的可能性链接第二个品种(僵尸) - 即,来自人类的海龟的可能性selected 与节点的 in-degree k_in
成正比。
在每次滴答时,我都会在网络中添加一个僵尸。
考虑到优先依恋模式,我写道:
let thisZombie one-of [both-ends] of one-of links
create-link-with thisZombie
但它返回了以下错误:
LINKS is a directed breed.
error while zombie 10 running CREATE-LINK-WITH
called by procedure ADD-ZOMBIE
called by procedure GO
called by Button 'go'.
这是这部分的全部代码:
create-zombies 1
[
if targeting = "first model"
[
let thisZombie self
ask one-of humans
[
ifelse random-float 1 < p
[create-link-from thisZombie [set color red]]
[ask thisZombie [die]]
]
]
if targeting = "second model (preferential_attachment)"
[
let thisZombie one-of [both-ends] of one-of links
create-link-with thisZombie
]
]
我有以下两个问题:
- 我如何select 人类基于其
in-degree
?
- 如果是两个不同的品种,使用
create-link-with one-of both-ends
是否正确?
谢谢
你有正确的通用方法(我想你已经从 NetLogo 模型库中的 Preferential Attachment 模型中提取出来了)但是有两件事导致了你的问题:
您正确地使用 one-of links
来选择一个 link,但是到那时选择 link 中的 one-of [both-ends]
,您可能会选择 要么人类要么僵尸,这不是你想要的。如果你的 link 总是从僵尸变成人类(就像它们似乎是基于你的 "first model"
的代码一样,那么人类将永远是 [=39] 的 end2
=],你可以写:[end2] of one-of links
。如果不知道link的方向,你可以写[one-of both-ends with [breed = humans]] of one-of links
,但效率会降低。
您不能混合定向和非定向 "unbreeded" links。 (有关详细信息,请参阅 the user manual。)
再次假设您的 link 总是从僵尸到人类,您的代码应该如下所示:
if targeting = "second model (preferential_attachment)" [
let thisZombie self
; pick the human end of a random link
ask [end2] of one-of links [ create-link-from thisZombie ]
]
我在创建两个不同品种(人类和僵尸)的链接时遇到了一些困难。
这些链接应该以这样的方式创建,即来自第一个品种(人类)的海龟具有更多链接(入度)有更高的可能性链接第二个品种(僵尸) - 即,来自人类的海龟的可能性selected 与节点的 in-degree k_in
成正比。
在每次滴答时,我都会在网络中添加一个僵尸。
考虑到优先依恋模式,我写道:
let thisZombie one-of [both-ends] of one-of links
create-link-with thisZombie
但它返回了以下错误:
LINKS is a directed breed.
error while zombie 10 running CREATE-LINK-WITH
called by procedure ADD-ZOMBIE
called by procedure GO
called by Button 'go'.
这是这部分的全部代码:
create-zombies 1
[
if targeting = "first model"
[
let thisZombie self
ask one-of humans
[
ifelse random-float 1 < p
[create-link-from thisZombie [set color red]]
[ask thisZombie [die]]
]
]
if targeting = "second model (preferential_attachment)"
[
let thisZombie one-of [both-ends] of one-of links
create-link-with thisZombie
]
]
我有以下两个问题:
- 我如何select 人类基于其
in-degree
? - 如果是两个不同的品种,使用
create-link-with one-of both-ends
是否正确?
谢谢
你有正确的通用方法(我想你已经从 NetLogo 模型库中的 Preferential Attachment 模型中提取出来了)但是有两件事导致了你的问题:
您正确地使用
one-of links
来选择一个 link,但是到那时选择 link 中的one-of [both-ends]
,您可能会选择 要么人类要么僵尸,这不是你想要的。如果你的 link 总是从僵尸变成人类(就像它们似乎是基于你的"first model"
的代码一样,那么人类将永远是 [=39] 的end2
=],你可以写:[end2] of one-of links
。如果不知道link的方向,你可以写[one-of both-ends with [breed = humans]] of one-of links
,但效率会降低。您不能混合定向和非定向 "unbreeded" links。 (有关详细信息,请参阅 the user manual。)
再次假设您的 link 总是从僵尸到人类,您的代码应该如下所示:
if targeting = "second model (preferential_attachment)" [
let thisZombie self
; pick the human end of a random link
ask [end2] of one-of links [ create-link-from thisZombie ]
]