Coder Social home page Coder Social logo

covid19-modeling / pyncov-19 Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 0.0 1.76 MB

Flexible mechanistic epidemiological model to learn and predict the spread of COVID-19

Home Page: https://covid19-modeling.github.io

License: MIT License

Jupyter Notebook 95.54% Python 4.46%
covid-19 forecasting simulation markov-chain sars-cov-2 agent-based-simulation python spread simulator predictive-modeling

pyncov-19's Introduction

logo

Pyncov-19: Learn and predict the spread of COVID-19

Open In Colab

Pyncov-19 is a tiny probabilistic simulator for SARS-CoV-2 implemented in Python 3, whose only dependency is Numpy 1.18. This simulator is used to learn and predict the temporal dynamics of COVID-19 that are shown in https://covid19-modeling.github.io. It implements a probabilistic compartmental model at the individual level using a Markov Chain model with temporal transitions that were adjusted using the most recent scientific evidence.

Quick Start

Basic installation using pip with minimal dependencies:

pip install pyncov

In order to install pyncov with the additional features (progress bar, plotting) use:

pip install pyncov[all]

Sampling 100 simulated trajectories of the SARS-CoV-2 spread in Madrid:

import pyncov as nc
import pyncov.io
# Requires pandas
import pyncov.plot

susceptible = 6680000
infected = 1
num_days = 80

infection_rates = nc.infection_rates(nc.io.get_trained_params('ESP-MD'), num_days=60)
# Instantiate the model with the default parameters and sample 100 chains
# NOTE: show_progress requires the TQDM library not installed by default.
m = nc.build_markovchain(nc.MARKOV_DEFAULT_PARAMS)
simulations = nc.sample_chains(susceptible, infected, m, infection_rates, 
                               num_chains=100, show_progress=True)

You can visualizate the trajectories and the average trajectory matching the observed values in Madrid using pyncov.plot:

import matplotlib.pyplot as plt

# Load the dataset with pandas
df = pd.read_csv(...)

fig, ax = plt.subplots(1, 3, figsize=(16, 4))
nc.plot.plot_state(simulations, nc.S.I1, ax=ax[0], index=df.index, title="New infections over time")
nc.plot.plot_state(simulations, nc.S.M0, diff=True, ax=ax[1], index=df.index, title="Daily fatalities")
nc.plot.plot_state(simulations, nc.S.M0, ax=ax[2], index=df.index, title="Total fatalities")
df.diff().plot(ax=ax[1]);
df.plot(ax=ax[2]);

A more detailed explanation can be found in the notebook included in the repository https://github.com/covid19-modeling/pyncov-19/blob/master/notebooks/basics.ipynb

About

The primary objective of this model is to estimate the infection levels (or seroprevalence) of the population based solely on the data from registered deaths attributed to COVID-19. While the model has the capability to project future outcomes (such as infection trends and fatality rates), that isn't its central focus. Given the unpredictability surrounding pivotal events that can shift the trajectory and dynamics of the virus spread—like mask mandates, lockdowns, and social distancing—it's challenging to make precise predictions. Consequently, we primarily use the model for backcasting to shed light on past events.

For more information please read our paper:

Matabuena, M., Rodriguez-Mier, P., Garcia-Meixide, C., & Leboran, V. (2021). COVID-19: Estimation of the transmission dynamics in Spain using a stochastic simulator and black-box optimization techniques. Computer Methods and Programs in Biomedicine, 211, 106399.

pyncov-19's People

Contributors

pablormier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.