赛斯的合并建议behaviorspace-run-number http://ccl.northwestern.edu/netlogo/docs/dict/behaviorspace-run-number.html在你的文件名中csv
输出是一种选择。它允许您将该文件与主BehaviorSpace 输出文件中的摘要数据相关联。
另一种选择是将报告者列表作为“度量”包含在行为空间实验定义中。例如,在你的情况下:
map [ t -> [ xcor ] of t ] sort turtles
map [ t -> [ ycor ] of t ] sort turtles
然后,您可以用您最喜欢的数据分析语言“手动”解析结果列表。我之前在 Julia 中使用过以下函数:
parselist(strlist, T = Float64) = parse.(T, split(strlist[2:end-1]))
我确信您可以轻松地用 Python 或 R 或您正在使用的任何语言编写一些等效代码。
在上面的示例中,我输出了单独的列表xcor
和ycor
海龟。您还可以输出单个“列表列表”,但解析会更加棘手。
编辑:如何使用csv
延伸和R
巧合的是,我今天必须为另一个项目做类似的事情,并且我意识到将csv扩大 https://ccl.northwestern.edu/netlogo/docs/csv.htmlR 可以使这变得非常容易。
总体思路如下:
在 NetLogo 中,使用csv:to-string https://ccl.northwestern.edu/netlogo/docs/csv.html#csv:to-string将列表数据编码为字符串,然后将该字符串直接写入BehaviorSpace 输出中。
在 R 中,使用purrr::map https://purrr.tidyverse.org/reference/map.html and readr::read_csv https://readr.tidyverse.org/reference/read_delim.html, 其次是tidyr::unnest https://www.rdocumentation.org/packages/tidyr/versions/0.8.1/topics/unnest,将所有内容解压到一个整洁的“每行一个观察”数据框中。
换句话说:我们喜欢 CSV,所以我们将 CSV 放入我们的 CSV 中,以便我们可以在解析时进行解析。
这是一个完整的例子。假设我们有以下 NetLogo 模型:
extensions [ csv ]
to setup
clear-all
create-turtles 2 [ move-to one-of patches ]
reset-ticks
end
to go
ask turtles [ forward 1 ]
tick
end
to-report positions
let coords [ (list who xcor ycor) ] of turtles
report csv:to-string fput ["who" "x" "y"] coords
end
然后,我们使用我们的方法定义以下小型行为空间实验,仅重复两次,时间限制为两次positions
记者作为输出:
处理这个问题的 R 代码非常简单:
library(tidyverse)
df <- read_csv("experiment-table.csv", skip = 6) %>%
mutate(positions = map(positions, read_csv)) %>%
unnest()
结果是以下数据框,一切整洁:
> df
# A tibble: 12 x 5
`[run number]` `[step]` who x y
<int> <int> <int> <dbl> <dbl>
1 1 0 0 16 10
2 1 0 1 10 -2
3 1 1 1 9.03 -2.24
4 1 1 0 -16.0 10.1
5 1 2 1 8.06 -2.48
6 1 2 0 -15.0 10.3
7 2 0 1 -14 1
8 2 0 0 13 15
9 2 1 0 14.0 15.1
10 2 1 1 -13.7 0.0489
11 2 2 0 15.0 15.1
12 2 2 1 -13.4 -0.902
朱莉娅也有同样的事情:
using CSV, DataFrames
df = CSV.read("experiment-table.csv", header = 7)
cols = filter(col -> col != :positions, names(df))
df = by(df -> CSV.read(IOBuffer(df[:positions][1])), df, cols)