gpt4 book ai didi

netlogo - 计算 NetLogo 中的相异指数

转载 作者:行者123 更新时间:2023-12-04 10:21:02 24 4
gpt4 key购买 nike

我想计算 index of dissimilarity在 NetLogo 中。我有一个分为不同区域的世界,我想检查物种在世界各地的分布情况。
考虑这个例子:一个世界被划分为 16 个不同的区域。世界上有两种 Ant ,红色和蓝色。它看起来像这样:
enter image description here
图中的世界是用以下代码生成的:

globals[indexdissimilarity] ; where I want the index of dissimilarity to be stored.

to setup
ca

;Setting world.
resize-world 0 19 0 19
set-patch-size 15

;Creating regions.
let x 5
let y 5
let col 45
while [y <= max-pycor + 1 ][
while [x <= max-pxcor + 1][
ask patches with [pxcor < x and pxcor >= x - 5 and pycor < y and pycor >= y - 5][
set pcolor col
]
set x x + 5
set col col + 3
]
set x 5
set y y + 5
]

ask n-of (count patches * 0.85) patches[sprout 1[
set shape "bug"
set color red]]

ask n-of (count turtles * 0.50) turtles [set color blue]
dissimilarity
end

; Here is where I want to calculate the index of dissimilarity.
to dissimilarity
let tot_red (count turtles with [color = red])
let tot_blue (count turtles with [color = blue])

; set indexdissimilarity

end
我的主要问题是如何迭代每个邻域的部分计算。
谢谢!

最佳答案

我想我设法解决了它。请让我知道它是否看起来正确。这是完整的更新代码。

globals[indexdissimilarity
dis
]

patches-own [reg]
to setup
ca

;Setting world.
resize-world 0 19 0 19
set-patch-size 15

;Creating regions.
let x 5
let y 5
let col 45
while [y <= max-pycor + 1 ][
while [x <= max-pxcor + 1][
ask patches with [pxcor < x and pxcor >= x - 5 and pycor < y and pycor >= y - 5][
set pcolor col
]
set x x + 5
set col col + 3
]
set x 5
set y y + 5
]

ask patches [set reg [pcolor] of self]

ask n-of (count patches * 0.85) patches[sprout 1[
set shape "bug"
set color red]]

ask n-of (count turtles * 0.7) turtles [set color blue]
update
end


to update
;Dissimilarity index.
let tot_red (count turtles with [color = red])
let tot_blue (count turtles with [color = blue])

let neighb1 [reg] of turtles
let neighb remove-duplicates neighb1
set dis []

foreach neighb [i -> set dis lput abs((count turtles with [reg = i and color = red] / tot_red) - (count turtles with [reg = i and color = blue] / tot_blue)) dis]
set indexdissimilarity sum(dis) / 2
print(indexdissimilarity)
end

关于netlogo - 计算 NetLogo 中的相异指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60847559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com