Skip to content

Commit

Permalink
Merge pull request #54 from anusii/develop
Browse files Browse the repository at this point in the history
Updating master for initial public release
  • Loading branch information
michaelpatrickpurcell authored Mar 21, 2021
2 parents caba865 + 5d6be14 commit 2794357
Show file tree
Hide file tree
Showing 35 changed files with 8,336 additions and 259 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ name: Python package

on:
push:
branches: [ master ]
branches: [ develop ]
pull_request:
branches: [ master ]
branches: [ develop ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand All @@ -34,4 +35,4 @@ jobs:
- name: Check formatting with black
run: |
pip install black
black --check relm tests
black --check relm tests
39 changes: 39 additions & 0 deletions .github/workflows/release-workflow.yml
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
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.11.1", features = ["extension-module"] }
rand = "0.7.3"
rand = "0.8.0"
rand_distr = "0.4.0"
rayon = "1.4.1"
numpy = "0.11.0"
rug = "1.11.0"
ndarray = "0.13.1"
21 changes: 21 additions & 0 deletions LICENSE
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.
159 changes: 159 additions & 0 deletions crisper_smalldb.ipynb
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
}
22 changes: 12 additions & 10 deletions docs-source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,37 @@
import sys

try:
build_folder = next(filter(lambda fn: "lib" in fn, os.listdir('../build')))
build_folder = next(filter(lambda fn: "lib" in fn, os.listdir("../build")))
except StopIteration:
RuntimeError("Project must be built before building docs. Run 'python setup.py install'.")
RuntimeError(
"Project must be built before building docs. Run 'python setup.py install'."
)

sys.path.insert(0, os.path.abspath(os.path.join('..', 'build', 'build_folder')))
sys.path.insert(0, os.path.abspath(os.path.join("..", "build", "build_folder")))

# -- Project information -----------------------------------------------------

project = 'Differential Privacy'
copyright = '2020, Kieran Ricardo, Michael Purcell'
author = 'Kieran Ricardo, Michael Purcell'
project = "Differential Privacy"
copyright = "2020, Kieran Ricardo, Michael Purcell"
author = "Kieran Ricardo, Michael Purcell"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.napoleon']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.coverage", "sphinx.ext.napoleon"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = '[en]'
language = "[en]"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -66,4 +68,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
2 changes: 1 addition & 1 deletion docs-source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Mechanisms
================================================

.. automodule:: relm.mechanisms
:members: LaplaceMechanism, GeometricMechanism, SnappingMechanism, AboveThreshold, SparseIndicator, SparseNumeric
:members: LaplaceMechanism, GeometricMechanism, SnappingMechanism, AboveThreshold, SparseIndicator, SparseNumeric, ReportNoisyMax, ExponentialMechanism


Indices and tables
Expand Down
Binary file not shown.
Loading

0 comments on commit 2794357

Please sign in to comment.