Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

Agent-Based Modeling in NetLogo
Artificial Intelligence

Agent-Based Modeling in NetLogo

Last Updated on May 13, 2020 by Editorial Team

Author(s): Prabod Dunuwila

Source

Agent-based modeling is a simulation technique that focuses on building a model of a system with a collection of autonomous decision-making entities called agents. Each individual agent can make decisions based on a set of rules provided with regard to their situation or properties. Using ABM techniques, people have identified that more complex patterns emerge as a result of simple interactions between individuals. Some of the examples are traffic jams, a flock of birds flying in V shape, housing patterns, and soΒ on.

You have probably seen a flock of birds flying in β€˜V formed shape.’ Most of you have probably thought that the leader bird is in the front, and other birds follow it. This is not the case. What happens is, rather than the same bird staying at their position, different birds occupy different spots while flying based on the independent movement based on the flying direction of the flock, avoiding other birds and not getting far away from the neighborΒ birds.

Likewise, ABM computational methodology enables us to model complex systems. ABM models are composed of agents, and agents have properties. In NetLogo, each agent has a graphical representation on the computer screen. Let’s try to build a simple scenario of a virus spread in society using NetLogo. In society, there are people(agents) who could be identified as infected and non-infected. So when agents interact with each other, infected agents may spread the virus to other agents. So let’s build a simple model to see how a virus is spread through a society based on a simple set ofΒ rules.

Properties of agentsΒ :

  • β€˜status’ to store whether infected or non-infected

RulesΒ :

  • each individual moveΒ randomly
  • a virus is infected if the non-infected individual is within the radius of the infected individual based on a spreadΒ rate

First, let’s build the interface of the model by using the β€˜interface’ in NetLogo. Here I have used two buttons named β€˜setup’ procedure to set up the environment and β€˜go’ procedure to run the modelΒ forever.

Then let’s create inputs named β€˜infected-count’ and β€˜people-count.’

A slider is used to change the global variable value’ spread-rate.’

Move to the β€˜code’ tab in NetLogo. Since we are using a global variable β€˜counter’ and creating a new breed type, we have to define it at the top of the code. Here the breed type is β€˜people,’ and we can use it to call all β€˜person’ agent set. And also, we have to define its properties.

globals[counter]
breed[people person]
people-own[infected?]

Let’s look at what we have to do in the β€˜setup’ procedure. We have to clear the environment first, then set up the environment with agents and reset the ticks. So the code will look likeΒ this.

to setup
clear-all
initialize-people
reset-ticks
end

You will get an error if you β€˜check’ the code using the β€˜Check’ button because you have not yet written β€˜initialize people’ procedure. We have to write that separately below setup. Write the β€˜initialize-people’ procedure to create the agents of people type based on the people-count provided. Agents will be of shape β€œperson” and random x, y coordinates. And people will have β€˜infected?’ property true or false based on the initial β€˜infected-count.’

to initialize-people 
set counter infected-count
create-people people-count[
set shape "person"
setxy random-xcor random-ycor
(ifelse (counter > 0)
[set color red
set infected? true]
[set color white
set infected? false])
set counter counter - 1
]
end

Then in the β€˜go’ procedure, we have to write what we expect to do when the model is running. So I will simply make people move randomly and spread the disease. I will not focus on the recovery of the infected people agents, and the model will stop when all the people get infected with theΒ disease.

to go
(ifelse any? people with [color = white] [
move-people
spread-disease
]
[stop])
tick
end

We have to write two separate procedures named β€˜move-people’ and β€˜spread-disease’ to run the model. First, let’s look at the move-people method. It will ask people to pick a random whole number between 0 and 50. Then the agent turns right this number of degrees. And then ask to choose a random number between 0 and 50 and turns left that number of degrees. Then move forward with the specified stepΒ value.

to move-people
ask people [
rt random 50
lt random 50
forward 0.1
]
end

In the β€˜spread-disease’ procedure, when a non-infected person meets an infected person, he/she will get infected with the disease based on the β€˜spread-rate’ provided.

to spread-disease
ask people [
if any? people with [infected? = true] in-radius 0.5 [
if random 100 < spread-rate * 100 [
set color red
set infected? true
]
]
]
end

Move back to the β€˜interface’ tab, and let’s create a plot to show the count of infected and non-infected people at each tick when the model isΒ running.

So the final interface will look like below after making all theΒ changes.

Before you run the model, don’t forget to fill input values for the inputΒ boxes.

I hope all of you have got an understanding of Agent-Based Modelling using NetLogo. If you want to read and learn more about ABM simulation using NetLogo, check out the references providedΒ below.

References

[1] NetLogo HomeΒ Page

[2] An Introduction to Agent-Based Modeling Modeling Natural, Social, and Engineered Complex Systems with NetLogo by Uri Wilensky, WilliamΒ Rand


Agent-Based Modeling in NetLogo was originally published in Towards AIβ€Šβ€”β€ŠMultidisciplinary Science Journal on Medium, where people are continuing the conversation by highlighting and responding to this story.

Published via Towards AI

Feedback ↓