Skip to main content

Local Differential Privacy for Range Queries

Project description

Hierarchical Mechanism for LDP

it is an implementation of the Hierarchical Mechanism in

Kulkarni, Tejas, Graham Cormode, and Divesh Srivastava. "Answering range queries under local differential privacy." arXiv preprint arXiv:1812.10942 (2018).

The LDP frequency protocol are implemented from the library https://github.com/Samuel-Maddock/pure-LDP

The library is intended for testing the LDP hierarchical mechanism locally.

Install

pip install hierarchical-mechanism-LDP

Usage

It is based on the class Private_Tree that implements the hierarchical mechanism for local differential privacy. The class has the following methods:

Initialization

# Initialization

from hierarchical_mechanism_LDP import Private_TreeBary
import numpy as np

B = 4000  # bound of the data, i.e., the data is in [0, B]
b = 4  # branching factor of the tree
eps = 1  # privacy budget
q = 0.4  # quantile to estimate
protocol = 'unary_encoding'  # protocol to use for LDP frequency estimation

tree = Private_TreeBary(B, b)

data = np.random.randint(0, B, 100000)  # generate random data

tree.update_tree(data, eps, protocol, post_process=True)  # update the tree with the data

The post_process boolean parameter is used to apply the post-processing step of the hierarchical mechanism. The post-processing step is used to improve the accuracy of the mechanism. The post-processing step is applied by default.

Post-processing applies the Hierarchial Mechanism proposed by Hay et al. in

M. Hay, V. Rastogi, G. Miklau, and D. Suciu. Boosting the accuracy of differentially private histograms through consistency. PVLDB, 3(1):1021–1032, 2010.

Quantile estimation

You can estimate the quantile of the data with Private_Tree.get_quantile(q), where q is the quantile to estimate.

# get quantile of the data
true_quantile = np.quantile(data, q)
private_quantile = tree.get_quantile(q)  # get the quantile
print(f"DP quantile: {private_quantile}")
print(f"True quantile: {true_quantile}")

Result

Private quantile: 1591
True quantile: 1598.0

Range Queries

You can estimate the range queries of the data with Private_Tree.get_range_query(a, b), where a and b are the bounds of the range query. Additionally, you can return a normalized range query.

left = 1000
right = 2000
true_range_query = np.sum(data >= left) - np.sum(data >= right)
private_range_query = tree.get_range_query(left, right, normalized=False)
print(f"True range query: {true_range_query}")
print(f"Private range query: {private_range_query}")

Result

True range query: 24980
Private range query: 25514.970123615636

Binning

Given a list of quantiles and an error alpha, you can create bins of the form [q_i - alpha, q_i + alpha] with Private_Tree.get_bins(quantiles, alpha). The bins are returned as a list of tuples.

# test binning
quantiles = [0.25, 0.50, 0.75]
alpha = 0.1
bins = tree.get_bins(quantiles, alpha)
print(bins)

Result

[(np.int64(664), np.int64(1441)), (np.int64(1591), np.int64(2562)), (np.int64(2669), np.int64(3365))]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ldp_hierarchical_mechanism-0.1.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ldp_hierarchical_mechanism-0.1.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file ldp_hierarchical_mechanism-0.1.1.tar.gz.

File metadata

File hashes

Hashes for ldp_hierarchical_mechanism-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5d01b2c54bec4403047ad351b437e8def16dc6ef8efee1ba38b7a4bb19392cf6
MD5 0b101b00c1333790f7910a705c94a3b6
BLAKE2b-256 7ec7a80b19a73010cf6d2a422950e33a78803bfffaccaa1fc1ce8cd8513ff42f

See more details on using hashes here.

File details

Details for the file ldp_hierarchical_mechanism-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ldp_hierarchical_mechanism-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd4796d129aa11f1406f7110286f8091f252237cd702fca460de7fe129269bcf
MD5 162441e2497801cc8ad70f3874df68c3
BLAKE2b-256 af95f44eca818c52caaefb1f87a92c605ae67e29c76ff47c7b75f48c88ed8d65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page