Simulates the spread of COVID-19 using a per-country sampled population and a simple Markov-chain per-person model.
This assignment-style project creates a per-person daily time-series, a per-country daily summary, and a visualization of infection waves. It also includes a small Streamlit app to run and visualize the results.
- Status: working (no automated CI or packaging yet).
- Language: Python
- Key files:
assignment2.py,app.py(Streamlit UI),helper.py,sim_parameters.py,a2-countries.csv,test.py. - Outputs:
a2-covid-simulated-timeseries.csva2-covid-summary-timeseries.csva2-covid-simulation.png.
- Builds sampled populations for selected countries (sample ratio, e.g.
1e6). - Runs a per-person, daily Markov chain using age-group specific transition probabilities (from
sim_parameters.py) between states:H(healthy)I(infected, no symptoms)S(symptomatic)M(immune)D(deceased).
- Saves:
a2-covid-simulated-timeseries.csv— long table of person/day/state.a2-covid-summary-timeseries.csv— aggregated counts per country/day for states D, H, I, M, S.a2-covid-simulation.png— chart created byhelper.py::create_plot().
- Create venv and install:
python -m venv .venv
source .venv/bin/activate # or .venv\Scripts\activate on Windows
pip install --upgrade pip
pip install -r requirements.txt # or: pip install pandas matplotlib streamlit- Run the simulation (default inputs are read from test.py):
# Run assignment script directly (example arguments)
python assignment2.py
# or if the file exposes run() and test.py calls it, run the test driver:
python test.py- Run the Streamlit app (interactive):
streamlit run app.py
# then open http://localhost:8501- assignment2.py — main simulator (implements run(countries_csv_name, countries, start_date, end_date, sample_ratio)).
- sim_parameters.py — transition probabilities and holding times per age group.
- helper.py — plotting helper (provides create_plot() used to produce PNG).
- app.py — Streamlit UI that calls assignment2.run(...).
- test.py — example driver and test harness.
- a2-countries.csv — country demographics input.
- ass2.ipynb — notebook used for experimentation.
Outputs (generated by running):
- a2-covid-simulated-timeseries.csv
- a2-covid-summary-timeseries.csv
- a2-covid-simulation.png
Example usage
Run the sim for ["Afghanistan", "Sweden", "Japan"] from 2021-04-01 to 2022-04-30 with sample ratio 1e6. Output CSV + PNG will be written to the project root.
