3 ms·
Building a command line tool to simulate the spread of an infection
- vegetablepotpie 7y agoI also wrote a very simple model of infection growth based on a system of non-linear differential equations [1]. My model has not at all followed the curve of the real infection in the US. John’s model is looks much more sophisticated. [1] https://github.com/eggsactly/corona/blob/master/corona.py https://github.com/eggsactly/corona/blob/master/corona.py
- bunje 7y agoAre you sure it's nonlinear? Looks like a system of linear ODE's to me.
- bunje 7y agoOops. Of course it's nonlinear. My bad.
- photonemitter 7y agoSmall note on this. You should probably check some on numerical integration methods and solving ode’s. Specifically try the midpoint method or Runge-Kutta 4. (Rk4) which is easily implemented from the wiki-page.
- kaunta 6y agoGarrett, thank you. * * * My inspiration for writing this came from watching 3Blue1Brown's YouTube video, "Simulating an epidemic": https://www.youtube.com/watch?v=gxAaO2rsdIs https://www.youtube.com/watch?v=gxAaO2rsdIs His simulations cover several scenarios: - Simulating social distancing. - Having people travel to a central location (e.g. a grocery store). - What if the government is able to identify and isolate cases? - Simulating multiple communities with travel, that put quarantine measures in place. - What happens when people get tired of social distancing. * * * Thanks for sharing your code. I see that you are using gnuplot to visualize the output of the script. Have you considered using the csv module (https://docs.python.org/3/library/csv.html https://docs.python.org/3/library/csv.html) to output the data, instead of using the print() function? That way, you wouldn't have to manually add in spaces around the data and stringify the numeric data. >>> import csv, sys >>> writer = csv.writer(sys.stdout, delimiter=" ") >>> writer.writerow(["#", "T", "S", "I", "R"]) # T S I R In the script, usage would look something like this: import csv import sys ... writer = csv.writer(sys.stdout, delimiter=" ") writer.writerow(["#", "T", "S", "I", "R"]) writer.writerow([T, S, I, R]) while I > 1000: ... writer.writerow([T, S, I, R])
- tromp 7y agoCoincidentally this month's IBM Ponder This challenge calls for a similar tool: https://www.research.ibm.com/haifa/ponderthis/challenges/April2020.html https://www.research.ibm.com/haifa/ponderthis/challenges/Apr...