# How to use behavior space

Behavior space is a tool of Netlogo to automatically run a large number of simulations and collect the data you are interested in in a text file and/or Excel file.

Behavior space can be found in Netlogo under Tools. If you click on Behaviorspace you will see the following

Before we go further, it would be useful to get a model from the library so that we can run some experiments for an actual model. We will get from the Netlogo library

PD N-Person Iterated

You will find this in: Social science -> unverified -> Prisoner’s Dilemma-> PD N-Person Iterated.

This model simulates a population of agents who every timestep randomly is partnered up to another agent and play a prisoner’s dilemma game. Each agent has a strategy. In the interface you can determine the amount for each of the 6 strategies. The strategy unknown is meant for you to try out new strategies. As a default it is a Tit-for-Tat strategy.

If you run the model, you will see that the strategies have different average payoffs in the longer term. Actually the defect strategy is found to give the highest amount of payoff.

Suppose we want to explore the results for a number of different distributions of strategies. Will defect always get the highest payoffs?

Instead of doing this manually, we will use behaviorspace. Go again to behaviorspace in “tools”. When you get the following screen popping up

Click on “new”. You will now generate the settings for running an experiment. In the following figure you will see that the global variables (including the sliders on the screen) are listed in the list of variables you can vary. The values given are the default values. We also see the number of *repetitions* you want to run the model for each parameter setting.

Then you see the information you will save in a text file or Excel file. As a default this is “count turtles”.

You can store information for each timestep or only the results at the end of the simulation (*Measure runs at every timestep*)

The setup commands define that the command *setup* will setup the model.

The go commands define that the command *go* will let the model run forever.

The time limit is the maximum number of ticks that you allow the model to run.

Now we like to run a series of experiments by varying the distribution of agents. We will vary the variables in the following ways:

[“n-defect” 5 10]

[“n-cooperate” 5 10]

[“n-unforgiving” 5 10]

[“n-random” 5 10]

[“n-unknown” 0]

[“n-tit-for-tat” 5 10]

This means that we run 2^5= 2*2*2*2*2=32 combinations of the model with different variations how many agents have strategy defect, cooperate, unforgiving, random, and tit-for-tat. These strategies have 5 or 10 agents. We do not include the unknown strategy.

Now we have to define what information to save. The default case of the amount of turtles, which is not very useful in our case since it remain constant. More interesting is the information in the plot of the interface.

If we go to the code and look what information is used to plot these graphs, we see that we can use the following information to save for our analysis

random-score / (num-random-games)

defect-score / (num-defect-games)

cooperate-score / (num-cooperate-games)

tit-for-tat-score / (num-tit-for-tat-games)

unforgiving-score / (num-unforgiving-games)

I don’t want to save the information for every timestep since the information that is saved is the average over all the timesteps so far. Therefore I uncheck Measure runs at every timestep.

I like the model to run 1000 ticks, so that’s why I put a time limit of 1000.

Now you get something like:

Now you click on OK and you get

Which means that you have defined 32 runs. Note that I only run each parameter settings only once. If I would have defined 10 repetitions, I would get 320 runs. For this exercise I like to keep the runtime short.

Now you have to click on “Run” and you get the following

You have to decide to save it as a spreadsheet (Excel), a table (ascii text file), both a table and spreadsheet, or whether you don’t want to save the data at all.

When you click on one of the options you are asked where to save the data on your computer.

When you have done this, the computer runs the simulations and stores the data. You will get the following window on your screen

You see here how many runs it has done sofar. You can speed up the runs by unchecking “Update view” and “Update plots and monitors” so that the computer does not spend time to update your screen for each calculation. And you can put the slider to high speed instead of normal speed. For this exercise it is not very important, but for more complex models you may run behavior space for many hours, and then it is useful to reduce the time for the calculations by 90%.

Now you can look at the results. For example by importing the data from the table file into Excel. This leads to the following picture. You may check the differences how information is stored between spreadsheet and table. I prefer to use table for my own analysis.

We found now for a few cases that the defect always strategy is not the best. Since the model is stochastic, you need to run each parameter setting many times to be statistically sure about this.

More information can be found at

- Printer-friendly version
- Log in or register to post comments