我正在尝试计算单个补丁上的乌龟拥有因子的方差。换句话说,在一个补丁中,我想知道该补丁上所有乌龟的因子的均值和方差。
我知道'海龟的意思是[因素] - 这里'会给我平均值,但由于某种原因,方差也没有效果。 问题1:要求补丁输出海龟拥有因子的方差的正确语法是什么?
我编写了一个超级简单的示例模型。只需将其粘贴到代码中,然后在界面上创建“setup”和“go”按钮。它应该有粉红色的乌龟寻找和停止黑色斑块。
turtles-own
[FACTOR]
patches-own
[DEPTH]
to setup
clear-all
reset-ticks
make_patches
make_turtles
end
to go
move
if count (turtles with [DEPTH > 0]) = 0 [stop]
end
to make_patches
ask patches [set depth 20 set pcolor green - 2]
ask n-of 5 patches [set depth -50 set pcolor black]
end
to make_turtles
create-turtles 10
ask turtles
[
set color pink
set size 2
set xcor random max-pxcor
set ycor random max-pycor
set FACTOR random 100
]
end
to move
ask turtles[
let D min [DEPTH] of patches in-radius 3
let Dn min-one-of patches in-radius 3 [DEPTH]
let LDe [DEPTH] of patch-here
ifelse DEPTH < 0
[
move-to patch-here
stop
]
[ifelse LDE > D AND D < 0
[
move-to DN
stop
]
[
right random-float 150
forward random 3
]
]
]
end
最后,我想做一个行为空间实验,在每次运行结束时,每个补丁都使用DEPTH&lt; 0计算并输出该精确斑块上海龟的FACTOR的均值,标准偏差和方差。我的计划是创建一个排序列表
ask patches with [DEPTH< 0] [set FACTOR_LIST (list ("[")(COORDINATES) (",") (VARIANCE_FACTOR) ("]") )]
其中FACTOR_LIST是导出列表,COORDINATES是由补丁的x和y坐标组成的列表,VARIANCE_FACTOR是因子的方差(我在这里询问如何做)。 问题2:是否有更有效的方法来获取此列表?
非常感谢!
答案 0 :(得分:0)
我改变了:
patches-own
[
DEPTH
DENSITY
FACTOR_VARIANCE
FACTOR_LIST
]
to go
move
if count (turtles with [DEPTH > 0]) = 0
[
final_tick
ask patches with [DEPTH < 0] [show FACTOR_LIST]
stop
]
end
并添加了一个计算方差的新程序,并将其放入我可以从补丁中调用的列表
to final_tick
ask patches with [DEPTH < 0] [set DENSITY count turtles-here]
ask patches with [DEPTH < 0 AND DENSITY <= 1] [set FACTOR_VARIANCE 0]
ask patches with [DEPTH < 0 AND DENSITY > 1] [set FACTOR_VARIANCE (variance [FACTOR] of turtles-here)]
ask patches with [DEPTH < 0] [set FACTOR_LIST (list (pxcor)(",")(pycor)(",")(FACTOR_VARIANCE))]
end
仍然想知道是否有人有更有效的方法来实现这一目标。