Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Age-region sampling enabled and other modifies #9

Merged
merged 25 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[run]
source = sampling
source = epios
omit =
sampling/tests/*
sampling/version_info.py
sampling/__init__.py
sampling/run_tests.py
epios/tests/*
epios/version_info.py
epios/__init__.py
epios/run_tests.py
40 changes: 40 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Coverage

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[dev]
python -m pip install coverage codecov

- name: Run coverage
run: |
coverage run epios/run_tests.py --unit

- name: Upload coverage reports to Codecov
if: success()
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
run: |
codecov
37 changes: 37 additions & 0 deletions .github/workflows/os_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This workflow will install Python dependencies, run tests and lint with a variety of operating systems
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Operating systems

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]
workflow_dispatch:

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: |
python --version
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[dev]
- name: Run unit tests
run: |
python epios/run_tests.py --unit
35 changes: 35 additions & 0 deletions .github/workflows/python_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[dev]
- name: Run unit tests
run: |
python epios/run_tests.py --unit

31 changes: 31 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Style tests (flake8)

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]
workflow_dispatch:

jobs:

build-and-test:
name: style test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: |
python --version
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[dev]
- name: Run style tests
run: |
python -m flake8 --max-line-length=120
171 changes: 171 additions & 0 deletions age_region.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import os\n",
"from pathlib import Path\n",
"sys.path.append(str(Path.cwd().parent))\n",
"import epios\n",
"import pandas as pd\n",
"import numpy as np\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"a = epios.Sampler('./input/Luxembourg_microcells.csv', './input/Luxembourg_pop_dist.json', './input/Luxembourg_data.csv')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"res = a.sample(10000)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"age_dist = a.get_age_dist()\n",
"region_dist = a.get_region_dist()\n",
"ar_dist = np.array(age_dist) * np.array(region_dist).reshape((-1, 1))\n",
"ar_dist = ar_dist.reshape((1, -1))[0]\n",
"size = 1000\n",
"num_sample, cap = a.multinomial_draw(size, ar_dist)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b = np.array(num_sample).reshape((-1, len(age_dist))) > cap\n",
"sum(b)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10000"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(res)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b = np.sum(np.array(num_sample).reshape((-1, len(age_dist))), axis=1) > np.array(cap).reshape((1, -1))[0]\n",
"sum(b)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# df = pd.read_csv('./input/Luxembourg_microcells.csv')\n",
"# with open('./input/Luxembourg_pop_dist.json', 'r') as f:\n",
"# config = json.loads(f.read())\n",
"# id_counter = 0\n",
"# for ind, row in df.iterrows():\n",
"# household = 1\n",
"# for i in range(int(row['Susceptible'])):\n",
"# draw = list(np.random.multinomial(1, config))\n",
"# index = draw.index(max(draw))\n",
"# age = index * 5 + np.random.randint(0, 4)\n",
"# text = '\\n' + str(id_counter) + ',' + str(age) + ',' + str(int(row['cell'])) + ',' + str(int(row['microcell'])) + ',' + str(household)\n",
"# household = min(household + 1, int(row['household_number']))\n",
"# id_counter += 1\n",
"# with open('./input/data.csv', 'a') as f:\n",
"# f.write(text)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# import epios\n",
"# import pandas as pd\n",
"# a = pd.DataFrame({'ID': ['0.0.0.0','0.1.0.0','1.0.0.0','0.2.0.0','0.0.0.1','0.0.1.0'], 'age': [1, 81, 45, 33, 20, 60]})\n",
"# pro = epios.DataProcess(a)\n",
"# pro.pre_process()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 3 additions & 0 deletions epios/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .age_region import Sampler # noqa
from .non_responders import NonResponder # noqa
from .data_process import DataProcess # noqa
Loading