如何将幂律可能性添加到 Netlogo 模型
How to add power law likelihood to Netlogo Model
我想在 power law 之后的环境 ABM 中添加自然灾害的可能性(通常很少损坏,一般损坏较少,很少有强烈损坏,很少完全损坏)。
到目前为止我编写了以下代码:
to environment ;environmental hits
create-hits 1 [ ; I do not know if it makes sense to do that?
set shape "circle"
set color white
set size 0.05
setxy random-xcor random-ycor
]
ask hits [
ifelse pcolor = red [die] ;if already red, then stop
[ ask n-of random (count patches) patches [ set pcolor red ]] ;otherwise turn red on an random amount of patches
]
end
现在,我不知道如何添加 "hit" 有多强(因此,有多少补丁会受到影响)和可能性有多大(根据幂律)的随机因素发生(或不发生)每个滴答声。有人可以帮我吗?
这是最终代码(Alan 回答):
to environment
create-hits 1 [
set shape "circle"
set color white
set size 0.05
setxy random-xcor random-ycor
]
ask hits [
let %draw (random-float 100)
let %strength 0 ;; no damage
if (%draw < 50) [set %strength (%strength + 1)] ;;1 for little damage
if (%draw < 10) [set %strength (%strength + 1)] ;;2 for middle damage
if (%draw < 5) [set %strength (%strength + 1)] ;;3 for strong damage
if (%draw < 1) [set %strength (%strength + 1)] ;;4 for complete destruction
ifelse pcolor = red [die]
[ ask n-of %strength patches [ set pcolor red ]]
]
end
这只是对@Mars 评论的阐述。
to-report hit-strength
let %draw (random-float 100)
let %strength 0 ;; no damage
if (%draw < 50) [set %strength (%strength + 1)] ;;1 for little damage
if (%draw < 10) [set %strength (%strength + 1)] ;;2 for middle damage
if (%draw < 5) [set %strength (%strength + 1)] ;;3 for strong damage
if (%draw < 1) [set %strength (%strength + 1)] ;;4 for complete destruction
report %strength
end
我想在 power law 之后的环境 ABM 中添加自然灾害的可能性(通常很少损坏,一般损坏较少,很少有强烈损坏,很少完全损坏)。
到目前为止我编写了以下代码:
to environment ;environmental hits
create-hits 1 [ ; I do not know if it makes sense to do that?
set shape "circle"
set color white
set size 0.05
setxy random-xcor random-ycor
]
ask hits [
ifelse pcolor = red [die] ;if already red, then stop
[ ask n-of random (count patches) patches [ set pcolor red ]] ;otherwise turn red on an random amount of patches
]
end
现在,我不知道如何添加 "hit" 有多强(因此,有多少补丁会受到影响)和可能性有多大(根据幂律)的随机因素发生(或不发生)每个滴答声。有人可以帮我吗?
这是最终代码(Alan 回答):
to environment
create-hits 1 [
set shape "circle"
set color white
set size 0.05
setxy random-xcor random-ycor
]
ask hits [
let %draw (random-float 100)
let %strength 0 ;; no damage
if (%draw < 50) [set %strength (%strength + 1)] ;;1 for little damage
if (%draw < 10) [set %strength (%strength + 1)] ;;2 for middle damage
if (%draw < 5) [set %strength (%strength + 1)] ;;3 for strong damage
if (%draw < 1) [set %strength (%strength + 1)] ;;4 for complete destruction
ifelse pcolor = red [die]
[ ask n-of %strength patches [ set pcolor red ]]
]
end
这只是对@Mars 评论的阐述。
to-report hit-strength
let %draw (random-float 100)
let %strength 0 ;; no damage
if (%draw < 50) [set %strength (%strength + 1)] ;;1 for little damage
if (%draw < 10) [set %strength (%strength + 1)] ;;2 for middle damage
if (%draw < 5) [set %strength (%strength + 1)] ;;3 for strong damage
if (%draw < 1) [set %strength (%strength + 1)] ;;4 for complete destruction
report %strength
end