---
# System prepended metadata

title: Model Intro.
tags: [others]

---

# Model Intro.
###### tags: `others`

[TOC]

## Model Overview

```graphviz
    digraph Omodel {
    node [shape=circle] raw_data, input_data, period_data, population_data
    node [shape=box] preprocessor, Initialization_Module, Simulation_Module, Visualization_Module
    
    raw_data -> preprocessor
    preprocessor -> input_data
    input_data -> Initialization_Module
    Initialization_Module -> population_data
    population_data -> Simulation_Module
    Simulation_Module -> period_data
    period_data -> Visualization_Module
    
    {rank = "same"; raw_data; preprocessor;input_data; Initialization_Module}
    rankdir = "LR"
}
```


* Initialization
    * Read data
    * Generate individuals and assign attribute to them

* Simulation
    * Simulate the transmission of COVID-19
    * Our model take morning or night as one **period**, and **period** is a base unit in simulation.
  (so if we simulate 180 days, then there's 360 periods in total)
    * In each periods, simulates the transmission of COVID-19
        * In each morning periods, simulates the rollout of vaccine

* Visualization
    * Read data of each periods
    * Visualize the data

## Data

* For initialization model
    1. city.csv
    2. census_tracts.csv
    3. age_population.csv
    4. town_population.csv
    5. contact_prob.csv 
    6. city_to_city_commute.csv
* For simulation model
    1. COVID_19.conf
    2. vaccine.conf

## Initialization Module

### Attribute of an Individual

#### State

```graphviz
digraph Emodel {
    node [shape=box] S, F, R, E, I, D
    S -> R [label="successful vaccination"]
    S -> F [label="fail vaccination", fontsize=7]
    S -> E [label="Infected"]
    F -> E [label="Infected"]
    E -> I [label="become infectious"]
    I -> R [label="Immune"]
    I -> D [label="Dead"]
    I -> F [label="Not Immune"]
    
    {rank = "same"; S; F}
    {rank = "same"; R; D}
    
    rankdir = "LR"
}
```

#### Age
* 4 age groups
    1. 0-4
    2. 5-18
    3. 19-64
    4. 65+


#### Contact group

* Geographic unit: **Census Tract**(人口普查區)
* 10 Groups and each of the groups has plenty subgroups
    1. community: 2000 persons each
    2. neighborhood: 4 household clusters each
    3. household cluster: 4 households each
    4. household: 7 persons each
    5. work group: 20 persons each
    6. high school: 155 persons each
    7. middle school: 128 persons each
    8. elementary school: 79 persons each
    9. daycare center: 14 persons each
    10. play group: 4 persons each

An individual can be in multiple contact groups.

![](https://i.imgur.com/uzJFL6G.png)

* A worker in worker flow means that he/she is in different census tracts on day and night , and hence in different contact group

### Generating

* The module reads the **data** and generate individuals in a census tract
* Stochastically assign attribute(age, contact groups) to an individual

```
for tract in census_tracts:
    read data of the tract
    generate individuals of 4 age groups based on data
    
    for each group type in contact_groups:
        specify the objects being grouped (e.g. children, adults, households)
        calculate # of groups of that type
        assign group no. for each node being grouped
```

## Simulation Module

![](https://i.imgur.com/hMSfKJe.png)

![](https://i.imgur.com/K7PWxaE.png)

### Naive Algorithm

Given infector $u$ and a to-infect group $g$ with susceptible set $S_g\subseteq g$ and contact matrix $C_g=\{c_{i,j}\}$.

```python
def naive_algorithm(v, S, C):
    for v in S:
        if trail() < C[u, v]:
            infect(v)
```
![](https://i.imgur.com/8QlzuLN.png)

### Sieve Algorithm

```python
def sieve_algorithm(v, S, C):
    p_max = max([C[u, v] for v in S])
    k = ceiling(p_max * len(S))
    S_tmp = random_choose(S, k)
    
    for v in S_tmp:
        if trail() < C[u, v] / p_max:
            infect(v)
```

Then the prob that $v\in S$ is infected is

$$\frac{k}{|S|}\cdot\frac{c_{u,v}}{p_{max}}=\frac{\lceil p_{max}\cdot |S|\rceil}{|S|}\cdot\frac{c_{u,v}}{p_{max}}\approx c_{u,v}$$

![](https://i.imgur.com/p5pMZG1.png)

- maintain $p_{max}$ for each group and infector
- maintain the set $S$ for each group

### Vaccine strategies

#### Graph based strategies
* Influential set
* Centrality

#### age based strategies

#### others?

## Visualization Module

Read the **period_data** from simulation module and plot the graph by using python library

### Plotly
#### Geojson data
https://raw.githubusercontent.com/g0v/twgeojson/master/json/twTown1982.geo.json

### Folium