I'm trying to find an efficient method of outputting a large number of turtle variables (20+) from a random selection of 100 turtles into an output field or text file. So far I have:
turtles-own [
variable1
variable2
variable3
variable4
.
.
.
]
to go
if (ticks < 1) [reset-timer]
ticks
if count turtles >= end-population [
ask n-of 100 turtles [
output-show variable1
output-show variable2
output-show variable3
output-show variable4
]
I then get a list of the variables of each cell in a single column:
My question is how can I get these variable values on the same line so of the output or a text file so I can easily work with these data? Furthermore, how would I implement this in BehaviorSpace? Using this same command:
ask n-of 100 turtles [
output-show variable1
output-show variable2
output-show variable3
output-show variable4
]
... in the final commands field does not result in any of these data showing up in the output file.
Thanks!
There are a variety of ways to do this- for example, the csv
extension is great candidate if you want to manually output your values. If you want to do this quickly in BehaviorSpace, here's how I usually go about it.
I'm assuming you want the variable values for the same 100 turtles each time, rather than sampling a new 100 turtles for each variable. So, I think the easiest way is to just make a globals
variable for each of the variables of interest, then make a procedure to fill those lists as needed. For example, with this setup:
globals [ a-final b-final c-final ]
turtles-own [ a b c ]
to setup
ca
crt 100
reset-ticks
end
to go
ask turtles [
set a random 100
set b one-of [ "Beep" "Boop" ]
set c precision random-float 10 2
]
end
Each tick the turtles are just randomly updating their a
, b
, and c
variables for the sake of this toy version. Then, you have a procedure that subsamples some number of turtles (here, 10) from your total population and updates the storage lists:
to output
let selected-turtles n-of 10 turtles
set a-final [a] of selected-turtles
set b-final [b] of selected-turtles
set c-final [c] of selected-turtles
end
Now as long as that output runs right before your BehaviorSpace experiment ends, you can output those lists as a string, which you can easily separate and clean with R or similar software. For example, if you have a setup like:
You will get output that looks something like: