I'm sure by now you've all seen the Washington Post article with the COVID-19 simulation, speaking to the public health benefits of social isolation in the face of a highly infectious disease. If you haven't, here's the article: https://www.washingtonpost.com/graphics/2020/world/corona-simulator/
Well, out of my quarantine boredom, I recreated this simulation in MATLAB, with more knobs to turn and parameters to play around with. For example, what if some of the carriers can die? What if the disease is Ebola instead (~50% mortality rate)?
This function simulates disease transmission among a set of n carriers, in a confined space, with some proportion of carriers socially isolating themselves. A simple multibody physics model (elastic collision between two equal-mass particles) determines carrier trajectory.
Hopefully this gives you a fun (albeit brief) respite from the doldrums of social isolation!
Joshua Gafford (2021). Simulitis (A Coronavirus Simulation) (https://www.mathworks.com/matlabcentral/fileexchange/74610-simulitis-a-coronavirus-simulation), MATLAB Central File Exchange. Retrieved .
Hi Angelo, look for the block of code under the title 'MODEL INPUTS.' You can change any of those parameters.
Thanks for creating this Joshua. I am a High School student and I want to use your simulation for a project on COVID-19 to explore different scenarios. I downloaded a trial offer for Matlab and ran the Simulitis code but can't seem to control change parameters. I love the simulation but for me to use this in my project I will need to be able to play with parameters to simulate different scenarios. Where should I go for help with this? Is the code you put up on this site the one with the controls? Thanks!
i am not getting any error and video_save = true
i will check again
I'm not sure, I just tested it and the video appears to save correctly for me. Have you made sure to set video_save = true? Are you getting any errors?
For whatever reason in the new version the video is not saved.
Checked and everything seemed fine but still video not saved.
Joshua, Your changes are very much appreciated. Thanks a lot
Thanks Joshua for the modification. Of course you were modelling the Washington post article, but seeing the code is so compact and beautiful, i might humbly suggest two simple modifications to make it closer to real world.
1. We see lots of patients test positive after getting recovered and this is a major issue in tackling this pandemic. So a modification in the sense that few recovered carriers(blue ones) turn into infected ones (red ones). I did that by assigning a finite probability of re-infection and later comparing with recovered ones.
2. Lots of patients are asymptomatic carriers, i.e they don't show symptoms yet can infect others. I tried modelling this by introducing a new carrier.
While I could do the first one, the second one is eluding me. Would it be possible to modify with these modifications.
Thanks anyways. The code is as i said, compact and beautiful.
Hi Vira, I have added the ability to simulate 4-quadrant quarantine with a horizontal wall. Setting the parameter 'w_loc_h' determines the placement of this wall (as a fraction of the total spatial limit).
Hi Mohand, I have replaced the title string with the real-time stats as you've suggested. I can't think of a great way to run three simulations at once, aside from running three separate simulations and comparing them after the fact, or using an external script to run three in parallel. I'll think about this a bit more.
I tried to do two things but I am not comfortble enough in Matlabe to do it.
1) Have a boz to display the numbers that are shown in each of the three curves, basically like a counter on the top of the Figure with Unaffected xx, Infected xx, Recovered xx, Deceased xx
2) Suppose someone build three scenarios. s there a way to show them at the same time on the same page Video1, Video2, Video3
Thnaks for your extraordinary work
wonderful Code Sir. I don't know if this is a correct place to ask you but i was playing with your code to try few different things. I wanted to add a horizontal wall along with the vertical one so as to model the system as four different quarantined region and see the effect of different community under quarantine. Could you may be help how to achieve that? Or would it be okay to ask this as question on mathworks forum.
Any hint would also be fine. Thank you.
Hi Mohand, good suggestion, I just added the ability to stop the gate from fully opening. Setting the 'w_open' parameter to a value between 0 and 1 determines the final gate opening width (as a fraction of the total width).
Can I keep the gate open at some level not go to wide open
@ James - you're right! Figured the refreshdata calls were necessary to push the new data to the axes handles but I guess drawnow takes care of that like you said. Runs much faster now!
Do you need those two refreshdata calls? They eat up a lot of time. I commented them out and it seems to run just fine and a whole lot faster ... I think the "drawnow" takes care of updating the figure.
@Joshua , Thanks.
I'm checking it now.
@Joshua: Thank you very much for such quick responses. Just to note: it might be a good idea to turn a direction trajectory into a random walk, so on each step it will choose a new direction vector cos(2*pi*rand).
@ mike: looks great and ran perfectly for me!
@ Tsotne: you are absolutely right. Modified the code so the initial infection rate is only applied to those behind (to the left of) the quarantine wall. Thanks!
@Joshua: Thank you for your response and update of the codes. However, once I ran them, I noticed that some infected are on both side of the gate. I thought that the whole idea of quarantine gate was to keep infected ones separately in the quarantine zone behind the gates.
@Joshua: here's the python code. https://github.com/mnfienen/pysimulitis Keen on any feedback.
@ mike: awesome! would love to see the code if you happen to have a github repository
@ Mostafa: Just added quarantine gate functionality, check it out. Probably not the most robust/efficient way since I was strapped for time, but it works. You can set the location of the quarantine gate through w_loc, and control the opening time and opening speed through w_init and w_speed, respectively.
This is super cool! Thanks for posting. I took the liberty of translating to Python (with attribution). Really timely work and nicely coded. Thanks for doing it!
Thanks for your work.
How to include a simulation with opened gate during simulation.
Similar to that in the article of weshenton post
Hello, the spatial limits variable 'lim' just refers to the 'size' of the 2D arena in nondimensional units. So lim = 200 generates an arena of 200 x 200. The carriers variable ('n') refers to the total number of particles (people), and you can modify the fraction initially infected by playing around with 'p_init'.
Hello, thank you very much for your work.
I'm interested in how to decide the number for spatial limits correctly. And by carriers do you mean the whole population or only the fraction that is infected?
Thanks for reporting this. I suppose there was a problem with the vector size in that element-wise operation since v is [n x 2] and isolate is [n x 1] (my MATLAB version I guess automatically assumes row-wise element multiplication if the column sizes differ, but maybe older versions don't?). Anyways it should work for you now.
Sorry I was commenting and accidentally pressed enter. Im having this error
Error using .*
Matrix dimensions must agree.
Error in simulitis (line 131)
pos_new = pos+v.*(~isolate).*delT;
Hi Abigail, what problems are you having? Any errors?
It has some bugs... I cannot run it.
Neatly written code, good help, easy to use... and most timely: thank you :)
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!