Permalink
Browse files

relocated

  • Loading branch information...
alvason committed Dec 31, 2015
1 parent 9388bad commit bb510eed690172f47f18fc3f9376c34044dae5cf
Showing with 5,826 additions and 6,008 deletions.
  1. 0 {sir-array → code}/.ipynb_checkpoints/alva_machinery-checkpoint.ipynb
  2. 0 {sir-array → code}/.ipynb_checkpoints/alva_machinery_event-checkpoint.ipynb
  3. +518 −0 code/.ipynb_checkpoints/sir-checkpoint.ipynb
  4. 0 {sir-array → code}/.ipynb_checkpoints/sir_array_cross_immunity-checkpoint.ipynb
  5. 0 {sir-array → code}/.ipynb_checkpoints/sir_array_immunity-checkpoint.ipynb
  6. +412 −0 code/.ipynb_checkpoints/sir_array_immunity_old-checkpoint.ipynb
  7. +1,416 −0 code/.ipynb_checkpoints/sir_array_mutation-checkpoint.ipynb
  8. 0 {sir-array → code}/.ipynb_checkpoints/sir_array_mutation_event-checkpoint.ipynb
  9. 0 {sir-array → code}/.ipynb_checkpoints/sir_array_mutation_immunity_event-checkpoint.ipynb
  10. 0 {sir-array → code}/.ipynb_checkpoints/sir_array_vaccine_event-checkpoint.ipynb
  11. 0 {sir-array → code}/alva_machinery.ipynb
  12. 0 {sir-array → code}/alva_machinery.py
  13. 0 {sir-array → code}/alva_machinery_event.ipynb
  14. 0 {sir-array → code}/alva_machinery_event.py
  15. +518 −0 code/sir.ipynb
  16. +51 −30 {sir → code}/sir.py
  17. 0 {sir-array → code}/sir_array_cross_immunity.ipynb
  18. 0 {sir-array → code}/sir_array_cross_immunity.py
  19. +424 −0 code/sir_array_immunity.ipynb
  20. +22 −27 {sir-array → code}/sir_array_immunity.py
  21. +412 −0 code/sir_array_immunity_old.ipynb
  22. +19 −26 {sir-array → code}/sir_array_immunity_old.py
  23. 0 {sir-array → code}/sir_array_mutation-Copy0.py
  24. +1,416 −0 code/sir_array_mutation.ipynb
  25. +38 −21 {sir-array → code}/sir_array_mutation.py
  26. 0 {sir-array → code}/sir_array_mutation_event.ipynb
  27. 0 {sir-array → code}/sir_array_mutation_event.py
  28. +558 −0 code/sir_array_mutation_immunity_event.ipynb
  29. +22 −27 {sir-array → code}/sir_array_mutation_immunity_event.py
  30. 0 {sir-array → code}/sir_array_vaccine_event.ipynb
  31. 0 {sir-array → code}/sir_array_vaccine_event.py
  32. BIN figure/many-virus-mutation-stacked-infectious-pulse.png
  33. BIN figure/one-virus-revival-equilibrium.png
  34. BIN figure/one-virus-sir.png
  35. +0 −492 sir-array/.ipynb_checkpoints/sir_array_immunity_old-checkpoint.ipynb
  36. +0 −1,174 sir-array/.ipynb_checkpoints/sir_array_mutation-checkpoint.ipynb
  37. BIN sir-array/figure/Alva2.png
  38. BIN sir-array/figure/infectious-pulse-mutation-continuous.png
  39. BIN sir-array/figure/infectious-pulse-mutation-discrete.png
  40. BIN sir-array/figure/infectious-pulse-mutation-immunity-discrete.png
  41. BIN sir-array/figure/infectious-pulse-mutation-immunity-event-stacked.png
  42. BIN sir-array/figure/infectious-pulse-mutation-immunity-event.png
  43. BIN sir-array/figure/infectious-pulse-normalization-stacked-prevalence.png
  44. BIN sir-array/figure/infectious-pulse-prevalence-incidence.png
  45. BIN sir-array/figure/many-strain-SIR.png
  46. +0 −508 sir-array/sir_array_immunity.ipynb
  47. +0 −492 sir-array/sir_array_immunity_old.ipynb
  48. +0 −1,174 sir-array/sir_array_mutation.ipynb
  49. +0 −522 sir-array/sir_array_mutation_immunity_event.ipynb
  50. +0 −577 sir/.ipynb_checkpoints/runge_kutta-checkpoint.ipynb
  51. +0 −469 sir/.ipynb_checkpoints/sir-checkpoint.ipynb
  52. BIN sir/figure/revivalSIR.png
  53. BIN sir/figure/sir.png
  54. +0 −469 sir/sir.ipynb

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,24 +1,25 @@
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <markdowncell>
# coding: utf-8
# # Infectious Pulse
# https://github.com/alvason/infectious-pulse/
#
# ### One-strain SIR evolution --- its revival and equilibrium state
# <codecell>
# In[1]:
'''
author: Alvason Zhenhua Li
date: 03/23/2015
'''
%matplotlib inline
get_ipython().magic(u'matplotlib inline')
import numpy as np
import matplotlib.pyplot as plt
import os
dir_path = '/Users/al/Desktop/GitHub/infectious-pulse/figure'
file_name = 'one-virus'
AlvaFontSize = 23
AlvaFigSize = (16, 6)
@@ -29,12 +30,9 @@
plt.figure(numberingFig, figsize=(12, 3))
plt.axis('off')
plt.title(r'$ Susceptible-Infectious-Recovered \ equation $', fontsize = AlvaFontSize)
plt.text(0, 2.0/3, r'$ \frac{\partial S(t)}{\partial t} = \
-\beta S(t)I(t) +\mu N -\mu S(t)$', fontsize = 1.2*AlvaFontSize)
plt.text(0, 1.0/3, r'$ \frac{\partial I(t)}{\partial t} = \
+\beta S(t)I(t) - \gamma I(t) -\mu I(t) $', fontsize = 1.2*AlvaFontSize)
plt.text(0, 0.0/3, r'$ \frac{\partial R(t)}{\partial t} = \
+\gamma I(t) - \mu R(t) $', fontsize = 1.2*AlvaFontSize)
plt.text(0, 2.0/3, r'$ \frac{\partial S(t)}{\partial t} = -\beta S(t)I(t) +\mu N -\mu S(t)$', fontsize = 1.2*AlvaFontSize)
plt.text(0, 1.0/3, r'$ \frac{\partial I(t)}{\partial t} = +\beta S(t)I(t) - \gamma I(t) -\mu I(t) $', fontsize = 1.2*AlvaFontSize)
plt.text(0, 0.0/3, r'$ \frac{\partial R(t)}{\partial t} = +\gamma I(t) - \mu R(t) $', fontsize = 1.2*AlvaFontSize)
plt.show()
# define RK4 for a list of coupled differential equations
@@ -92,7 +90,8 @@ def AlvaRungeKutta4List(pde_array, startingOut_Value, min_Input, max_Input, tota
# end of loop
return (gridOutIn_array[:-inWay])
# <codecell>
# In[2]:
''' starting from one infected '''
# setting parameter
@@ -105,7 +104,7 @@ def AlvaRungeKutta4List(pde_array, startingOut_Value, min_Input, max_Input, tota
day = float(1)/365
totalSIR = float(1) # total population
reprodNum = float(1.8) # basic reproductive number R0: one infected person will transmit to 1.8 person
reprodNum = float(1.5) # basic reproductive number R0: one infected person will transmit to 1.8 person
recovRate = float(1)/(4*day) # 4 days per period ==> rate/year = 365/4
inOutRate = float(1)/(30*year) # birth rate per year
infecRate = reprodNum*(recovRate + inOutRate)/totalSIR # per year, per person, per total-population
@@ -157,8 +156,14 @@ def dRdt(SIRT = [], *args):
gridS = gridOut_array[0]
gridI = gridOut_array[1]
gridR = gridOut_array[2]
numberingFig = numberingFig + 1;
plt.figure(numberingFig, figsize = AlvaFigSize)
# plotting
figure_name = '-sir'
file_suffix = '.png'
save_figure = os.path.join(dir_path, file_name + figure_name + file_suffix)
numberingFig = numberingFig + 1
figure = plt.figure(numberingFig, figsize = AlvaFigSize)
plt.plot(gridT, gridS, label = r'$ S(t) $')
plt.plot(gridT, gridR, label = r'$ R(t) $')
plt.plot(gridT, gridI, label = r'$ I(t) $')
@@ -174,9 +179,14 @@ def dRdt(SIRT = [], *args):
plt.text(maxT, totalSIR*5.0/6, r'$ \gamma = %f $'%(recovRate), fontsize = AlvaFontSize)
plt.text(maxT, totalSIR*4.0/6, r'$ \beta = %f $'%(infecRate), fontsize = AlvaFontSize)
plt.text(maxT, totalSIR*3.0/6, r'$ \mu = %f $'%(inOutRate), fontsize = AlvaFontSize)
plt.xticks(fontsize = AlvaFontSize*0.7)
plt.yticks(fontsize = AlvaFontSize*0.7)
figure.tight_layout()
plt.savefig(save_figure, dpi = 100, bbox_inches='tight')
plt.show()
# <codecell>
# In[3]:
''' approaching equilibrium state from one infected '''
# setting parameter
@@ -189,7 +199,7 @@ def dRdt(SIRT = [], *args):
day = float(1)/365
totalSIR = float(1) # total population
reprodNum = float(1.8) # basic reproductive number R0: one infected person will transmit to 1.8 person
reprodNum = float(1.5) # basic reproductive number R0: one infected person will transmit to 1.8 person
recovRate = float(1)/(4*day) # 4 days per period ==> rate/year = 365/4
inOutRate = float(1)/(30*year) # birth rate per year
infecRate = reprodNum*(recovRate + inOutRate)/totalSIR # per year, per person, per total-population
@@ -241,8 +251,16 @@ def dRdt(SIRT = [], *args):
gridS = gridOut_array[0]
gridI = gridOut_array[1]
gridR = gridOut_array[2]
# plotting
figure_name = '-revival-equilibrium'
file_suffix = '.png'
save_figure = os.path.join(dir_path, file_name + figure_name + file_suffix)
numberingFig = numberingFig + 1;
figure = plt.figure(numberingFig, figsize = AlvaFigSize)
plt.xticks(fontsize = AlvaFontSize*0.7)
plt.yticks(fontsize = AlvaFontSize*0.7)
axis = figure.add_subplot(1, 1, 1)
axis.plot(gridT, gridS, label = r'$ S(t) $')
axis.plot(gridT, gridR, label = r'$ R(t) $')
@@ -261,13 +279,18 @@ def dRdt(SIRT = [], *args):
axis2.set_ylabel(r'$ I $', fontsize = AlvaFontSize, color = 'red')
for tl in axis2.get_yticklabels(): tl.set_color('red')
axis2.legend(loc = (1.1, 0.5))
plt.xticks(fontsize = AlvaFontSize*0.7)
plt.yticks(fontsize = AlvaFontSize*0.7)
plt.legend(loc = (1.1, 0.3))
plt.title(r'$ Revival \ and \ equilibrium \ of \ SIR $', fontsize = AlvaFontSize)
plt.grid(True)
figure.tight_layout()
plt.savefig(save_figure, dpi = 100, bbox_inches='tight')
plt.show()
# <codecell>
# In[4]:
''' starting from equilibrium infected number '''
# setting parameter
@@ -332,8 +355,11 @@ def dRdt(SIRT = [], *args):
gridS = gridOut_array[0]
gridI = gridOut_array[1]
gridR = gridOut_array[2]
numberingFig = numberingFig + 1;
plt.figure(numberingFig, figsize = AlvaFigSize)
plt.xticks(fontsize = AlvaFontSize*0.7)
plt.yticks(fontsize = AlvaFontSize*0.7)
plt.plot(gridT, gridS, label = r'$ S(t) $')
plt.plot(gridT, gridR, label = r'$ R(t) $')
plt.plot(gridT, gridI, label = r'$ I(t) $')
@@ -357,20 +383,15 @@ def dRdt(SIRT = [], *args):
plt.figure(numberingFig, figsize=(12,4))
plt.axis('off')
plt.title(r'$ Susceptible-Infectious-Recovered \ equation \ (equilibrium \ state) $',fontsize = AlvaFontSize)
plt.text(0, 3.0/4,r'$ \frac{\partial S(t)}{\partial t} = \
-\beta S(t)I(t) +\mu N -\mu S(t) = 0 \Longrightarrow I(t) = \frac{\mu}{\beta S(t)} (N - S(t)) \
\Longrightarrow I_0 = \frac{\mu N}{\beta} (\frac{N}{S_0} - 1) $'
plt.text(0, 3.0/4,r'$ \frac{\partial S(t)}{\partial t} = -\beta S(t)I(t) +\mu N -\mu S(t) = 0 \Longrightarrow I(t) = \frac{\mu}{\beta S(t)} (N - S(t)) \Longrightarrow I_0 = \frac{\mu N}{\beta} (\frac{N}{S_0} - 1) $'
, fontsize = 1.2*AlvaFontSize)
plt.text(0, 2.0/4,r'$ \frac{\partial I(t)}{\partial t} = \
+\beta S(t)I(t) - \gamma I(t) -\mu I(t) = 0 \Longrightarrow \beta S(t) - \gamma - \mu = 0 \
\Longrightarrow S_0 = \frac{\gamma + \mu}{\beta} $', fontsize = 1.2*AlvaFontSize)
plt.text(0, 1.0/4, r'$ \frac{\partial R(t)}{\partial t} = \
+\gamma I(t) - \mu R(t) \Longrightarrow R_0 = \frac{\gamma}{\mu} I_0 $', fontsize = 1.2*AlvaFontSize)
plt.text(0, 0.0/4,r'$ since \ \beta = \frac{\Re_0 (\gamma + \mu)}{N} \Longrightarrow S_0 = \frac{N}{\Re_0} \
\ and \ I_0 = \frac{\mu N}{\beta} (\Re_0 - 1) \
\ and \ R_0 = \frac{\gamma N}{\beta} (\Re_0 - 1)$', fontsize = 1.2*AlvaFontSize)
plt.text(0, 2.0/4,r'$ \frac{\partial I(t)}{\partial t} = +\beta S(t)I(t) - \gamma I(t) -\mu I(t) = 0 \Longrightarrow \beta S(t) - \gamma - \mu = 0 \Longrightarrow S_0 = \frac{\gamma + \mu}{\beta} $', fontsize = 1.2*AlvaFontSize)
plt.text(0, 1.0/4, r'$ \frac{\partial R(t)}{\partial t} = +\gamma I(t) - \mu R(t) \Longrightarrow R_0 = \frac{\gamma}{\mu} I_0 $', fontsize = 1.2*AlvaFontSize)
plt.text(0, 0.0/4,r'$ since \ \beta = \frac{\Re_0 (\gamma + \mu)}{N} \Longrightarrow S_0 = \frac{N}{\Re_0} \ and \ I_0 = \frac{\mu N}{\beta} (\Re_0 - 1) \ and \ R_0 = \frac{\gamma N}{\beta} (\Re_0 - 1)$', fontsize = 1.2*AlvaFontSize)
plt.show()
# <codecell>
# In[ ]:

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,20 +1,18 @@
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <markdowncell>
# coding: utf-8
# # Infectious Pulse
# https://github.com/alvason/infectious-pulse/
#
# ### Many-strain SIR evolution --- its equilibrium state and infectious pulse due to mutation and cross-immunity
# <codecell>
# In[1]:
'''
author: Alvason Zhenhua Li
date: 03/23/2015
'''
%matplotlib inline
get_ipython().magic(u'matplotlib inline')
import numpy as np
import matplotlib.pyplot as plt
@@ -31,16 +29,11 @@
plt.figure(numberingFig, figsize=(12, 6))
plt.axis('off')
plt.title(r'$ n-strain \ SIR \ equations \ (mutation \ and \ cross-immunity) $',fontsize = AlvaFontSize)
plt.text(0, 4.0/5,r'$ \frac{\partial S_i(t)}{\partial t} = \
+ \mu N - \mu S_i(t) - \beta S_i(t)\sum_{j = 1}^{n} (1 - \frac{|j - i|}{r + |j - i|})I_{i}(t) $'
plt.text(0, 4.0/5,r'$ \frac{\partial S_i(t)}{\partial t} = + \mu N - \mu S_i(t) - \beta S_i(t)\sum_{j = 1}^{n} (1 - \frac{|j - i|}{r + |j - i|})I_{i}(t) $'
, fontsize = 1.2*AlvaFontSize)
plt.text(0, 2.0/5, r'$ \frac{\partial I_i(t)}{\partial t} = \
+ \beta S_i(t)I_i(t) - \gamma I_i(t) - \mu I_i(t) \
+ m \frac{I_{i - 1}(t) - 2I_i(t) + I_{i + 1}(t)}{(\Delta i)^2} $'
plt.text(0, 2.0/5, r'$ \frac{\partial I_i(t)}{\partial t} = + \beta S_i(t)I_i(t) - \gamma I_i(t) - \mu I_i(t) + m \frac{I_{i - 1}(t) - 2I_i(t) + I_{i + 1}(t)}{(\Delta i)^2} $'
, fontsize = 1.2*AlvaFontSize)
plt.text(0, 0.0/5,r'$ \frac{\partial R_i(t)}{\partial t} = \
+\gamma I_i(t) - \mu R_i(t) - \beta S_i(t)I_i(t)\
+ \beta S_i(t)\sum_{j = 1}^{n} (1 - \frac{|j - i|}{r + |j - i|})I_{i}(t) $'
plt.text(0, 0.0/5,r'$ \frac{\partial R_i(t)}{\partial t} = +\gamma I_i(t) - \mu R_i(t) - \beta S_i(t)I_i(t) + \beta S_i(t)\sum_{j = 1}^{n} (1 - \frac{|j - i|}{r + |j - i|})I_{i}(t) $'
, fontsize = 1.2*AlvaFontSize)
plt.show()
@@ -54,8 +47,7 @@ def dSdt_array(SIRxt = [], *args):
# there are n dRdt
dS_dt_array = np.zeros(x_totalPoint)
# each dSdt with the same equation form
dS_dt_array[:] = - infecRate*S[:]*crossI_neighborSum_X(I, cross_radius, gX)[:] \
+ inOutRate*totalSIR - inOutRate*S[:]
dS_dt_array[:] = - infecRate*S[:]*crossI_neighborSum_X(I, cross_radius, gX)[:] + inOutRate*totalSIR - inOutRate*S[:]
return(dS_dt_array)
def dIdt_array(SIRxt = [], *args):
@@ -73,9 +65,7 @@ def dIdt_array(SIRxt = [], *args):
rightX = np.roll(Icopy[:], -1)
leftX[0] =centerX[0]
rightX[-1] = centerX[-1]
dI_dt_array[:] = + infecRate*S[:]*I[:] \
- recovRate*I[:] - inOutRate*I[:] \
+ mutatRate*(leftX[:] - 2*centerX[:] + rightX[:])/(dx**2)
dI_dt_array[:] = + infecRate*S[:]*I[:] - recovRate*I[:] - inOutRate*I[:] + mutatRate*(leftX[:] - 2*centerX[:] + rightX[:])/(dx**2)
return(dI_dt_array)
def dRdt_array(SIRxt = [], *args):
@@ -87,9 +77,7 @@ def dRdt_array(SIRxt = [], *args):
# there are n dRdt
dR_dt_array = np.zeros(x_totalPoint)
# each dIdt with the same equation form
dR_dt_array[:] = + recovRate*I[:] - inOutRate*R[:] \
- infecRate*S[:]*I[:] \
+ infecRate*S[:]*crossI_neighborSum_X(I, cross_radius, gX)[:]
dR_dt_array[:] = + recovRate*I[:] - inOutRate*R[:] - infecRate*S[:]*I[:] + infecRate*S[:]*crossI_neighborSum_X(I, cross_radius, gX)[:]
return(dR_dt_array)
# inverted-monod equation
@@ -113,7 +101,8 @@ def crossI_neighborSum_X(gI, half_radius, gX):
I_neighborSum = np.copy(gI)
return (I_neighborSum)
# <codecell>
# In[2]:
# setting parameter
timeUnit = 'year'
@@ -198,7 +187,8 @@ def crossI_neighborSum_X(gI, half_radius, gX):
figure.tight_layout()
plt.show()
# <codecell>
# In[ ]:
# Normalization stacked graph
cutting_X = -1
@@ -246,7 +236,8 @@ def crossI_neighborSum_X(gI, half_radius, gX):
plt.text(maxT*1.1, -2, r'$ \beta = %f $'%(infecRate), fontsize = AlvaFontSize)
plt.show()
# <codecell>
# In[ ]:
# plot by listing each strain
numberingFig = numberingFig + 1
@@ -271,7 +262,8 @@ def crossI_neighborSum_X(gI, half_radius, gX):
plt.title(r'$ SIR \ of \ strain-%i $'%(i), fontsize = AlvaFontSize)
plt.show()
# <codecell>
# In[ ]:
# 3D plotting
# define GridXX function for making 2D-grid from 1D-grid
@@ -306,7 +298,8 @@ def AlvaGridXX(gX, totalPoint_Y):
figure.tight_layout()
plt.show()
# <codecell>
# In[ ]:
numberingFig = numberingFig + 1
plt.figure(numberingFig, figsize = AlvaFigSize)
@@ -323,6 +316,8 @@ def AlvaGridXX(gX, totalPoint_Y):
plt.text(maxT*4.0/3, maxX*0.0/6, r'$ r = %f $'%(cross_radius), fontsize = AlvaFontSize)
plt.show()
# <codecell>
# In[ ]:

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit bb510ee

Please sign in to comment.