Apr-11-2020, 03:59 PM
Hello!
I am experimenting with SIR model for spread of disease using the following code. In particular, at each iteration I feed in different N, I0, and R0 values in the model from the CSV file. For each set of parameters, the model makes predictions for S, I, and R outcomes 1-75 days ahead. Usually, I make a plot and examine the result visually, but how can I record the predicted value for "I" parameter after each iteration in a 7-day time and store it as a separate column in the CSV file?
Your help would be greatly appreciated.
I am experimenting with SIR model for spread of disease using the following code. In particular, at each iteration I feed in different N, I0, and R0 values in the model from the CSV file. For each set of parameters, the model makes predictions for S, I, and R outcomes 1-75 days ahead. Usually, I make a plot and examine the result visually, but how can I record the predicted value for "I" parameter after each iteration in a 7-day time and store it as a separate column in the CSV file?
Your help would be greatly appreciated.
import pandas as pd import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt df = pd.read_csv('params_temp.csv', encoding="utf-8") for n, i, r in zip(df["N"], df["I0"], df["R0"]): N = n I0, R0 = i, r S0 = N - I0 - R0 beta, gamma = 0.5, 0.05 t = np.linspace(0, 75, 75) # Days ahead def deriv(y, t, N, beta, gamma): S, I, R = y dSdt = -beta * S * I / N dIdt = beta * S * I / N - gamma * I dRdt = gamma * I return dSdt, dIdt, dRdt y0 = S0, I0, R0 ret = odeint(deriv, y0, t, args=(N, beta, gamma)) S, I, R = ret.T