Privacy Lab 03 — Differential Privacy
WARMUP: Chapter 8 (k-anonymity, l-diversity, differential privacy).
The idea
k-anonymity (Lab 02) transforms a dataset and degrades as auxiliary data grows. Differential privacy (DP) instead adds calibrated noise to query results so the output is provably almost identical whether or not any single individual is in the data — a mathematical guarantee bounded by ε (smaller ε = more privacy, more noise). It underlies the US Census 2020 and Apple/Google telemetry. This lab implements the Laplace mechanism, sensitivity for counts and bounded sums (with clipping), sequential composition of an ε budget, and randomized response (local DP).
What you build (lab.py)
laplace_scale(sensitivity, epsilon)=sensitivity/epsilon.laplace_mechanism(true_value, sensitivity, epsilon, noise_fn)— noise injectable for deterministic tests; smaller ε ⇒ larger noise.clamp,private_count(sensitivity 1),private_bounded_sum(clip to[lower,upper], sensitivityupper-lower).PrivacyBudget— sequential composition: ε's add, can't exceed the total.randomized_response(true_bit, first_coin, second_coin)— plausible-deniability local DP.
Cases the tests cover
- Scale math and rejection of bad ε/sensitivity; injected-noise mechanism; smaller ε ⇒ more noise; count sensitivity = 1; bounded-sum clipping and range sensitivity; budget composition and a budget-exceeded error; randomized response's truthful/coin-flip branches.
Run
pip install -r requirements.txt
LAB_MODULE=solution pytest -q
pytest -q
Hardening / extensions
- Add the Gaussian mechanism and (ε, δ)-DP; add advanced composition.
- Add the exponential mechanism for non-numeric outputs.
- Build a small DP query API with per-analyst budgets and report the accuracy/privacy tradeoff.
Interview / resume
"Implemented the Laplace mechanism with count/bounded-sum sensitivity and clipping, an ε-budget with sequential composition, and randomized response — demonstrating DP's per-query, auxiliary-data-proof guarantee versus k-anonymity's dataset transformation."
Limitations: pure ε-DP with the Laplace mechanism (no Gaussian/(ε,δ), no advanced composition); noise is injectable for testing, so production use needs a vetted CSPRNG-backed sampler.