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_Tree
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_Tree(B, b)

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

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

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"Closest item to {q}: {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

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.tar.gz (8.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-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ldp_hierarchical_mechanism-0.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for ldp_hierarchical_mechanism-0.1.tar.gz
Algorithm Hash digest
SHA256 b578cc44387a8453bc8486288f7b19150687bb76f4ad8351338ec069d30346b2
MD5 662fc8adad26badb77e5022b74b4a67b
BLAKE2b-256 a170317e9716458eacfb206df9f0270556791ecbcf44dcbf4924b2a88cd28142

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ldp_hierarchical_mechanism-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8ccd25b28e402228e34f42b97d2ddc671ca4adbfd270b80afe6ca356ca6d323
MD5 0ba8d2471ddbba7ec5079e601523fef3
BLAKE2b-256 9ecd772a4a6733e771f53fe3e6dcb18d4115672585ed4d61505ac7b26431a482

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