I'm working on a model in Netlogo and I'm having a problem understanding how to set up an "experiment". In my model, I have a matrix that has all of the values that I'm interested in (6 in total) and the matrix is updated whenever a condition is met (every time X turtles are killed off) basically capturing a snapshot of the model at that point. The previous values in the matrix are cleared, so the matrix is a 1x6, not a 10000x6 matrix with only one line being updated for each snapshot.
What I would like to do is to set up an experiment to run my model several hundred times, collecting this matrix each time for the first X number of snapshots or until Y ticks have occurred. But I can't see a way to do that in the experiment setup?
Is this possible to do, or would I have to create the 100x6 (100 snapshots) and then just export that matrix to a CSV somehow?
I've never set up an experiment in Netlogo, so this might be super easy to do or just be completely impossible.
If I understand your question correctly, then you want 6 values reported at specific ticks during the run. Those ticks are chosen by meeting a condition rather than a certain number of ticks. NetLogo has an experiment management tool called BehaviorSpace. It is straightforward to set up your several hundred runs (potentially with different values for any inputs on sliders etc). It's not so straightforward to only output on certain ticks.
The BehaviorSpace dialogue box has a checkmark for every tick or at the end only. If you have it set to every tick, then you can export your six numbers every tick automatically. In your case, it is likely to be easier to do that than to try and only output occasionally. You could add a seventh reporter that is true/false for whether the matrix is being reset this tick. Then all you have to do in post-processing is select the lines where that seventh reporter is true.
If you want to run the model for exactly N snapshots, then you would also need to set up a global variable that is incremented each snapshot point. Your BehaviorSpace settings would then use that counter for the stop condition.
I'm not sure I understand your question, but usually you will have a Setup function and a Run function, correct? So I'm guessing the code structure below should be kind of what you are looking for. I haven't used netlogo in a while so the exact matrix code you'll have to figure out yourself.
globals your-1by6-matrix your-100by6-matrix
to setup
;reset your experiment
end
to run
;run your experiment
end
to run100times
repeat 100[
setup
run
;save your 1by6matrix into your 100by6matrix
]
;use your 100by6matrix to plot or export
end
Related
I'm trying to run experiments for a model of mine. I need it to output certain variable values for every tick but when I run the experiment I only get the values of either tick = 0 or the values at the end of the simulation. I need the values for every tick, anyone knows how this can be done in the NetLogo behaviour space experiments? Thanks in advance!
When you setup an experiment, there is a checkbox for saving the "reports" of a reporter at every step:
When I setup this experiment for the Wolf Sheep Predation Model from the Models Library, it outputs the count turtles for every tick.
I would like to know whether is it possible in NetLogo to set the random-seed according to the number of repetitions in the Behavior Space.
I know there is the command random-seed behaviorspace-run-number, but it sets a different seed for every run of the model. This is not what I want because I am trying to explore the impact of a variation in the values of a parameter on a specific random network structure. By using random-seed behaviorspace-run-number I get a different network structure for each value of the parameter within the same repetition of the experiment, which is not what I want.
Can anyone help me on this?
Thanks a lot,
Emanuele
There's not a variable that gives you exactly what you want, but BehaviorSpace runs through the parameter sets in a specific order. Say you have 5 repetitions of 20 parameter combinations, so there's 100 runs. It will do the first run of 20 combinations, then the second series etc. So you can do some mathematics or some if/then to go from the behaviorspace-run-number to the random-seed (eg floor behaviorspace-run-number / 20 if you want it to change every 20 runs).
I am running Netlogo program to simulate if a drunk person manages to cross to another side of the pier safely. I then stored this result in a global variable.
Now I would like to run a repetition of this simulation 100x through BehaviorSpace to find out the percentages of different outcomes.
However, I am unable to extract the value of that variable at the end of each repetition.
I would like to ask if there are any ways I can extract the value of a global variable at the end of each repetition in BehaviorSpace.
Thank you.
You can just at the global to Measure runs using these reporters.
If you only want the last result, uncheck Measure runs at every step.
If you have other things you want to report every step and you insist on not recording the global at every step, you can add to Final commands to write the value to a separate file.
I'm currently modelling the dynamics of an ice sheet. I therefore made a script that plots the volume of an ice sheet throughout time (in steps of 500 years). The volume increases rapidly at first, but the curve flattens later on as the volume does not change anymore and the ice sheet is in steady state... its shape is familiar like y=ln(x)... I thus have 2 output arrays, namely a) vol_time with the time in steps of 500 years and b) vol with the corresponding volume. Now, the program runs until a fixed time that I inserted (200 000 years) but I want to run the program only until this steady state is reached. So my question is: how can I make the program run only until the volume changes with only 0.002% per 500 years?
Thanks
You can ether wrap your ice-sheet thickness calculation in a while loop so the code performs the calculation until the 0.0002% condition is met or you loop through the whole 200.000 years.
Another option could be to add a if check end the end of your ice-sheet thickness calculation and if you enter and then add break in the if, this way the loop terminate.
I'm using behaviour space to run 100 simulations.
The problem is when I try to run more than 1 simulation at a time, some of the variables don't seem to be cleared properly.
Here is an example output:
Each simulation (the first column is the run number) has a variable (in the last column) reset to 0. It then adds a number between 0 and 5 until it eventually maxes out at 25. Since it only runs 2 ticks, the max result should be 10...
However as can be seen, the next simulation occasionally starts out with the max value for the variable. Is this a glitch or has someone seen something like it before? (perhaps the parallel processing isn't properly working?)
Problem/Solution
I had a setup function that initialized certain variables, THEN used clear-all, and then created turtles using the variables at the beginning. By looking at the results, it looks like rather than the new turtles being initialized... they somehow retained values from the previous simulation (with the score property already maxed). The problem was fixed by repositioning clear-all at the top. Note that this only caused problems when running multiple simulations
Interface globals (e.g., sliders) do not have a default value (unfortunately!) so clear-all does not affect them. This means you can run into problems if your BehaviorSpace experiments (i) do not specify values for all interface globals and (ii) describe simulations that alter the values of some interface globals. In this case, one foreground run can affect the next foreground run, even though you call clear-all in your setup.
If you instructed BehaviorSpace to call your setup, which includes a call to clear-all, this is the only way I see for your problem to arise. If it is something else, I hope you will post a description.
It seems possible that you are running into https://github.com/NetLogo/NetLogo/issues/105.
Are you calling clear-all at the start of your setup procedure?