# SIR model example
\begin{align}
\dot{S} & = \alpha\beta\frac{SI}{N} + \rho_{RS} R + \phi_S\\
\dot{I} & = \alpha\beta\frac{SI}{N} - I\frac{1}{\tau_{IR}} + \phi_I\\
\dot{R} & = 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
* $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 


```python
# Util libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime

# cv19 libraries
from cv19gm.models.sir import SIR
import cv19gm.utils.cv19functions as cv19functions
```


```python
# 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?)')
```

# Build a basic SIR model using a configuration file


```python
# Input configuration file
config = 'cfg/SIR.toml'
```


```python
# Build simulation object
model = SIR(config = config,beta=0.3)
```


```python
model.solve()
```


```python
# Plot matplotlib
plt.plot(model.t,model.S,label='S')
plt.plot(model.t,model.I,label='I')
plt.plot(model.t,model.R,label='R')
plt.xlim(0,150)
plt.legend(loc=0)
plt.title('SIR states over time')
plt.show()
```


```python
# Show results
model.results
```


```python

```

c2c5f8f1694e96ea03528aabe9e90f0e3bb0e460
ipynb
Jupyter Notebook
Examples/SIR.ipynb
DLab/covid19geomodeller
a3a9eedf064078b21be0928ee41b41c902938eff
MIT
Examples/SIR.ipynb
DLab/covid19geomodeller
a3a9eedf064078b21be0928ee41b41c902938eff
MIT
Examples/SIR.ipynb
DLab/covid19geomodeller
a3a9eedf064078b21be0928ee41b41c902938eff
MIT
Qwen/Qwen-72B
1. YES
2. YES