在 Netlogo 中累积每步死亡率模型程序
Accumulating per-step mortality model procedure in Netlogo
请告知我在以下每步死亡率的 netlogo 程序中可能做错了什么(我正在实施 "Pass-Away" 程序作为 "GO" 程序中的一个步骤):
to Pass-Away
ask turtles [
let chances 1 - exp( -1 * mortality * ticks )
let dead-count 0
if chances >= 1 [die]
set dead-count dead-count + 1
]
end
以上代码是否正确?即使它是正确的,是否有改进或更好的替代方法来实现海龟在世界中移动时的恒定(累积)每时间步长死亡率?最后,如何让变量 "dead-count" 向 netlogo 界面上的监视器报告?
除了您的死机计数始终为 1 外,这将基本有效。但它可能无法按您的预期工作。你应该开始探索你所写的东西。当你感到困惑时,首先要做的就是把事情分成更小的部分。第二件事是添加一些有用的视觉效果。在这种情况下,您将通过绘制您的机会表示来学到很多东西。我将不得不猜测您的死亡率属性是随机浮动,因为您没有这么说。以下是您的代码的部分修复,它提供了足够的线索来继续。您将需要在界面选项卡中添加一个绘图 - 请参阅 https://subversion.american.edu/aisaac/notes/netlogo-basics.xhtml#core-concepts-plotting - 如果您发现使用 print
进行监控太笨拙,您可以以相同的方式添加一个监视器。
globals [dead-count]
turtles-own [mortality]
to setup
ca
set dead-count 0
crt 100 [set mortality random-float 1]
reset-ticks
end
to go
ask turtles [pass-away]
print (word "dead count = " dead-count) ;easiest monitor
clear-plot ;you'll need to have added a plot
foreach sort [chances] of turtles [
[?] -> plot ?
] ;keep an eye on the largest value in this plot ... get it?
tick
end
to-report chances ;turtle proc
report 1 - exp( -1 * mortality * ticks )
end
to pass-Away ;turtle proc
if chances >= 1 [
set dead-count dead-count + 1 ;*inside* the conditional! must come first!
print (word "chances: " chances)
die
]
end
请告知我在以下每步死亡率的 netlogo 程序中可能做错了什么(我正在实施 "Pass-Away" 程序作为 "GO" 程序中的一个步骤):
to Pass-Away
ask turtles [
let chances 1 - exp( -1 * mortality * ticks )
let dead-count 0
if chances >= 1 [die]
set dead-count dead-count + 1
]
end
以上代码是否正确?即使它是正确的,是否有改进或更好的替代方法来实现海龟在世界中移动时的恒定(累积)每时间步长死亡率?最后,如何让变量 "dead-count" 向 netlogo 界面上的监视器报告?
除了您的死机计数始终为 1 外,这将基本有效。但它可能无法按您的预期工作。你应该开始探索你所写的东西。当你感到困惑时,首先要做的就是把事情分成更小的部分。第二件事是添加一些有用的视觉效果。在这种情况下,您将通过绘制您的机会表示来学到很多东西。我将不得不猜测您的死亡率属性是随机浮动,因为您没有这么说。以下是您的代码的部分修复,它提供了足够的线索来继续。您将需要在界面选项卡中添加一个绘图 - 请参阅 https://subversion.american.edu/aisaac/notes/netlogo-basics.xhtml#core-concepts-plotting - 如果您发现使用 print
进行监控太笨拙,您可以以相同的方式添加一个监视器。
globals [dead-count]
turtles-own [mortality]
to setup
ca
set dead-count 0
crt 100 [set mortality random-float 1]
reset-ticks
end
to go
ask turtles [pass-away]
print (word "dead count = " dead-count) ;easiest monitor
clear-plot ;you'll need to have added a plot
foreach sort [chances] of turtles [
[?] -> plot ?
] ;keep an eye on the largest value in this plot ... get it?
tick
end
to-report chances ;turtle proc
report 1 - exp( -1 * mortality * ticks )
end
to pass-Away ;turtle proc
if chances >= 1 [
set dead-count dead-count + 1 ;*inside* the conditional! must come first!
print (word "chances: " chances)
die
]
end