我有一个生成黄色斑块簇的模型,我有兴趣查看簇大小的频率分布。为此,我从 NetLogo 代码库中的“补丁集群示例”中选择了代码。它似乎在查找簇方面起作用(参见下面的照片)(尽管我希望它不计算簇中的绿色斑块),但我不知道如何获取大小(或斑块计数)每个集群的。理想情况下,我想制作簇大小(不包括绿色斑块)的频率分布的直方图,并能够导出该数据。
此外,如果我能找到一种方法在模型运行时获取簇大小频率的直方图,那就太好了。
我用来获取集群的代码正好来自“补丁集群示例”,只是我杀死了所有代理,以便我可以读取数字。这里是...
to find-clusters
ask turtles [die] ;; this clears the board so I can see the clusters
loop [
;; pick a random patch that isn't in a cluster yet
let seed one-of patches with [(cluster = nobody)]
;; if we can't find one, then we're done!
if seed = nobody
[ show-clusters
stop ]
;; otherwise, make the patch the "leader" of a new cluster
;; by assigning itself to its own cluster, then call
;; grow-cluster to find the rest of the cluster
ask seed
[ set cluster self
grow-cluster ]
]
end
to grow-cluster ;; patch procedure
ask neighbors with [(cluster = nobody) and
(pcolor = [pcolor] of myself )]
[ set cluster [cluster] of myself
grow-cluster ]
end
;; once all the clusters have been found, this is called
;; to put numeric labels on them so the user can see
;; that the clusters were identified correctly
to show-clusters
let counter 0
loop
[ ;; pick a random patch we haven't labeled yet
let p one-of patches with [plabel = ""]
if p = nobody
[ stop ]
;; give all patches in the chosen patch's cluster
;; the same label
ask p
[ ask patches with [cluster = [cluster] of myself]
[ set plabel counter] ]
set counter counter + 1 ]
end
感谢您的帮助!
寻找聚类之前的模型 https://i.stack.imgur.com/EqvCk.png
找到聚类后的模型 https://i.stack.imgur.com/QebLC.png
基本上,对于模型中的每个聚类值,您希望对具有相同标识符的所有补丁进行计数。这可以通过使用地图来实现。它使用唯一补丁簇值的列表(remove-duplicates [cluster] of patches
),然后对于该列表中的每个条目,它会计算具有该集群值的所有补丁。结果存储在一个列表中,它们代表所有集群的大小。可以使用以下函数将该列表绘制为频率直方图histogram
原始。请务必将绘图的 x 轴设置为合理的最大值,并将绘图笔设置为条形模式。
NetLogo 6 语法:
to calc-frequency
let freq map [[i] -> count patches with [cluster = i]] remove-duplicates [cluster] of patches
set-current-plot "hist"
histogram freq
end
NetLogo 5 语法:
to calc-frequency
let freq map [count patches with [cluster = ?]] remove-duplicates [cluster] of patches
set-current-plot "hist"
histogram freq
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)