looping instead of manual input of multiple initial numbers variable Netlogo - netlogo

I have a variable (grass) where you set in an initial number of grass. I want to see the result for different initial numbers, such as 50, 100, 150, ...., 1000, but it is too troublesome to set it manually, then run one by one. Is there anyway where I can just set a loop with 50 as the increment and stop at 1000, then release a certain value. Is that possible in Net Logo?
I have tried using the for function for other programming languages, but I do not know if it works here.

Look at BehaviorSpace - it's in the Tools menu. This is the batch simulation tool that exports the results so you can then do a summary etc. This will also allow you to do multiple repetitions for each of these values so you can calculate the average results for each, which is important when your simulation has randomness. There is a specific manual in the documentation, see https://ccl.northwestern.edu/netlogo/docs/behaviorspace.html

Related

Why does every simulation I perform in Arena Simulation give the same results?

Every time I run a simulation with the same parameters in the Run window I get exactly the same results. The results are different if a different number of replications is set each time the run is started
These are my settings in the run window:
enter image description here
I have a lot of Process blocks. Most of them have a normal distribution in duration. Why are the results not different?
If it helps in any way, her is a photo of the constructed model:
enter image description here
Arena uses the same random nr stream for your run unless you tell it to use another - so your first rep will look the same every time. The answer depends on the distributions you sample from. If you change the logic and sample at other times, the answer will change. Each following rep will have a unique answer based on the random nr streams you are sampling from. It makes it easier/possible to find errors if you can execute exactly the same run.
Arena provides (by default) ten different "streams" of (pseudo) random numbers. If you don't ask the system to use a particular stream, it will use stream 10. For example NORM(10,2) will use stream 10 to calculate a random normally distributed number (mean 10, standard deviation 2); NORM(10,2,4) will use stream 4 to calculate a similarly distributed number.
By default, the 10 random number generators for the streams are initialised at the beginning of each run to 14561, 25971, 31131, 22553, 12121, 32323, 19991, 18765, 14327, and 32535 (from Arena help). At the end of one replication, the generators will not be re-initialised, so they will start the next replication with a new value.
You can control the random number generator initialisation with the SEEDS element.
As #Marlize says, this helps to ensure that you can reproduce a simulation result if you need to.

AnyLogic Sensitivity analysis visualization

I am new to this and lost about how to create visualization for the AnyLogic sensitivity analysis. Here is the summary:
I have dataset that captures dependent and independent variables at the end of simulation run (just captures one pair at the end). Trying to vary independent variable to see the impact on dependent variable. The resulting dataset is correct (when I copy and paste in Excel) but the chart looks blank.
Also, output states that it completed 5 iterations but I specified 10 and the data shows that there were in fact 10 iterations.
There are no parameters for the chart data (see the screenshot) but I am guessing it is automatically populated at the end simulation based on the code (also copied below)? Otherwise, I cannot figure out what goes into the chart data (tried to manually enter variables/datasets to no avail).
This is the code after each simulation runs:
Color color = lerpColor( (getCurrentIteration() - 1) / (double) (getMaximumIterations() - 1), blue, red );
chart0.addDataSet( root.died_friend, format( root.SocFriendBrave ), color, true, `Chart.INTERPOLATION_LINEAR, 1, Chart.POINT_NONE );`
I realize this is a very basic question but I am lost and cannot get on the right path based on the help I found. thank you.
Let's say you have 2 experiments: simulation (normal one) and sensitivity analysis (new one)
The only way for the chart to look blank is if your dataset died_friend is empty. This can happen for many reasons, but the reason I suspect it happens here, is because you fill this dataset with information at the end of the simulation run, which means that you are probably using the java actions of the simulation experiment.
The sensitivity experiment DOES NOT read what you write on the java actions of the simulation experiment, so that might be the problem.
If this is not the case, you need to check other possible reasons on why your dataset is empty when you run the sensitivity analysis.
Remember: the fact that your dataset has data in your simulation experiment, does not necessarily mean the dataset will not be empty on the sensitivity experiment.
Since the Sensitivity Analysis experiment is set up via the wizard, it would be better if you showed us how you'd set that up, rather than the resultant AnyLogic-generated code.
From what you've said here, it looks like you may be incorrectly trying to use datasets instead of scalar values. If there's one 'dependent variable' (model output of interest) then the 'independent variable' needs to be a model parameter (parameter of your top-level agent, normally Main, which the experiment will be varying).
So you should specify:
Varying the relevant parameter (looks like you wanted it to be 0, 0.25, 0.5, 0.75, 1 so min 0, max 1 with step size of 0.25)
Producing a chart for the scalar output you want. (If this was, say, a variable called outputValue, you'd use expression root.outputValue when setting up the chart in the wizard.)
Also you should only be getting more than 5 iterations if you set up your parameter variation criteria incorrectly.
(Dataset outputs in the experiment's charts are typically for where your model produces a time series as an output --- i.e., a dataset of sim time vs. value --- and you want the Sensitivity Analysis experiment to show charts with each run's time series as separate lines (i.e., time on the X-axis). Scalar charts are for where the X-axis is the varying parameter and the Y-axis the output of interest.)

NetLogo Experiment Setup

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

How to extract global variables values at the end of each experiment in Netlogo Behaviour Space

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.

Tuning and optimizing a MATLAB/Simulink Model

I would like to optimize output signals, by tuning some of the input parameters with ease (preferably in real-time) by looping the simulation of the model again and again at a speed where the speed of simulation can be controlled.
You have various options as far as I can see.
The first one is to have the parameters of interest defined as workspace variables, and then write a MATLAB script looping over those variables, with the use of the sim command to run the Simulink model programmatically. You can control the "speed" of the simulations with things such as step size used by the solver. If you want to combine this with optimizing parameters, you can put the call to sim in a cost function, and then pass this to the optimization routine.
The second option is to use an add-on product called Simulink Design Optimization, which provides a nice interface and uses optimization routines under the hood to loop over the parameters. This requires the Optimization Toolbox.
If you want to invest nothing in the creation of your user interface, you might want to use cell evaluation. Check out this link.
Increment Values in Code Sections
You can increment numbers within a section, rerunning that section
after every change. This helps you fine-tune and experiment with your
code.
To increment or decrement a number in a section:
Highlight or place your cursor next to the number. Right-click to open
the context menu. Select Increment Value and Run Section. A small
dialog box appears.
Input appropriate values in the / text box or / text box. Click
the , , , or button to add to, subtract from, multiply, or divide
the selected number in your section. MATLAB runs the section after
every click.