# SEIRHVD model example
## Work in progress (equations not ready)
\begin{align}
\dot{S} & = S_f - \alpha\beta\frac{SI}{N+k_I I+k_R R} + r_{R\_S} R\\
\dot{E} & = E_f + \alpha\beta\frac{SI}{N+k_I I+k_R R} - E\frac{1}{t_{E\_I}} \\
\dot{I} & = I_f + E\frac{1}{t_{E\_I}} - I\frac{1}{t_{I\_R}} \\
\dot{R} & = R_f + I\frac{1}{t_{I\_R}} - r_{I\_R} R\\
\end{align}
Where:  
* $S:$ Susceptible
* $E:$ Exposed
* $I:$ Infectious
* $R:$ Removed
* $\alpha:$ Mobilty
* $\beta:$ Infection rate
* $N:$ Total population
* $t_{E\_I}:$ # Transition time between exposed and infectious
* $t_{I\_R}:$ # Transition time between infectious and recovered
* $r_{R\_S}:$ Immunity loss rate ($\frac{1}{t_{R\_S}}$)  
* $S_f,E_f,I_f,R_f:$ External flux
* $k_I:$ Infected saturation   
* $k_R:$ Immunity shield    



```python
# Util libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Adding lib paths

# cv19 libraries
from cv19gm.models.seirhvd import SEIRHVD  
from cv19gm.utils import 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?)')
```

# Variable CFR 

## Discrete change
* pH_r de 0.7 a 0.6
* pH_D de 0.3 a 0.4


```python
pH_R = cv19functions.events(values=[0.7,0.5],days=[[0,30],[30,500]])
pH_D = cv19functions.events(values=[0.3,0.5],days=[[0,30],[30,500]])
```


```python
%%capture
# Input configuration file
config = 'cfg/SEIRHVD.toml'
# Build simulation object
model1 = SEIRHVD(config = config, H_cap=4000, pH_R = pH_R,pH_D = pH_D)
# Simulate (solve ODE)
model1.solve()
```


```python
t = np.linspace(0,50,1000)
plt.plot(t,100*pH_R(t),label='pH_R')
plt.plot(t,100*pH_D(t),label='pH_D')
plt.plot(t,100*pH_D(t)*model1.pE_Icr(t),label='CFR')
plt.legend(loc=0)
plt.title('CFR change (%)')
plt.show()
```


```python
t = model1.t
plt.plot(t,100*model1.pH_R(t),label='pH_R')
plt.plot(t,100*model1.pH_D(t),label='pH_D')
plt.plot(t,100*model1.CFR,label='CFR')
plt.xlim(0,50)
plt.legend(loc=0)
plt.title('CFR change (%)')
plt.show()
```

* Nota: la transicion pareciera ocurrir en 2 días, pero tiee que ver con la resolución en la cual se entregan los datos, la transición que utiliza el integrador es "instantánea".


```python
# Plot matplotlib
fig, axs = plt.subplots(figsize=(13,9),linewidth=5,edgecolor='black',facecolor="white")
axs2 = axs.twinx()

axs.plot(model1.t,model1.D_d,color='tab:red',label='Daily deaths')
axs.set_ylabel('Deaths',color='tab:red')
axs.tick_params(axis='y', labelcolor='tab:red')

t = model1.t
axs2.plot(t,100*pH_D(t)*model1.pE_Icr(t),color='tab:blue',label='CFR')
axs2.set_ylabel('CFR',color='tab:blue')
axs2.tick_params(axis='y',labelcolor='tab:blue')

axs.set_xlim(0,200)
axs2.set_xlim(0,200)
fig.legend(loc=8)
fig.suptitle('CFR vs Deaths')
fig.show()
```

## Continious change
* pH_r de 0.7 a 0.6
* pH_D de 0.3 a 0.4


```python
pH_R = cv19functions.sigmoidal_transition(t_init=20,t_end=40,initvalue = 0.7, endvalue = 0.5)
pH_D = cv19functions.sigmoidal_transition(t_init=20,t_end=40,initvalue = 0.3, endvalue = 0.5)
```


```python
%%capture
# Input configuration file
config = 'cfg/SEIRHVD.toml'
# Build simulation object
model2 = SEIRHVD(config = config, H_cap=4000, pH_R = pH_R,pH_D = pH_D)
# Simulate (solve ODE)
model2.solve()
```


```python
t = model2.t
plt.plot(t,100*model2.pH_R(t),label='pH_R')
plt.plot(t,100*model2.pH_D(t),label='pH_D')
plt.plot(t,100*model2.CFR,label='CFR')
plt.xlim(0,50)
plt.legend(loc=0)
plt.title('CFR change (%)')
plt.show()
```


```python
# Plot matplotlib
fig, axs = plt.subplots(figsize=(13,9),linewidth=5,edgecolor='black',facecolor="white")
axs2 = axs.twinx()

axs.plot(model2.t,model2.D_d,color='tab:red',label='Daily deaths')
axs.set_ylabel('Deaths',color='tab:red')
axs.tick_params(axis='y', labelcolor='tab:red')

t = model2.t
axs2.plot(t,100*pH_D(t)*model2.pE_Icr(t),color='tab:blue',label='CFR')
axs2.set_ylabel('CFR',color='tab:blue')
axs2.tick_params(axis='y',labelcolor='tab:blue')

axs.set_xlim(0,200)
axs2.set_xlim(0,200)
fig.legend(loc=8)
fig.suptitle('CFR vs Deaths')
fig.show()
```

# Access CFR value

## As a variable


```python
model2.CFR 
```

## As part of the pandas array


```python
model2.results['CFR']
```


```python

```

4a4aa1e3065cd96aa857b9723f43fd0b96577738
ipynb
Jupyter Notebook
Examples/SEIRHVD_CFR.ipynb
DLab/covid19geomodeller
a3a9eedf064078b21be0928ee41b41c902938eff
MIT
Examples/SEIRHVD_CFR.ipynb
DLab/covid19geomodeller
a3a9eedf064078b21be0928ee41b41c902938eff
MIT
Examples/SEIRHVD_CFR.ipynb
DLab/covid19geomodeller
a3a9eedf064078b21be0928ee41b41c902938eff
MIT
Qwen/Qwen-72B
1. YES
2. YES