diff --git a/117109-1493-1vf424u.z0v8n9izfr.png b/117109-1493-1vf424u.z0v8n9izfr.png new file mode 100644 index 0000000..524adce Binary files /dev/null and b/117109-1493-1vf424u.z0v8n9izfr.png differ diff --git a/Exercise10_1(a)_plot.png b/Exercise10_1(a)_plot.png new file mode 100644 index 0000000..05f73f7 Binary files /dev/null and b/Exercise10_1(a)_plot.png differ diff --git a/Exercise10_1(b)_plot.png b/Exercise10_1(b)_plot.png new file mode 100644 index 0000000..31edf1b Binary files /dev/null and b/Exercise10_1(b)_plot.png differ diff --git a/Exercise10_1(c)_plot.png b/Exercise10_1(c)_plot.png new file mode 100644 index 0000000..22898c0 Binary files /dev/null and b/Exercise10_1(c)_plot.png differ diff --git a/Exercise10_2_plot.png b/Exercise10_2_plot.png new file mode 100644 index 0000000..d283c9a Binary files /dev/null and b/Exercise10_2_plot.png differ diff --git a/Paragraph b/Paragraph new file mode 100644 index 0000000..ab888f5 --- /dev/null +++ b/Paragraph @@ -0,0 +1,5 @@ +#When there is only one person infected, and with a time frame of 500 days, the graphs +#even out to all peopel being susceptible, but recovered +#If half of the people are infected, the graph evens out to remain that 50% of people +#are still infected and 50% are susceptible after 500 days +#the different rates of beta and gamma do not significantly affect these observations \ No newline at end of file diff --git a/Q1 Part C b/Q1 Part C new file mode 100644 index 0000000..3e98db2 --- /dev/null +++ b/Q1 Part C @@ -0,0 +1,35 @@ + +#Import Packages +import pandas +import numpy +from scipy.optimize import minimize +from scipy.stats import norm +import scipy.integrate as si +import re +import os +from plotnine import * + +#Plot of population size with 3 populations with different initial populations +def ddSim(y,t0,r,K): + N=y[0] + dNdt=r*(1-N/K)*N + return [dNdt] + +params=(0.3,10) +N0=[1,50,100] +times=range(0,50) + +modelSim=si.odeint(func=ddSim,y0=N0,t=times,args=params) + +rs=[0.1] +store_rs=pandas.DataFrame({"times":times,"r1":0,"r3":0,"r4":0,"r5":0}) + +for i in range(0,len(rs)): + pars=(rs[i],50) + sim=si.odeint(func=ddSim,y0=10,t=times,args=pars) + store_rs.iloc[:,i]=sim[:,0] + +modelOutput=pandas.DataFrame({"t":times,"rs":modelSim[:,0]}) + +#plot +ggplot(modelOutput,aes(x="t",y="rs"))+geom_line()+theme_classic() \ No newline at end of file diff --git a/Question 2 b/Question 2 new file mode 100644 index 0000000..185fe15 --- /dev/null +++ b/Question 2 @@ -0,0 +1,305 @@ +##Question2 +#Import Packages +import pandas +import numpy +from scipy.optimize import minimize +from scipy.stats import norm +import scipy.integrate as spi +from scipy.integrate import odeint +import matplotlib.pyplot as plt +import re +import os +from plotnine import * + +#Total Population=1000 (999 susceptible, 1 infected, 0 resistant) +N=1000 +#Initial infected (I0) & Initial Resistant (R0) +I0=1 +R0=0 +#Everyone susceptible +S0=N-I0-R0 +N=S0+I0+R0 +#Recovery Rates +beta, gamma=0.2,1/10 + +#Time +t=0 +t = np.linspace(0, 500, 500) +#number susceptible +sList=[] +#number infected +iList=[] +#number recovered +rList=[] +#new infections +newList=[] + + +#Time +t = np.linspace(0, 500, 500) + +#SIR Differential Equations +def deriv(y, t, N, beta, gamma): + S = y + I = y + R = y + dSdt = -beta * S * I / N + dIdt = beta * S * I / N - gamma * I + dRdt = gamma * I + return dSdt, dIdt, dRdt + +#Initial Conditions +y0 = S0, I0, R0 + +#Integrate +ret = odeint(deriv, y0, t, args=(N, beta, gamma)) +S, I, R = ret.T + +#Variable Equations +#Incidence +I(t) = I(t)-I(t-1) +#prevalence +P=I/(S+I+R) +#percent affected +A=(I+R)/(S+I+R) +#Basic Repduction +R0=beta*(S+I+R)/gamma + +#values +beta=0.0005 +gamma=0.05 +#time (days) + t = np.linspace(0, 500, 500) + while I > 0: + newI = 0 + for i in range(S): + + if random.random() < b*(I/N): + newI += 1 + recoverI = 0 + for i in range(I): + if random.random() < g: + recoverI += 1 + + S -= newI + I += (newI - recoverI) + R += recoverI + + #Append + sList.append(S) + iList.append(I) + rList.append(R) + newIList.append(newI) + + print('t', t) + t += 1 +#Print +print('sList', sList) +print('iList', iList) +print('rList', rList) +print('newIList', newIList) + +#values +beta=0.005 +gamma=0.5 +#time (days) + t = np.linspace(0, 500, 500) + while I > 0: + newI = 0 + for i in range(S): + + if random.random() < b*(I/N): + newI += 1 + recoverI = 0 + for i in range(I): + if random.random() < g: + recoverI += 1 + + S -= newI + I += (newI - recoverI) + R += recoverI + + #Append + sList.append(S) + iList.append(I) + rList.append(R) + newIList.append(newI) + + print('t', t) + t += 1 +#Print +print('sList', sList) +print('iList', iList) +print('rList', rList) +print('newIList', newIList) + +#values +beta=0.0001 +gamma=0.1 +#time (days) + t = np.linspace(0, 500, 500) + while I > 0: + newI = 0 + for i in range(S): + + if random.random() < b*(I/N): + newI += 1 + recoverI = 0 + for i in range(I): + if random.random() < g: + recoverI += 1 + + S -= newI + I += (newI - recoverI) + R += recoverI + + #Append + sList.append(S) + iList.append(I) + rList.append(R) + newIList.append(newI) + + print('t', t) + t += 1 +#Print +print('sList', sList) +print('iList', iList) +print('rList', rList) +print('newIList', newIList) + +#values +beta=0.00005 +gamma=0.1 +#time (days) + t = np.linspace(0, 500, 500) + while I > 0: + newI = 0 + for i in range(S): + + if random.random() < b*(I/N): + newI += 1 + recoverI = 0 + for i in range(I): + if random.random() < g: + recoverI += 1 + + S -= newI + I += (newI - recoverI) + R += recoverI + + #Append + sList.append(S) + iList.append(I) + rList.append(R) + newIList.append(newI) + + print('t', t) + t += 1 +#Print +print('sList', sList) +print('iList', iList) +print('rList', rList) +print('newIList', newIList) + +#values +beta=0.0001 +gamma=0.05 +#time (days) + t = np.linspace(0, 500, 500) + while I > 0: + newI = 0 + for i in range(S): + + if random.random() < b*(I/N): + newI += 1 + recoverI = 0 + for i in range(I): + if random.random() < g: + recoverI += 1 + + S -= newI + I += (newI - recoverI) + R += recoverI + + #Append + sList.append(S) + iList.append(I) + rList.append(R) + newIList.append(newI) + + print('t', t) + t += 1 +#Print +print('sList', sList) +print('iList', iList) +print('rList', rList) +print('newIList', newIList) + +#values +beta=0.0002 +gamma=0.05 +#time (days) + t = np.linspace(0, 500, 500) + while I > 0: + newI = 0 + for i in range(S): + + if random.random() < b*(I/N): + newI += 1 + recoverI = 0 + for i in range(I): + if random.random() < g: + recoverI += 1 + + S -= newI + I += (newI - recoverI) + R += recoverI + + #Append + sList.append(S) + iList.append(I) + rList.append(R) + newIList.append(newI) + + print('t', t) + t += 1 +#Print +print('sList', sList) +print('iList', iList) +print('rList', rList) +print('newIList', newIList) + +#values +beta=0.0001 +gamma=0.06 +#time (days) + t = np.linspace(0, 500, 500) + while I > 0: + newI = 0 + for i in range(S): + + if random.random() < b*(I/N): + newI += 1 + recoverI = 0 + for i in range(I): + if random.random() < g: + recoverI += 1 + + S -= newI + I += (newI - recoverI) + R += recoverI + + #Append + sList.append(S) + iList.append(I) + rList.append(R) + newIList.append(newI) + + print('t', t) + t += 1 +#Print +print('sList', sList) +print('iList', iList) +print('rList', rList) +print('newIList', newIList) + diff --git a/Tutorial 10 Part A b/Tutorial 10 Part A new file mode 100644 index 0000000..137094a --- /dev/null +++ b/Tutorial 10 Part A @@ -0,0 +1,35 @@ + +#Import Packages +import pandas +import numpy +from scipy.optimize import minimize +from scipy.stats import norm +import scipy.integrate as si +import re +import os +from plotnine import * + +#Plot of five population sizes +def ddSim(y,t0,r,K): + N=y[0] + dNdt=r*(1-N/K)*N + return [dNdt] + +params=(0.3,10) +N0=[10] +times=range(0,100) + +modelSim=si.odeint(func=ddSim,y0=N0,t=times,args=params) + +rs=[-0.1,0.1,0.4,0.8,1.0] +store_rs=pandas.DataFrame({"times":times,"r1":0,"r3":0,"r4":0,"r5":0}) + +for i in range(0,len(rs)): + pars=(rs[i],100) + sim=si.odeint(func=ddSim,y0=10,t=times,args=pars) + store_rs.iloc[:,i]=sim[:,0] + +modelOutput=pandas.DataFrame({"t":times,"rs":modelSim[:,0]}) + +#plot +ggplot(modelOutput,aes(x="t",y="rs"))+geom_line()+theme_classic() \ No newline at end of file diff --git a/Tutorial Q1 Part B b/Tutorial Q1 Part B new file mode 100644 index 0000000..87fecaf --- /dev/null +++ b/Tutorial Q1 Part B @@ -0,0 +1,34 @@ +#Import Packages +import pandas +import numpy +from scipy.optimize import minimize +from scipy.stats import norm +import scipy.integrate as si +import re +import os +from plotnine import * + +#Plot of Population Size as a function of time with 3 populations with different carrying capacities +def ddSim(y,t0,r,K): + N=y[0] + dNdt=r*(1-N/K)*N + return [dNdt] + +params=(0.3,10) +N0=[1] +times=range(0,100) +ks=["0,10","0,50","0,100"] +r=[0.2] + +modelSim=si.odeint(func=ddSim,y0=N0,t=times,args=params) + +store_rs=pandas.DataFrame({"times":times,"k1":0,"k2":0,"k3":0}) + +for i in range(0,len(rs)): + pars=(rs[i],K) + sim=si.odeint(func=ddSim,y0=10,t=times,args=pars) + store_rs.iloc[:,i]=sim[:,0] +modelOutput=pandas.DataFrame({"t":times,"ks":modelSim[:,0]}) + +#plot +ggplot(modelOutput,aes(x="t",y="rs"))+geom_line()+theme_classic() \ No newline at end of file