Simple pure LDP frequency oracle implementations
Project description
Pure-LDP
pure-LDP is a Python package that provides simple implementations of pure LDP frequency oracles detailed in the paper "Locally Differentially Private Protocols for Frequency Estimation" by Wang et al
The package has implementations of all three main techniques:
- (Optimal) Unary Encoding - Under
pure_ldp.unary_encoding.ue_client
andpure_ldp.unary_encoding.ue_server
- (Summation/Thresholding) Histogram encoding - Under
pure_ldp.histogram_encoding.he_client
andpure_ldp.histogram_encoding.he_sever
- (Optimal) Local Hashing - Under
pure_ldp.local_hashing.lh_client
andpure_ldp.local_hashing.lh_server
The package also includes an implementation of the heavy hitter algorithm Prefix Extending Method (PEM)
- This is under
pure_ldp.prefix_extending.pem_client
andpure_ldp.prefix_extending.pem_server
There is also support for the frequency oracle Hadamard Response, the code implemented for this is simply a pure-LDP wrapper of hadamard_response
- This is under
pure_ldp.hadamard_response.hr_client
andpure_ldp.hadamard_response.hr_server
Installation
Use the package manager pip to install.
pip install pure-ldp
To upgrade to the latest version
pip install pure-ldp --upgrade
Requires numpy, scipy, xxhash, bitarray and bitstring
Usage
import numpy as np
from pure-ldp.local_hashing.lh_client import LHClient
from pure-ldp.local_hashing.lh_server import LHServer
# Using Optimal Local Hashing (OLH)
epsilon = 3 # Privacy budget of 3
d = 4 # For simplicity, we use a dataset with 4 possible data items
client_olh = LHClient(epsilon=epsilon, d=d, use_olh=True)
server_olh = LHServer(epsilon=epsilon, d=d, use_olh=True)
# Test dataset, every user has a number between 1-4, 10,000 users total
data = np.concatenate(([1]*4000, [2]*3000, [3]*2000, [4]*1000))
for item in data:
# Simulate client-side privatisation
priv_data = client_olh.privatise(item)
# Simulate server-side aggregation
server_olh.aggregate(priv_data)
# Simulate server-side estimation
print(server_olh.estimate(1)) # Should be approximately 4000 +- 200
See example.py for more examples.
Acknowledgements
- Some OLH code is based on the implementation by Tianhao Wang: repo
- The Hadamard Response code is just a wrapper of the k2khadamard.py code in the repo hadamard_response by Ziteng Sun
Contributing
If you feel like this package could be improved in any way, open an issue or make a pull request!
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pure-ldp-1.0.2.tar.gz
.
File metadata
- Download URL: pure-ldp-1.0.2.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecad1545e40b562ac8b935142986f05971bebed115a2609728386f2f32784d15 |
|
MD5 | 631200c01d55a7d5cd3a5d6e2e073c70 |
|
BLAKE2b-256 | e949677f1814dc4b6adf1a42bcdcd48f0c432b3b57e64549ba604145a68e6346 |
File details
Details for the file pure_ldp-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: pure_ldp-1.0.2-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dceb9cda21abd4f82fa71112ddfd56e1cfe09942fbe1326ca0ed6b067217b0f |
|
MD5 | 4a076fa5736875e3f8f18c0f5b525ff8 |
|
BLAKE2b-256 | a2a4d5656243a233faf84eed7d1cedb2182dbf50acda28ee947a001739fc30d7 |