How to extract variables from Behaviour Space in NetLogo - netlogo

I'm using a model that returns a series of variables at the end of the simulation. I'm trying to analyze this set of variables for 100 times with Behaviour Space but I'm not able to get the same variables that I can easily find with a single simulation. In particular, launching the experiment the output is just a repetition for 100 times of the parameters of the model.
This is what I see when I create a new experiment
I've also tried to write on "Measure runs using these reporters" the code count individuals-own because i've seen on the code of the model this individuals-own [talent success n-lucky-events n-unlucky-events] but I'im not sure of what it is, and with this command it returns an error "END expected".

(1) I am trying to get all the variables values of this model for every
run made in behaviour space.
(2) I almost managed to get what I need
writing in "Final commands" export-world "file-name" but it returns
only one world instead of the 10 runs made in behaviour space. How can
I get export-world for each run? – Davide Cacozza 12 hours ago
(1) If you simply list the variables you want, one per row in the Behavior Space Experiment section "Measure runs using these reporters" they should all be exported.
(2) I suspect you are putting export-world in BehaviorSpace as a "final command" which is only run once at the end of all the runs, as you noticed.
If you want to export everything each run, you need to export as the last step in your actual CODE section. To avoid over-writing conflicts a unique name should be used. I had trouble with timestamps ( which at least would be sequential ) and Windows doesn't like colons ( so raw date-and-time is out ) so here's an example just using random numbers to get uniqueness ( well, 99.9999% of the time )
globals [ x y z ]
to setup
clear-all
set state random 5
reset-ticks
end
to go
if ticks > 10 [ print ( word state " " x " " y " " z) wrap stop]
set x state * ticks
set y x * x + random 3333
set z sqrt x + random 2222
tick
end
to wrap
let cmd (word " export-world \"myfilenumber" random 8000 ".txt\"")
run cmd
print (word "exported world via : " cmd )
end
I checked, it works.

Related

How to measure a set of attributes of individual agents in Behaviour Space?

So far, all the experiments I have run using Behaviour Space have been to either record global variables or the average values of agent variables across different agentsets.
However, I need to measure a set of attributes (violence, entitativity, homogeneity, size) of individual emergent agents (extremist groups) at two/three different timesteps each run. I also need to do this across a number of different model scenarios and ideally have it all summarised in the same spreadsheet. The aim is to plot the relationship between each agent attributes, with individual agents as my cases.
I can't seem to workout if this is possible using Behaviour Space. I have tried using e.g. [violence] of groups as a reporter in Behaviour Space, but the output is then a single string variable that I can't do anything with. I've also thought about using the export-world primitive but, from what I understand, this will overwrite the file every time it is executed or create separate files each time.
There may be a more elegant way to do this but the following should work.
Create global variables, say v0, v1, v2 ...,vn for the individual violence within group n.
Set these at each tick. Report them separately in Behavior space.
Example:
globals [ mass-violence v0 v1 v2]
turtles-own [ violence]
to setup
clear-all
create-turtles 3 [ setxy random-xcor random-ycor set violence 0 ]
reset-ticks
end
to go
set mass-violence 0
if ( ticks > 4 ) [ stop ]
ask turtles [ set violence random 100 set mass-violence mass-violence + violence]
set v0 [violence] of turtle 0
set v1 [violence] of turtle 1
set v2 [violence] of turtle 2
print (word mass-violence " " v0 " " v1 " " v2 )
tick
end
Or you could parse the string you ended up with in Excel using Excel commands to pull selected items out of the string and put them into separate columns. That would end you up in the same place. For example, 5 runs of the above code produces this:

Reporting a list in behaviorspace Netlogo

I want to capture the agent set of agent variable X in behaviorspace.
to-report MeanOfX
report mean [X] of turtles
end
to-report AgentSetOfX
report [X] of turtles
end
After I run the experiment I am not getting the same mean of my agent set, and also weird numbers. Is this the right way to do it?
Yes, those reporters will report the mean value of X for your turtles and a LIST of the X VALUES for the turtles, like "[ 1 34 3 4 8 92 ]" It will not return an "agent-set" containing a SET of TURTLES themselves despite your name. Did you want such an agent-set for some reason?
If you are using any randomization at all anywhere there is no reason the means should come out the same for different runs. If you need the randomization-generated X values to be identical across runs you should set "random-seed" to some value in your setup.
if the values of X are "weird numbers" you need to debug using some logic or printing out the X values as you generate them to see where they deviate from not being weird.

How to test if mortality rate is correct

This question is related to a question I asked some time ago.
I am trying to create a population in NetLogo. Therefore, I am trying to start with the mortality rate. However, I am not sure how to test if my code works. The age of the oldest dying turtles seems to be fine, however when I print the mean death-ages it is way too high and I don't know how to solve that.
The model is available here.
The problem might be the calculation of the probability of dying which I did as follows:
if (gender = "female") [
let die-val mortality-female age ; mortality prob included for the age of the turtle
if (die-val >= random-float 1)[
set prob-die? true
]
]
It looks like your code is working fine, but your implementation may be unrealistic.Your turtles all eventually die, and because your mortality likelihoods increase as age increases, your older turtles contribute far more to the death-ages list than the younger turtles. For example, after running go until all turtles were 90, there were still 52 turtles alive- so all of those (over half) would contribute their old age to the death-ages list. So, your death-ages list is strongly left-skewed, something like:
Where your average death-age over 100 replicates is around 90.5 years. I think this is due to your aging process- try only having your turtle age increase by 1 instead of 5- see if that gives output more like you're expecting. It immediately changes the distribution to look more normal, where your mean death-age for 100 reps is around 81.2 years:
Edit:
You can quickly set up a histogram using a plot widget with settings like this:
Note that the code
if length death-ages > 0 [
set-plot-x-range ( min death-ages - 5 ) ( max death-ages + 5)
]
is included because auto-scaling does not work for the x-scale of histograms. You can exclude that code in the "Plot update commands" field and manually set your x min and max if you'd like, but you'll miss any turtles that die after whatever x max value that you choose.
You also need to change your pen settings from line to bar- click the pencil icon at the right of the pen field to open the menu below and select "Bar" from the "Mode" drop-down menu. Note as well that I've set my "Interval" to 5 to get the plots as shown above.

NetLogo - Behavior Space - controlling variable value

I am having a problem in working on Behavior Space. I have 3 parameters, percentage A, Percentage B and Percentage C. I want to vary values of these three in behavior space experiment but the sum of it must be always 100. For example, Percentage A 30%, Percentage B 30%, Percentage C 40%.
["percentage A" 50]
["percentage B" 25]
["percentage C" 25]
One way to skip unsufficient parameter settings would be the use of a stop condition. In the variables section of "Behaviour space" you can vary your parameters automatically by a range definition like:
["percentageA" [0 10 100]]
["percentageB" [0 10 100]]
["percentageC" [0 10 100]]
This would of course generate combinations which do not have a sum of 100.
Next in the reporter section you could add a reporter, which helps to filter your results later on:
(percentageA + percentageB + percentageC)
In the bottom section of the Behaviour Space Menu you can then simply add a stop condition like:
(percentageA + percentageB + percentageC != 100)
This condition will skip all unsufficient variations. Nevertheless you still would have entries in the output file for runs with unsufficient combinations but you can easily filter them. Just use the defined reporter and select only those entries with a value of 100 in that column.

Why is the sum of INT(RND*100)+1 always equal to 0? _QBasic

I'm writing a guessing game in QBasic , which kind of tells you that im not to this, and every time I run the code the rndnum is always 0. what should i change?
To get a different random number you must first seed it. Here's the example from the QB 4.5 Help file:
RANDOMIZE TIMER ' This is the best seed. The time is constantly changing
A = INT(RND*100)+1 ' Generate a random number
Print A
If you are saying that the very first returned number is zero every time the program is run then all you need is to add the randomize statement as a one-time called procedure. If you are instead saying that as you are iterating through the same code in a loop it is returning zero every time then there is something else wrong - most likely that for whatever reason QBasic does not recognize RND as a function and therefore assumes it's a variable, which would by default be set to zero. The correct syntax would be something like:
Lowerbound = 1
Upperbound = 100
RANDOMIZE
FOR X = 1 TO 10
PRINT INT((Upperbound - Lowerbound + 1) * RND + Lowerbound)
NEXT X