Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. def model(init_vals, params, t):
  4. S_0, E_0, I_0, R_0, D_0 = init_vals
  5. S, E, I, R, D = [S_0], [E_0], [I_0], [R_0], [D_0]
  6. alpha, beta, gamma, cfr = params
  7. dt = t[1] - t[0]
  8. for _ in t[1:]:
  9. next_S = S[-1] - (beta*S[-1]*I[-1])*dt
  10. next_E = E[-1] + (beta*S[-1]*I[-1] - alpha*E[-1])*dt
  11. next_I = I[-1] + (alpha*E[-1] - gamma*I[-1])*dt
  12. next_R = R[-1] + (gamma*I[-1])*dt
  13. next_D = next_R*cfr
  14. S.append(next_S)
  15. E.append(next_E)
  16. I.append(next_I)
  17. R.append(next_R)
  18. D.append(next_D)
  19. return np.stack([S, E, I, R, D]).T
  20. t_max = 100
  21. dt = 1
  22. t = np.linspace(0, t_max, int(t_max/dt) + 1)
  23. N = 21300000
  24. init_vals = 1 - 7000/N, 7000/N, 0, 0, 0
  25. alpha = 0.2
  26. beta = 1.75
  27. gamma = 0.5
  28. cfr = 0.02
  29. params = alpha, beta, gamma, cfr
  30. results = model(init_vals, params, t)
  31. plt.figure(figsize=(12,8))
  32. plt.plot(results)
  33. plt.legend(['Susceptible', 'Exposed', 'Infected','Recovered', 'Dead'])
  34. plt.axvline(x=35,color='gray',linestyle='--')
  35. plt.xlabel('Days')
  36. plt.savefig('death.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement