A simple agent-based model used to teach the basics of OOP in my lectures

Overview

Pydemic

A simple agent-based model of a pandemic.

This is used to teach basic principles of object-oriented programming to master students.

It is not at all optimized for performance and does not have any predictive skill.

Based on an original idea by Georg Wohlfahrt.

image

Rules

We are simulating a square 2-dimensional (nx x nx pixel) domain which is populated by a maximum number of agents (na), i.e. human individuals. The initial position of the agents on the domain is determined with a pseudo-random number generator. Two or more agents may populate the same pixel.

The simulation runs to a maximum of nt time steps. During every time step each agent may move a maximum number of pixels in the horizontal (x) and vertical (y) direction, as determined by the movemax parameter. If movemax = 2, this means that agents may move between -2 and +2 pixels in the x/y-direction – the actual number of moves within these limits is again determined with the random number generator.

If the random moves would cause an agent to leave the domain, the agent is perfectly “reflected” into the domain, i.e. if a random move would bring an agent to the position nx + 2, the position is corrected to nx – 2.

At the start of the simulation, a number n_initial_infected of randomly selected agents carries the virus.

If two or more agents meet on the same pixel and at least one of them is infected there is a certain probability (probability_of_infection) that non-infected, non-immune agents become infected. This dice roll is repeated for each infected agent at this location.

If infected, agents remain infectious until they recover (time_until_recovery). At the end of the infection period, there is also some probability that agents do not recover, but instead decease (mortality_rate), which reduces the total number of agents on the domain. After recovery, the past infection conveys immunity from another infection.

Potential improvements

There are many. See exercises on the topic.

Getting started

Download the code and run pydemic.py in the terminal or in the ipython interpreter.

TODO Fabien

  • Write tests.
  • Add a visualisation of the spatial domain (with density plots or similar).
Owner
Fabien Maussion
Climate, glaciers, and programming.
Fabien Maussion
Insert SVGs into matplotlib

Insert SVGs into matplotlib

Andrew White 35 Dec 29, 2022
Create charts with Python in a very similar way to creating charts using Chart.js

Create charts with Python in a very similar way to creating charts using Chart.js. The charts created are fully configurable, interactive and modular and are displayed directly in the output of the t

Nicolas H 68 Dec 08, 2022
DataVisualization - The evolution of my arduino and python journey. New level of competence achieved

DataVisualization - The evolution of my arduino and python journey. New level of competence achieved

1 Jan 03, 2022
Lumen provides a framework for visual analytics, which allows users to build data-driven dashboards from a simple yaml specification

Lumen project provides a framework for visual analytics, which allows users to build data-driven dashboards from a simple yaml specification

HoloViz 120 Jan 04, 2023
Open-source demos hosted on Dash Gallery

Dash Sample Apps This repository hosts the code for over 100 open-source Dash apps written in Python or R. They can serve as a starting point for your

Plotly 2.7k Jan 07, 2023
Investment and risk technologies maintained by Fortitudo Technologies.

Fortitudo Technologies Open Source This package allows you to freely explore open-source implementations of some of our fundamental technologies under

Fortitudo Technologies 11 Dec 14, 2022
A simple code for plotting figure, colorbar, and cropping with python

Python Plotting Tools This repository provides a python code to generate figures (e.g., curves and barcharts) that can be used in the paper to show th

Guanying Chen 134 Jan 02, 2023
Collection of data visualizing projects through Tableau, Data Wrapper, and Power BI

Data-Visualization-Projects Collection of data visualizing projects through Tableau, Data Wrapper, and Power BI Indigenous-Brands-Social-Movements Pyt

Jinwoo(Roy) Yoon 1 Feb 05, 2022
CPG represent!

CoolPandasGroup CPG represent! Arianna Brandon Enne Luan Tracie Project requirements: use Pandas to clean and format datasets use Jupyter Notebook to

Enne 3 Feb 07, 2022
High-level geospatial data visualization library for Python.

geoplot: geospatial data visualization geoplot is a high-level Python geospatial plotting library. It's an extension to cartopy and matplotlib which m

Aleksey Bilogur 1k Jan 01, 2023
simple tool to paint axis x and y

simple tool to paint axis x and y

G705 1 Oct 21, 2021
Automatically Visualize any dataset, any size with a single line of code. Created by Ram Seshadri. Collaborators Welcome. Permission Granted upon Request.

AutoViz Automatically Visualize any dataset, any size with a single line of code. AutoViz performs automatic visualization of any dataset with one lin

AutoViz and Auto_ViML 1k Jan 02, 2023
a python function to plot a geopandas dataframe

Pretty GeoDataFrame A minimum python function (~60 lines) to draw pretty geodataframe. Based on matplotlib, shapely, descartes. Installation just use

haoming 27 Dec 05, 2022
BGraph is a tool designed to generate dependencies graphs from Android.bp soong files.

BGraph BGraph is a tool designed to generate dependencies graphs from Android.bp soong files. Overview BGraph (for Build-Graphs) is a project aimed at

Quarkslab 10 Dec 19, 2022
EPViz is a tool to aid researchers in developing, validating, and reporting their predictive modeling outputs.

EPViz (EEG Prediction Visualizer) EPViz is a tool to aid researchers in developing, validating, and reporting their predictive modeling outputs. A lig

Jeff 2 Oct 19, 2022
HW_02 Data visualisation task

HW_02 Data visualisation and Matplotlib practice Instructions for HW_02 Idea for data analysis As I was brainstorming ideas and running through databa

9 Dec 13, 2022
The Python ensemble sampling toolkit for affine-invariant MCMC

emcee The Python ensemble sampling toolkit for affine-invariant MCMC emcee is a stable, well tested Python implementation of the affine-invariant ense

Dan Foreman-Mackey 1.3k Jan 04, 2023
Tandem Mass Spectrum Prediction with Graph Transformers

MassFormer This is the original implementation of MassFormer, a graph transformer for small molecule MS/MS prediction. Check out the preprint on arxiv

Röst Lab 13 Oct 27, 2022
A Jupyter - Leaflet.js bridge

ipyleaflet A Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook. Usage Selecting a basemap for a leaflet map: Loading a geojso

Jupyter Widgets 1.3k Dec 27, 2022
Make sankey, alluvial and sankey bump plots in ggplot

The goal of ggsankey is to make beautiful sankey, alluvial and sankey bump plots in ggplot2

David Sjoberg 156 Jan 03, 2023