Algorithm Search⌘K

Algorithmcore

Gaussian mechanism

Also called Gaussian noise mechanism.

Adds Gaussian noise scaled to the l2 sensitivity, which gives (epsilon, delta)-differential privacy and composes well.

Time
O(k + T) worst
Space
O(k) extra
Where
T = the number of bisection steps of the analytic calibration; k = the number of coordinates of the query
Properties
randomizedrandomized
Origin
Cynthia Dwork, Krishnaram Kenthapadi, Frank McSherry, Ilya Mironov, Moni Naor, 2006

The Gaussian mechanism answers a numeric query about a private dataset with independent normal noise added to each coordinate. The noise has standard deviation σ\sigma proportional to the ℓ2\ell_2 sensitivity Δ2f\Delta_2 f, and the output is (ε,δ)(\varepsilon, \delta)-differentially private. It is never ε\varepsilon-DP with δ=0\delta = 0. Its strength is that it scales to the ℓ2\ell_2 norm and not to the ℓ1\ell_1 norm, so a vector of kk counts needs noise of size about k\sqrt k per count in place of kk, and that its privacy loss is itself a normal random variable, so many runs compose in a simple closed form. It is the noise of DP-SGD.

In plain words

You want to publish many numbers about a table at once, for example 100 counts, and one person can change each count by at most one. The Laplace mechanism must protect the worst total change, which is 100, so it adds a lot of noise to each count. The Gaussian mechanism measures the change of the whole vector as a length, which is only 100=10\sqrt{100} = 10. It adds bell-shaped noise of that scale to each count.

The price is a small δ\delta. Bell-shaped noise has thin tails. On a rare output far out in a tail, the ratio between the probabilities under two neighboring tables can be very large. So the guarantee is "the ratio is at most eεe^{\varepsilon}, except on events of total probability about δ\delta". You choose δ\delta much smaller than one over the number of people.

The problem

The input is a dataset x=(x1,…,xn)x = (x_1, \ldots, x_n) of records from a universe X\mathcal X, a query ff that maps datasets to Rk\mathbb R^k, a number Δ≥Δ2f\Delta \ge \Delta_2 f, and privacy parameters ε≥0\varepsilon \ge 0 and 0<δ<10 < \delta < 1. Here

Δ2f=max⁡x∼x′∥f(x)−f(x′)∥2,\Delta_2 f = \max_{x \sim x'} \lVert f(x) - f(x') \rVert_2 ,

and x∼x′x \sim x' means that xx and x′x' are neighbors. The page uses add/remove neighbors (one record added or removed) unless it says otherwise. A histogram has Δ2=1\Delta_2 = 1 under add/remove and Δ2=2\Delta_2 = \sqrt 2 under replace (one record changes, so one count falls and one rises). Note that 2<2=Δ1\sqrt 2 < 2 = \Delta_1 under replace.

The output is a random vector y∈Rky \in \mathbb R^k. The map from xx to the distribution of yy must be (ε,δ)(\varepsilon, \delta)-DP: Pr⁡[y∈S∣x]≤eεPr⁡[y∈S∣x′]+δ\Pr[y \in S \mid x] \le e^{\varepsilon} \Pr[y \in S \mid x'] + \delta for all neighbors and all sets SS.

The normal distribution N(0,σ2)N(0, \sigma^2) has density 1σ2πe−z2/(2σ2)\frac{1}{\sigma\sqrt{2\pi}} e^{-z^2/(2\sigma^2)}. We write Φ\Phi for the standard normal distribution function. The site has no page on the normal distribution, so this is its definition here.

The algorithm

There are two ways to choose σ\sigma. The classical bound of Dwork and Roth is a closed form, and it is proved only for 0<ε<10 < \varepsilon < 1. The analytic bound of Balle and Wang is the smallest σ\sigma that works, for every ε≥0\varepsilon \ge 0, and it is found by bisection on the function

δΔ(s)=Φ(Δ2s−εsΔ)−eε Φ(−Δ2s−εsΔ),\delta_\Delta(s) = \Phi\Big(\frac{\Delta}{2s} - \frac{\varepsilon s}{\Delta}\Big) - e^{\varepsilon}\, \Phi\Big(-\frac{\Delta}{2s} - \frac{\varepsilon s}{\Delta}\Big),

which falls as ss grows.

  1. GAUSSIAN-MECHANISM(x, f, Delta, epsilon, delta) ▷ Delta >= the l2 sensitivity of f
  2. 1sigma <- the smallest s with delta_Delta(s) <= delta ▷ analytic; classical: Delta sqrt(2 ln(1.25/delta)) / epsilon
  3. 2v <- f(x) ▷ v = (v_1, ..., v_k)
  4. 3for i <- 1 to k do
  5. 4draw z from N(0, sigma^2)
  6. 5y_i <- v_i + z
  7. 6return y = (y_1, ..., y_k)

Line L1 does not read the data. It depends only on Δ\Delta, ε\varepsilon and δ\delta, so it can run once and be reused for every query with the same parameters. The code doubles an upper end until δΔ\delta_\Delta is at most δ\delta, then halves the bracket TT times, and returns the upper end of the final bracket, so the returned σ\sigma is never too small. Line L2 is the only line that reads the data. Line L4 draws a fresh normal sample for each coordinate, and the samples are never published or reused.

The code on this site uses floats and the seeded generator random.Random.gauss, so that the tests can repeat each run. A deployment needs a cryptographic source of randomness and an exact sampler, because float noise leaks through its low-order bits (Mironov 2012). The discrete Gaussian mechanism adds integer noise with an exact sampler (Canonne, Kamath and Steinke 2020).

Example

The universe is {0,1,2}\{0, 1, 2\} and the dataset is x=(0,0,1,2,2,2)x = (0, 0, 1, 2, 2, 2), so the histogram is f(x)=(2,1,3)f(x) = (2, 1, 3) with Δ2f=1\Delta_2 f = 1 under add/remove neighbors. Take ε=1\varepsilon = 1 and δ=10−5\delta = 10^{-5}. The classical bound does not apply, because it needs ε<1\varepsilon < 1. Line L1 with the analytic bound gives σ=3.730632\sigma = 3.730632. Assume that line L4 draws z=σgz = \sigma g for the standard normal values g=0.5,−1.2,0.1g = 0.5, -1.2, 0.1.

step ii viv_i gg zz (line L4) yiy_i (line L5)
L1, L2 σ=3.730632\sigma = 3.730632, v=(2,1,3)v = (2, 1, 3)
L3 to L5 1 2 0.5 1.865316 3.865316
L3 to L5 2 1 −1.2-1.2 −4.476758-4.476758 −3.476758-3.476758
L3 to L5 3 3 0.1 0.373063 3.373063
L6 y=(3.865316,−3.476758,3.373063)y = (3.865316, -3.476758, 3.373063)

A negative count is a normal output. Rounding and clamping it to [0,n][0, n] is post-processing and keeps the guarantee.

The two calibrations for Δ=1\Delta = 1, δ=10−5\delta = 10^{-5}:

ε\varepsilon classical σ\sigma analytic σ\sigma ratio of the variances
0.1 48.448053 30.749566 0.403
0.5 9.689611 7.031827 0.527
0.9 5.383117 4.106624 0.582
1 not proved 3.730632
2 not proved 1.993812

So the analytic bound removes 40 to 60 percent of the variance in this range. At the classical σ=9.6896\sigma = 9.6896 for ε=0.5\varepsilon = 0.5, the exact δΔ\delta_\Delta is only 1.6×10−81.6 \times 10^{-8}, far below the target 10−510^{-5}. Two more check values: with Δ=1\Delta = 1 and ε=1\varepsilon = 1, σ=1\sigma = 1 gives the exact δ=0.126937\delta = 0.126937 and σ=2\sigma = 2 gives δ=0.0068296\delta = 0.0068296.

Correctness

Theorem (classical; Dwork-Roth Theorem 3.22, proved as Theorem A.1). Let 0<ε<10 < \varepsilon < 1 and 0<δ<10 < \delta < 1. If σ≥cΔ/ε\sigma \ge c\Delta/\varepsilon with c2≥2ln⁡(1.25/δ)c^2 \ge 2\ln(1.25/\delta) and Δ≥Δ2f\Delta \ge \Delta_2 f, then GAUSSIAN-MECHANISM is (ε,δ)(\varepsilon, \delta)-DP. Dwork and Roth state it with a strict inequality for c2c^2; the proof of this page covers equality, which is what the code uses.

Theorem (analytic; Balle and Wang 2018, Theorem 8). For every ε≥0\varepsilon \ge 0 and δ∈[0,1]\delta \in [0, 1], adding N(0,σ2I)N(0, \sigma^2 I) noise to a query of ℓ2\ell_2 sensitivity Δ\Delta is (ε,δ)(\varepsilon, \delta)-DP if and only if δΔ(σ)≤δ\delta_\Delta(\sigma) \le \delta.

The key step is that the privacy loss is normal. For neighbors with D=∥f(x)−f(x′)∥2D = \lVert f(x) - f(x') \rVert_2 and μ=D/σ\mu = D/\sigma, the loss L=ln⁡(px(Y)/px′(Y))L = \ln(p_x(Y)/p_{x'}(Y)) with Y∼M(x)Y \sim M(x) has the distribution N(μ2/2,μ2)N(\mu^2/2, \mu^2), because only the noise along the direction of f(x)−f(x′)f(x) - f(x') matters. The tight δ\delta for this pair is Pr⁡[L>ε]−eεPr⁡[L′>ε]\Pr[L > \varepsilon] - e^{\varepsilon}\Pr[L' > \varepsilon], with L′∼N(−μ2/2,μ2)L' \sim N(-\mu^2/2, \mu^2) the loss under x′x', and this is exactly δD(σ)\delta_D(\sigma). It grows with DD, so the worst pair has D=ΔD = \Delta. The full proofs, with the proof of the classical bound from the normal tail, are in the correctness proof of this page.

Accuracy. Each coordinate has error N(0,σ2)N(0, \sigma^2), so Pr⁡[∣yi−f(x)i∣>t]=2Φ(−t/σ)\Pr[|y_i - f(x)_i| > t] = 2\Phi(-t/\sigma). By a union bound, with probability at least 1−β1 - \beta all kk errors are at most σ2ln⁡(2k/β)\sigma \sqrt{2 \ln(2k/\beta)}. The total squared error has mean kσ2k\sigma^2.

Proof: The Gaussian mechanism is (epsilon, delta)-DP under the analytic and the classical calibrationfull

We work in the real RAM, where line L4 draws an exact sample of N(0,σ2)N(0, \sigma^2). Fix a neighbor relation ∼\sim, a query ff with values in Rk\mathbb R^k, a number Δ≥Δ2f=max⁡x∼x′∥f(x)−f(x′)∥2\Delta \ge \Delta_2 f = \max_{x \sim x'} \lVert f(x) - f(x') \rVert_2, ε≥0\varepsilon \ge 0 and δ∈(0,1)\delta \in (0, 1). Write Φ\Phi for the standard normal distribution function, Φˉ=1−Φ\bar\Phi = 1 - \Phi, and φ\varphi for the standard normal density. The output of line L6 is M(x)=f(x)+ZM(x) = f(x) + Z with Z∼N(0,σ2Ik)Z \sim N(0, \sigma^2 I_k), because each pass of line L3 draws a fresh independent sample.

For D>0D > 0 and s>0s > 0 let

δD(s)=Φ(D2s−εsD)−eε Φ(−D2s−εsD).\delta_D(s) = \Phi\Big(\frac{D}{2s} - \frac{\varepsilon s}{D}\Big) - e^{\varepsilon}\, \Phi\Big(-\frac{D}{2s} - \frac{\varepsilon s}{D}\Big).

Lemma 1 (the privacy loss is normal). Fix x∼x′x \sim x' with v=f(x)−f(x′)v = f(x) - f(x') and D=∥v∥2>0D = \lVert v \rVert_2 > 0, and let μ=D/σ\mu = D/\sigma. Let pp and qq be the densities of M(x)M(x) and M(x′)M(x'), and ℓ(y)=ln⁡(p(y)/q(y))\ell(y) = \ln(p(y)/q(y)). If Y∼M(x)Y \sim M(x), then ℓ(Y)∼N(μ2/2,μ2)\ell(Y) \sim N(\mu^2/2, \mu^2). If Y′∼M(x′)Y' \sim M(x'), then ℓ(Y′)∼N(−μ2/2,μ2)\ell(Y') \sim N(-\mu^2/2, \mu^2).

Proof. The normalizing constants of pp and qq are equal, so ℓ(y)=(∥y−f(x′)∥2−∥y−f(x)∥2)/(2σ2)\ell(y) = (\lVert y - f(x') \rVert^2 - \lVert y - f(x) \rVert^2)/(2\sigma^2). For Y=f(x)+ZY = f(x) + Z, we have Y−f(x′)=Z+vY - f(x') = Z + v, so

ℓ(Y)=∥Z+v∥2−∥Z∥22σ2=D2+2⟨Z,v⟩2σ2.\ell(Y) = \frac{\lVert Z + v \rVert^2 - \lVert Z \rVert^2}{2\sigma^2} = \frac{D^2 + 2\langle Z, v \rangle}{2\sigma^2}.

The scalar ⟨Z,v⟩\langle Z, v \rangle is a linear combination of independent normal coordinates, so it is N(0,σ2D2)N(0, \sigma^2 D^2). Hence ℓ(Y)\ell(Y) is normal with mean D2/(2σ2)=μ2/2D^2/(2\sigma^2) = \mu^2/2 and variance 4σ2D2/(4σ4)=μ24\sigma^2 D^2/(4\sigma^4) = \mu^2. For Y′=f(x′)+ZY' = f(x') + Z, Y′−f(x)=Z−vY' - f(x) = Z - v and ℓ(Y′)=(∥Z∥2−∥Z−v∥2)/(2σ2)=(2⟨Z,v⟩−D2)/(2σ2)\ell(Y') = (\lVert Z \rVert^2 - \lVert Z - v \rVert^2)/(2\sigma^2) = (2\langle Z, v\rangle - D^2)/(2\sigma^2), which is N(−μ2/2,μ2)N(-\mu^2/2, \mu^2). □\square

Lemma 2 (the tight delta of one pair). For x∼x′x \sim x' as in Lemma 1,

sup⁡S(Pr⁡[M(x)∈S]−eεPr⁡[M(x′)∈S])=δD(σ).\sup_S \big(\Pr[M(x) \in S] - e^{\varepsilon}\Pr[M(x') \in S]\big) = \delta_D(\sigma).

Proof. For any measurable SS, Pr⁡[M(x)∈S]−eεPr⁡[M(x′)∈S]=∫S(p−eεq)\Pr[M(x) \in S] - e^{\varepsilon}\Pr[M(x') \in S] = \int_S (p - e^{\varepsilon} q). This is largest for S∗={y:p(y)>eεq(y)}={y:ℓ(y)>ε}S^* = \{y : p(y) > e^{\varepsilon} q(y)\} = \{y : \ell(y) > \varepsilon\}, because S∗S^* holds every point where the integrand is positive and no other point. So the supremum is Pr⁡[ℓ(Y)>ε]−eεPr⁡[ℓ(Y′)>ε]\Pr[\ell(Y) > \varepsilon] - e^{\varepsilon}\Pr[\ell(Y') > \varepsilon]. By Lemma 1,

Pr⁡[ℓ(Y)>ε]=Φˉ(ε−μ2/2μ)=Φ(μ2−εμ),Pr⁡[ℓ(Y′)>ε]=Φ(−μ2−εμ).\Pr[\ell(Y) > \varepsilon] = \bar\Phi\Big(\frac{\varepsilon - \mu^2/2}{\mu}\Big) = \Phi\Big(\frac{\mu}{2} - \frac{\varepsilon}{\mu}\Big), \qquad \Pr[\ell(Y') > \varepsilon] = \Phi\Big(-\frac{\mu}{2} - \frac{\varepsilon}{\mu}\Big).

With μ=D/σ\mu = D/\sigma, μ/2=D/(2σ)\mu/2 = D/(2\sigma) and ε/μ=εσ/D\varepsilon/\mu = \varepsilon\sigma/D, which gives δD(σ)\delta_D(\sigma). □\square

The same value comes out for the pair in the other order, because the pair (x′,x)(x', x) has the same DD.

Lemma 3 (monotonicity). For fixed ε≥0\varepsilon \ge 0, the function g(μ)=Φ(μ/2−ε/μ)−eεΦ(−μ/2−ε/μ)g(\mu) = \Phi(\mu/2 - \varepsilon/\mu) - e^{\varepsilon}\Phi(-\mu/2 - \varepsilon/\mu) is strictly increasing on μ>0\mu > 0. Hence δD(σ)=g(D/σ)\delta_D(\sigma) = g(D/\sigma) grows with DD and falls with σ\sigma.

Proof. Let a=μ/2−ε/μa = \mu/2 - \varepsilon/\mu and b=−μ/2−ε/μb = -\mu/2 - \varepsilon/\mu. Then a2−b2=(a−b)(a+b)=μ⋅(−2ε/μ)=−2εa^2 - b^2 = (a - b)(a + b) = \mu \cdot (-2\varepsilon/\mu) = -2\varepsilon, so φ(b)=φ(a) e(a2−b2)/2=e−εφ(a)\varphi(b) = \varphi(a)\, e^{(a^2 - b^2)/2} = e^{-\varepsilon}\varphi(a). The derivative is

g′(μ)=φ(a)(12+εμ2)−eεφ(b)(−12+εμ2)=φ(a)(12+εμ2+12−εμ2)=φ(a)>0.□g'(\mu) = \varphi(a)\Big(\frac12 + \frac{\varepsilon}{\mu^2}\Big) - e^{\varepsilon}\varphi(b)\Big(-\frac12 + \frac{\varepsilon}{\mu^2}\Big) = \varphi(a)\Big(\frac12 + \frac{\varepsilon}{\mu^2} + \frac12 - \frac{\varepsilon}{\mu^2}\Big) = \varphi(a) > 0. \quad \square

Theorem 1 (analytic calibration; Balle and Wang 2018, Theorem 8). If δΔ(σ)≤δ\delta_\Delta(\sigma) \le \delta, then MM is (ε,δ)(\varepsilon, \delta)-DP. If some pair of neighbors has D=ΔD = \Delta, the converse also holds.

Proof. For a pair with D=0D = 0 the two output distributions are equal. For a pair with 0<D≤Δ0 < D \le \Delta, Lemma 2 and Lemma 3 give Pr⁡[M(x)∈S]−eεPr⁡[M(x′)∈S]≤δD(σ)≤δΔ(σ)≤δ\Pr[M(x) \in S] - e^{\varepsilon}\Pr[M(x') \in S] \le \delta_D(\sigma) \le \delta_\Delta(\sigma) \le \delta for every SS, which is the definition. Conversely, for a pair with D=ΔD = \Delta, Lemma 2 gives a set S∗S^* with difference exactly δΔ(σ)\delta_\Delta(\sigma), so (ε,δ)(\varepsilon, \delta)-DP needs δΔ(σ)≤δ\delta_\Delta(\sigma) \le \delta. □\square

Lemma 4 (line L1 with the analytic bound). The bisection of line L1 stops and returns a σ\sigma with δΔ(σ)≤δ\delta_\Delta(\sigma) \le \delta, within relative distance 10−1210^{-12} of the smallest such value.

Proof. As s→∞s \to \infty, δΔ(s)→0\delta_\Delta(s) \to 0: for ε>0\varepsilon > 0 both arguments of Φ\Phi tend to −∞-\infty, and for ε=0\varepsilon = 0 the value is Φ(Δ/(2s))−Φ(−Δ/(2s))→0\Phi(\Delta/(2s)) - \Phi(-\Delta/(2s)) \to 0. So the doubling loop stops with δΔ(hi)≤δ\delta_\Delta(hi) \le \delta. As s→0s \to 0, the first argument tends to +∞+\infty and the second to −∞-\infty, so δΔ(s)→1>δ\delta_\Delta(s) \to 1 > \delta, and the halving loop stops with δΔ(lo)>δ\delta_\Delta(lo) > \delta. Each bisection step keeps the invariant δΔ(lo)>δ≥δΔ(hi)\delta_\Delta(lo) > \delta \ge \delta_\Delta(hi). By Lemma 3, the set {s:δΔ(s)≤δ}\{s : \delta_\Delta(s) \le \delta\} is an interval [s∗,∞)[s^*, \infty), so lo<s∗≤hilo < s^* \le hi at every step. The loop stops when hi−lo≤10−12 hihi - lo \le 10^{-12}\, hi, and it returns hihi. □\square

Theorem 2 (classical calibration; Dwork-Roth Theorem 3.22 and Theorem A.1). Let 0<ε<10 < \varepsilon < 1, 0<δ<10 < \delta < 1, c=2ln⁡(1.25/δ)c = \sqrt{2\ln(1.25/\delta)} and σ≥cΔ/ε\sigma \ge c\Delta/\varepsilon. Then MM is (ε,δ)(\varepsilon, \delta)-DP.

Proof. Fix a pair with 0<D≤Δ0 < D \le \Delta and let μ=D/σ≤ε/c\mu = D/\sigma \le \varepsilon/c. By Lemma 2 the worst difference is at most Pr⁡[ℓ(Y)>ε]=Φˉ(tμ)\Pr[\ell(Y) > \varepsilon] = \bar\Phi(t_\mu) with tμ=ε/μ−μ/2t_\mu = \varepsilon/\mu - \mu/2. The map μ↦ε/μ−μ/2\mu \mapsto \varepsilon/\mu - \mu/2 is decreasing, so tμ≥t=c−ε/(2c)t_\mu \ge t = c - \varepsilon/(2c), and Φˉ(tμ)≤Φˉ(t)\bar\Phi(t_\mu) \le \bar\Phi(t). We show Φˉ(t)≤δ\bar\Phi(t) \le \delta in two cases. Since ε<1\varepsilon < 1 and c−1/(2c)c - 1/(2c) is increasing in cc, t>c−1/(2c)t > c - 1/(2c).

Case δ≥0.54\delta \ge 0.54. Then c≥2ln⁡1.25=0.668047c \ge \sqrt{2\ln 1.25} = 0.668047, so t>0.668047−0.748450=−0.080403t > 0.668047 - 0.748450 = -0.080403 and Φˉ(t)<Φ(0.080403)=0.532041<δ\bar\Phi(t) < \Phi(0.080403) = 0.532041 < \delta.

Case δ<0.54\delta < 0.54. Then c>2ln⁡(1.25/0.54)=1.295623c > \sqrt{2\ln(1.25/0.54)} = 1.295623, so t>1.295623−0.385915=0.909708>0t > 1.295623 - 0.385915 = 0.909708 > 0. The tail bound Φˉ(t)≤φ(t)/t\bar\Phi(t) \le \varphi(t)/t for t>0t > 0 holds because ∫t∞φ(u) du≤∫t∞(u/t)φ(u) du=φ(t)/t\int_t^\infty \varphi(u)\,du \le \int_t^\infty (u/t)\varphi(u)\,du = \varphi(t)/t. Also t2=c2−ε+ε2/(4c2)>c2−1t^2 = c^2 - \varepsilon + \varepsilon^2/(4c^2) > c^2 - 1, so e−t2/2<e1/2e−c2/2=e1/2δ/1.25=1.318977 δe^{-t^2/2} < e^{1/2} e^{-c^2/2} = e^{1/2}\delta/1.25 = 1.318977\,\delta. Hence

Φˉ(t)≤e−t2/2t2π<1.318977 δ0.909708×2.506628=0.578437 δ<δ.\bar\Phi(t) \le \frac{e^{-t^2/2}}{t\sqrt{2\pi}} < \frac{1.318977\,\delta}{0.909708 \times 2.506628} = 0.578437\,\delta < \delta.

In both cases every pair has difference at most δ\delta for every set SS. □\square

Dwork and Roth assume c2>2ln⁡(1.25/δ)c^2 > 2\ln(1.25/\delta); the proof above also covers equality, which is the value line L1 uses. The bound is far from tight: for Δ=1\Delta = 1, ε=0.5\varepsilon = 0.5 and δ=10−5\delta = 10^{-5}, the exact δΔ\delta_\Delta at the classical σ=9.6896\sigma = 9.6896 is 1.6×10−81.6 \times 10^{-8}.

Theorem 3 (accuracy). For 0<β<10 < \beta < 1, with probability at least 1−β1 - \beta, max⁡i∣yi−f(x)i∣≤σ2ln⁡(2k/β)\max_i |y_i - f(x)_i| \le \sigma\sqrt{2\ln(2k/\beta)}.

Proof. Each error yi−f(x)iy_i - f(x)_i is N(0,σ2)N(0, \sigma^2). For u>0u > 0, Φˉ(u)≤e−u2/2\bar\Phi(u) \le e^{-u^2/2}: for u≥1/2πu \ge 1/\sqrt{2\pi} this follows from Φˉ(u)≤φ(u)/u\bar\Phi(u) \le \varphi(u)/u, and for smaller uu we have Φˉ(u)≤1/2<e−1/(4π)≤e−u2/2\bar\Phi(u) \le 1/2 < e^{-1/(4\pi)} \le e^{-u^2/2}. So Pr⁡[∣yi−f(x)i∣>σu]=2Φˉ(u)≤2e−u2/2\Pr[|y_i - f(x)_i| > \sigma u] = 2\bar\Phi(u) \le 2e^{-u^2/2}. With u=2ln⁡(2k/β)u = \sqrt{2\ln(2k/\beta)} this is β/k\beta/k, and the union bound over the kk coordinates gives total failure probability at most β\beta. □\square

Complexity

The model is the real RAM: a normal sample, an exponential, an evaluation of Φ\Phi and an arithmetic step each cost one unit. The cost is counted per query, after the one evaluation of ff in line L2.

  • Time. Line L1 with the classical bound is O(1)O(1). With the analytic bound it is O(T)O(T) evaluations of δΔ\delta_\Delta, where TT is the number of bisection steps; the code stops when the bracket is below 10−1210^{-12} times its upper end, which is about 40 steps, plus a few doublings to find the bracket. The loop of line L3 runs kk times with O(1)O(1) work. So the time is O(k+T)O(k + T) in the worst case.
  • Space. The output has kk numbers, and the rest is O(1)O(1). So the extra space is O(k)O(k).

Properties

  • Approximate only. For δ=0\delta = 0 no σ\sigma works: the log ratio of the two densities at yy is linear in yy, so it is unbounded. The tests measure it on a grid: 3.5 on [−3,3][-3, 3] and 30.5 on [−30,30][-30, 30] for Δ=σ=1\Delta = \sigma = 1.
  • Tight. The analytic condition is necessary and sufficient. A σ\sigma below the analytic value fails for the worst pair, and the tests check that 0.999999 σ0.999999\,\sigma gives a δ\delta above the target.
  • ℓ2\ell_2 scale. For kk counts that one record can each change by 1, Δ2=k\Delta_2 = \sqrt k while Δ1=k\Delta_1 = k. So the noise per count grows like k\sqrt k for the Gaussian mechanism and like kk for the Laplace mechanism, for a fixed ε\varepsilon and δ\delta.
  • Closed-form composition. For one pair of neighbors, the losses of mm independent runs add, and a sum of independent normal losses N(μj2/2,μj2)N(\mu_j^2/2, \mu_j^2) is the normal loss with μ2=∑jμj2\mu^2 = \sum_j \mu_j^2. Dong, Roth and Su (2019) prove the same rule for adaptive runs: the composition is ∑jμj2\sqrt{\sum_j \mu_j^2}-GDP. In the language of other pages, the mechanism is μ\mu-GDP with μ=Δ/σ\mu = \Delta/\sigma (Gaussian differential privacy), ρ\rho-zCDP with ρ=Δ2/(2σ2)\rho = \Delta^2/(2\sigma^2) (zero-concentrated DP), and (α,αΔ2/(2σ2))(\alpha, \alpha\Delta^2/(2\sigma^2))-RDP for every α>1\alpha > 1 (Renyi DP). With Δ=1\Delta = 1 and σ=2\sigma = 2 this is ρ=1/8\rho = 1/8.
  • Unbiased. E[y]=f(x)\mathbb E[y] = f(x) and the covariance is σ2I\sigma^2 I, so the noise adds cleanly to other normal errors in a statistical analysis.

Variants and improvements

  • Analytic calibration. Balle and Wang (2018) give the condition of line L1 and a stable way to solve it. This is the version the code uses by default.
  • Discrete Gaussian. The discrete Gaussian mechanism adds integer noise with Pr⁡[Z=z]∝e−z2/(2σ2)\Pr[Z = z] \propto e^{-z^2/(2\sigma^2)}, with almost the same guarantees and an exact sampler.
  • Correlated noise. Noise N(0,Σ)N(0, \Sigma) with a general covariance fits queries whose sensitivity set is an ellipsoid. The matrix mechanism is one way to design it.
  • Denoising. Balle and Wang also post-process the output with estimators that know the noise distribution, which reduces the error in high dimension. This is post-processing and costs no privacy.
  • Noisy gradients. DP-SGD clips each gradient to ℓ2\ell_2 norm CC, so that the sum has Δ2=C\Delta_2 = C, and adds Gaussian noise to the sum at each step. Its accounting uses the moments accountant or numerical privacy accounting.

When to use it

Use the Gaussian mechanism when you answer many numeric queries, or a vector query whose ℓ2\ell_2 sensitivity is much smaller than its ℓ1\ell_1 sensitivity, and a small δ\delta is acceptable. It is also the right choice when the release is one step of an iterative algorithm, because its composition is exact in closed form. For one or a few low-dimensional queries with pure ε\varepsilon-DP, use the Laplace mechanism. For integer output, use the discrete Gaussian mechanism.

Pitfalls

  • The classical formula for ε≥1\varepsilon \ge 1. Line L1 with σ=Δ2ln⁡(1.25/δ)/ε\sigma = \Delta\sqrt{2\ln(1.25/\delta)}/\varepsilon is proved only for ε<1\varepsilon < 1, and it fails for larger ε\varepsilon. With Δ=1\Delta = 1, ε=10\varepsilon = 10 and δ=10−5\delta = 10^{-5} it gives σ=0.4845\sigma = 0.4845, and the exact δ\delta at this σ\sigma is 2.27×10−52.27 \times 10^{-5}, more than twice the target. Use the analytic calibration for any ε\varepsilon; the code raises an error for the classical formula outside (0,1)(0, 1).
  • ℓ1\ell_1 in place of ℓ2\ell_2, or the reverse. Line L1 must use Δ2f\Delta_2 f. Using Δ1\Delta_1 is safe but wastes accuracy. Using Δ2\Delta_2 in the Laplace mechanism is not safe.
  • The wrong neighbor relation. A histogram has Δ2=1\Delta_2 = 1 under add/remove and 2\sqrt 2 under replace. A calibration with Δ=1\Delta = 1 under replace gives a larger δ\delta than claimed.
  • A large δ\delta. The mechanism that publishes each record with probability δ\delta is (0,δ)(0, \delta)-DP, and it publishes about nδn\delta records. Choose δ\delta much smaller than 1/n1/n (Dwork-Roth Section 2.3).
  • Float noise. random.gauss on floats is fine for study and not for a release (Mironov 2012). Use an exact discrete sampler from a cryptographic source.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

dpkit.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the security and privacy pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Checkers for differential privacy on small finite examples.

A dataset is a tuple of records from a finite universe. A pmf is a dict from
outputs to probabilities; the probabilities may be fractions.Fraction (exact)
or float. A mechanism pmf is a function from a dataset to the pmf of the
output of the mechanism on that dataset.

This module holds the neighbor relations, the privacy loss, the hockey-stick
and Renyi divergences, the pure and approximate DP checks over a list of
neighbor pairs, an empirical pmf, the Hoeffding margin for Monte Carlo
checks, and a grid check of a log density ratio. It holds no mechanism, no
noise sampler and no accountant: those belong to the pages that define them.

Natural logarithms are used throughout, as in the DP literature.
"""

from __future__ import annotations

import math
from fractions import Fraction
from typing import Callable, Hashable, Iterable, Mapping, Sequence, Union

Number = Union[int, float, Fraction]
Pmf = Mapping[Hashable, Number]
Dataset = tuple
Pair = tuple[Dataset, Dataset]


def neighbors_add_remove(dataset: Sequence[Hashable], universe: Iterable[Hashable]) -> list[Dataset]:
    """All datasets at add/remove distance 1 from dataset.

    A neighbor removes one record, or appends one record from the universe.
    Datasets are treated as multisets: a removal keeps the order of the other
    records, and equal results are listed once. Cost: O(n (n + |universe|)).
    """
    x = tuple(dataset)
    out: list[Dataset] = []
    seen: set[Dataset] = set()
    for i in range(len(x)):
        y = x[:i] + x[i + 1:]
        key = tuple(sorted(y, key=repr))
        if key not in seen:
            seen.add(key)
            out.append(y)
    for v in universe:
        y = x + (v,)
        key = tuple(sorted(y, key=repr))
        if key not in seen:
            seen.add(key)
            out.append(y)
    return out


def neighbors_replace(dataset: Sequence[Hashable], universe: Iterable[Hashable]) -> list[Dataset]:
    """All datasets of the same size that differ from dataset in one record.

    The record at index i is replaced by a different value of the universe.
    Equal multisets are listed once. Cost: O(n^2 |universe|).
    """
    x = tuple(dataset)
    values = list(universe)
    out: list[Dataset] = []
    seen: set[Dataset] = set()
    for i in range(len(x)):
        for v in values:
            if v == x[i]:
                continue
            y = x[:i] + (v,) + x[i + 1:]
            key = tuple(sorted(y, key=repr))
            if key not in seen:
                seen.add(key)
                out.append(y)
    return out


def _ratio(a: Number, b: Number) -> Number:
    if isinstance(a, (int, Fraction)) and isinstance(b, (int, Fraction)):
        return Fraction(a) / Fraction(b)
    return float(a) / float(b)


def privacy_loss(p: Pmf, q: Pmf) -> dict[Hashable, float]:
    """The privacy loss ln(p(y) / q(y)) at each output y with p(y) > 0 or q(y) > 0.

    The value is +inf where q(y) = 0 < p(y) and -inf where p(y) = 0 < q(y).
    Outputs with p(y) = q(y) = 0 are left out. Cost: O(|support|).
    """
    out: dict[Hashable, float] = {}
    for y in set(p) | set(q):
        a, b = p.get(y, 0), q.get(y, 0)
        if a == 0 and b == 0:
            continue
        if b == 0:
            out[y] = math.inf
        elif a == 0:
            out[y] = -math.inf
        else:
            out[y] = math.log(_ratio(a, b))
    return out


def max_privacy_loss(p: Pmf, q: Pmf) -> float:
    """The largest privacy loss ln(p(y) / q(y)) over the outputs y with p(y) > 0.

    Returns -inf when p has no output of positive probability. Cost: O(|support|).
    """
    best = -math.inf
    for y, v in privacy_loss(p, q).items():
        if p.get(y, 0) > 0 and v > best:
            best = v
    return best


def hockey_stick(p: Pmf, q: Pmf, epsilon: float) -> float:
    """The hockey-stick divergence: the sum over y of max(0, p(y) - e^epsilon q(y)).

    It is sup over sets S of P(S) - e^epsilon Q(S). Cost: O(|support|).
    """
    a = math.exp(epsilon)
    total = 0.0
    for y in set(p) | set(q):
        d = float(p.get(y, 0)) - a * float(q.get(y, 0))
        if d > 0:
            total += d
    return total


def is_pure_dp(mech_pmf: Callable[[Dataset], Pmf], pairs: Iterable[Pair], epsilon: float, tol: float = 1e-12) -> bool:
    """True if max privacy loss <= epsilon + tol for both orders of every pair.

    Precondition: mech_pmf returns the exact output pmf of the mechanism.
    Cost: O(|pairs|) calls of mech_pmf and O(|support|) work per call.
    """
    for x, y in pairs:
        p, q = mech_pmf(x), mech_pmf(y)
        if max_privacy_loss(p, q) > epsilon + tol or max_privacy_loss(q, p) > epsilon + tol:
            return False
    return True


def is_approx_dp(mech_pmf: Callable[[Dataset], Pmf], pairs: Iterable[Pair], epsilon: float, delta: float, tol: float = 1e-12) -> bool:
    """True if the hockey-stick divergence at e^epsilon is <= delta + tol for both orders of every pair.

    Precondition: mech_pmf returns the exact output pmf of the mechanism.
    Cost: O(|pairs|) calls of mech_pmf and O(|support|) work per call.
    """
    for x, y in pairs:
        p, q = mech_pmf(x), mech_pmf(y)
        if hockey_stick(p, q, epsilon) > delta + tol or hockey_stick(q, p, epsilon) > delta + tol:
            return False
    return True


def renyi_divergence(p: Pmf, q: Pmf, alpha: float) -> float:
    """The Renyi divergence of order alpha > 1: ln(sum_y p(y)^alpha q(y)^(1 - alpha)) / (alpha - 1).

    Returns +inf when q(y) = 0 < p(y) for some y. Cost: O(|support|).
    """
    if alpha <= 1:
        raise ValueError("alpha must be greater than 1")
    s = 0.0
    for y in set(p) | set(q):
        a, b = float(p.get(y, 0)), float(q.get(y, 0))
        if a == 0:
            continue
        if b == 0:
            return math.inf
        s += a * (a / b) ** (alpha - 1)
    return math.log(s) / (alpha - 1)


def empirical_pmf(samples: Iterable[Hashable]) -> dict[Hashable, float]:
    """The fraction of the samples equal to each value. Cost: O(number of samples)."""
    counts: dict[Hashable, int] = {}
    n = 0
    for s in samples:
        counts[s] = counts.get(s, 0) + 1
        n += 1
    if n == 0:
        return {}
    return {k: c / n for k, c in counts.items()}


def hoeffding_margin(n: int, beta: float) -> float:
    """The margin t = sqrt(ln(2 / beta) / (2 n)).

    For n independent samples of a [0, 1] variable, the empirical mean is
    within t of the true mean with probability at least 1 - beta (Hoeffding).
    """
    if n <= 0 or not 0 < beta < 1:
        raise ValueError("need n >= 1 and 0 < beta < 1")
    return math.sqrt(math.log(2 / beta) / (2 * n))


def log_ratio_grid(logpdf_x: Callable[[float], float], logpdf_y: Callable[[float], float], grid: Iterable[float]) -> float:
    """The largest |logpdf_x(z) - logpdf_y(z)| over the points z of the grid.

    Use it to check the log density ratio of a continuous mechanism on two
    neighbors. Cost: O(|grid|) calls of each function.
    """
    best = 0.0
    for z in grid:
        d = abs(logpdf_x(z) - logpdf_y(z))
        if d > best:
            best = d
    return best
gaussian_mechanism.py 110 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gaussian-mechanism/. The authors are listed in prov/B229GK.jsonl.
"""The Gaussian mechanism with the classical and the analytic calibration.

The mechanism adds independent N(0, sigma^2) noise to each coordinate of a
query with l2-sensitivity Delta. The classical calibration of Dwork and Roth
(Theorem 3.22) needs 0 < epsilon < 1. The analytic calibration of Balle and
Wang (2018) finds the smallest sigma with delta(epsilon) <= delta, using the
exact formula

    delta(epsilon) = Phi(Delta / (2 s) - epsilon s / Delta)
                     - e^epsilon Phi(-Delta / (2 s) - epsilon s / Delta).

Floats and random.Random.gauss are used so that the tests are reproducible.
They are not a safe sampler: a deployment needs a cryptographic source of
randomness and an exact sampler such as the discrete Gaussian.
"""

from __future__ import annotations

import math
import random
from typing import Callable, Sequence, TypeVar

X = TypeVar("X")


def normal_cdf(t: float) -> float:
    """Phi(t), the standard normal CDF, from math.erfc. Cost: O(1)."""
    return 0.5 * math.erfc(-t / math.sqrt(2.0))


def classical_sigma(sensitivity: float, epsilon: float, delta: float) -> float:
    """sigma = sqrt(2 ln(1.25 / delta)) Delta / epsilon (Dwork and Roth, Theorem 3.22).

    Precondition: Delta > 0, 0 < epsilon < 1 and 0 < delta < 1. The bound is
    proved only for epsilon < 1, so other values raise. Cost: O(1).
    """
    if sensitivity <= 0 or not 0 < epsilon < 1 or not 0 < delta < 1:
        raise ValueError("need Delta > 0, 0 < epsilon < 1 and 0 < delta < 1")
    return math.sqrt(2.0 * math.log(1.25 / delta)) * sensitivity / epsilon


def analytic_delta(sensitivity: float, sigma: float, epsilon: float) -> float:
    """The exact smallest delta at epsilon for N(0, sigma^2) noise and l2-sensitivity Delta.

    Precondition: Delta > 0, sigma > 0, epsilon >= 0. Cost: O(1).
    """
    if sensitivity <= 0 or sigma <= 0 or epsilon < 0:
        raise ValueError("need Delta > 0, sigma > 0 and epsilon >= 0")
    a = sensitivity / (2.0 * sigma)
    b = epsilon * sigma / sensitivity
    return max(0.0, normal_cdf(a - b) - math.exp(epsilon) * normal_cdf(-a - b))


def analytic_sigma(sensitivity: float, epsilon: float, delta: float, rel_tol: float = 1e-12) -> float:
    """The smallest sigma with analytic_delta(Delta, sigma, epsilon) <= delta, by bisection.

    delta(epsilon) falls as sigma grows, so bisection applies. The returned
    sigma is the upper end of the final bracket, so it is never too small.
    Precondition: Delta > 0, epsilon >= 0, 0 < delta < 1.
    Cost: O(log(1 / rel_tol)) evaluations of analytic_delta.
    """
    if sensitivity <= 0 or epsilon < 0 or not 0 < delta < 1:
        raise ValueError("need Delta > 0, epsilon >= 0 and 0 < delta < 1")
    lo, hi = sensitivity, sensitivity
    while analytic_delta(sensitivity, hi, epsilon) > delta:
        lo, hi = hi, 2.0 * hi
    while analytic_delta(sensitivity, lo, epsilon) <= delta and lo > 1e-300:
        hi, lo = lo, lo / 2.0
    while hi - lo > rel_tol * hi:
        mid = 0.5 * (lo + hi)
        if analytic_delta(sensitivity, mid, epsilon) <= delta:
            hi = mid
        else:
            lo = mid
    return hi


def gaussian_mechanism(
    x: X,
    f: Callable[[X], Sequence[float]],
    sensitivity: float,
    epsilon: float,
    delta: float,
    rng: random.Random,
    analytic: bool = True,
) -> list[float]:
    """Return f(x) + Z with Z_i independent N(0, sigma^2).

    Precondition: f has l2-sensitivity at most Delta under the chosen neighbor
    relation. With analytic=True the output is (epsilon, delta)-DP for any
    epsilon >= 0; with analytic=False it needs 0 < epsilon < 1.
    Cost: O(k) for k coordinates, plus O(log(1 / rel_tol)) for the calibration.
    """
    if analytic:
        sigma = analytic_sigma(sensitivity, epsilon, delta)  # @line L1
    else:
        sigma = classical_sigma(sensitivity, epsilon, delta)  # @line L1
    v = list(f(x))  # @line L2
    y: list[float] = []
    for vi in v:  # @line L3
        z = rng.gauss(0.0, sigma)  # @line L4
        y.append(vi + z)  # @line L5
    return y  # @line L6


def gaussian_log_density(y: float, center: float, sigma: float) -> float:
    """ln of the N(center, sigma^2) density at y."""
    return -((y - center) ** 2) / (2.0 * sigma * sigma) - math.log(sigma * math.sqrt(2.0 * math.pi))
test_gaussian_mechanism.py 137 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gaussian-mechanism/. The authors are listed in prov/B229GK.jsonl.

import math
import random

import pytest

import dpkit
from gaussian_mechanism import (
    analytic_delta,
    analytic_sigma,
    classical_sigma,
    gaussian_log_density,
    gaussian_mechanism,
    normal_cdf,
)


def simpson(g, a, b, n=1200):
    h = (b - a) / n
    s = g(a) + g(b)
    for i in range(1, n):
        s += (4 if i % 2 else 2) * g(a + i * h)
    return s * h / 3


def hockey_stick_by_integration(sens, sigma, eps):
    """Oracle: integrate max(0, p - e^eps q) for p = N(0, s^2), q = N(Delta, s^2).

    The integrand is positive exactly left of the point where the log ratio equals eps.
    """
    p = lambda y: math.exp(gaussian_log_density(y, 0.0, sigma))
    q = lambda y: math.exp(gaussian_log_density(y, sens, sigma))
    cut = sens / 2 - eps * sigma * sigma / sens
    g = lambda y: max(0.0, p(y) - math.exp(eps) * q(y))
    return simpson(g, cut - 14 * sigma, cut)


def test_check_values():
    assert abs(classical_sigma(1, 0.5, 1e-5) - 9.6896) < 5e-5
    assert abs(analytic_delta(1, 1, 1) - 0.126937) < 5e-7
    assert abs(analytic_delta(1, 2, 1) - 0.0068296) < 5e-8
    # mu-GDP with mu = Delta / sigma = 1 gives the same delta at epsilon = 1.
    assert analytic_delta(3, 3, 1) == pytest.approx(0.126937, abs=5e-7)
    assert normal_cdf(0) == 0.5


def test_analytic_delta_matches_numeric_integration():
    rng = random.Random(21)
    for _ in range(500):
        sens = rng.uniform(0.2, 3.0)
        sigma = rng.uniform(0.3, 4.0) * sens
        eps = rng.uniform(0.0, 3.0)
        want = hockey_stick_by_integration(sens, sigma, eps)
        assert abs(analytic_delta(sens, sigma, eps) - want) < 1e-8


def test_analytic_delta_falls_with_sigma():
    for eps in (0.0, 0.5, 2.0):
        prev = 1.0
        for k in range(1, 60):
            d = analytic_delta(1.0, 0.1 * k, eps)
            assert d <= prev
            prev = d


def test_analytic_sigma_is_tight_and_beats_classical():
    rng = random.Random(4)
    for _ in range(500):
        eps = rng.uniform(0.01, 0.99)
        delta = 10 ** rng.uniform(-9, -1)
        sens = rng.uniform(0.5, 2.0)
        s = analytic_sigma(sens, eps, delta)
        assert analytic_delta(sens, s, eps) <= delta
        assert analytic_delta(sens, s * (1 - 1e-6), eps) > delta
        assert s <= classical_sigma(sens, eps, delta)


def test_classical_formula_fails_outside_its_range():
    # A measurement: with epsilon = 10 the classical sigma gives a larger delta than asked.
    s = math.sqrt(2 * math.log(1.25 / 1e-3)) / 10
    assert analytic_delta(1, s, 10) > 1e-3
    with pytest.raises(ValueError):
        classical_sigma(1, 10, 1e-3)


def test_privacy_loss_is_gaussian_by_monte_carlo():
    # L = ln p(Y) / q(Y) with Y ~ p is N(mu^2 / 2, mu^2), mu = Delta / sigma.
    # delta(eps) = E[max(0, 1 - e^(eps - L))], a mean of [0, 1] values.
    rng = random.Random(31)
    n = 2000
    for sens, sigma, eps in ((1.0, 1.0, 1.0), (1.0, 2.0, 0.5), (2.0, 1.5, 0.2)):
        total = 0.0
        for _ in range(n):
            y = rng.gauss(0.0, sigma)
            loss = gaussian_log_density(y, 0.0, sigma) - gaussian_log_density(y, sens, sigma)
            total += max(0.0, 1 - math.exp(eps - loss))
        assert abs(total / n - analytic_delta(sens, sigma, eps)) <= dpkit.hoeffding_margin(n, 1e-6)


def test_log_ratio_is_unbounded_so_no_pure_dp():
    sigma = 1.0
    px = lambda z: gaussian_log_density(z, 0.0, sigma)
    py = lambda z: gaussian_log_density(z, 1.0, sigma)
    narrow = dpkit.log_ratio_grid(px, py, [i / 10 for i in range(-30, 31)])
    wide = dpkit.log_ratio_grid(px, py, [i / 10 for i in range(-300, 301)])
    assert abs(narrow - 3.5) < 1e-9
    assert abs(wide - 30.5) < 1e-9


def test_sampler_tail_and_coordinates():
    rng = random.Random(55)
    n = 2000
    eps, delta = 1.0, 1e-5
    sigma = analytic_sigma(1.0, eps, delta)
    t = 1.5 * sigma
    hits = 0
    for _ in range(n):
        y = gaussian_mechanism(None, lambda _: [0.0], 1.0, eps, delta, rng)
        hits += abs(y[0]) > t
    assert abs(hits / n - math.erfc(t / (sigma * math.sqrt(2)))) <= dpkit.hoeffding_margin(n, 1e-6)
    out = gaussian_mechanism([1.0, 2.0, 3.0], lambda v: v, 1.0, 0.5, 1e-5, rng, analytic=False)
    assert len(out) == 3


def test_edge_cases():
    rng = random.Random(0)
    with pytest.raises(ValueError):
        classical_sigma(1, 0.5, 0)
    with pytest.raises(ValueError):
        analytic_sigma(1, 1, 1)
    with pytest.raises(ValueError):
        analytic_delta(0, 1, 1)
    assert gaussian_mechanism(None, lambda _: [], 1.0, 1.0, 1e-5, rng) == []
    # At epsilon = 0, sigma = Delta / (2 delta) is enough (Balle and Wang, Theorem 2).
    assert analytic_delta(1, 1 / (2 * 0.01), 0) <= 0.01

History

Dwork, Kenthapadi, McSherry, Mironov and Naor (EUROCRYPT 2006) introduced the additive δ\delta in the definition and used Gaussian noise, which is a sum of many small contributions in their distributed setting. Dwork and Roth (2014) give the classical bound for ε<1\varepsilon < 1 with its proof, and note that the bound is folklore. Balle and Wang (ICML 2018) showed that the classical bound is loose for small ε\varepsilon and does not extend to large ε\varepsilon, and gave the exact condition. Bun and Steinke (2016), Mironov (2017) and Dong, Roth and Su (2019) built the zCDP, RDP and GDP frameworks around the normal privacy loss of this mechanism.

References

  1. Cynthia Dwork, Krishnaram Kenthapadi, Frank McSherry, Ilya Mironov and Moni Naor, Our data, ourselves: privacy via distributed noise generation, EUROCRYPT 2006, LNCS 4004, pages 486 to 503, the relaxed definition with an additive delta and the use of Gaussian noise
  2. Cynthia Dwork and Aaron Roth, The Algorithmic Foundations of Differential Privacy, Foundations and Trends in Theoretical Computer Science 9(3-4), 2014, pages 211 to 407, Section 3.5.3, Definition 3.8 (l2 sensitivity) and Theorem 3.22 (the classical bound, for epsilon in (0, 1)); Appendix A, Theorem A.1 (the same theorem with its proof)
  3. Borja Balle and Yu-Xiang Wang, Improving the Gaussian mechanism for differential privacy: analytical calibration and optimal denoising, ICML 2018, PMLR 80, Theorem 1 (the classical mechanism), Lemma 3 (the privacy loss is Gaussian), Theorem 5 (the exact condition for (epsilon, delta)-DP), Theorem 8 (the analytic Gaussian mechanism)
  4. Ilya Mironov, On significance of the least significant bits for differential privacy, ACM CCS 2012, pages 650 to 661, why floating-point noise is not private
  5. Clement L. Canonne, Gautam Kamath and Thomas Steinke, The discrete Gaussian for differential privacy, NeurIPS 2020, the discrete Gaussian and its exact sampler

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example