Separating each turtle-owned variable in behaviorspace

156 views
Skip to first unread message

Nicole Dimitrov

unread,
Jun 3, 2022, 11:23:49 AM6/3/22
to netlogo-users
Hi there, 

I have a turtle-owned variable called infection-counter which counts the number of times each turtle infects another turtle. The simulation runs for 1500 ticks and I would like to report the infection-counter for each turtle in behaviorspace. I've tried to simply put [infection-counter] of turtles but that gives me a list of the values for all turtles at each timestep which is hard to work with. Is there a way to separate those values into individual columns for each turtle rather than have them be reported as a list in excel? 

Thanks! 
Nicole





Charles Staelin

unread,
Jun 3, 2022, 3:16:58 PM6/3/22
to netlogo-users
Not a very elegant solution, but if you take the output file and put it into a simple text editor, you can turn all the brackets into blanks.  Since lists are blank separated, you can then tell Excel to import it as a blank-delimited file.

Pradeesh Kumar K V

unread,
Jun 4, 2022, 8:56:05 AM6/4/22
to netlogo-users
Hello Nicole,

I used the following sample code to export the xcor and ycor values of each agent in each tick to a text file during Behavior space runs. 

to setup
  ca
  reset-ticks
  create-turtles 10
  [
    set xcor random-xcor
    set ycor random-ycor
  ]
end


to go
  file-open "test.txt"   #open the destination file
  ask turtles
  [
    file-write behaviorspace-run-number file-write ticks file-write who file-write xcor file-write " " file-print ycor   #write data to file
  ]
  file-close #close the file
  tick
end

You have to first create an empty destination text file (i.e. before running the model). Once the Behavior space runs are complete, each line of the text file will contain Behavior space run number, step, who of the turtle, xcor and ycor.

Xcor and ycor can be replaced with attributes specific to your model. Once you have the text file, then as Charles suggested, you can use Excel to separate the entries into columns.

There seems to be a space before the behaviorspace-run-number which shows up during Excel operation and results in an empty first column. However, this is not an issue and the column can be deleted for further operations with the data.

Hope this helps.

Best,

Pradeesh

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/c49c802d-78dc-4a68-8858-9ddf0c05bb88n%40googlegroups.com.

Wade Schuette

unread,
Jun 4, 2022, 1:54:01 PM6/4/22
to netlogo-users
Another way to deal with Behavior Space output as a list is to split the list up in Excel using a macro.

In most cases getting this working is more work than other suggestions, but it might be worth it if you
need to parse the output many times AND you are comfortable working with macros in Excel.

How this works:
If you save an Excel macro in the very special file PERSONAL.XLSB once it will then be available to all Excel macros
on your computer from then on,  so you do NOT need to put it into any csv file that Behavior Space generates.  It will automatically be in the list of macros available to you.

Here's info on how that works:   https://www.youtube.com/watch?v=VvZMuPMY4C4

If you generate the variable that generates a list as your last variable in Behavior Space, so it is the rightmost column in the csv file,  the attached macro can unpack the lists to the columns to the right and optionally add a header row.  

You just need to\ open your csv excel file ( "experiment-table.csv", say),  click to select the topmost cell containing a list, and type  CTRL-SHIFT-Y to run the macro.    It will ask if you want headers generated as well.

 It also does an emergency stop after 10,001 rows, just in case you edit the macro and leave something
out since it can be a problem to stop a macro that's in an infinite loop -- so if you expect over 10,000 rows of
output you need to up that number in the macro.  The optional column header is "TCxxxx" where xxxx starts at zero
and counts up.  You can edit that in the macro as well if you want something else.

Attached is a sample csv file before running the macro,  after clicking to select cell D8 ( containing "[7 5 0 7 4]"),  running the macro using CTRL-SHIFT-Y, and the macro itself.

Again, this is probably overkill for most cases, but variations on this template might help someone with something someday!
Feel free to copy, modify, or otherwise use as you like.  I'm sure the VBA could be cleaner but this seems to work.

Wade




list-unpacker-macro.txt
experiment-table.csv
experiment-table-after.csv

Nicole Dimitrov

unread,
Jun 6, 2022, 12:34:47 PM6/6/22
to netlogo-users
Thank you all for the detailed responses! 
Reply all
Reply to author
Forward
0 new messages