如何存储/计算单个群集大小并在NetLogo中绘制它们 [英] How store/count individual cluster sizes and plot them in NetLogo

查看:219
本文介绍了如何存储/计算单个群集大小并在NetLogo中绘制它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成黄色斑点簇的模型,并且我对观察簇大小的频率分布感兴趣.为此,我选择了NetLogo代码库中补丁集群示例"中的代码.在查找群集方面似乎可行(请参见下面的照片)(尽管我更希望它不对群集中的绿色补丁进行计数),但是我不知道如何获取大小(或补丁计数)这些集群中的每个集群.理想情况下,我想对群集大小(不包括绿色补丁)的频率分布进行直方图处理,并能够导出该数据.

I have a model that generates clusters of yellow patches and I am interested in looking at the frequency distribution of cluster sizes. To do this I have co-opted the code from 'Patch Clusters Example' in the Code Library of NetLogo. It seems to be working (see photos below) in terms of finding the clusters (although I would prefer that it did not count green patches in the clusters), but I can't figure out how to get the sizes (or patch counts) of each of these clusters. Ideally I would like to make a histogram of the frequency distribution of cluster sizes (excluding green patches) and be able to export that data.

此外,如果我能找到一种在模型运行时获取簇大小频率直方图的方法,那就太好了.

Furthermore, it would be great if I could figure out a way to get the histogram of cluster size frequencies while the model is running.

我用来获取集群的代码正好是补丁集群示例"中的内容,除了我杀死了所有代理之外,这样我就可以读取数字了.在这里...

The code I am using to get the clusters is right out of 'Patch Clusters Example' except I kill all the agents so I can read the numbers. Here it is...

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

感谢您的帮助!

找到簇之前的模型

找到簇后的模型

推荐答案

基本上,对于模型中的每个群集值,您都希望对具有相同标识符的所有色块进行计数.这可以通过使用地图来实现.它使用唯一补丁程序簇值(remove-duplicates [cluster] of patches)的列表,然后针对该列表中的每个条目计算具有该簇值的所有补丁程序.结果存储在列表中,它们代表所有群集的大小.可以使用histogram原语将该列表绘制为频率直方图.确保将绘图的x轴设置为合理的最大值,并将绘图笔设置为条形模式.

Basically, for each cluster value in your model, you want to count all patches with the same identifier. This can be acchieved by using map. It uses a list of unique patch cluster values (remove-duplicates [cluster] of patches) and then for each entry in that list it counts all patches with this cluster value. The results are stored in a list and they represent the sizes of all your clusters. This list can be plotted as a frequency histogram by using the histogram primitive. Be sure to set the x-Axis of your plot to a plausible maximum value and set the plot pen to bar mode.

NetLogo 6语法:

NetLogo 6 syntax:

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语法:

NetLogo 5 syntax:

to calc-frequency
  let freq map [count patches with [cluster = ?]] remove-duplicates [cluster] of patches

  set-current-plot "hist"
  histogram freq
end

这篇关于如何存储/计算单个群集大小并在NetLogo中绘制它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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