netlogo中基于距离的死亡率模型 [英] Distance-based mortality model in netlogo
问题描述
我正在计算netlogo中海龟的累计死亡率,作为海龟(其中100只)从netlogo界面世界中的原点(start-patch
)移动的距离的函数.在下面的代码中,"Pass-Away
"过程链接到一个称为"space-death"的全局接口开关,该开关在打开时会产生由"Pass-Away-Space
"过程承担的基于距离的死亡率,否则保持正常的运行状态.通过称为"Pass-Away-Time
"的程序进行的时间步长(tick
):
I am calculating cumulative turtle mortality in netlogo as a function of distance moved by turtles (100 of them) from the origin (start-patch
) in the netlogo interface world. In the code below the 'Pass-Away
' procedure is linked to a global interface switch called "space-death" which when switched on yields said distance-based mortality undertaken by the procedure called "Pass-Away-Space
", otherwise maintains regular per-time-step (tick
) mortality undertaken by the procedure called "Pass-Away-Time
":
to Pass-Away-Time
ask turtles [
let chances 1 - exp( -1 * mortality * ticks )
if chances >= 1 [die
set dead-count dead-count + 1
]
]
end
to Pass-Away-Space
ask turtles [
let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles)
if chances >= 1 [die
set dead-count dead-count + 1
]
]
end
to Pass-Away
ask turtles [
ifelse space-death [
Pass-Away-Space][
Pass-Away-Time
]
]
end
我在执行此操作时遇到两个错误,都可能是由于"Pass-Away-Space
"过程的编码问题所致.第一个是,只有观察者可以询问所有乌龟的集合.然后,当我将let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles)
移到ask turtles[]
括号之外时,此错误才得到解决,只会产生另一个表示**预期输入的错误是一个数字,但得到列表*,后跟一个数字序列.也许是由于对多只海龟调用了死亡率方程中的* [distance start-patch] of turtles
部分(这正是我想要达到的目标-让每只随机游走的海龟都使用其距原点的距离来计算其累积的-步死亡率和超过阈值死亡-在不同时间,不同距离的不同海龟在不同时间发生的事件).关于如何解决这个问题有什么想法吗?
I get two errors doing this, both likely due to issues with the coding of the "Pass-Away-Space
" procedure. The first is Only the observer can ASK the set of all turtles. Then when I move the let chances 1 - exp( -1 * mortality * [distance start-patch] of turtles)
outside of the ask turtles[]
brackets this error is resolved only yield another that says ** expected input to be a number but got the list* followed by a sequence of numbers. Perhaps due to the fact that the section of the mortality equation that reads * [distance start-patch] of turtles
is invoked for multiple turtles (which is exactly what I want to achieve - have each random-walking turtle use its distance from the origin to calculate its cumulative per-step mortality and die above a threshold - an event that occurs at different times for different turtles at different distances). Any thoughts on how to resolve this?
推荐答案
第一个错误是因为您要所有乌龟都问所有乌龟.从Pass-Away
过程开始,并假定space-death
设置为TRUE.怎么了?您要求所有乌龟运行Pass-Away-Space
过程.也就是说,每只乌龟都会依次运行该程序.该过程的第一步是ask turtles [ ]
.因此,一只乌龟正在要求所有的乌龟做某事.因此是错误.
The first error is because you are asking all turtles to ask all turtles. Starting with your Pass-Away
procedure and assuming space-death
is set to TRUE. What happens? You ask all turtles to run the Pass-Away-Space
procedure. That is, each turtle will run that procedure in turn. The first step of that procedure is to ask turtles [ ]
. So a turtle is asking all turtles to do something. Hence the error.
要修复此问题,您需要重写Pass-Away-Space
过程,以便该过程可以运行需要为单个乌龟运行的任何代码(对于Pass-Away-Time
类似).您可能想要类似的东西:
To fix it, you need to rewrite the Pass-Away-Space
procedure so it runs whatever code needs to be run for a SINGLE turtle (and similarly for Pass-Away-Time
). You probably want something like:
to Pass-Away-Space
if exp( -1 * mortality * [distance start-patch]) < 0
[ die
set dead-count dead-count + 1
]
end
这篇关于netlogo中基于距离的死亡率模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!