{"id":26578841,"url":"https://github.com/pprunty/covid_19_model","last_synced_at":"2025-08-01T08:15:08.731Z","repository":{"id":168300389,"uuid":"462725625","full_name":"pprunty/covid_19_model","owner":"pprunty","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-23T23:41:21.000Z","size":465,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T05:17:09.794Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pprunty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-02-23T12:29:17.000Z","updated_at":"2022-02-23T12:30:13.000Z","dependencies_parsed_at":"2023-11-24T00:27:10.664Z","dependency_job_id":"1e1be1f5-03c9-425c-adcc-5ad0fa2c0c21","html_url":"https://github.com/pprunty/covid_19_model","commit_stats":null,"previous_names":["pprunty/covid_19_model"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pprunty/covid_19_model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fcovid_19_model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fcovid_19_model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fcovid_19_model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fcovid_19_model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pprunty","download_url":"https://codeload.github.com/pprunty/covid_19_model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pprunty%2Fcovid_19_model/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268191479,"owners_count":24210525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-23T05:17:16.345Z","updated_at":"2025-08-01T08:15:08.680Z","avatar_url":"https://github.com/pprunty.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Part of a college assignment...\n\n# COVID-19 Model\nThis program uses Monte Carlo simulation to model the spread of an infectious disease using the\nMetropolis algorithm to control people's degree of social distancing on the grid along with survival\nprobabilities with a constant hazard rate to determine how many days a person has until death given \nthat they are currently infected and have survived up to time t.\n\n![Screenshot](graphics/i100_k0_p10000_t0.5.png)\n\n## Contents\n\n1. [Overview](#overview)\n2. [Requirements](#requirements)\n3. [Compilation and Usage](#compilation-and-usage)\n4. [Known Issues](#known-issues)\n\n## Overview\n\n### Metropolis Algorithm\n\nA person on the grid's degree of social distancing is controlled by the idea of the Metropolis algorithm. Given the \ncurrent configuration of a system with current energy E1, we can propose an update which would leave the system with \nenergy E2. If that update decreases the energy of the system, i.e. E2 \u003c E1, we will accept the update. If it increases \nthe energy from E1 to E2 then we will accept the update with probability:\n\nThe degree of social distancing is controlled by the variable k. An illustration for different values of k and degree\nof social distancing can be seen below:\n\nk = 0\n\n![Screenshot](graphics/k_0_timesteps_100.png)\n\nk = 0.5\n\n![Screenshot](graphics/k_0.5_timesteps_100.png)\n\nk = 1\n\n![Screenshot](graphics/k_1_timesteps_100.png)\n\nAs illustrated, as k increases, the degree to which this person stays close to \"home\" increases. This gives us control to\nmodel the spread of an infectious disease for different degrees of social distancing k.\n\n### Survival Probability and Hazard Rates\n\nThe hazard rate is the he conditional probability density of an event X happening at x given that it survives to that \npoint and is given by:\n\n![Screenshot](equations/hazard_rate.png)\n\nThe survival function is thus:\n\n![Screenshot](equations/survival_function.png)\n\nIf we assume a constant hazard rate hX(x) = λ then this just becomes:\n\n![Screenshot](equations/survival_function_constant.png)\n\nOr equivalently, we can write:\n\n![Screenshot](equations/survival_function_cum.png)\n\nThis is just an exponential distribution. You can invert the equation above and use the inverse transform method to \nmap a uniform random variate, y ∈ U(0,1), back to exponentially distributed t\n\n![Screenshot](equations/exponential_t.png)\n\nFor the model we will assume a constant hazard rate. When a person is “infected” we will \nrandomly assign a days-to-death variable. We will have a fixed time-to-recovery parameter (e.g. 14 days/turns). If the \ndays-to-death is greater than the recovery time, then the person will be cured and become immune at 14 days. If their \nrandomly assigned days-to-death is say 5, then they will die and be removed after 5 days.\n\n## Requirements\n\n- g++\n- gnuplot (if you would like to produce graphics)\n\n## Compilation and Usage\n\nTo compile the code simply run the following command inside a terminal in the project directory:\n\n```shell\nmake\n```\n\nTo run the program, simply run the following command inside a terminal in the project directory:\n\n```shell\n./main\n```\n\nTo produce graphics for the 2d walk, run the following commands inside the gnuplot terminal in the project directory:\n\n```shell\n./2d_walk 0 \u003e k_0_timesteps_100.txt\n```\n\nTo produce graphics for the random walk, run the following commands inside the gnuplot terminal in the project directory:\n\n```shell\nset title \"k=0, timesteps=100\"\nset xrange [0:10]\nset yrange [0:10]\nset grid ytics lt 0 lw 1 lc rgb \"#bbbbbb\"\nset grid xtics lt 0 lw 1 lc rgb \"#bbbbbb\"\nplot 'k_0.5_timesteps_100.txt' with lines title \"2d random walk\"\n```\n\nTo produce graphics for the disease simulation, run the following commands inside the gnuplot terminal in the project directory:\n\n```shell\nset key outside\nset xrange [0:80]\nset yrange [0:10000]\nset title \"set title i=100, k=1, p=10000, t=0.3\"\nplot '100x100_p10000_i100_k0.5_d0.2_t0.5.txt' using 1:2 with filledcurves x2 title \"Didn't Catch\" linetype 4, \\\n'100x100_p10000_i100_k0.5_d0.2_t0.5.txt' using 1:4 with filledcurves x1 title \"Dead\" linetype 3, \\\n'100x100_p10000_i100_k0.5_d0.2_t0.5.txt' using 1:3 with filledcurves x1 title \"Reovered\" linetype 2, \\\n'100x100_p10000_i100_k0.5_d0.2_t0.5.txt' using 1:2 with filledcurves x1 title \"Infected\" linetype 1, \\\n```\n\nNote: I know I can add this to the Makefile as 'make plot' but I prefer to leave the commands here so I can return to them.\n\n## Results\n\n![Screenshot](graphics/i100_k0_p10000_t0.5.png)\n\n![Screenshot](graphics/i100_k1_p10000_t0.5.png)\n\n\n\n## Known Issues\n\nNone at present.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpprunty%2Fcovid_19_model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpprunty%2Fcovid_19_model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpprunty%2Fcovid_19_model/lists"}