Integrating and fitting coupled ODE's for SIR modelling

Viewed 21

In this case, there are 3 ODE's that describe a SIR model. The issue comes in I want to calculate which beta and gamma values are the best to fit onto the datapoints from the x_axis and y_axisvalues. The method I'm currently using is to integrate the ODE's using odeintfrom the scipy library and the curve_fit method also from the same library. In this case, how would you calculate the values for beta and gamma to fit the datapoints?

P.S. the current error is this: ValueError: operands could not be broadcast together with shapes (3,) (14,)


#initial values
S_I_R = (0.762/763, 1/763, 0)

x_axis = [m for m in range(1,15)]
y_axis = [3,8,28,75,221,291,255,235,190,125,70,28,12,5]


# ODE's that describe the system
def equation(SIR_Values,t,beta,gamma):
    Array = np.zeros((3))
    SIR = SIR_Values
    Array[0] = -beta * SIR[0] * SIR[1]
    Array[1] = beta * SIR[0] * SIR[1] - gamma * SIR[1]
    Array[2] = gamma * SIR[1]
    return Array


# Results = spi.odeint(equation,S_I_R,time)

#fitting the values
beta_values,gamma_values = curve_fit(equation, x_axis,y_axis)
1 Answers

as this example from scipy documentation, the 'function' must output an array with the same size as x_axis and y_axis.

Related