Coder Social home page Coder Social logo

lewuathe / covid19-sir Goto Github PK

View Code? Open in Web Editor NEW
131.0 6.0 77.0 1.47 MB

COVID-19 SIR model estimation

Home Page: https://www.lewuathe.com/covid-19-dynamics-with-sir-model.html

License: Apache License 2.0

Python 100.00%
covid-19 coronavirus opendata simulation sir

covid19-sir's People

Contributors

bolinches avatar gasilva avatar kyprifog avatar lewuathe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

covid19-sir's Issues

x-axis

hi,
your program is awesome! I noticed however that the x-axis comes out empty in the .png image produced (there are no dates). I'm new at python so I'm having difficulty understanding how to fix this.. could you fix it or explain to me what to do?
Thank you so much!!

Suggestions of some improvements

Here are some improvements possible:

  • Use scipy.integrate.odeint to solve the ODE system. The results may differ from solve_ivp, which is common for nonlinear equations, but the code is very fast because is FORTRAN compiled. The solver is used by several people to solve Lotka Volterra equations (predator-prey type)
def lossOdeint(point, data, recovered, death, s_0, i_0, r_0, d_0):
    size = len(data)
    beta, a, b = point
    def SIR(y,t):
        return [-beta*y[0]*y[1], beta*y[0]*y[1]-(a+b)*y[1], a*y[1], b*y[1]]
    y0=[s_0,i_0,r_0,d_0]
    tspan=np.arange(0, size, 1)
    res=odeint(SIR,y0,tspan)
    l1 = np.sqrt(np.mean((res[:,1]- data)**2))
    l2 = np.sqrt(np.mean((res[:,2]- recovered)**2))
    l3 = np.sqrt(np.mean((res[:,3] - death)**2))
    #weight for cases
    u = 0.25
    #weight for recovered
    v = 0.02 ##Brazil France 0.04 US 0.02 China 0.01 (it has a lag in recoveries) Others 0.15
    #weight for deaths
    w = 1 - u - v - z
    return u*l1 + v*l2 + w*l3
  • Use different delays/lags in equations of recovered and deaths due to incubation, hospital time. China data shows a very clear delay in recovery for example. The optimizer must find the and in order to start the curves in the right time.

  • Implement an improvement in infected people because Covid19 has a lot of undetectable cases. See that at See paper here! A Time-dependent SIR model for COVID-19 with Undetectable Infected Persons from Cornell University.

docs: methodology

Great stuff! I wish I could use it for my dashboard Pandemic Estimator but for that your data lacks documentation on methodology. I'm using JHU directly and I know what chaos it is, the most blatant example being that they provide "cumulative data" that's not cumulative quite often in practice. And the whole change of file formats, etc.

Can you please describe methodology how you deal with it? What has been omitted, what has been "adjusted" and how? Thank you!

Solve IVP doesn't response

Hello,

I have been having troubles with the following line:

solution = solve_ivp(SIR, [0, size], [s_0,i_0,r_0], t_eval=np.arange(0, size, 1), vectorized=True)

At fourth iteration, it never ends processing. Should I let it more time? How long does it take? I have let the process until 20-30 min and it doesn't response

Thank you in advance!

Not to remove country with provinces

As the current code exclude countries with provinces, you can not analyze Canada, Australia, France, United Kingdom and China.`

See below a code to sum the cases of the provinces in one country entry:

`

def sumCases_province(input_file, output_file):

   with open(input_file, "r") as read_obj, open(output_file,'w',newline='') as write_obj:
       csv_reader = reader(read_obj)
       csv_writer = writer(write_obj)
           
       lines=[]
       for line in csv_reader:
           lines.append(line)    
       i=0
       ix=0
       for i in range(0,len(lines[:])-1):
           if lines[i][1]==lines[i+1][1]:
               if ix==0:
                   ix=i
               lines[ix][4:] = np.asfarray(lines[ix][4:],float)+np.asfarray(lines[i+1][4:] ,float)
           else:
               if not ix==0:
                   csv_writer.writerow(lines[ix])
                   ix=0
               else:
                   csv_writer.writerow(lines[i])
           i+=1    

`

you can call remove_province of sumCases_province

The list from data repository is not sorted

There is a strange thing in data from repository: the UK data repeats at end of file. That should be solved by sorting. I did not manage to implement a sorting in the code. If you know it will be good. Probably the best place to sort is after the reading of the lines in my version. In your version it is not possible since you read and write at same time.

Shouldn't S0 be tied to the population of the country?

Same as the title, the total suspectable should start at the total population of the country, correct? I can't think of any reason the data itself can help infer the actual suspectable population, what do you think?

Always fails with convergence error

I cannot get the program to work. It runs for about a minute and then fails with a CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH.
I've tried with countries "France" and "Italy", with the default values.
I tried again with those countries after updating the data from HDX (fixing the file names and the data a little bit), and then it always failed with an ABNORMAL_TERMINATION_IN_LNSRCH error.

Estimate number of deaths

Hi. I found your work very interesting :)

I see you are using a SIR-based model, but that doesn't seem to model the number of deaths. I propose a simple modification to this model. Basically SIR consists of three differential equations:

SIR

Here, the number of 'recovery' englobes both cured and deaths. This parameter is represented by γ, and therefore it could be split in two by γ = a + b, where a is the rate of cure, and b is the rate of death. Since the death rate seems to be linear (1.5% in China, for example), this linear decomposition of γ looks precise to me. After this, we can add a new variable k, (Kill rate), and add to the system of equations. Therefore:

SIRK

I could generate the following graphic using this method:

Italy

With S_0 = 200000

Italy

However, I am not sure about how to handle this expression:
return alpha * l1 + (1 - alpha)
What is exactly the point of this linear interpolation? Here I will need to add another parameter to compensate for the death rate.

I can open a PR if you guys are interested.

I am also interested in using this software to simulate the situation here in Brazil. I have already collected some data. The idea is that a and b can change according to the situation of the healthcare system.

Thank you.

Add a file with collaborators

HI

I think few people has already collaborated into this project it would be nice to have a file into the repo with the collaborators names/users

thanks

The running time is too long

Hello,
The running time is too long,more than 12 hours, maybe my computer performance is poor, can it be optimized? or change the parameters.
The hotspot functions are "minimize" and "solve_ ivp".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.