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.
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.
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
- Python 3.8+
- NetworkX
- NumPy
Install dependencies:
pip install networkx numpypython scripts/generate_ba_network.py --n 256 --m 2 --output BA_N256.edgesThis creates a .edges file representing a Barabási–Albert network with 256 nodes.
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.1Positional arguments:
input_path: Path to network file (edgelist)output_file: Output file for simulation resultsn_samples: Number of simulationslambda_: Infection ratesigma: Incubation rategamma: Recovery rategamma_hosp: Recovery rate for hospitalized individualsdelta: Hospitalization rateeta: Quarantine ratetmax: Max time stepsalpha: Fraction of deniersa: Hospitalization probabilityb: Quarantine probability
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 ).
| 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 |
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()This project is released under the MIT License.