Differential Privacy & Privacy Budget Accounting
Synthetic Test Data Sprint β Day 6
Protect aggregate queries and telemetry payloads against membership inference using the Laplace Mechanism and epsilon-delta privacy budget accounting.
Even when individual records are masked, repeated aggregate API queries (e.g. counts, sums, or histograms) can reconstruct an individual user's data via differencing attacks. Differential Privacy mathematically guarantees that an attacker cannot determine whether any single user was in the dataset by adding calibrated Laplace noise.
The official reference codebase for Day 6 is hosted in the repository. Clone the repository and navigate to day-6-differential-privacy to run the working solution.
git clone https://github.com/777abhi/synthetic-test-data-roadmap.git
cd synthetic-test-data-roadmap/day-6-differential-privacyInspect Differential Privacy Mechanism
Review Laplace noise generation, sensitivity scaling, and privacy budget accounting.
cat synthlab/diff_privacy.py | head -45import unittest
from synthlab.diff_privacy import LaplaceDPMechanism, PrivacyBudgetTracker
class TestDay6DifferentialPrivacy(unittest.TestCase):
def setUp(self):
self.dp = LaplaceDPMechanism()
self.tracker = PrivacyBudgetTracker(max_epsilon=2.0)
def test_higher_epsilon_yields_tighter_dispersion(self):
# Higher epsilon = less noise / higher data utility
noisy_high = self.dp.noisy_count(1000, epsilon=5.0)
noisy_low = self.dp.noisy_count(1000, epsilon=0.1)
def test_privacy_budget_exhaustion_raises_error(self):
tracker = PrivacyBudgetTracker(max_epsilon=1.0)
tracker.consume_budget(0.6)
tracker.consume_budget(0.4)
with self.assertRaises(PermissionError):
tracker.consume_budget(0.1)Execute Day 6 Tests
Run the differential privacy mechanism test suite.
npm run test:day6- Sampled calibrated noise from the Laplace distribution proportional to query sensitivity and epsilon.
- Understood the fundamental privacy-utility trade-off: higher epsilon yields higher accuracy, lower privacy.
- Enforced cumulative privacy budget accounting, rejecting queries once the maximum epsilon limit is reached.
π§ Knowledge Check
What does the parameter epsilon (Ξ΅) represent in Differential Privacy?