分布满足幂律的无标度网络有一个奇特的性质——“小世界”特性,虽然WWW中的页面数已超过80亿,但平均来说,在WWW上只需点击19次超链接,就可从一个网页到达任一其它页面。“小世界”现象在社会学上也称为“六度分离”。所以小世界是一种现象,其主要描述了同等规模节点的随机网络,具有较短的平均路径长度和较大的聚类系数特征的网络模型。
考虑到现实中单独使用小世界网络上的疾病传播模型极少,大多为无标度网络模型。在此展示的小世界网络基本模型,主要来源于NetLogo模型库中的Small Worlds
其主要界面如下:
调整总节点个数后可以对模型进行运行:
在上述模型基础上进行改进(SEIR模型)
假设人与人间构成了 BA 网络,人类社会组织存在小世界性、无标度性;而个体间存在差异,结点的度服从幂律分布。由此将小世界和无标度网络模型相结合构建的模型。
基本界面及运行结果如下:
模型假设感染者不会死亡,只会传染其他易感染者或者被隔离并治愈。模型假设康复者体内含有抗体,不会再感染病毒;模型假设潜伏者没有被收治,感染者会被收治,被收治的感染者会一直占用医院隔离区域;模型假设被隔离的感染者无法再感染其他人;模型假设患者只能通过医院收治再被治愈。通过对比仿真绘图我们可以发现,人们如果不进行隔离而去接触许多人的话,被感染的人数峰值会大很多而且会提前,如果大家都减少活动范围,自己宅在家中,潜伏者和感染者那两条线就几乎消失了,这就是为什么说,在病毒蔓延之际,采用自我隔离的方法是控制疫情最有效的措施之一。
话不多说,上源码(在NetLogo运行中务必完整设计页面布局,滑块与按钮不能少,不然会提示)
turtles-own[
state
initial-xcor
initial-ycor
exposed-start
received?
cured?
]
globals[remain-hospital-segregation-area]
to setup
clear-all
reset-ticks
create-turtles population[
set shape "circle"
set initial-xcor (random-xcor * 0.95)
set initial-ycor (random-ycor * 0.95)
setxy initial-xcor initial-ycor
set received? 0
become-susceptible
]
ask n-of initial-infectious-num turtles[
become-exposed
]
set remain-hospital-segregation-area hospital-patient-segregation-area
end
to go
ask turtles [
move-turltes
spread
transform
]
received-and-cured
tick
end
to received-and-cured
let current-time ticks
if current-time >= (receive-cure-response-time + latent-time)[
ask n-of remain-hospital-segregation-area patches [
if receive-rate >= random-float 1[ ;;receive-rate影响收治效率
let agents turtles-here
if count agents > 0[
ask one-of agents[
if state = 2 and received? = 0 [
if remain-hospital-segregation-area > 0 [
set remain-hospital-segregation-area (remain-hospital-segregation-area - 1)
set received? 1
recovery
]
]
]
]
]
]
let has-infected-not-cure turtles with [state = 2 and received? = 1 and cured? = 0]
let num count has-infected-not-cure
if num > 0 [
ask has-infected-not-cure [
recovery
]
]
]
end
to move-turltes
ifelse human-flow-range = 0[
fd 0
][
if random-float 1 < 0.2[
set heading random 360
]
ifelse (distancexy initial-xcor initial-ycor) < human-flow-range
[
fd 1
][
facexy initial-xcor initial-ycor
fd 1
]
]
end
to spread
let touch-agents other turtles-here
if count touch-agents >= 1[
if (state = 1 or state = 2) and received? = 0 [
ask touch-agents with [state = 0][infect-turtles]
]
]
end
to transform
if state = 1[
let current-ticks ticks
if current-ticks - exposed-start >= latent-time[
if transform-rate >= random-float 1 [become-infected]
]
]
end
to recovery
if state = 2 and recovery-rate >= random-float 1 [
become-recovered
]
end
to infect-turtles
if infection-rate >= random-float 1[
become-exposed
]
end
to become-susceptible
set state 0
set color green
end
to become-exposed
set state 1
set color yellow
set exposed-start ticks
end
to become-infected
set state 2
set color red
set cured? 0
end
to become-recovered
set state 3
set color blue
set cured? 1
end
无标度网络具有严重的异质性,其各节点之间的连接状况(度数)具有严重的不均匀分布性:大多数“普通”节点拥有很少的连接,而少数“热门”节点拥有极其多的连接,网络中的“热门”节点称作枢纽节点(Hub)。少数Hub点对无标度网络的运行起着主导的作用。从广义上说,无标度网络的无标度性是描述大量复杂系统整体上严重不均匀分布的一种内在性质。无标度网络的重要特征为:其节点度分布服从幂律分布。
传统的SIR模型与无标度网络模型进行结合,未加改进
将感染者、疑似感染者和康复者三者的关系进行了仿真与可视化。
由运行结果我们可以明显的看出,类似于我们的新冠肺炎疫情:随着时间的增长,感染者在逐步增多,但是从出现感染者时我们便会人为干预疾病的传播,这时会有少数的康复者,那么当感染者到峰值以后康复者的数量也在逐步增加,最终感染者数量趋近于0,而康复者数量在逐渐增多:而当出现第一例感染者时,与之相关的就会有大多数疑似感染者,而当我们人为干预后,患病率逐步下降,所以疑似感染者也在逐步下降
源码如下:
turtles-own
[
infected?
resistant?
virus-check-timer
]
to setup
clear-all
set-default-shape turtles "circle"
make-node nobody
make-node turtle 0
reset-ticks
end
to go
ask links [ set color gray ]
make-node find-partner
tick
if layout? [ layout ]
end
to setup2
ask turtles [
set infected? false
set resistant? false
]
ask n-of initial-outbreak-size turtles
[ become-infected ]
reset-ticks
end
to set-all-susceptible
ask turtles [
set color blue
]
end
to remove-infected
ask turtles with [color = red][
set color blue
]
end
to spread
if all? turtles [not infected?]
[ stop ]
ask turtles
[
set virus-check-timer virus-check-timer + 1
if virus-check-timer >= virus-check-frequency
[ set virus-check-timer 0 ]
]
spread-virus
do-virus-checks
tick
end
to make-node [old-node]
create-turtles 1
[
set color blue
if old-node != nobody
[ create-link-with old-node [ set color green ]
move-to old-node
fd 8
]
]
end
to-report find-partner
report [one-of both-ends] of one-of links
end
to resize-nodes
ifelse all? turtles [size <= 1]
[
ask turtles [ set size sqrt count link-neighbors ]
]
[
ask turtles [ set size 1 ]
]
end
to layout
repeat 3 [
let factor sqrt count turtles
layout-spring turtles links (1 / factor) (7 / factor) (1 / factor)
display
]
let x-offset max [xcor] of turtles + min [xcor] of turtles
let y-offset max [ycor] of turtles + min [ycor] of turtles
set x-offset limit-magnitude x-offset 0.1
set y-offset limit-magnitude y-offset 0.1
ask turtles [ setxy (xcor - x-offset / 2) (ycor - y-offset / 2) ]
end
to-report limit-magnitude [number limit]
if number > limit [ report limit ]
if number < (- limit) [ report (- limit) ]
report number
end
to become-infected
set infected? true
set resistant? false
set color red
end
to become-susceptible
set infected? false
set resistant? false
set color blue
end
to become-resistant
set infected? false
set resistant? true
set color gray
ask my-links [ set color gray - 2 ]
end
to spread-virus
ask turtles with [ infected? ]
[ ask link-neighbors with [not resistant?]
[ if random-float 100 < virus-spread-chance
[ become-infected ] ] ]
end
to do-virus-checks
ask turtles with [infected? and virus-check-timer = 0]
[
if random 100 < recovery-chance
[
ifelse random 100 < gain-resistance-chance
[ become-resistant ]
[ become-susceptible ]
]
]
end
与普通网络图比较,随机网络具有以下几个特点:
随机网络的箭线和节点不一定都能实现,实现的可能性取决于节点的类型和箭线的概率系数;
随机网络中各项活动的时间可以是常数,也可以是服从某种概率分布的密度函数,更具有不确定性;
随机网络中可以有循环回路,表示节点或活动可以重复出现;
随机网络中的两个中间节点之间可以有一条以上箭线;
随机网络中可以有多个目标,每个目标反映一个具体的结果,即可以有多个起点或终点
传统的随机网络(如ER模型),尽管连接是随机设置的,但大部分节点的连接数目会大致相同,即节点的分布方式遵循钟形的泊松分布,有一个特征性的“平均数”。连接数目比平均数高许多或低许多的节点都极少,随着连接数的增大,其概率呈指数式迅速递减。故随机网络亦称指数网络。随机图中一个有趣的性质是,当节点的平均度数达到1的时候,网络中就会出现一个明显的巨大部分(giant component)本模型主要来源于NetLogo模型库中的Giant Component
假设一个团体中有很多的个体,之后两个人随机的认识并且成为朋友,那么随着时间的推移,这个团体会变成什么样子呢?该模型将此情景很好的模拟了出来。
左下角表示度中心性,也就是每个节点和其他多少个节点直接相连,可以理解为一个人交到了多少个好朋友。统计结果显示,当度中心度到达1左右的时候,也就是每个人都有一个好朋友之后,网络中最大的成分会爆炸性增长,也就是说认识朋友的圈子会快速的增加。如果在中途统计网络中所有人员交朋友的数量,我们会发现这个数量实际上是符合正态分布的。
而基于随机网模型的疾病扩散是以随机分布的方式,随机结合,但是同样也是以一个人为基准,其余随机连接的仿真模型。
随着周数的增加,感染者的人数在不断增加,但是随着人为干预的效果逐渐增加,治愈的和有免疫力的人数也在不断增加,类似于生物学中的拮抗作用,此时感染者的人数就开始下降了,最终趋近于0,健康的人和有免疫力的人都在不断增加,疾病传播得到有效的抑制。与其他网络模型不同的是,我们可以看到随机网的是基于一个人,以此为基准随机产生的关系进行传播 。
源码源码!在这里!
turtles-own
[ sick?
remaining-immunity
sick-time
age ]
globals
[ %infected
%immune
lifespan
chance-reproduce
carrying-capacity
immunity-duration ]
to setup
clear-all
setup-constants
setup-turtles
update-global-variables
update-display
reset-ticks
end
to setup-turtles
create-turtles number-people
[ setxy random-xcor random-ycor
set age random lifespan
set sick-time 0
set remaining-immunity 0
set size 1.5
get-healthy ]
ask n-of 10 turtles
[ get-sick ]
end
to get-sick
set sick? true
set remaining-immunity 0
end
to get-healthy
set sick? false
set remaining-immunity 0
set sick-time 0
end
to become-immune
set sick? false
set sick-time 0
set remaining-immunity immunity-duration
ask my-links [ die ]
end
to setup-constants
set lifespan 50 * 52
set carrying-capacity 300
set chance-reproduce 1
set immunity-duration 52
end
to go
ask turtles [
get-older
move
if sick? [ recover-or-die ]
ifelse sick? [ infect ] [ reproduce ]
]
update-global-variables
update-display
tick
end
to update-global-variables
if count turtles > 0
[ set %infected (count turtles with [ sick? ] / count turtles) * 100
set %immune (count turtles with [ immune? ] / count turtles) * 100 ]
end
to update-display
ask turtles
[ if shape != turtle-shape [ set shape turtle-shape ]
set label ifelse-value show-age? [ floor (age / 52) ] [ "" ]
set color ifelse-value sick? [ red ] [ ifelse-value immune? [ grey ] [ green ] ] ]
stop-inspecting-dead-agents
if watch-a-person? and subject = nobody
[ watch one-of turtles with [ not hidden? ]
clear-drawing
ask subject [ pen-down ]
inspect subject ]
if not watch-a-person? and subject != nobody
[ stop-inspecting subject
ask subject
[ pen-up
ask my-links [ die ] ]
clear-drawing
reset-perspective ]
end
to get-older
set age age + 1
if age > lifespan [ die ]
if immune? [ set remaining-immunity remaining-immunity - 1 ]
if sick? [ set sick-time sick-time + 1 ]
end
to move
rt random 100
lt random 100
fd 1
end
to infect
ask other turtles-here with [ not sick? and not immune? ]
[ if random-float 100 < infectiousness
[ get-sick
if self = subject
[ create-link-with myself
[ set color red
set thickness .3 ] ] ] ]
end
to recover-or-die
if sick-time > duration
[ ifelse random-float 100 < chance-recover
[ become-immune ]
[ die ] ]
end
to reproduce
if count turtles < carrying-capacity and random-float 100 < chance-reproduce
[ hatch 1
[ set age 1
lt 45 fd 1
pen-up
get-healthy ] ]
end
to-report immune?
report remaining-immunity > 0
end
to startup
setup-constants
end
本程序使用NetLogo6.2.0版本,可以从 NetLogo 6.2.0下载地址 下载