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?
Related
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'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
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 building a cost effectiveness model (infectious disease related) in NetLogo consisting of an intervention and "status quo" cohort that should behave identically except for the influence of the intervention. I can reproduce base case results (default parameter values) using the random-seed statement. However, when I change parameters influence intervention efficacy (e.g., compliance) it changes the random number generation process and then causes the outcomes in the status quo cohort to change. How can I get around this? How do I isolate one cohort from changes taking place in another cohort with respect to the random number generation process? the with-local-randomness statement doesn't really help me ..
Unfortunately, you face two serious problems: NetLogo really does not provide access to random number generators other than the global one, and much of the access to that PRNG is implicit. So for example, whenever you use ask, you are implicitly drawing from the global PRNG.
You may be able to use with-local-randomness. E.g., use it every time you ask turtles outside the status-quo cohort to do something. Or, to use with-local-randomness for the special cohort, you could start the simulation by generating a seed sequence that you then consume as the simulation runs, resetting the random state each time you ask that cohort to do something (or generate random numbers, etc.).
Do the cohorts need to be run simultaneously (ie do they interact)? If not, could you simply run two completely separate experiments - one for the control and one for the intervention scenario.
I would like that BehaviorSpace runs my model 100 times. In my model, I created three buttons :
the 1st button creates a landscape (procedure "create-landscape")
the 2nd button initializes turtles (procedure "setup-simulation" in the figure below)
and the 3rd button runs the model (procedure "start-simulation" in the figure below)
I would like that the 1st button is used once during the 1st simulation in order to keep the same landscape during the 100 simulations (procedures "setup-simulation" and "start-simulation" runs 100 times). How can I do that from "Experiment" (see figure below) ?
Thanks very much for your help.
I assume that the reason you're asking this is that you have randomness involved in your landscape generation, such that you get a different landscape each time you run create-landscape.
If you want to get the same landscape each time, you could use a fixed random-seed for the landscape generation.
For example:
random-seed 0
create-landscape
...would always generate the same landscape.
But since you want the rest of your simulation to behave differently from run to run, you can't just use a fixed random seed for the whole thing.
One way to get a fixed seed for the landscape and a varying seed for the rest of the simulation is to use with-local-randomness for the landscape generation.
Imagine you have an input widget for a random-seed-for-landscape global variable. You can create your landscape from your setup-simulation procedure like this:
to setup-simulation
with-local-randomness [
random-seed random-seed-for-landscape
create-landscape
]
; rest of your setup procedure...
end
Then even if you ask BehaviorSpace for 100 repetitions, you will always get the same landscape.
And if you would like to experiment with different landscapes, you could put:
["random-seed-for-landscape" 0 1 2]
In the "Vary variables as follow" section of your BehaviorSpace dialog and run 100 repetitions for each of these three landscapes.
To get a better understanding of the way NetLogo deals with randomness in general, I suggest reading the Random numbers topic in the programming guide.