我试图计算netlogo中受感染乌龟的累积平均值 我不知道我应该使用什么代码以及将其放在netlogo代码中的位置 我做了一些测试,并尝试计算节点的平均值但这不正确。 我也尝试创建一个列表,但我也没有成功。 我应该把代码放在哪里?
这里有一些代码:
observer> show mean [num-infected] of turtles
observer: 198
observer> show mean [num-infected] of turtles / length num-infected
observer> show mean [num-infected] of turtles / length [num-infected] of turtles
observer: 0.99
observer> show sum [num-infected] of turtles / length [num-infected] of turtles
observer: 197
observer> show count [num-infected] of turtles / length [num-infected] of turtles
observer> show mean [num-infected] of turtles / length [num-infected] of turtles
observer: 0.955
observer> show sum [num-infected] of turtles / length [num-infected] of turtles
observer: 191
observer> show sum [mean num-infected] of turtles
observer> show mean [ num-infected] of turtles
observer: 191
observer> show mean [ num-infected] of turtles
observer: 1
observer> show mean [ num-infected] of turtles
observer: 198
observer> show mean [ num-infected] of turtles
observer: 198
observer> show mean [ num-infected] of turtles
observer: 198
observer> show [ num-infected] of turtles
observer> show count turtles with [infected? = true]
observer: 198
observer> show count turtles with [infected? = true] / length [num-infected] of turtles
observer: 0.99
observer> show count num-infected / count turtles with [infected? = true]
ERROR: Expected an agentset here, rather than a list or block.
感谢。
答案 0 :(得分:0)
请参阅http://groups.yahoo.com/neo/groups/netlogo-users/conversations/topics/16345
上netlogo-users组的回答 Travis Hinkelman写道:如果我理解正确,那么您的记者程序应如下所示:
to-report cumul-av-sum
;; drop the first member of the list, but not until there are at least 200 items in the list
if (length cumul-av-list > 200) [ set cumul-av-list but-first
cumul-av-list ]
;; add the number of raindrops created in last tick to the end of the list
set cumul-av-list lput num-infected cumul-av-list
report sum cumul-av-list
end
需要在每个tick(可能是作为绘图的一部分)中调用此报告程序来正确更新列表。