[[SEIR Model]]
Here we use `odeint` from `scipy` to implement [[Forward Euler Method]].
```run-python
# import libraries
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import pandas as pd
#read the csv file (put 'r' before the path string to address any special characters
full_data = pd.read_csv (r'/Users/damilaref/Documents/Zettelkasten/Resources/Data/Epidemology/Covid-19 Infections in Wales.csv')
infected_data = pd.DataFrame (full_data,columns=['newCasesByPublishDate'])
I_data = np.array (infected_data[::-1])
plt.plot(I_data[0:74],label='Covid-19 infections, Wales')
plt.title('Covid-19 infections in Wales, first 75 days')
plt.legend()
plt.show ()
def seirDt(x, times, beta, gamma, epsilon) :
S, E, I, R = x
N = S + E + I + R
# Define ODEs
dS = - beta * S * I / N
dE = beta * S * I / N - epsilon * E
dI = epsilon * E - gamma * I
dR = gamma * I
return np.array([ dS, dE, dI, dR ])
def solve (init, timeArray, theta) :
# Generate SEIR values based on deterministic model
solution = odeint (seirDt, init, timeArray, args = theta)
return solution
```
Below is a typical solution to the system.
```run-python
t = np.arange(0 , 100 , 1.0)
x0 = np.array([ 1999 , 0 , 3 , 0 ])
SEIR = solve(x0, t , (1.53 , 0.24 , 0.24))
S_vals = SEIR [ : , 0 ]
E_vals = SEIR [ : , 1 ]
I_vals = SEIR [ : , 2 ]
R_vals = SEIR [ : , 3 ]
plt.plot (t, S_vals, 'blue', label='S')
plt.plot (t, E_vals, 'orange', label='E')
plt.plot (t, I_vals, 'red', label='I')
plt.plot (t, R_vals, 'green', label='R')
plt.title ('A typical solution to an SEIR model')
plt.legend ()
plt.show ()
```