Last active
January 13, 2021 14:51
-
-
Save ShuaiGuo16/ac542b93b3ad6929d61aa77916e3f0e3 to your computer and use it in GitHub Desktop.
Simulate SIR model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assign infection and recovery rate parameters | |
beta, gamma = 0.22, 0.1 | |
# Grid of time points (in days) | |
t = np.arange(0, 101, 2) | |
# Run SIR model to predict epidemic evolution | |
S, I, R = SIR_model(beta, gamma, t, I0=8, N=1000, R0=0) | |
# Extract output of interest | |
max_infection = I.max() | |
max_time = t[I.argmax()] | |
# Visualize epidemic evolution | |
fig, ax = plt.subplots(figsize=(7,5)) | |
ax.plot(t, S, 'b', lw=2, label='Susceptible') | |
ax.plot(t, I, 'r', lw=2, label='Infected') | |
ax.plot(t, R, 'g', lw=2, label='Recovered') | |
ax.set_xlabel('Time /days', fontsize=15) | |
ax.set_ylabel('Number', fontsize=15) | |
ax.set_ylim(-20,1020) | |
ax.legend(loc="center right",prop={'size': 12}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment