Skip to content

SEIR-deniers simulates epidemic spreading with behavioral heterogeneity, modeling Deniers and Cooperators in a compartmental SEIR framework. Includes both network-based Gillespie simulations and mean-field ODE integration.

License

Notifications You must be signed in to change notification settings

CoMuNeLab/seir_deniers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SEIR-Deniers Simulation on Networks

This project implements a stochastic, network-based SEIR-like epidemic model that distinguishes between cooperative and denier agents. It simulates the spread of an infectious disease on a contact network using an optimized Gillespie algorithm with support for additional compartments such as quarantined and hospitalized individuals.

Model Overview

The model extends the classic SEIR (Susceptible–Exposed–Infectious–Recovered) framework with:

  • IC: Infected Cooperators
  • ID: Infected Deniers
  • H: Hospitalized
  • Q: Quarantined
  • R: Recovered

Infected individuals are probabilistically either cooperators (follow public health interventions) or deniers (do not). Their behavior influences transition rates to quarantine or hospitalization, and ultimately recovery.

Project Structure

seir_deniers/
├── __init__.py
├── cli.py                 # Command-line interface
├── parameters.py          # SimulationParams dataclass
├── io.py                  # Network loading and output writing
├── simulation.py          # Main simulation loop
├── transitions.py         # Compartmental transitions
generate_ba_network.py     # Standalone script to generate BA networks

Requirements

  • Python 3.8+
  • NetworkX
  • NumPy

Install dependencies:

pip install networkx numpy

Quickstart

1. Generate a Network

python scripts/generate_ba_network.py --n 256 --m 2 --output BA_N256.edges

This creates a .edges file representing a Barabási–Albert network with 256 nodes.

2. Run the Simulation

python -m seir_deniers.cli \
    BA_N256.edges \
    output.dat \
    10 0.002 0.1 1.0 1.0 0.05 0.02 10000 0.3 0.1 0.1

Positional arguments:

  1. input_path: Path to network file (edgelist)
  2. output_file: Output file for simulation results
  3. n_samples: Number of simulations
  4. lambda_: Infection rate
  5. sigma: Incubation rate
  6. gamma: Recovery rate
  7. gamma_hosp: Recovery rate for hospitalized individuals
  8. delta: Hospitalization rate
  9. eta: Quarantine rate
  10. tmax: Max time steps
  11. alpha: Fraction of deniers
  12. a: Hospitalization probability
  13. b: Quarantine probability

Output Format

Each row in the output file contains the normalized compartment sizes at each time step:

time S E ID IC H Q R sample_id

Where each entry (except time and sample) is a fraction of the total population ( N ).

Example Parameters

Parameter Description Suggested Value
lambda_ Infection rate 0.002
sigma Incubation rate 0.1
gamma Recovery rate 1.0
gamma_hosp Hospital recovery rate 1.0
delta Hospitalization rate 0.05
eta Quarantine rate 0.02
alpha Fraction of deniers 0.3
a Probability to go to hospital (IC/ID) 0.1
b Probability to go to quarantine (IC) 0.1
tmax Max simulation steps 10000

Visualization

You can use libraries like pandas, matplotlib, or seaborn to visualize the .dat output:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("results/output.dat", delim_whitespace=True, 
                 names=["time", "S", "E", "ID", "IC", "H", "Q", "R", "sample"])

plt.plot(df["time"], df["IC"], label="Infected Cooperators")
plt.plot(df["time"], df["ID"], label="Infected Deniers")
plt.plot(df["time"], df["R"], label="Recovered")
plt.xlabel("Time")
plt.ylabel("Fraction of Population")
plt.legend()
plt.show()

License

This project is released under the MIT License.

About

SEIR-deniers simulates epidemic spreading with behavioral heterogeneity, modeling Deniers and Cooperators in a compartmental SEIR framework. Includes both network-based Gillespie simulations and mean-field ODE integration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages