Created
March 31, 2026 21:58
-
-
Save Shoeboxam/14a5d0cd57515ed773f61b391a602caf to your computer and use it in GitHub Desktop.
Convert approx-zCDP to approx-DP with OpenDP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import opendp.prelude as dp | |
| def approx_zcdp_to_approx_dp(rho: float, delta: float, delta_prime: float): | |
| """ | |
| Convert a (rho, delta) approx-zCDP guarantee into an (eps, delta + delta_prime) approx-DP guarantee | |
| using OpenDP's measure casting and fix-delta combinators. | |
| Returns: | |
| eps (float): epsilon after conversion | |
| delta (float): delta + delta_prime | |
| """ | |
| from opendp._internal import _make_measurement | |
| # given a mechanism that satisfies rho, delta... | |
| m_base = _make_measurement( | |
| input_domain=dp.atom_domain(T=bool), | |
| input_metric=dp.discrete_distance(), | |
| output_measure=dp.approximate(dp.zero_concentrated_divergence()), | |
| function=lambda _: (), | |
| privacy_map=lambda _: (rho, delta), | |
| ) | |
| # convert (ρ, δ) -> (δ(ε)), δ) -> (ε, δ) | |
| meas_curve = dp.c.make_zCDP_to_approxDP(m_base) | |
| meas_fixed = dp.c.make_fix_delta(meas_curve, delta=delta + delta_prime) | |
| # Since the privacy map is constant, any d_in gives the same result; use d_in=1 by convention | |
| return meas_fixed.map(1) | |
| dp.enable_features("contrib") | |
| print(approx_zcdp_to_approx_dp(0.1, 5e-9, 5e-9)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment