<jupyter_start><jupyter_text>SEIR model example\begin{align}\dot{S} & = - \alpha\beta\frac{SI}{N}\\\dot{E} & =  \alpha\beta\frac{SI}{N} - E\frac{1}{\tau_{EI}}\\\dot{I} & =  E\frac{1}{\tau_{EI}} - I\frac{1}{\tau_{IR}}\\\dot{R} & =  I\frac{1}{\tau_{IR}} \\\end{align} SEIR model example\begin{align}\dot{S} & = S_f - \alpha\beta\frac{SI}{N} + \rho_{RS} R + \phi_S\\\dot{E} & = E_f + \alpha\beta\frac{SI}{N} - E\frac{1}{\tau_{EI}} + \phi_E\\\dot{I} & = I_f + E\frac{1}{\tau_{EI}} - I\frac{1}{\tau_{IR}} + \phi_I\\\dot{R} & = R_f + I\frac{1}{\tau_{IR}} - \rho_{IR} R + \phi_R\\\dot{\Phi} & = \sum_{i} (\phi_{i}) \\N & = N_0 + \Phi \\N_0 & = S_0+E_0+I_0+R_0  \\\end{align}Where:  * $S:$ Susceptible Individuals* $E:$ Exposed Individuals* $I:$ Infectious Individuals* $R:$ Removed Individuals* $\alpha:$ Average number of contacts per person per time* $\beta:$ Probability of disease transmission in a contact between a susceptible and an infectious subject* $N:$ Total population* $\tau_{EI}:$ Transition time between exposed and infectious* $\tau_{IR}:$ Transition time between infectious and recovered* $\rho_{RS}:$ Immunity loss rate. Inverse of Immunity loss rate medium time ($\frac{1}{t_{RS}}$)  * $\phi_S,\phi_E,\phi_I,\phi_R:$ External flux per compartment* $\Phi$: Total external population flux<jupyter_code># Util libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime

# cv19 libraries
from cv19gm.models.seir import SEIR
import cv19gm.utils.cv19functions as cv19functions
# For pop-up plots execute this code (optional)
import platform
OS = platform.system()

if OS == 'Linux':    
    %matplotlib tk
    print('Linux')
elif OS == 'Windows':
    %matplotlib qt
    print('Windows')
elif OS == 'Darwin':
    %matplotlib tk
    print('Mac (Funciona?)')<jupyter_output>Linux<jupyter_text>Build a basic SEIR model using a configuration file  Constant parameters<jupyter_code># Input configuration file
config = 'cfg/SEIR.toml'
# Build simulation object
model = SEIR(config = config,beta=0.3)
%%capture
# Simulate (solve ODE)
model.solve()
# Show results
model.results
plt.plot(model.t,model.S+model.E+model.I+model.R)
# Plot matplotlib
plt.plot(model.t,model.S,label='S')
plt.plot(model.t,model.E,label='E')
plt.plot(model.t,model.I,label='I')
plt.plot(model.t,model.R,label='R')
plt.xlim(0,300)
plt.legend(loc=0)
plt.show()
# Plot with pandas
ax = model.results.plot(x='t',y=['S','E','I','R'])
ax.set_xlim(0,300)
ax.set_title('SEIR simulation plot')<jupyter_output><empty_output><jupyter_text>Variable parametersCreate a function with time dependent parameters. Check covid19functions notebook for more information on this.<jupyter_code>config2 = 'cfg/SEIR_v2.toml'
model2 = SEIR(config = config2)
%%capture
model2.solve()
plt.plot(model2.t,model2.S,label='S')
plt.plot(model2.t,model2.E,label='E')
plt.plot(model2.t,model2.I,label='I')
plt.plot(model2.t,model2.R,label='R')
plt.xlim(0,300)
plt.legend(loc=0)
plt.show()<jupyter_output><empty_output><jupyter_text>SEIR desde cmd<jupyter_code>beta = 0.2
population = 10000
I = 100
model = SEIR(config = config)
model.solve()<jupyter_output><empty_output><jupyter_text>Variable parameters<jupyter_code>t = np.linspace(0,6,1000)
beta = lambda t: np.sin(t)
plt.plot(t,beta(t))
model = SEIR(config = config,beta=beta)
model.solve()
plt.plot(model.t,model.I)
plt.title('Active Infected')
plt.xlim(0,50)
plt.show()
beta2 = cv19functions.events(days=[[0,10],[10,60],[60,100]],values=[0.12,0.2,0.3],default = 0.1)
t = np.linspace(0,200,10000)
plt.plot(t,beta2(t))
model2 = SEIR(config = config,beta=beta2)
model2.solve()
plt.plot(model2.t,model2.I)<jupyter_output><empty_output><jupyter_text>Study<jupyter_code># Input configuration file
config = 'cfg/SEIR.toml'
# Build simulation object
model1 = SEIR(config = config, I_d_det = 600, population = 1000000)
model2 = SEIR(config = config, I_d_det = 600, population = 10000000)
%%capture
# Simulate (solve ODE)
model1.solve()
model2.solve()
model1.I_d[0]
# Plot matplotlib
#plt.plot(model.t,model1.S,label='S')
#plt.plot(model.t,model1.E,label='E')
plt.plot(model.t,model1.I_d,label='I_1')
plt.plot(model.t,model2.I_d,label='I_2')
plt.xlim(0,300)
plt.yscale('log')
plt.legend(loc=0)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18398876404494383, 'fraction_numerical': 0.035580524344569285, 'mean_word_length': 5.687010954616588, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '486299', 'license': 'MIT', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1674, 'n_words': 325, 'path': 'Examples/SEIR.ipynb', 'repo_name': 'DLab/covid19geomodeller', 'size': '4272'}