Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added EX10_P2_Plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions EX10_P2_results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Maximum daily incidence:
87.3691177314
586.170819125
1.35394595053
0.979180304854
19.390316567

Maximum daily prevalence:
0.669182090042
0.667294350986
0.0941045383845
0.001
0.403596344712

Percent affected:
0.999954624904
0.999954624904
0.676436543943
0.0019970073129
0.980194131568

Basic reproduction number:
10.0
10.0
1.0
0.5
2.0
4.0
1.6666666666666667
63 changes: 63 additions & 0 deletions EX_10_Script_Q2
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import pandas
import numpy as np
import scipy
import scipy.integrate as spint
from plotnine import *

beta = [0.0005,0.005,0.0001,0.00005,0.0001,0.0002,0.0001]
gamma = [0.05,0.5,0.1,0.1,0.05,0.05,0.06]
beta_gamma_dict = {}
prev_I = 1
incidence_arr = []
prevalence_arr = []
for i in range(0,len(beta)):
beta_gamma_dict[beta[i]] = gamma[i]
#beta_gamma_dict_2 = {0.0005: 0.05, 0.005: 0.5, 0.0001: 0.1, 0.00005: 0.1, 0.0001: 0.05, 0.0002: 0.05, 0.0001: 0.06}
basic_repr_num = (beta[i]*1000)/(gamma[i])
print (basic_repr_num)

def ddSim(y,t0,beta,gamma):
# "unpack" lists containing state variables (y)
# y = np.zeros(3)
# [S,I,R] = y
S = y[0]
I = y[1]
R = y[2]
N = S + I + R
dSdt = (-1)*beta*I*S
dIdt = beta*I*S - gamma*I
dRdt = gamma*I

return dSdt,dIdt,dRdt

for key, value in beta_gamma_dict.items():
### Define parameters, initial values for state variables, and time steps
params=(key,value)
N = S + I + R

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this equation here

S0=999
I0=1
R0=0
N=1000
times=range(0,500)
y0 = [S0, I0, R0]
modelSim0=spint.odeint(func=ddSim, y0=y0, t=times, args=params)


### put model output in a dataframe for plotting purposes
modelOutput=pandas.DataFrame({"t":times,"S":modelSim0[:,0],"I":modelSim0[:,1],"R":modelSim0[:,2]})
#print (modelOutput)
for i in modelSim0[:,1]:
incidence = i - prev_I
prevalence = i / N
prev_I = i
incidence_arr.append(incidence)
prevalence_arr.append(prevalence)
print(max(incidence_arr))
print(max(prevalence_arr))
incidence_arr = []
prevalence_arr = []
#print(modelOutput)
percent_affected = ((modelSim0[:,1][-1]) + (modelSim0[:,2][-1]))/ N
print (percent_affected)
ggplot(modelOutput,aes(x="t",y="y0"))+geom_line(aes(x="t",y="S"),color='red')+geom_line(aes(x="t",y="I"),color='black')+geom_line(aes(x="t",y="R"),color='green')

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job

76 changes: 76 additions & 0 deletions Ex10P1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Import packages:

import numpy
import os
import pandas
import scipy
import sklearn
import scipy.integrate as si
from plotnine import *

# Define custom function:

def ddSim(y,t0,r,K):

# Unpack lists containing state variables (y)
N=y[0]

dNdt=r*(1-N/K)*N

return [dNdt]

# Define paramaters, initial values for state variables and time steps:

N0=[10]
times=range(0,600)
K=100

# Part 1a:
# Define initial parameters:

rs=[-0.1,0.1,0.4,0.8,1]
store_rs=pandas.DataFrame({"time":times,"r1":0,"r2":0,"r3":0,"r4":0,"r5":0})

for i in range(0,len(rs)):
pars=(rs[i],K)
sim=si.odeint(func=ddSim,y0=N0,t=times,args=pars)
store_rs.iloc[:,i]=sim[:,0]

ggplot(store_rs,aes(x="times",y="r1",color="-0.1"))+geom_line()+geom_line(aes(y="r2",color="0.1"))+geom_line(aes(y="r3",color="0.4"))+geom_line(aes(y="r4",color="0.8"))+geom_line(aes(y="r5",color="1.0"))

# Part 1b:
# Define initial parameters:

r2=0.2
N2=1.0
times2=range(0,600)

Ks=[10,50,100]
store_Ks=pandas.DataFrame({"time":times,"K1":0,"K2":0,"K3":0})

for j in range(0,len(Ks)):
pars2=(r2,Ks[j])
sim=si.odeint(func=ddSim,y0=N2,t=times2,args=pars2)
store_Ks.iloc[:,j]=sim[:,0]

ggplot(store_Ks,aes(x="times2",y="K1",color="10"))+geom_line()+geom_line(aes(y="K2",color="50"))+geom_line(aes(y="K3",color="100"))

# Part 1c:
# Define initial parameters:

r3=0.1
K3=50.0
times3=range(0,600)

Ns=[1,50,100]
store_Ns=pandas.DataFrame({"time":times,"N1":0,"N2":0,"N3":0})

for k in range(0,len(Ns)):
pars3=(r3,K3)
sim=si.odeint(func=ddSim,y0=Ns[k],t=times3,args=pars3)
store_Ns.iloc[:,k]=sim[:,0]

ggplot(store_Ns,aes(x="times3",y="N1",color="1"))+geom_line()+geom_line(aes(y="N2",color="50"))+geom_line(aes(y="N3",color="100"))


Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job


11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# Intro_Biocom_ND_319_Tutorial10
# Intro_Biocom_ND_319_Tutorial10
All the 4 types of results observed max. incidence, max. prevalence, % affected
and basic reproduction no. stays constant in the beginning, then drops
and then increases towards the end again.
This can be interpreted in this way: since the model focuses on the host of
the disease, the no. of people susceptible to the diseases will be high during
the initial stage of the disease spread, the more people get infected;
later as the host develops resistance to the diseases and
would become almost immune to it.