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.
Here are some improvements possible:
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.