计算netlogo中单个补丁上的乌龟拥有的因子的方差 [英] calculating variance of a turtle-owned factor on a single patch in netlogo

查看:206
本文介绍了计算netlogo中单个补丁上的乌龟拥有的因子的方差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在单个补丁上计算乌龟拥有的因子的方差.换句话说,在一个补丁中,我想知道该补丁中所有海龟之间因子的均值和方差.

I'm trying to calculate the variance of a turtle owned factor on a single patch. In other words at a single patch I'd like to know the mean and variance of the factor among all turtles on that patch.

我知道海龟的平均值[FACTOR]-在这里"会给我平均值,但是由于某种原因,方差也不起作用. 问题1:要求补丁输出乌龟拥有的因子的方差的正确语法是什么?

I know 'mean [FACTOR] of turtles-here' will give me the mean, but for some reason variance isn't working as well. Question 1: What is the proper syntax for asking a patch to output the variance of a turtle-owned factor?

我已经建立了一个超级简单的示例模型.只需将其粘贴为您的代码,然后在界面上创建设置"和执行"按钮即可.它应该有寻找和停在黑色斑块上的粉红色海龟.

I've worked up a super simple example model. Just paste this in for your code, then create 'setup' and 'go' buttons on the interface. It should have pink turtles seeking and stopping on black patches.

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 <0计算并输出该精确斑块上的海龟的FACTOR的平均值,标准偏差和方差.我的计划是创建一个排序列表

In the end I'd like to do a behavior-space experiment where at the end of each run every patch with DEPTH< 0 calculates and outputs the mean, standard deviation, and variance of FACTOR for turtles on that exact patch. My plan is to create a list of the sort

 ask patches with [DEPTH< 0] [set FACTOR_LIST (list ("[")(COORDINATES) (",") (VARIANCE_FACTOR) ("]") )]

其中FACTOR_LIST是导出的列表,COORDINATES是由补丁的x和y坐标组成的列表,而VARIANCE_FACTOR是因子的方差(我在这里问如何做). 问题2:是否有更有效的方法来获取此列表?

where FACTOR_LIST is the exported list, COORDINATES is a list consisting of the x and y coordinates of the patch, and VARIANCE_FACTOR is the variance of the factor (which I'm asking how to do here). Question 2: Is there a more efficient way to get this list?

非常感谢!

推荐答案

写问题至少使我对第一个问题有了答案.

writing the question led me to the answer to the first one at least.

我更改了:

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

并添加了一个新的过程,该过程计算了方差并将其放在我可以从补丁程序调用的列表中

and added a new procedure that calculated the variance and put it in a list I can call from the patch

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

仍然想知道是否有人能够以更有效的方式实现这一目标.

Would still like to know if anyone has a more efficient way of accomplishing this goal.

这篇关于计算netlogo中单个补丁上的乌龟拥有的因子的方差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆