如何在 Netlogo 中保存多次迭代的输出数据
How to save output data for many iterations in Netlogo
我使用以下方法将模拟数据保存为 csv 文件:文件>导出>导出世界,适用于 1 次迭代。我想 运行 我的模型进行 1000 次模拟(以及更多)并在每次迭代时保存数据。因为在每个 运行,输出都是不同的。我在 BehaviourSpace 中完成了一个示例,但我的输出数据并不像我使用 File>Export>Export World 获得的那样详细。我还尝试了 csv 示例,所有海龟自己的输出(感染?、感染2?、感染3?、易感?)都是一样的。
在 BehaviourSpace 中,在 Measure 运行s using these reporters 的选项下,我想计算 turtles-own like infected?, infected1?但是当我这样做时,我得到了一个错误; 实验因语法错误而中止:您不能使用 INFECTED?在观察者上下文中,因为感染?仅限海龟。
我的问题是如何在多次迭代中以 csv 文件的形式跟踪感染者、感染者 2 和感染者 3 的数量,而无需手动进行(附上我的代码)。非常感谢任何帮助。谢谢。
globals
[
sink-patches
time1
time2
signs
timeA
prob1
prob2
]
breed [popns popn] ;;T defines the name of a single member of the breed.
breed [ppls ppl]
popns-own
[
infected?
infected2?
infected3?
susceptible?
infected-time
infection2-time
]
;; setup procedures
to setup
clear-all
setup-patches
setup-globals
setup-people
reset-ticks ; Resets the tick counter to zero, sets up all plots, then updates all plots.
end
to setup-globals
set signs 13
set timeA signs + time1
set prob1 25
set prob2 50
end
to setup-patches ; Create a patch ; Enlarge this patch to increase BU stage 1 infections.
clear-all
let sink-patch-radius 2 ;increase the size of the patch here
let sink-centre patch 0 0 ;centre of the patch
set sink-patches [patches in-radius sink-patch-radius] of sink-centre ; neighbouring patches
;set sink-patches with [abs pxcor <= 8 and abs pycor <= 8]
ask sink-patches [ set pcolor gray ] ;set the patch to color gray
end
to setup-people
create-popns start-people ;setting up people
[
setxy random-xcor random-ycor
set infected? false
set infected2? false
set infected3? false
set susceptible? true
set shape "circle"
set color brown
set infected-time 0
set infection2-time 0
]
create-ppls start-otherPeople ; other population
[
setxy random-xcor random-ycor
set shape "circle"
set color white
]
end
to assign-color ;; turtle procedure
if infected?
[ set color red ]
if infected2?
[ set color blue ]
if infected3?
[ set color yellow ]
end
;; Go procedures
to go
ask popns[ assign-color]
ask popns[ infect_start]
ask popns with [ infected? ]
[ infect_two ]
ask popns with [ infected2? ]
[ infect_three ]
ask popns [count-update] ;
ask turtles [move]
tick
end
;; People move about at random.
to move ;; turtle procedure
rt random-float 360 ;the turtle turns right by 360 degrees.
fd 1
end
to infect_start ;stage one;;
let healthy (popns-on sink-patches) with [ susceptible? ]
if (random-float 100 < Infection-Rate)
[
ask healthy
[
set infected? true
set susceptible? false
]
]
end
to infect_two ;Infect stage two = green
if infected-time > timeA
[set infected? false
set infected2? true
]
end
to infect_three ;Infect stage three= yellow
if infection2-time > time2
[
set infected2? false
set infected3? true
]
end
to count-update ; This updates the count of time in the various stages of infection or treatments
if (infected? or infected2? or infected3?) [set infected-time infected-time + 1 ]
if infected2? [set infection2-time infection2-time + 1 ]
end
听起来您可以使用 BehaviorSpace 进行导出,您只是错误地格式化了代码。 BehaviorSpace 比尝试创建自己的导出和管理它要容易得多。所以第一步是在你的界面上创建监视器来捕获你想要输出的度量,也许:
count turtles with [infected?]
一旦你让它们工作(并显示你想要的任何东西),那么你就知道你的语法是正确的,你只需将监视器的代码复制到 BehaviorSpace 实验的输出位中。
我使用以下方法将模拟数据保存为 csv 文件:文件>导出>导出世界,适用于 1 次迭代。我想 运行 我的模型进行 1000 次模拟(以及更多)并在每次迭代时保存数据。因为在每个 运行,输出都是不同的。我在 BehaviourSpace 中完成了一个示例,但我的输出数据并不像我使用 File>Export>Export World 获得的那样详细。我还尝试了 csv 示例,所有海龟自己的输出(感染?、感染2?、感染3?、易感?)都是一样的。
在 BehaviourSpace 中,在 Measure 运行s using these reporters 的选项下,我想计算 turtles-own like infected?, infected1?但是当我这样做时,我得到了一个错误; 实验因语法错误而中止:您不能使用 INFECTED?在观察者上下文中,因为感染?仅限海龟。
我的问题是如何在多次迭代中以 csv 文件的形式跟踪感染者、感染者 2 和感染者 3 的数量,而无需手动进行(附上我的代码)。非常感谢任何帮助。谢谢。
globals
[
sink-patches
time1
time2
signs
timeA
prob1
prob2
]
breed [popns popn] ;;T defines the name of a single member of the breed.
breed [ppls ppl]
popns-own
[
infected?
infected2?
infected3?
susceptible?
infected-time
infection2-time
]
;; setup procedures
to setup
clear-all
setup-patches
setup-globals
setup-people
reset-ticks ; Resets the tick counter to zero, sets up all plots, then updates all plots.
end
to setup-globals
set signs 13
set timeA signs + time1
set prob1 25
set prob2 50
end
to setup-patches ; Create a patch ; Enlarge this patch to increase BU stage 1 infections.
clear-all
let sink-patch-radius 2 ;increase the size of the patch here
let sink-centre patch 0 0 ;centre of the patch
set sink-patches [patches in-radius sink-patch-radius] of sink-centre ; neighbouring patches
;set sink-patches with [abs pxcor <= 8 and abs pycor <= 8]
ask sink-patches [ set pcolor gray ] ;set the patch to color gray
end
to setup-people
create-popns start-people ;setting up people
[
setxy random-xcor random-ycor
set infected? false
set infected2? false
set infected3? false
set susceptible? true
set shape "circle"
set color brown
set infected-time 0
set infection2-time 0
]
create-ppls start-otherPeople ; other population
[
setxy random-xcor random-ycor
set shape "circle"
set color white
]
end
to assign-color ;; turtle procedure
if infected?
[ set color red ]
if infected2?
[ set color blue ]
if infected3?
[ set color yellow ]
end
;; Go procedures
to go
ask popns[ assign-color]
ask popns[ infect_start]
ask popns with [ infected? ]
[ infect_two ]
ask popns with [ infected2? ]
[ infect_three ]
ask popns [count-update] ;
ask turtles [move]
tick
end
;; People move about at random.
to move ;; turtle procedure
rt random-float 360 ;the turtle turns right by 360 degrees.
fd 1
end
to infect_start ;stage one;;
let healthy (popns-on sink-patches) with [ susceptible? ]
if (random-float 100 < Infection-Rate)
[
ask healthy
[
set infected? true
set susceptible? false
]
]
end
to infect_two ;Infect stage two = green
if infected-time > timeA
[set infected? false
set infected2? true
]
end
to infect_three ;Infect stage three= yellow
if infection2-time > time2
[
set infected2? false
set infected3? true
]
end
to count-update ; This updates the count of time in the various stages of infection or treatments
if (infected? or infected2? or infected3?) [set infected-time infected-time + 1 ]
if infected2? [set infection2-time infection2-time + 1 ]
end
听起来您可以使用 BehaviorSpace 进行导出,您只是错误地格式化了代码。 BehaviorSpace 比尝试创建自己的导出和管理它要容易得多。所以第一步是在你的界面上创建监视器来捕获你想要输出的度量,也许:
count turtles with [infected?]
一旦你让它们工作(并显示你想要的任何东西),那么你就知道你的语法是正确的,你只需将监视器的代码复制到 BehaviorSpace 实验的输出位中。