agent-based model impossible to analyze in the reality ...€¦ · keywords: agent based models,...

13
Manuela Testa [email protected] Economic Sociology and Labour Studies University of Milan and University of Brescia AGENT-BASED MODEL Impossible to analyze in the reality? Simulation is the way! Abstract With this work I'd like to show you the fun and useful world of the agent-based modelling system. Simulation is an easy way to study phenomena which are difficult, dangerous or even illegal to analyze in the real world. The agent-base modelling system is a kind of simulation which is based on a bottom-up perspective, which starts from the single agents' behaviour and studies a macro phenomenon given by the interaction between them. Starting from a short description of the underlying theory and history, the article focuses on the practical perspective, as this is the best way to understand how modelling works. I used an easy example in which students interact with each other in order to share knowledge (or not). In the example, students are divided by cooperative and competitive behaviour. Their interactions can be analyzed to understand the frequency of spread or disappearance of these two different types of students. Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study a phenomenon that seems curious and interesting, or you had an intuition for an innovative research, but the costs are too high or the protocol is too long, maybe even dangerous? That's why, since the '50s, there has been made extensive use of the method of “simulation” in various fields of interest (e.g. medicine, economics) to support decision- making. The first research group to use this technique was the Centre of Operational Research of BISRA, metals technology industry research group in England, who also produced the first specialized “languages”, which then expanded in the United States, and further on throughout the world. What are ABMS? The really interesting aspect of simulation is that with this method it is possible to re-create "micro-worlds" that can have two characteristics at the same time as they are in fact, checking and highlighting the interdependencies between different parts and protagonists possibly amending their characteristics during construction, while at the same time representing new scenarios and

Upload: others

Post on 08-Oct-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

Manuela Testa

[email protected]

Economic Sociology and Labour Studies

University of Milan and University of Brescia

AGENT-BASED MODEL

Impossible to analyze in the reality? Simulation is the way!

Abstract

With this work I'd like to show you the fun and useful world of the agent-based modelling system.

Simulation is an easy way to study phenomena which are difficult, dangerous or even illegal to

analyze in the real world. The agent-base modelling system is a kind of simulation which is based

on a bottom-up perspective, which starts from the single agents' behaviour and studies a macro

phenomenon given by the interaction between them. Starting from a short description of the

underlying theory and history, the article focuses on the practical perspective, as this is the best

way to understand how modelling works. I used an easy example in which students interact with

each other in order to share knowledge (or not). In the example, students are divided by

cooperative and competitive behaviour. Their interactions can be analyzed to understand the

frequency of spread or disappearance of these two different types of students.

Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo

Introduction

How many times did you want to study a phenomenon that seems curious and interesting, or you

had an intuition for an innovative research, but the costs are too high or the protocol is too long,

maybe even dangerous? That's why, since the '50s, there has been made extensive use of the

method of “simulation” in various fields of interest (e.g. medicine, economics) to support decision-

making. The first research group to use this technique was the Centre of Operational Research of

BISRA, metals technology industry research group in England, who also produced the first

specialized “languages”, which then expanded in the United States, and further on throughout the

world.

What are ABMS?

The really interesting aspect of simulation is that with this method it is possible to re-create

"micro-worlds" that can have two characteristics at the same time as they are in fact, checking and

highlighting the interdependencies between different parts and protagonists possibly amending

their characteristics during construction, while at the same time representing new scenarios and

Page 2: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

possibly "impossible" phenomena detected in the world we live in (the word impossible is in

quotation marks because who is to say what is impossible?). Simulations show the unfolding of

events, under certain parameters (which we are able to control in the simulation) over a certain

time span and lets us search for new solutions, even to old problems.

With a simulation we can "see how things would be if ...", without changing the actual fact, it

allows us not only to do repeated tests always starting from the same condition (which is

impossible in reality as there are no time machines to take us back the conditions before the

experiment, for now!), but it also allows us to formulate and test hypotheses that might otherwise

be very expensive or dangerous (for example the study of some natural disasters ...).

From what has been said so far, we can summarize a number of important advantages of

simulations over other modes of research:

• Substantial reduction of costs: with simulation just a computer and an idea are needed to

"shake up" the world. Study a phenomena in the reality could be dangerous and have some

risk. If you make some mistakes, in most of the cases, you can't try again with same

situation of the first time, so the use of simulation is a really good substitute for a first

experiment.

• Speed: through simulation we can study events, which in reality could need ten years,

within only few seconds.

• Safety and legality: I have mentioned that some objects of study could be dangerous or

even illegal. With the simulation, this problem can be overcome and allow studies on

innovative ideas, which for fear of failure and consequence are often not even attempted.

Repeatability and better understanding of the object of study: in reality you cannot repeat

experiments without the prior attempt somehow changing the new starting conditions. A

simulation allows a continuous repetition of an experiment including the initial conditions

and to have the opportunity to gather more data, in order to evaluate the result that most

satisfies us and allows us to run a more detailed analysis due to the large amount of data

collected.

Obviously, as in all techniques, we also have disadvantages:

• As a simulation, and not reality, the results can be only approximate of what ultimately will

actually post the behavior of the system; so we can't take the result as absolutely true.

• In addition, the output of a simulation has to be interpreted in an effective way in order to

find an optimal resolution. This may require a complex data analysis which beats high risks

of error created by the user.

How it works

Simulation models, so called ABMs (agent-based modelling), are based on agents (from the Latin

agens, identifying someone or something that does something, sometimes even by describing the

means through which such action occurs) that interact and move coordinated within the virtual

Page 3: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

environment in which they "live". A more operational definition of agents, useful to explain their

role in the simulations, is provided by Shoam (1997, pp. 272): "an agent is an entity whose state is

viewed as consisting of mental components such as beliefs, capabilities, choices, and

commitments”. The actions of agents, usually an expression of these mental components, are

based on perceptions of the environment in which the agents operate. The behaviours that

emerge from the individual agents in the interaction with others and with the environment create

a particular system (economic, territorial, social, etc.) through a bottom-up mechanism. These

behaviours are therefore defined by rules that allow the agent to evaluate its own status (priority,

preferences, and available resources) and consequently make decisions. The different behaviours

of several agents together can finally create something totally new, something that is not

deductible from the mere sum of the behaviours. That is the reason why we talk about complex

systems.

It seems only right to open a small parenthesis here to explain the difference between

complicated and complex in this situation. A system is complicated if it is difficult to understand,

but once you understand the function of each part, you can also include the operation of all

parties, because it is simply given by its sum or overlap. In a complex system, understanding how a

single agent (whether person, animal or thing) behaves does not ensure understanding the

phenomenon that emerges from the interaction between more agents, because often this

interaction gives an added value that cannot be estimated from the study of the individual parts.

An interesting reading in this regard is Seth Lloyd, who developed, a physicist at MIT and the Santa

Fe Institute, who developed the so called Complexity theory (the institute also provides courses on

NetLogo, with video tutorials tours, slides and test for free).

Let's Simulate

Now we can narrow down the simulation as part of ABM. We describe our situation in a software

program applied to the analysis of an environmental system circumscribed, conducted by actors

that perceive a certain state of the system, interact with one another and express some

preference structure that tend to change over the same simulation. Once the model is built, it

must be translated into a language appropriate to the use of the program. This should not scare

you if you do not know programming languages general purpose as Pascal, C, or specialized

languages as SIMSCRIPT, ModSim, GPS. There were many interactive applications developed that

are easy to use for everyone but are much more suitable for quickly build models which are still

sophisticated.

There are several software platforms for the construction of ABM. Among the best known:

• Swarm, http://www.swarm.org;

• Netlogo, www.ccl.northwestern.edu/Netlogo.;

• repast, http://repast.sourceforge.net/;

• Ascape, http://www.brook.edu/dynamics/models/ascape/;

• StarLogo, http://el.www.media.mit.edu/groups/el/Projects/starlogo/;

• AgentSheets, http://www.agentsheets.com;

• AutoMod, http://www.automod.it/v2/index.php;

Page 4: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

• SIMUL8, http://www.simul8.com/;

• Arena simulation, http://www.arenasimulation.com/Arena_Home.aspx;

• EcosimPro, http://www.ecosimpro.com/.

An Example using NetLogo

To design an example of a simulation I chose the platform NetLogo Version 5.2.0. The software

combines the performance of a powerful programming tool with the advantage of having a

graphical interface which is simple and immediate to commands. The program has an excellent

graphics support and many advanced features for implementation. Moreover, it is able to simulate

very complex systems that evolve over time. There are several tutorials online that can be used for

creating models. Additionally there are simulations in the Models Library of the program, useful

for information about the countless fields of investigation in which the program can be used as the

ABM source for basic procedures. It is challenging and interesting to note the wide variety of areas

referred to by the simulations which are present in the log: biology, mathematics, economics,

sociology, medicine, chemistry, retrogames, etc.). In addition to the interaction with the existing

models, NetLogo is also an environment Authoring (Creation) that allows users to create their own

models. NetLogo, in fact, is quite simple to allow ordinary users to easily perform or even build

their own simulations, and it is advanced enough to be used as a powerful forecasting tool by

experiences researchers. There are also some useful applications for using NetLogo that facilitate

interaction. The description of which and some possible implementations are available in the

"features" on the site http://ccl.northwestern.edu/netlogo/docs/

The software has the potential to operate in all important operation platforms (Mac, Windows,

Linux) thanks to the programming language Java. The screen that appears when opening NetLogo,

presents a black box where the simulation models will be displayed (with the help of colours,

images and wallpapers), a 2D representation of a world made of turtle and patch. You can also

open the 3D view, using the 3D button.

Page 5: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

Figure 1. Home Screen- Interface

What is named “Patches” and “Turtles” above are only two of four possible agents that will make

what is just a black box at first become "a populated world". The former (patches) are the

background upon which you move the latter (turtles). Both have the coordinates to be "arranged"

in an environment: (pxcor: pycore) for Patch and (xcore: ycore) for Turtles, only that the former

are stationary and arranged in a grid, whereas the latter will move in the world according rules

assigned by the user. Since they are not created automatically, the Turtles can be created by the

observer and the patches and may take different forms (some of them are very funny and you can

also import or create your shape from the library: going on the top bar → Tools → Turtle shapes

Editor).

The other two agents that populate NetLogo are the links and the observer. The first, defined by

two points for each turtle, connecting the latter to form networks and grids. The observer exists

because the first three agents are not able to control their own commands independently, it acts

as a supervisor and it is “located” outside of the turtles and patches, without having a specific

location. It can be useful to group these agents, in order to make the language more powerful and

flexible, in subgroups such agent-sets. The actions are assigned to agents by commands and

reporters. The controls define actions that agents must fulfil; reporters perform operations and

report a result to a command or to another reporter. Commands and reporters already in NetLogo

are called primitive, and are listed in a special dictionary, which can be downloaded from the this

website: http://www.cytomaize.org/outreach/sas/p/ppts/NetLogo%202.1/docs/dictionary.html ).

Those defined by the user, instead, are called procedures. Each procedure begins with the name

assigned by the keyword "to" and ends with the keyword "end".

Once defined, a procedure can be used in any part of the program.

The variables are the characteristics associated to the agents, indicated by values. They may be

global, refer to the patches or turtles. Some variables are already existing in NetLogo such as, for

example, the colour of the turtles or patches, while others may be defined user through the

Page 6: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

In the main NetLogo interface, above, there are three labels: "Interface", "Information", "Code".

In the "Interface" (Figure 2) it we can be see then running of the model. Below the labels is the

toolbar that contains several buttons that allow you to create, modify or delete elements in the

interface mode, which and we will see gradually by in the example. The buttons (drop-down menu

in Figure 2) allow the user to check and change the model without acting writing continuously on

the code. For does this purpose interface there are created at least two buttons created on the

interface, which can handle the setting and the subsequent launch of the simulation: the setup

and the go buttons.

Figure 2. Interface

There are two different types of buttons: the button once and forever button. The first triggers a

procedure that will stop as soon as it comes to completion, so when the program read one times

all the rows of the “procedure” code ore “setup” code. The second triggers a procedure that needs

a second pressure to be stopped (e.g. go). If you want to assign to the button by a different name

and procedure to the button to which it refers, go to in the Display name of the button and you

can change type any label.

Other features are:

The “sliders” on the other hand (Figure 5) are global variables that apply to all agents of the

model. They allow to change the values of some variables in a quick and immediate

manner. In practice, without having recoded procedures, but simply moving the bar from

one value to another, the user can instantly observe the changes in the model.

The “chooser” provides the ability to assign values to the global variables by setting a menu

of alternatives as users that agents can be followed by agents.

The “monitors” are viewers that allow us to see the current value of a variable, as well as a

complex expression also which is updated automatically based on the timeline set. The

plots are graphs displaying the development of data in real time which of the data that the

model generates during the simulation.

Page 7: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

“Text boxes” are useful to write down information about the model directly in the interface

section. The Command Centre, located always inside the interface on the bottom, allows

you to enter commands directly without adding them to the procedures of the model that

remain so unchanged, so you can manipulate the agents in order to observe immediately

rations to different commands assigned. The commands are placed in the line observer.

Once you launch a command it will be moved in the white space above with all previous

commands forming a list available and can be called in a special menu, which is you may

cancel by clicking on the clear button.

In the section Information (Figure 3) there is information introduced relating to into the model and

explains the way in which we can use it, explore it, but also extend it.

Figure 3. Information

The Code section (Figure 4) stores the code of the model. Indeed, while in the Command Center

commands are not permanent, those that are found in the code determine the structure of the

simulation and are permanent. Under the series of sections is a bar that contains a set of controls.

The commands are different for each card-section.

Figure 4. Code

Page 8: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

After this first introductory phase of the peculiarities and structure of the program, let's develop a

simulation model itself (it is recommended to keep on hand a glossary of primitives).

The example:

The agents (or turtles), meaning the protagonists of the simulation, are university students divided

into two main categories: cooperative students and competitive students. Each student category,

according to its characteristics, interacts in an environment recreated to provide knowledge and

develop knowledge. In practice, the two types decide according to the "attitudes" which have

been prescribed to them (through the instructions given to the agents in the code) and how to

deal with the learning process. By all of these interactions between agents you can analyze how

often students sprout or disappear, how often they behave competitively or cooperatively. In

reality this difference is always present and seems to have found an equilibrium, the purpose of

the simulation is to understand under which conditions this balance is present (with which

parameters) and observe if by changing the instructions that agents follow (both of turtles and

patches) a new equilibrium can be found.

The model begins by mentioning the global variables as “Globals” (which refer to the entire

context) and their proprietary (i.e. those variables that refer only to the agent who is associated).

Then species of turtles used in the simulation are defined:

The model continues by drafting the procedure "setup" (referred to the button that establishes

the initial parameters, and that should always be present in the interface). Remember that each

procedure must begin with "to" followed by a name (this is usually also assigned to the button in

the interface), and ends with "end":

Page 9: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

After setting the setup parameters we pass to the second button, which is essential for how the

program works: go. As mentioned, this button is used to run the model continuously. Is the button

pressed, the pattern runs and does not stop until it is pressed a second time. The model could

therefore potentially run indefinitely.

This procedure has the following features:

Page 10: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

As you can see within the code written so far, some procedures have been "recalled", this means

that such procedures are defined and configured in another section of code which, with a single

command line, are easily called on. At this point, it is important to note that the procedures will

be executable only when the under-mentioned procedures will be completed. The plot written in

code will have an equivalent configuration interface and global variables created by us will have

sliders in the interface to define the numerical value.

The procedures referred to are divided into two procedures that characterize the environment

(Patches) which moves the agents (growth-awareness and colour-concepts) and two that instruct

the turtles on the way of interaction with other agents and the environment (dissemination and

learning):

Page 11: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

After configuring the plot in the code, we will end the process in the interface mode adding the

actual graphics support and setting its values. We have seen the commands that define the actions

the agents must fulfil; we conclude the list of code with reporters that perform operations and

report the result to a command or another reporter (in this case to a command):

Page 12: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

At this point the part of the code is completed, we have drawn the architecture of our simulation,

but still cannot start the experiment. As we have said before the graphical user interface is closely

linked to the code in order to define the variables that we included (e.g. t-waiting, n-steps, cost-of-

diffusion, cognitive-processes, etc.). As long as all the sliders, corresponding to all twelve global

variables inserted, will not have been defined in the program we will not be able to "read" (or

compute) the numerical values that we want to assign to those variables. This table lists all the

values of the sliders in the simulation: The content of the last column (value) corresponds to the

actual parameters of the slider starting time of the simulation and they can be changed by simply

sliding the bar. These variations are helpful to simulate different scenarios, in fact, changing the

values attributed to the twelve variables included, the agents will create interactions and the

outcome still unpublished are sometimes unpredictable. Also the arranged sliders simulation is

ready to be launched, but if we want to see the flow of the cycles in real time and the increase or

decrease created in turtles, we need to set the parameters of the monitor (time, cooperative,

competitive).

Nothing is easier than to create your monitor from the list of buttons in the interface and write

time in reporter section of the dialog box. Repeat this for the remaining two monitors writing the

section reporter, respectively, count cooperative-students and count competitive-students, you can

add in the Display Name, simply name them "Cooperative" and "Competitive". Finally, we can find

in the code the check button, which reveals errors in the code. Even in case of errors in the

connection between the code and the interface. If the check result is positive, the simulation is

ready to be launched. It 's time to go back in the interface mode, press the setup button to set the

initial moment, and start the simulation with the button go. Have fun changing the parameters

with the Sliders also during construction. Once you have learned the rudiments of an ABM in

NetLogo, you can create new and original simulations very easily. Increasingly refining your

technique, the ABM will become the tool that can give "life" to your ideas, visions and follies.

Page 13: AGENT-BASED MODEL Impossible to analyze in the reality ...€¦ · Keywords: Agent Based Models, ABM, Simulation, Model, NetLogo Introduction How many times did you want to study

An old saying reminds that "the finer simulation is good use of the truth" and reading this, a

young thinker might ask, "What is truth? Concept or a rigid and dichotomous rather a gradient

value, as suggested by the fuzzy logic? I can still imagine worlds Different? I could try to create

one ... ". Now is the time to become "the Demiurge" (craftsmen).

Bibliography

Shoham, Yoav (1997): An overview of agent-oriented programming. Software agents 4.

Tisue, S., & Wilensky, U. (2004, May): Netlogo: A simple environment for modeling

complexity. In International conference on complex systems.