set - 计算一定数量的刻度的平均值

标签 set mean netlogo

我希望观察者计算过去 10 年(=刻度)发生特定操作(在本例中为海龟申请保险)时房屋被洪水淹没的次数(=斑 block )的平均值。这种情况的发生并不是有规律的,它可以被视为随机发生(或多或少)。

所以基本上,我需要一些代码来计算保险申请发生时过去 10 个刻度的洪水平均值。

最佳答案

假设floodings是一个补丁变量,并且您想确定给定补丁的平均洪水数量:

patches-own [
    floodings
    floodingsHistory
    floodingsMean10
]

; At the end of each tick, patches store the current 
; number of floodings in a list:

ask patches [ set floodingsHistory fput floodings floodingsHistory ]


; In case of [insurance application] patches (or a certain patch) calculate 
; the mean over a sublist that only comprises the values of the latest 10 ticks:

ask patches [ set floodingsMean10 mean (sublist floodingsHistory 0 10) ]

关于set - 计算一定数量的刻度的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22783293/

相关文章:

javascript - "right way"在一台服务器上托管多个 NodeJS 域?

time - 每蜱释放两只海龟 netlogo

NetLogo:找出所有相互链接的海龟并将它们分配给一个组ID

c++ - STL Set inside Map ,奇怪的段错误和Valgrind分析

python - Python 3 中 len(set) 与 set.__len__() 的性能分析

c++ - std::set 的 find()

r - 在 R 中生成数字

java - 如何在 Java 中对 EnumSet 中的元素进行洗牌/随机化?

python - dataframe.mean() 的结果不正确

NetLogo - 踩补丁初始化新功能