<jupyter_start><jupyter_text>PROJECT 2 : TEAM 11 Members: <NAME>, <NAME><jupyter_code># Configure Jupyter so figures appear in the notebook
%matplotlib inline

# Configure Jupyter to display the assigned value after an assignment
%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'

# import functions from the modsim.py module
from modsim import *
import math<jupyter_output><empty_output><jupyter_text>http://www.worldometers.info/world-population/us-population/US pop in 2017 = 324,459,463https://www.cdc.gov/vaccines/imz-managers/coverage/childvaxview/data-reports/mmr/trend/index.htmlMMR immunization rate in 2017 = 90.7%https://www.acha.org/documents/Programs_Services/ConEd/Measles_Update_2015_Implications_for_the_College_Setting.pdfMMR Measles importatoin number = 33/yearhttps://wwwnc.cdc.gov/travel/yellowbook/2018/infectious-diseases-related-to-travel/measles-rubeolaMeasles incubation period 11 days average, infectious period 2-4 days before rash to after rash.https://www.researchgate.net/figure/Daily-average-number-of-contacts-per-person-in-age-group-j-The-average-number-of_fig2_228649013Daily average number of contacts per person. https://academic.oup.com/jid/article/189/Supplement_1/S91/8250771999 overall immunity for measles were expected to be 93% for US population.https://www.statista.com/statistics/195943/birth-rate-in-the-united-states-since-1990/Birth rate = 12.2/1000 per year = 0.0122 Death rate = 8.4/1000 per year = 0.0084<jupyter_code>pop = 1000  #population
init_im = 0.5    #initial immunity of the US population
beta = 0.9
gamma = 1/7      #US recovery rate from measles
sigma = 0.091     #US rate from exposure period of 11 days to infected
contact_num = beta/gamma<jupyter_output><empty_output><jupyter_text>What would be the impact of getting rid of the MMR vaccination in newborn babies over the course of 10 years?Background/why we thought this was interesting-Explanation of the disease: symptoms, contagious- Reference the fake study where the guy said vaccinations are bad for your baby    --WHAT IF PEOPLE BELIEVED HIM???- MMR is very super infections and has high herd immunity so when you drop the vaccination rate, it drops the infection rate. MethodologyIn order to creat this model, we:1. Did background research on MMR vaccination and the measles diseases and found a set of constants we would implement in our model.2. Put the variables into a state function.3. Ran the simulation based on measles infections every day.4. Expanded simuluation for a course of 10 years.5. Implemented the idea of a measles outbreak to make the simulation more realistic.6. Created graphs to visually represent our results.<jupyter_code>def make_system (pop, init_im, beta, gamma, sigma):
    """Make a system object for the SCIR model
    
    pop: Total US population
    init_im: Initial Population Immunity
    gamm: recovery rate for infected people
    sigma: rate of incubation group moving to infectious group
    return: System object"""
    
    init = State(S = int(pop*(1 - init_im)), E = 0, I = 1, R = int(pop*init_im))
    init /= np.sum(init)
    #S: susceptible, E: exposed period, I: infected, R: recovered(immune to disease)
    
    t0 = 0
    t_end = 365 #number of days in 1 year
    
    return System(init = init,
                  beta = beta,
                  gamma = gamma,
                  sigma = sigma,
                  t0 = t0,
                  t_end = t_end,
                  init_im = init_im)
def update_func(state, time, system):
    """Update the SEIR model
    
    state: starting variables of SEIR
    t: time step
    system: includes alpha,beta,gamma,omega rates
    contact: current contact number for the state
    
    """
    
    unpack(system)
    
    s,e,i,r = state
            
    #current population
    total_pop = s+e+i+r
    
    #change rate for each status
    ds = (-beta*s*i)/total_pop #change in number of people susceptible
    de = ((beta*s*i)/total_pop) - sigma*e #change in number of people moving to exposed period
    di = sigma*e - gamma*i     #change in people moving to infectious period
    dr = gamma*i     #change in people recovered

    s += ds      #number of people susceptible
    e += de      #number of people exposed
    i += di      #number of people infected
    r += dr      #number of people recovered
    
    return State(S=s, E=e, I=i, R=r)
def run_simulation(system, update_func):
    """Runs a simulation of the system.
        
    system: System object
    update_func: function that updates state
    
    returns: TimeFrame
    """
    unpack(system)
    
    #creates timeframe to save daily states
    frame = TimeFrame(columns=init.index)
    frame.row[t0] = init
    
    for time in linrange(t0, t_end):
        frame.row[time+1] = update_func(frame.row[time], time, system)
    
    return frame
def plot_results (S,E,I,R):
    
    plot(S, '--', label = 'Susceptible')
    plot(E, '-', label = 'Exposded')
    plot(I, '.', label = 'Infected')
    plot(R, ':', label = 'Recovered')
    decorate(xlabel='Time (days)',
            ylabel = 'Fraction of population')
system = make_system(pop, init_im, beta, gamma, sigma)
results = run_simulation(system, update_func)
results
plot_results(results.S, results.E, results.I, results.R)
imax = max(results.I)
def calc_highest_infected(results):
    """Fraction of population infected during the simulation.
    
    results: DataFrame with columns S, I, R
    
    returns: fraction of population
    """
    return max(results.I)
def sweep_init_im(imun_rate_array):
    """Sweep a range of values for beta.
    
    beta_array: array of beta values
    gamma: recovery rate
    
    returns: SweepSeries that maps from beta to total infected
    """
    sweep = SweepSeries()
    for init_im in imun_rate_array:
        system = make_system(pop, init_im, beta, gamma, sigma)
        results = run_simulation(system, update_func)
        sweep[system.init_im] = calc_highest_infected(results)*pop
    return sweep
imun_rate_array = linspace(0, 1, 11)
sweep = sweep_init_im(imun_rate_array) 
sweep
plot(sweep)
decorate(xlabel='Immunity Rate',
        ylabel = 'Highest number of people infected during 1 outbreak')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08856502242152467, 'fraction_numerical': 0.02290198590647021, 'mean_word_length': 3.379382889200561, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '627498', 'license': 'MIT', 'n_tokens_mistral': 2072, 'n_tokens_neox': 1871, 'n_words': 630, 'path': 'code/Project2-v2.ipynb', 'repo_name': 'ttandler/ModSimPy', 'size': '6255'}