Adjoint Contact Sensitivity — Python code for eigenvector-based sensitivity of age-structured epidemic models
Authors/Creators
Description
Overview
This deposit contains the Python implementation for eigenvector-based sensitivity analysis of age-structured epidemic models. The software computes the sensitivity of key outcomes to perturbations in age-specific contact patterns using the Next Generation Matrix (NGM) framework and automatic differentiation in PyTorch. It accompanies the manuscript “Eigenvector-Based Sensitivity Analysis of Contact Patterns in Epidemic Modeling.” The method, models, and equations are described in detail in the paper.
What the code does
• Builds a computation graph from contact matrices to the dominant eigenvalue of the NGM (R0) and to mortality-weighted targets.
• Computes pairwise (age-by-age) and group-level sensitivities via gradients of R0 with respect to independent contact-matrix entries.
• Supports full and aggregated age partitions and produces heatmaps and bar plots.
Models implemented
1) Pitman et al. SEIR/SEIRS influenza model (England & Wales contact data).
2) Röst et al. COVID-19 model with 16 age groups and multiple infectious/hospital compartments (Hungary contact data).
Both model constructions and equations are as in the manuscript.
Data access (Google Drive fetch)
The repository does not bundle large data files. Instead, the code downloads the required inputs from Google Drive at runtime using `gdown`. File IDs are declared in `data/model_config.json`; the `DataLoader` class fetches:
• model parameters (JSON),
• contact matrices (Excel),
• age distributions (Excel), and
• shared labels (JSON).
Downloaded files are stored under `./data/`. See `src/data_loader.py` for the exact workflow.
Contents
• `main.py` — entry point for running experiments and producing figures
• `src/` — model builders, gradient/sensitivity routines, plotting utilities
• `requirements.txt` — pinned dependencies (PyTorch, xlrd, gdown, matplotlib, etc.)
• `flowchart.png` — pipeline overview
• `README.md` — usage instructions
Reproducibility
1) Python 3.10+ recommended.
2) `pip install -r requirements.txt`
3) Run, e.g., rost or seir
`python main.py --rost`
`python main.py --rost_agg`
Figures are written to the `./outputs/` directory; the code reproduces the sensitivity heatmaps and group-level summaries shown in the paper.
Files
adjoint-contact-sensitivity-revision.zip
Files
(298.3 kB)
| Name | Size | Download all |
|---|---|---|
|
md5:e62ac9bed6b2dd9397f6fcd40f20489e
|
298.3 kB | Preview Download |
Additional details
Dates
- Accepted
-
2025-10-07Accepted for publication in Journal of the Royal Society Interface
Software
- Repository URL
- https://github.com/Evanskorir/adjoint-contact-sensitivity/tree/revision
- Programming language
- Python
- Development Status
- Active