-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from anusii/develop
Updating master for initial public release
- Loading branch information
Showing
35 changed files
with
8,336 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Python package | ||
|
||
"on": | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.6, 3.7, 3.8, 3.9] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Build | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install . | ||
- name: Test with pytest | ||
run: | | ||
pip install .[tests] | ||
pytest tests | ||
- name: Check formatting with black | ||
run: | | ||
pip install black | ||
black --check relm tests |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 anusii | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import pandas as pd\n", | ||
"from relm.histogram import Histogram\n", | ||
"from relm.mechanisms import SmallDB\n", | ||
"import numpy as np\n", | ||
"from itertools import product\n", | ||
"import scipy.sparse as sps\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fp = 'examples/20200811_QLD_dummy_dataset_individual_v2.xlsx'\n", | ||
"df = pd.read_excel(fp)\n", | ||
"df.drop([\"NOTF_ID\", \"LGA\", \"HHS\"] + list(df.columns[12:]), axis=1, inplace=True)\n", | ||
"\n", | ||
"hist = Histogram(df)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"_cols = [\"AGEGRP5\", \"SEX\", \"INDIG_STATUS\"]\n", | ||
"queries = []\n", | ||
"\n", | ||
"# this creates the queries for:\n", | ||
"# df.groupby([\"AGEGRP5\", \"SEX\", \"INDIG_STATUS\", col]).count()\n", | ||
"# where col is in [\"HOSPITALISED\", \"VENTILATED\", \"ICU\", \"DIED_OF_CONDITION\"]\n", | ||
"for col in [\"HOSPITALISED\", \"VENTILATED\", \"ICU\", \"DIED_OF_CONDITION\"]:\n", | ||
" cols = _cols + [col,]\n", | ||
" vals = product(*[list(hist.column_sets[hist.column_dict[c]]) for c in cols])\n", | ||
" queries.extend(dict(zip(cols, val)) for val in vals)\n", | ||
"\n", | ||
"# this creates the queries for:\n", | ||
"# df.groupby([\"ONSET_DATE\", \"AGEGRP5\", \"INDIG_STATUS\", \"SEX\"]).count()\n", | ||
"cols = [\"ONSET_DATE\", \"AGEGRP5\", \"INDIG_STATUS\", \"SEX\"]\n", | ||
"vals = product(*[list(hist.column_sets[hist.column_dict[c]]) for c in cols])\n", | ||
"queries.extend(dict(zip(cols, val)) for val in vals)\n", | ||
"\n", | ||
"# this creates the queries for:\n", | ||
"# df.groupby([\"ONSET_DATE\", \"POSTCODE\"]).count()\n", | ||
"cols = [\"ONSET_DATE\", \"POSTCODE\"]\n", | ||
"vals = product(*[list(hist.column_sets[hist.column_dict[c]]) for c in cols])\n", | ||
"queries.extend(dict(zip(cols, val)) for val in vals)\n", | ||
"\n", | ||
"queries = sps.vstack([hist.get_query_vector(q) for q in queries])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"smalldb = SmallDB(epsilon=4, data=hist.get_db(), alpha=0.1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"CPU times: user 2min 1s, sys: 1.68 s, total: 2min 3s\n", | ||
"Wall time: 2min 3s\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%time x = smalldb.release(queries)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"array([0, 0, 0, ..., 1, 0, 0], dtype=uint64)" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"x" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"28554240" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"len(x)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.