We now have an example about the spread of COVID-19, and a way to plot any agent based model using
An agent-based (or individual-based) model is a computational simulation of autonomous agents that react to their environment (including other agents) given a predefined set of rules . ABM has gained wide usage in a variety of research disciplines. One reason for its popularity is that it allows relaxing many simplifying assumptions usually made by mathematical models. Relaxing such assumptions of a "perfect world" can change a model's behavior . ABM is specifically an important tool for studying complex systems where a system's behavior cannot be predicted and has to be explored (see the "Why we need ABM" section for detailed examples).
- Simple, intuitive model structure where agents are identified by a unique id:
- Scheduler interface (with default schedulers), making it easy to activate agents in a specific order (e.g. by the value of some property)
- Default grids to run the simulation (e.g. simple or toroidal regular rectangular and triangular in 1, 2 and 3D)
- Users can use any arbitrary graph as a grid
- Automatic data collection in a
DataFrameat desired intervals
- Aggregating collected data during model evolution
- Distributed computing
- Batch running and batch data collection
- Visualize agent distributions on regular grids
Implementing an ABM framework in Julia has several advantages:
- Using a general purpose programming language instead of a custom scripting language, such as NetLogo's, removes a learning step and provides a single environment for building the models and analyzing their results.
- Julia has a rich ecosystem for data analysis and visualization, implemented and maintained independently from Agents.jl.
- Julia is easier-to-use than Java (used for Repast and MASON), and provides a REPL (Read-Eval-Print-Loop) environment to build and analyze models interactively.
- Unlike Python (used for Mesa), Julia is fast to run. This is a crucial criterion for models that require considerable computations.
- Because the direct output of Agents.jl is a
DataFrame, it makes it easy to use tools as DataVoyager.jl, which provide an interactive environment to build custom plots from
DataFrames. (and of course the
DataFrameitself is a tabular data format similar to Python's Pandas).
Agents.jl is lightweight and modular. It has a short learning curve, and allows one to extend its capabilities and express complicated modeling scenarios. Agents.jl is inspired by Mesa framework for Python.
The package is in Julia's package list. Install it using this command:
Agent-based models (ABMs) are increasingly recognized as the approach for studying complex systems [3,4,5,6]. Complex systems cannot be fully understood using the traditional mathematical tools that aggregate the behavior of elements in a system. The behavior of a complex system depends on the behavior and interaction of its elements (agents). Small changes in the input to complex systems or the behavior of its agents can lead to large changes in system's outcome. That is to say a complex system's behavior is nonlinear, and that it is not the sum of the behavior of its elements. Use of ABMs have become feasible after the availability of computers and has been growing since, especially in modeling biological and economical systems, and has extended to social studies and archaeology.
An ABM consists of autonomous agents that behave given a set of rules. A classic example of an ABM is Schelling's segregation model, which we implement in the Tutorial page. This model also uses a regular grid and defines agents as the cells of the grid. Agents can be from different social groups. Agents are happy/unhappy based on the fraction of their neighbors that belong to the same group as they are. If they are unhappy, they keep moving to new locations until they are happy. Schelling's model shows that even small preferences of agents to have neighbors belonging to the same group (e.g. preferring that at least 30% of neighbors to be in the same group) could lead to total segregation of neighborhoods. This is another example of an emergent phenomenon from simple interactions of agents.
Agents.jl targets complicated ABMs that are defined on arbitrary complex graphs. Because of this, the core datastructure of this package is a dictionary that maps unique IDs to Agents, as shown in the Tutorial and specifically in
AgentBasedModel. As all agents are unique entities, if one "dies" it is entirely and forever removed from memory. Similarly, when a new agent becomes "alive", this literally means that a new agent datastructure is initialized and added to this dictionary.
This is not necessary for cellular-automata-like models, where the grid cell and the "agent" identity are fully equivalent, and the agents have a single "property". This is the case e.g. in the Forest fire model. For such applications the Julia package DynamicGrids.jl is more performant than Agents.jl.
Use DynamicGrids.jl when your model lives on a rectangular grid, while the value of each grid cell does not have an identity (equivalently, the "identity" of each entity in your model is equivalent with its grid cell). Also use it for animating cellular automata.
Use Agents.jl if any of the following applies:
- You use individual agents whose identity (and other properties) is detached from their location
- Multiple agents can occupy the same location
- The spatial model of your structure is an arbitrary graph instead of a rectangular grid
- The agents have multiple values attached to them
- You want the output of your simulation to be a
DataFramefor easier further analysis
- You care about stability
- You want something simple to learn and use (Agents.jl has a simpler API and is much better documented)