-
Notifications
You must be signed in to change notification settings - Fork 10
Buynak-Yingying Submission #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
dd3d502
7362baf
eaea79b
e4621cc
1ca6a7c
536fd53
d260b2e
c54dfd2
40761e8
a218d23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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('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('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('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('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('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('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('sList', sList) | ||
| print('iList', iList) | ||
| print('rList', rList) | ||
| print('newIList', newIList) | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define the function: Define the parameters: betas=numpy.array([0.0005,0.005,0.0001,0.00005,0.0001,0.0002,0.0001]) Make a new dataframe to store the parameters: Using the for loop to simulate: -0.5 pts |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set t = 0 to 500?
t = np.linspace(0, 500, 501)