Last active
December 2, 2019 03:41
-
-
Save NTT123/ccb5ecbb7f737c2630624dda463201dd to your computer and use it in GitHub Desktop.
DP demo.ipynb
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "DP demo.ipynb", | |
"provenance": [], | |
"private_outputs": true, | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/NTT123/ccb5ecbb7f737c2630624dda463201dd/dp-demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "bpePf2AZtYkw", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## Install Tools/Libraries" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "JG7nn9cyGote", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## compilation\n", | |
"apt install g++ unzip zip build-essential bison flex \n", | |
"\n", | |
"## download from google drive\n", | |
"pip install gdown\n", | |
"\n", | |
"## bazel build system\n", | |
"wget https://github.com/bazelbuild/bazel/releases/download/1.2.1/bazel-1.2.1-installer-linux-x86_64.sh\n", | |
"chmod +x bazel-1.2.1-installer-linux-x86_64.sh\n", | |
"## install bazel\n", | |
"./bazel-1.2.1-installer-linux-x86_64.sh --user" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "_vk6EJiRtfuP", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## Compile Postgres + differential-privacy library" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Wk1P8KZRj4uo", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## activate bazel\n", | |
"source /home/scriptsuser/.bazel/bin/bazel-complete.bash" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "FCcGIPsXGiGL", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## clone modified google differrential privacy library\n", | |
"git clone https://github.com/NTT123/differential-privacy.git" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "4bZsfWgGHKc9", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"cd differential-privacy/" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "JVlisUJlNGgj", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## download, compile postgresql\n", | |
"wget https://ftp.postgresql.org/pub/source/v11.6/postgresql-11.6.tar.bz2\n", | |
"tar xjf postgresql-11.6.tar.bz2\n", | |
"cd postgresql-11.6; ./configure; make -j2\n", | |
"\n", | |
"# install postgres + add postgres user\n", | |
"sudo -s\n", | |
"make install; echo -e \"abc123\\nabc123\\n\\n\\n\\n\\n\\n\\n\\n\" | adduser postgres; mkdir /usr/local/pgsql/data; chown postgres /usr/local/pgsql/data\n", | |
"exit # back to ScriptUsers" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "1n21Z7TFkxYA", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## go back to differential privacy directory\n", | |
"cd .." | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "MMfrYnasOiH7", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## fix build config (from macOS -> Linux)\n", | |
"sed -i 's/darwin-fastbuild/k8-fastbuild/g' differential_privacy/postgres/BUILD" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "JnNt2gxQk-PB", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## build dp library\n", | |
"bazel build differential_privacy/..." | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "A7XxnUUqRawT", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## build and install dp extention for postgres\n", | |
"export PG_DIR=/usr/local/pgsql; export PATH=\"$PATH:$HOME/bin\"; cd /content/differential-privacy; ./differential_privacy/postgres/install_extension.sh" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "NVP8AbIIp0qo", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## Run postgres server + Initialize database" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Tr8GZGSBMZtn", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## start postgres server under posgres user\n", | |
"su - postgres\n", | |
"/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data\n", | |
"/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start\n", | |
"exit" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "6L9RyURwQgPc", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## create a database `test`\n", | |
"sudo -u postgres /usr/local/pgsql/bin/createdb test" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "C-xKi6jgTVsQ", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## download csv dataset\n", | |
"PATH=/home/scriptsuser/.local/bin gdown https://drive.google.com/uc?id=1_Iq_UWUngLX6nSGycqb8N5_9wBJ_cJ8E" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "N9kQdaGHT6g6", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## create an SQL script \n", | |
"\n", | |
"cat > init.sql <<EOL\n", | |
"select current_database();\n", | |
"create table transactions (InvoiceNo int,StockCode text,Description text,Quantity int,InvoiceDate text,UnitPrice numeric,CustomerID int,Country text);\n", | |
"\n", | |
"\\COPY transactions (InvoiceNo,StockCode,Description,Quantity,InvoiceDate,UnitPrice,CustomerID,Country) FROM './onlineretail.csv' CSV HEADER DELIMITER ',' encoding 'windows-1251';\n", | |
"\n", | |
"CREATE EXTENSION anon_func;\n", | |
"EOL" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "FuPNEjv-RRiC", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"## run initial SQL script\n", | |
"sudo -u postgres /usr/local/pgsql/bin/psql -d test -f init.sql" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment