-
Notifications
You must be signed in to change notification settings - Fork 10
exercise_10 Bruzzese_Inskeep_Nemera #8
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
Open
bruzecruise
wants to merge
25
commits into
lyy005:master
Choose a base branch
from
bruzecruise:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5e84cdc
created python file
55de376
Starting skeleton for Q1
kinskeep 0aecd59
Added function and loop to Q1
kinskeep b2afef6
pseudocode for q2
b09a67e
Merging with Dan
kinskeep 45dab7c
Merge branch 'master' of https://github.com/omegadan01/Intro_Biocom_N…
kinskeep 10f1267
Added ggplots. Only Plot 3 isn't working
kinskeep c423030
I tried to fix Plot 3 and made it worse lol
kinskeep ef27e7b
pseudocode for q2
d533625
q2
3d29e0e
got sim working for q2.... see comments in code
5a9b3cd
Added file for simulation data
MatiNem 35a74d9
no actual changes, just need to pull
MatiNem 6882eca
Got three n naughts in problem 1-3
MatiNem 7c23725
q2 is here now!
9bba9ee
Merge remote-tracking branch 'origin/master'
e393685
moved q2 to 10B.py file
4fc815a
Saved and Fixed initial NO values for problem 1 part 2
MatiNem 685f97f
Merge branch 'master' of https://github.com/omegadan01/Intro_Biocom_N…
MatiNem 7941576
removed problem 2 stuff from problem 1 file
MatiNem 0d0880e
made a dataframe
55665b4
made a billion lists and have then make a dataframe of the output
edfdb31
OMG IT WORKS!
9600e5b
pushed observations
93d5d8a
added some kind of reflection. WE ARE DONE
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| ## exercise 10 ## | ||
|
|
||
| # 1 | ||
| #Load packages | ||
| import pandas | ||
| import scipy | ||
| import scipy.integrate as si | ||
| from plotnine import * | ||
|
|
||
|
|
||
| #Define custom function | ||
| def popGrowth(y,t0,r,K,N): | ||
| N=y[0] | ||
| dNdt=r*(1-N/K)*N | ||
| return [dNdt] | ||
| times=range(0,100) | ||
| NO=[.01] | ||
| #Set a pool of values for growth rate | ||
| growthRates=[-.1,.1,.4,.8,1.0] | ||
| #Dataframe for storing model output | ||
| store_growthRates=pandas.DataFrame({"time":times,"r1":0,"r2":0,"r3":0,"r4":0,"r5":0}) | ||
|
|
||
| #Using a for loop to make my life easier | ||
| for i in range(0,len(growthRates)): | ||
| pars=(growthRates[i],100,10) | ||
| sim=si.odeint(func=popGrowth,y0=NO,t=times,args=pars) | ||
| store_growthRates.iloc[:,i]=sim[:,0] | ||
| print(store_growthRates) | ||
|
|
||
| #Plot 1- pop size as function of time | ||
| g=(ggplot(data=store_growthRates) | ||
| +geom_line(store_growthRates,aes(x="time",y="r1"))+theme_classic() | ||
| +ylab("population size") | ||
| +geom_line(store_growthRates,aes(x="time",y="r2"),color="green") | ||
| +geom_line(store_growthRates,aes(x="time",y="r3"),color="red") | ||
| +geom_line(store_growthRates,aes(x="time",y="r4"),color="orange") | ||
| +geom_line(store_growthRates,aes(x="time",y="r5"),color="purple")) | ||
| print(g) | ||
|
|
||
| #set a pool of values for carrying capacity | ||
| carryCap=[10,50,100] | ||
| #Dataframe for storing model output | ||
| store_carryCap=pandas.DataFrame({"time":times,"K1":0,"K2":0,"K3":0}) | ||
| NO = 1 | ||
| #for loop for Plot 2 | ||
| for i in range(0,len(carryCap)): | ||
| pars=(.2,carryCap[i],1) | ||
| sim=si.odeint(func=popGrowth,y0=NO,t=times,args=pars) | ||
| store_carryCap.iloc[:,i]=sim[:,0] | ||
| print(store_carryCap) | ||
|
|
||
| #Plot 2- | ||
| k=(ggplot(data=store_carryCap) | ||
| +geom_line(store_carryCap,aes(x="time",y="K1"),color="blue")+theme_classic() | ||
| +ylab("population size") | ||
| +geom_line(store_carryCap,aes(x="time",y="K2"),color="green") | ||
| +geom_line(store_carryCap,aes(x="time",y="K3"),color="purple")) | ||
| print(k) | ||
|
|
||
| #Set a pool of values for init pop size | ||
| initPop=[1,50,100] | ||
| #Dataframe for storing model output | ||
| store_initPop=pandas.DataFrame({"time":times,"N1":0,"N2":0,"N3":0}) | ||
|
|
||
| #Using a for loop to make my life easier | ||
| for i in range(0,len(initPop)): | ||
| pars=(.1,50,initPop[i]) | ||
| sim=si.odeint(func=popGrowth,y0=initPop[i],t=times,args=pars) | ||
| store_initPop.iloc[:,i]=sim[:,0] | ||
| print(store_initPop) | ||
|
|
||
| #Plot 3- effect of initial Pop size differences | ||
| p=(ggplot(data=store_initPop) | ||
| +geom_line(store_initPop,aes(x="time",y="N1"),color="orange")+theme_classic() | ||
| +ylab("population size") | ||
| +geom_line(store_initPop,aes(x="time",y="N2"),color="yellow") | ||
| +geom_line(store_initPop,aes(x="time",y="N3"),color="red")) | ||
| print(p) | ||
|
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. Everything else looks good. Good job |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #Load packages | ||
| import pandas | ||
| import scipy | ||
| import scipy.integrate as si | ||
| from plotnine import * | ||
|
|
||
| # function | ||
| def SIR (y,t0,beta,gamma): | ||
| S = y[0] | ||
| I = y[1] | ||
| R = y[2] | ||
| dS = -1*(beta*I*S) | ||
| dI = (beta*I*S)-(gamma*I) | ||
| dR = (gamma*I) | ||
| return dS, dI, dR | ||
|
|
||
| # initial conditions | ||
| times = range(0,500) | ||
| NO = [999, 1, 0] | ||
|
|
||
| # dataframe of gamma and beta values | ||
| data = [{'beta' : .0005, 'gamma' : .05}, | ||
| {'beta': .005, 'gamma': .5}, | ||
| {'beta': .0001, 'gamma': .1}, | ||
| {'beta': .00005, 'gamma': .1}, | ||
| {'beta': .0001, 'gamma': .05}, | ||
| {'beta': .0002, 'gamma': .05}, | ||
| {'beta': .0001, 'gamma': .06}, | ||
| {'beta': .0001, 'gamma': .9}, | ||
| {'beta': .0001, 'gamma': .5}, | ||
| {'beta': .0001, 'gamma': .25}, | ||
| {'beta': .0001, 'gamma': .1}, | ||
| {'beta': .0001, 'gamma': .05}, | ||
| {'beta': .0001, 'gamma': .01}, | ||
| {'beta': .0001, 'gamma': .001}, | ||
| {'beta': .0001, 'gamma': .0001}, | ||
| {'beta': .9, 'gamma': .0001}, | ||
| {'beta': .5, 'gamma': .0001}, | ||
| {'beta': .25, 'gamma': .0001}, | ||
| {'beta': .1, 'gamma': .0001}, | ||
| {'beta': .05, 'gamma': .0001}, | ||
| {'beta': .01, 'gamma': .0001}, | ||
| {'beta': .001, 'gamma': .0001}, | ||
| {'beta': .0001, 'gamma': .0001}, | ||
| {'beta': .00001, 'gamma': .0001}, | ||
| ] | ||
| my_data = pandas.DataFrame(data) | ||
|
|
||
| # make lists to hold the results | ||
| mdi = [] | ||
| mdp = [] | ||
| pa = [] | ||
| ro = [] | ||
| b = [] | ||
| g = [] | ||
|
|
||
| # start big loop here | ||
| for line in range(0,len(my_data),): | ||
| q = my_data.iloc[line]['beta'] | ||
| p = my_data.iloc[line]['gamma'] | ||
| params = (q, p) # make tuple | ||
|
|
||
| b.append(params[0]) # append list | ||
| g.append(params[1]) | ||
|
|
||
| # make dataframe | ||
| infection = pandas.DataFrame({"time":times,"S":0,"I":0,"R":0}) | ||
|
|
||
| # sim shite | ||
| sim = si.odeint(func=SIR, y0=NO, t=times, args=params) | ||
|
|
||
| # fill dataframe | ||
| infection.iloc[:,2]=sim[:,0] | ||
| infection.iloc[:,0]=sim[:,1] | ||
| infection.iloc[:,1]=sim[:,2] | ||
|
|
||
| # calc max daily incidence | ||
| daily_incidence = [] | ||
| for i in range(0,len(infection),): | ||
| if infection.time[i]==0: | ||
| continue | ||
| else: | ||
| I = infection.iloc[i]['I'] | ||
| Iold = infection.iloc[i-1]['I'] | ||
| incidence = I-Iold | ||
| daily_incidence.append(incidence) | ||
| max_daily_incidence = max(daily_incidence) | ||
| mdi.append(max_daily_incidence) | ||
|
|
||
| # calc max daily prevalence | ||
| daily_prev = [] | ||
| for i in range(0,len(infection),): | ||
| I = infection.iloc[i]['I'] | ||
| R = infection.iloc[i]['R'] | ||
| S = infection.iloc[i]['S'] | ||
| prev = I/(S+I+R) | ||
| daily_prev.append(prev) | ||
| max_daily_prev = max(daily_prev) | ||
| mdp.append(max_daily_prev) | ||
|
|
||
| #calc percent affected over simulation- use last time step (499) | ||
| I= infection.iloc[499]['I'] | ||
| R= infection.iloc[499]['R'] | ||
| S= infection.iloc[499]['S'] | ||
| percent_affected = (I+R)/(S+I+R) | ||
| pa.append(percent_affected) | ||
|
|
||
| # basic reproduction number initial SIR | ||
| beta = params[0] | ||
| gamma = params[1] | ||
| I= infection.iloc[0]['I'] | ||
| R= infection.iloc[0]['R'] | ||
| S= infection.iloc[0]['S'] | ||
| repo_number = (beta*(S+I+R))/gamma | ||
| ro.append(repo_number) | ||
|
|
||
| # make a dataframe for results from all the lists | ||
| results = pandas.DataFrame( | ||
| {'beta' : b, | ||
| 'gamma' : g, | ||
| 'max_daily_incide' : mdi, | ||
| 'max_daily_prev' : mdp, | ||
| 'percent_affect' : pa, | ||
| 'repo_num' : ro}) | ||
|
|
||
| print results | ||
| #need these to fill into a list or a dataframe | ||
| # need to put all this intoa bigger loop | ||
|
|
||
| ''' | ||
| * observations * | ||
| We noticed that if beta is held constant while gamma gets smaller the max incidence, daily prevalence, percent infection, | ||
| and reproductive number all rise. Thus a bigger gamma causes, things to get smaller If we hold gamma constant, as beta | ||
| gets bigger the max incidence, daily prevalence, percent affected, and reproductive number all rise. Thus a small beta, | ||
| causes things to get smaller To summarize, a high beta and a small gamma cause the disease to have a higher rate and | ||
| srpead of infection in the population. | ||
|
|
||
| ''' | ||
|
|
||
|
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. Good job! |
||
|
|
||
|
|
||
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
N0 should be 10