【问题标题】:calculating variance of a turtle-owned factor on a single patch in netlogo在netlogo中计算单个补丁上的乌龟拥有因子的方差
【发布时间】:2017-04-05 11:39:35
【问题描述】:

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

我知道'mean [FACTOR] of turtles-here'会给我平均值,但由于某种原因,方差不能正常工作。 问题 1:要求补丁输出海龟拥有因子的方差的正确语法是什么?

我设计了一个超级简单的示例模型。只需将其粘贴到您的代码中,然后在界面上创建“设置”和“开始”按钮。它应该有粉红色的海龟在黑色的斑块上寻找和停下来。

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

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

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

非常感谢!

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    写下这个问题至少让我找到了第一个问题的答案。

    我变了:

    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
    

    仍然想知道是否有人有更有效的方法来实现这一目标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 2020-04-15
      相关资源
      最近更新 更多