Simulator charts 

I have an expdef with 2 food types - apple and orange - that get replaced as they are eaten. I've built a Hamming neural net into my creature to make it prefer oranges to apples. I'd like to trace the comparative numbers of apples and oranges eaten (and therefore replaced) over time. I've gone to the simulator charts and found that charts have automatically been made available for Orange:Count and Apple:Count, which sound like what I want. I've added these as I usually do for charts (select -> apply -> add) and the charts show in the chart window but neither has a trace in it when I run the simulation.

I'd be grateful for some help with this. I presume that I need to do something more than just add the charts. For example, do I need to add my own count variables to my expdef and then somehow link them to the charts, and, if so, how do I do this?

Thanks in advance...

Ian

Forums: 
Maciej Komosinski's picture

A good idea for logging non-standard parameters is to create a File in your expdef and append to it... this way you can monitor the simulation using external programs that draw any kind of charts (like gnuplot).

Regarding Count, it shows the number of creatures in a population. You could try "reproduction.expdef": select it, initialize, start, and add two charts: Creatures count and Food count. Works for me!

Thanks Maciej - I'll try that. You've also prompted me to realise that Count wasn't what I need - Count is instantaneous population size whereas I want a cumulative count of food creatures created, so I'll look at creating a file as you suggest.

Cheers

Ian

Maciej Komosinski's picture

In standard.expdef "Extras" settings, there is the "Log fitness" option. When active, it creates a log file in the "scripts_output" subdirectory. There you can also find scripts that process all *.log files and automatically create charts for each of them using gnuplot (awk is also required).

This example can help you develop your customized charts.

Is there an onStop event or equivalent?

Thanks Maciej - I've tried that and got it working apart from not knowing how to ensure that my file is closed when the user stops the simulation.

I want my file to be available globally for the life of the simulation. I create it in OnExpDefLoad and write to it every time a new food item is created. Is there an onStop event or equivalent that I can detect when the user clicks stop (or the simulator stops for some other reason) so that I can then call File.close()? The file will be forceably closed if I quit Framsticks but I want to be able to look at the file in an editor without having to quit. I'd also like to catch an onRun (or equivalent) event to reopen the file for writing again if the user restarts a stopped simulation.

Any suggestions about how I might do this? I've tried doing a File.open() and File.close() either side of my write statement to ensure that the file is always closed unless being written to but that throws an "illegal write attempt" error. (I note from the Class Browser that File.open() may be only for reading from files, not writing to them, so perhaps a closed file can't be reopened for writing?)

Cheers

Ian

Maciej Komosinski's picture

How about this - no global file variable needed:

function log(msg)
{
  var f=File.appendDirect("log.txt","description");
  f.writeString(""+msg+"\n");
  f.close();
}

Thanks Maciej - Works beautifully, so simple.

Cheers

Ian