Algorithmresearch
Numerical privacy loss distribution accounting
Also called PRV accountant, privacy loss distribution accountant, PLD accountant, FFT accountant.
Composes mechanisms by convolving discretized privacy loss distributions with the FFT, which gives near-exact epsilon for given delta.
- Time
- O(k n log(k n)) worst
- Space
- O(k n) extra
- Where
- k = the number of composed steps; n = the number of grid points of one privacy loss distribution
- Model
- Real RAM
- Properties
- deterministicnot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Sebastian Meiser, Esfandiar Mohammadi, Antti Koskela, Joonas Jalko, Antti Honkela, Sivakanth Gopi, Yin Tat Lee, Lukas Wutschitz, 2018
Numerical privacy accounting computes the privacy guarantee of many composed mechanisms almost exactly. The tight of a mechanism at a given is a function of the distribution of its privacy loss random variable, the PLD. When mechanisms with independent noise are composed, their privacy losses add, so the PLD of the composition is the convolution of their PLDs. The accountant rounds each PLD to a grid of step , convolves the grids with the FFT, and reads off . If every loss is rounded up, the result is an upper bound on the true ; if every loss is rounded down, it is a lower bound. A finer grid closes the gap. For ten Gaussian steps that together are -GDP, a grid of step puts the true between and . The method is due to Meiser and Mohammadi (2018), Koskela, Jalko and Honkela (2020), and Gopi, Lee and Wutschitz (2021), who call their version the PRV accountant.
In plain words
Each private step leaks a random amount about a person. Some outcomes leak a lot and most leak little. The full pattern of the leak is a list: how likely each size of leak is. When we run many steps, the leaks add up, and the list for the total can be computed from the lists of the steps.
The accountant writes each list on a fine ruler, and moves each entry to the next mark up, so that it never claims less leak than there is. It then combines the lists with a fast method for adding up all the ways the steps can combine. From the final list it reads the usual privacy numbers. A second run that moves each entry down gives a number that is too small. The true answer is between the two.
The problem
A PLD on a grid of step is a list of masses at the losses for an integer offset , and a mass at . For a pair of output distributions of a mechanism on two neighbors, the exact PLD is the law of for , and
where the term is 1 when . Input: a grid PLD , a number of steps , and . Output: for the sum of independent copies of the loss. For the inverse problem, a target is given and the output is the least with , which bisection finds because does not increase with .
Two discretizations of a continuous PLD with distribution function :
- pessimistic: the mass of each cell goes to ; the mass below the grid goes to its lowest point, and the mass above it goes to ;
- optimistic: the mass of each cell goes to , and the mass outside the grid is dropped.
The algorithm
NUMERICAL-ACCOUNTANT(omega, k, epsilon)- 1
N <- the least power of 2 with N >= k(n - 1) + 1 - 2
W <- FFT(omega_0, ..., omega_{n-1}, 0, ..., 0) ▷ zero padded to length N - 3
W_s <- (W_s)^k for s = 0..N-1 - 4
omega' <- the first k(n - 1) + 1 entries of INVERSE-FFT(W) - 5
omega'_inf <- 1 - (1 - omega_inf)^k - 6
delta <- omega'_inf + sum over j with loss (kl + j)h > epsilon of omega'_j (1 - e^(epsilon - (kl + j)h)) - 7
return delta
Line L1 picks a transform length that holds the whole -fold convolution, which has entries, so that the cyclic convolution of the FFT does not wrap around. Line L2 takes the discrete Fourier transform of the zero-padded masses. By the convolution theorem, the transform of a -fold convolution is the -th power of the transform, so line L3 raises each entry to the power and line L4 transforms back. The offset of the result is , because the losses add. Line L5 gives the mass at : the sum is infinite when at least one step is infinite. Line L6 evaluates the formula for on the composed grid, and line L7 returns it.
To compose different mechanisms on the same grid, multiply their transforms at line L3 instead of taking a power. To find for a target , compose once and run bisection on with line L6 alone.
The accountant does only arithmetic on public parameters; it reads no data and draws no noise. The mechanisms that it accounts for must draw their noise from a cryptographic source of randomness with an exact sampler, because float noise from a seeded generator leaks through its low-order bits (Mironov 2012; Canonne, Kamath and Steinke 2020). The discrete Gaussian mechanism page shows an exact sampler.
Example
Take randomized response with on the grid : the loss is with probability and otherwise, so , and . Compose steps.
| step | state |
|---|---|
| L1 | , so |
| L2 to L4 | at losses ; offset |
| L5 | |
| L6, | |
| L6, | |
| L6, | |
| L6, |
The composed masses are the binomial law of the number of losses, as they must be. Randomized response is the worst case among -DP mechanisms, so these numbers are also the tight values of the optimal composition theorem for three -DP steps.
A second example uses a continuous PLD. Ten Gaussian steps, each with , compose to -GDP, whose exact is . The pessimistic and optimistic grids give:
| grid step | grid points | optimistic | pessimistic |
|---|---|---|---|
| 0.01 | 635 | 0.118074 | 0.136234 |
| 0.005 | 1267 | 0.122451 | 0.131531 |
| 0.002 | 3165 | 0.125129 | 0.128761 |
The gap shrinks in proportion to . On the 4-fold composition of with , bisection gives at from the pessimistic grid and from the optimistic grid; the exact value is .
Correctness
Theorem. Let be a pair of distributions with PLD , and let be the curve of . In the real RAM, NUMERICAL-ACCOUNTANT on a grid PLD returns for the sum of independent draws from . If is the pessimistic discretization of , the result is at least ; if is the optimistic one, it is at most .
The proof in proofs/correctness.md has four steps. First, , the hockey-stick divergence written as an expectation under . Second, the PLD of a product pair is the law of the sum of independent PLDs, so comes from the -fold convolution. Third, lines L1 to L5 compute that convolution exactly, by the convolution theorem and because is large enough that the cyclic convolution equals the linear one. Fourth, the function does not decrease, so rounding every loss up, or moving mass to , can only increase the result, and rounding down, or dropping mass, can only decrease it. When is a dominating pair for each step of an adaptive composition, as for the Gaussian mechanism, the same bounds hold for the adaptive composition.
Proof: The numerical accountant computes the composed delta, and the two grids bracket itfull
We work in the real RAM, where arithmetic on reals and are exact. Write for and . For each , takes values in and does not decrease on .
Let and be distributions on a countable set (the argument for densities is the same with integrals in place of sums). The privacy loss of with is , which is when . The PLD of is the law of for , a probability measure on . For let .
Lemma 1 (delta as an expectation). .
Proof. For each , , and this is largest for , where it equals . A point with adds nothing. For , , also when , where both sides are . Summing gives the claim.
Lemma 2 (composition adds losses). Let for be pairs with PLDs . The PLD of is the law of with independent , where a sum with an infinite term is .
Proof. For with ,
and both sides are exactly when some . Under the product law are independent with , so the terms are independent with laws .
So for copies of one pair with PLD , Lemmas 1 and 2 give with independent draws from .
Lemma 3 (lines L1 to L5 compute the k-fold convolution). Let be a grid PLD with finite masses at and mass at , and let be the sum of independent draws from . Then lines L1 to L5 return the law of : mass at for , and at .
Proof. The finite part. Let be the -fold linear convolution of the vector . Its entry is the sum of over all tuples with , which is the probability that all draws are finite and , because . The entries with are zero. Let be padded with zeros to length , and let be cyclic convolution modulo . By the convolution theorem for the discrete Fourier transform, the transform of is the pointwise -th power of the transform of , so lines L2 to L4 return . An entry of at index is the sum of over . Every nonzero has by line L1, so each residue class holds at most one such , and equals padded with zeros. Line L4 keeps the first entries, which are . The offset is .
The infinite part. exactly when at least one draw is , which has probability by independence. This is line L5.
Line L6 computes , where the terms with are zero. By Lemma 3 this is , and line L7 returns it.
Lemma 4 (monotone coupling). Let and be random variables on , each family independent, with a coupling such that for each . Then .
Proof. Under the coupling, pointwise, with the rule that a sum with an infinite term is . Since does not decrease, the inequality holds pointwise, and so for expectations. To couple pairs with independence across , couple each pair on its own and take the product of the couplings.
Lemma 5 (dropping mass). Let be a measure on with total mass at most 1, and let setwise, where is a probability measure. Define . Then .
Proof. The integrand is non-negative, and setwise, because is a non-negative measure and the product of the two expands into plus non-negative cross terms.
Lines L1 to L6 apply unchanged to a sub-probability grid: Lemma 3 holds with "law" replaced by the measure , since its proof only uses the multinomial expansion. With , line L5 gives 0.
Theorem. Let be the PLD of and the curve of . Let and be the pessimistic and optimistic discretizations of on a grid of step with cells indexed by . Then for every ,
Proof. By Lemmas 1 and 2, with independent draws from . By Lemma 3 and line L6, the accountant on a grid returns the same expression with draws from the grid PLD.
Upper bound. Define the map on by for , for with , and for , including . Then for every , and for has law by its definition. Couple . Lemma 4 gives , which is the accountant on .
Lower bound. Let and let be restricted to , so . By Lemma 5, . Define for , so on , and the image of under is . The coupling argument of Lemma 4 applies to the finite measure after normalizing it, with the same factor on both sides, and gives under . The left side is the accountant on . If , the accountant returns 0 and the bound is trivial.
Both bounds hold for every . Since the curves do not increase in , bisection on the pessimistic curve returns an whose true is at most the target.
The theorem is about independent copies of one pair. For the Gaussian mechanism with , the pair is the worst case over neighbors, and the composition theorem of Gaussian differential privacy (Dong, Roth and Su) says that adaptive -GDP steps are -GDP, which is the curve of independent copies of that pair. So for the Gaussian mechanism the same bracket holds for adaptive composition.
Complexity
The composed grid has points, so . In the real RAM, each FFT costs , the powers at line L3 cost , and line L6 costs . The total is time and extra space. Each bisection step for costs .
The grid step sets the accuracy. Rounding moves each loss by less than , so the sum of losses moves by less than , and the two bounds bracket in an window of width . Gopi, Lee and Wutschitz show that a much coarser grid suffices, because the rounding errors of independent steps partly cancel when the rounding is done in expectation, and they give a running time of for a fixed target accuracy.
Properties
- Two-sided. The pessimistic and optimistic grids give a certified bracket on , so the user can see how far the reported value is from the exact one.
- Tight in the limit. As and the grid range grows, both bounds tend to the exact , unlike the bounds of the moments accountant or the advanced composition theorem, which stay above it.
- Any mechanism with a known PLD. The method needs only the PLD of each step, which is known for the Laplace, Gaussian and randomized response mechanisms and can be computed numerically for the subsampled Gaussian.
- Pure arithmetic. It reads no data and has no randomness.
Variants and improvements
- Privacy buckets. Meiser and Mohammadi put the loss into buckets with geometric boundaries and convolve the buckets directly, with upper and lower bounds.
- FFT accountant. Koskela, Jalko and Honkela truncate the losses to an interval , let the FFT wrap around, and bound the error of the truncation and of the wrap. Their version handles the subsampled Gaussian of DP-SGD.
- PRV accountant. Gopi, Lee and Wutschitz round each loss so that its mean is kept, and truncate the domain using a tail bound on the composed loss. This gives a grid that grows like rather than , with explicit error bounds on .
- Characteristic functions. Later work composes the Fourier transforms of the continuous PLDs directly and inverts only once at the end.
- Heterogeneous steps. Steps with different noise multiply their own transforms at line L3; the grid step must be the same for all.
When to use it
Use numerical accounting when the exact matters, as in a public release or a long training run where the last ten or twenty percent of the budget decides the noise level. It applies whenever the PLD of each step is known. Use the moments accountant for a fast bound during development, and the closed form of Gaussian differential privacy when every step is a Gaussian mechanism without subsampling.
Pitfalls
- Wrap-around at line L1. If is smaller than the length of the composed grid, the cyclic convolution of the FFT adds the top of the distribution to the bottom, and comes out too small. Choose as in line L1, or bound the wrapped mass.
- Wrong rounding direction. The upper bound needs every loss rounded up and the top tail moved to , not dropped. Rounding to the nearest grid point at line L2 gives neither bound.
- Float error at lines L2 to L4. The FFT in floats has an absolute error near the machine precision times the total mass, and some masses come out slightly negative. A of is then below the noise floor; the bracket from the two grids does not account for this error.
- Forgetting the mass at infinity at line L5. A mechanism with , such as one with a nonzero of its own, adds at least to the final .
- A pair that does not dominate. The result is a guarantee only if the PLD comes from a pair that is the worst case over all neighbors, in both orders. For subsampled mechanisms the two orders give different PLDs, and both must be checked.
- Floating-point noise in the mechanism. The accounting assumes exact noise. Noise from a float sampler or a non-cryptographic generator is not covered by the bound.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/numerical-privacy-accounting/. The authors are listed in prov/XTW2ZE.jsonl.
"""Numerical privacy loss distribution (PLD) accounting with the FFT.
A PLD on a grid of step h is a list of masses: mass[j] sits at the loss
(lo + j) * h, and inf_mass sits at +infinity. Composing k mechanisms with
independent noise convolves their PLDs, which the FFT does in
O(N log N) for N about k times the grid size. The tight delta at epsilon is
delta(epsilon) = inf_mass + sum_j mass[j] * max(0, 1 - e^(epsilon - loss_j)),
and epsilon for a target delta comes from bisection. Rounding each loss up
to the grid (pessimistic) gives an upper bound on delta; rounding down
(optimistic) gives a lower bound, so the two bracket the exact value.
The code is accounting only, in floats, in the real RAM model. The mechanisms
that it accounts for need a cryptographic source of randomness and exact
sampling of their noise in a deployment (Mironov 2012; Canonne, Kamath and
Steinke 2020).
"""
from __future__ import annotations
import cmath
import math
from dataclasses import dataclass
from statistics import NormalDist
from typing import List, Sequence, Tuple
@dataclass(frozen=True)
class Pld:
"""A privacy loss distribution on the grid (lo + j) * step."""
lo: int
masses: Tuple[float, ...]
step: float
inf_mass: float = 0.0
def loss(self, j: int) -> float:
return (self.lo + j) * self.step
def fft(a: Sequence[complex], invert: bool = False) -> List[complex]:
"""Iterative radix-2 FFT. Precondition: len(a) is a power of 2.
With invert=True it computes the inverse transform, including the 1/N.
Cost: O(N log N) arithmetic operations, O(N) space.
"""
n = len(a)
if n & (n - 1):
raise ValueError("the length must be a power of 2")
out = list(a)
j = 0
for i in range(1, n): # bit-reversal permutation
bit = n >> 1
while j & bit:
j ^= bit
bit >>= 1
j |= bit
if i < j:
out[i], out[j] = out[j], out[i]
length = 2
sign = 1.0 if invert else -1.0
while length <= n:
w_len = cmath.exp(sign * 2j * math.pi / length)
half = length // 2
for start in range(0, n, length):
w = 1.0 + 0j
for k in range(half):
u = out[start + k]
v = out[start + k + half] * w
out[start + k] = u + v
out[start + k + half] = u - v
w *= w_len
length <<= 1
if invert:
out = [x / n for x in out]
return out
def compose(pld: Pld, k: int) -> Pld:
"""The PLD of k independent copies of the mechanism with PLD pld.
Precondition: k >= 1. Cost: O(N log N) with N < 2 k n for n grid points.
"""
if k < 1:
raise ValueError("k must be at least 1")
n = len(pld.masses)
size = 1
while size < k * (n - 1) + 1: # @line L1
size <<= 1
spectrum = fft([complex(m) for m in pld.masses] + [0j] * (size - n)) # @line L2
powered = [z**k for z in spectrum] # @line L3
values = fft(powered, invert=True) # @line L4
masses = tuple(max(0.0, z.real) for z in values[: k * (n - 1) + 1])
inf_k = 1.0 - (1.0 - pld.inf_mass) ** k # @line L5
return Pld(k * pld.lo, masses, pld.step, inf_k)
def delta_for_epsilon(pld: Pld, epsilon: float) -> float:
"""The delta of the PLD at epsilon. Cost: O(n) for n grid points."""
total = pld.inf_mass # @line L6
for j, m in enumerate(pld.masses):
loss = pld.loss(j)
if m > 0.0 and loss > epsilon:
total += m * -math.expm1(epsilon - loss)
return min(1.0, total)
def numerical_accountant(pld: Pld, k: int, epsilon: float) -> float:
"""delta(epsilon) for the k-fold composition of pld (lines L1 to L7).
Precondition: k >= 1, epsilon >= 0. Cost: O(k n log(k n)) for n grid points.
"""
composed = compose(pld, k) # lines L1 to L5
return delta_for_epsilon(composed, epsilon) # @line L7
def epsilon_for_delta(pld: Pld, delta: float, tol: float = 1e-9) -> float:
"""The least epsilon >= 0 with delta_for_epsilon(pld, epsilon) <= delta, up to tol.
It returns an epsilon with delta(epsilon) <= delta, found by bisection.
Precondition: delta > pld.inf_mass. Cost: O(n log(L / tol)) for loss range L.
"""
if delta <= pld.inf_mass:
raise ValueError("delta must exceed the mass at infinity")
lo = 0.0
if delta_for_epsilon(pld, lo) <= delta:
return lo
hi = max(pld.loss(len(pld.masses) - 1), 0.0) + 1.0 # delta(hi) = inf_mass < delta
while hi - lo > tol:
mid = (lo + hi) / 2
if delta_for_epsilon(pld, mid) <= delta:
hi = mid
else:
lo = mid
return hi
def gaussian_pld(mu: float, step: float, pessimistic: bool = True, width: float = 10.0) -> Pld:
"""The discretized PLD of the Gaussian mechanism with mu = sensitivity / sigma.
The exact PLD is N(mu^2 / 2, mu^2). Each grid cell ((i-1) h, i h] goes to
i h (pessimistic) or to (i-1) h (optimistic). Pessimistic: the mass below
the grid goes to the lowest grid point and the mass above it goes to
+infinity. Optimistic: both tails are dropped. So the pessimistic PLD
gives an upper bound on delta and the optimistic PLD a lower bound.
Precondition: mu > 0, step > 0. Cost: O(n) with n = 2 width mu / step.
"""
if mu <= 0 or step <= 0:
raise ValueError("mu and step must be positive")
law = NormalDist(mu * mu / 2, mu)
i_lo = math.floor((law.mean - width * mu) / step)
i_hi = math.ceil((law.mean + width * mu) / step)
cdf = [law.cdf(i * step) for i in range(i_lo - 1, i_hi + 1)]
cells = [max(0.0, cdf[j + 1] - cdf[j]) for j in range(len(cdf) - 1)]
if pessimistic:
cells[0] += cdf[0] # the mass below (i_lo - 1) h, rounded up to i_lo h
return Pld(i_lo, tuple(cells), step, 1.0 - cdf[-1])
return Pld(i_lo - 1, tuple(cells), step, 0.0)
def randomized_response_pld(m: int, step: float) -> Pld:
"""The PLD of randomized response with epsilon_0 = m * step, on the grid of step.
The loss is +epsilon_0 with probability e^eps0 / (1 + e^eps0) and
-epsilon_0 otherwise; both are grid points, so there is no rounding.
Precondition: m >= 1, step > 0. Cost: O(m).
"""
if m < 1 or step <= 0:
raise ValueError("need m >= 1 and step > 0")
p = 1.0 / (1.0 + math.exp(-m * step))
masses = [0.0] * (2 * m + 1)
masses[0] = 1.0 - p
masses[-1] = p
return Pld(-m, tuple(masses), step, 0.0)
test_numerical_privacy_accounting.py 167 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/numerical-privacy-accounting/. The authors are listed in prov/XTW2ZE.jsonl.
import cmath
import itertools
import math
import random
from fractions import Fraction
from math import comb
from statistics import NormalDist
import pytest
from numerical_privacy_accounting import (
Pld,
compose,
delta_for_epsilon,
epsilon_for_delta,
fft,
gaussian_pld,
numerical_accountant,
randomized_response_pld,
)
def gaussian_delta(epsilon, mu):
"""The exact delta of mu-GDP (the Gaussian mechanism), in closed form."""
phi = NormalDist().cdf
return phi(-epsilon / mu + mu / 2) - math.exp(epsilon) * phi(-epsilon / mu - mu / 2)
def brute_delta(pld, k, epsilon):
"""An independent oracle: sum over all k-tuples of grid points, no FFT."""
finite = 1.0 - pld.inf_mass
total = 1.0 - finite**k
for idx in itertools.product(range(len(pld.masses)), repeat=k):
weight = math.prod(pld.masses[j] for j in idx)
loss = sum(pld.loss(j) for j in idx)
if weight > 0 and loss > epsilon:
total += weight * (1 - math.exp(epsilon - loss))
return min(1.0, total)
def rr_delta_exact(b, k, i):
"""Exact delta of k-fold randomized response with e^eps0 = b, at epsilon = i * eps0.
The loss is (2j - k) eps0 when j of the k answers have loss +eps0, so
e^(epsilon - loss) = b^(i - 2j + k), a rational number.
"""
b = Fraction(b)
total = Fraction(0)
for j in range(k + 1):
ratio = b ** (i - 2 * j + k)
if ratio < 1:
total += comb(k, j) * b**j / (1 + b) ** k * (1 - ratio)
return total
def test_worked_example():
# Randomized response with eps0 = 1, k = 2 steps, epsilon = 0.
pld = randomized_response_pld(1, 1.0)
p = math.e / (1 + math.e)
composed = compose(pld, 2)
assert composed.lo == -2
assert composed.masses[0] == pytest.approx((1 - p) ** 2)
assert composed.masses[2] == pytest.approx(2 * p * (1 - p))
assert composed.masses[4] == pytest.approx(p * p)
want = p * p * (1 - math.exp(-2))
assert numerical_accountant(pld, 2, 0.0) == pytest.approx(want, abs=1e-12)
assert want == pytest.approx(0.462117, abs=1e-6)
def test_gaussian_brackets_the_exact_value():
# 10 Gaussian steps with mu_i = 1 / sqrt(10) compose to exactly 1-GDP.
k, mu = 10, 1 / math.sqrt(10)
upper = numerical_accountant(gaussian_pld(mu, 2e-3, pessimistic=True), k, 1.0)
lower = numerical_accountant(gaussian_pld(mu, 2e-3, pessimistic=False), k, 1.0)
exact = gaussian_delta(1.0, 1.0)
assert exact == pytest.approx(0.126937, abs=1e-6)
assert lower <= exact <= upper
assert upper - lower < 5e-3
def test_randomized_response_exact_fraction():
for b_num, k in [(3, 5), (2, 8), (5, 3)]:
eps0 = math.log(b_num)
pld = randomized_response_pld(1, eps0)
for i in range(0, k + 1):
got = numerical_accountant(pld, k, i * eps0)
assert got == pytest.approx(float(rr_delta_exact(b_num, k, i)), abs=1e-12)
def test_edges_and_bad_input():
pld = randomized_response_pld(2, 0.25)
same = compose(pld, 1)
assert same.lo == pld.lo
assert all(abs(a - b) < 1e-15 for a, b in zip(same.masses, pld.masses))
# Far above the largest loss, only the mass at infinity is left.
inf_pld = Pld(0, (0.5, 0.25), 1.0, 0.25)
assert delta_for_epsilon(inf_pld, 100.0) == pytest.approx(0.25)
assert compose(inf_pld, 3).inf_mass == pytest.approx(1 - 0.75**3)
# epsilon = 0 for a point mass at loss 0: the two outputs are the same.
assert numerical_accountant(Pld(0, (1.0,), 0.5), 4, 0.0) == 0.0
with pytest.raises(ValueError):
compose(pld, 0)
with pytest.raises(ValueError):
fft([1, 2, 3])
with pytest.raises(ValueError):
gaussian_pld(0.0, 0.01)
with pytest.raises(ValueError):
randomized_response_pld(0, 0.1)
with pytest.raises(ValueError):
epsilon_for_delta(inf_pld, 0.2)
def test_fft_against_naive_dft():
rng = random.Random(11)
for size in [1, 2, 4, 8, 32]:
a = [complex(rng.uniform(-1, 1), rng.uniform(-1, 1)) for _ in range(size)]
naive = [sum(a[t] * cmath.exp(-2j * math.pi * s * t / size) for t in range(size)) for s in range(size)]
got = fft(a)
assert all(abs(x - y) < 1e-9 for x, y in zip(got, naive))
back = fft(got, invert=True)
assert all(abs(x - y) < 1e-12 for x, y in zip(back, a))
def test_monotone_in_epsilon_and_steps():
pld = gaussian_pld(0.5, 0.02)
composed = compose(pld, 4)
deltas = [delta_for_epsilon(composed, e / 4) for e in range(13)]
assert all(x >= y for x, y in zip(deltas, deltas[1:]))
by_k = [numerical_accountant(pld, k, 1.0) for k in range(1, 6)]
assert all(x <= y for x, y in zip(by_k, by_k[1:]))
def test_epsilon_for_delta_inverts():
pld = compose(gaussian_pld(0.5, 0.01), 4) # close to 1-GDP
eps = epsilon_for_delta(pld, 1e-5)
assert delta_for_epsilon(pld, eps) <= 1e-5
assert delta_for_epsilon(pld, eps - 1e-6) > 1e-5
# The exact 1-GDP value is 4.3772; the pessimistic grid stays above it.
assert 4.3772 < eps < 4.42
assert epsilon_for_delta(pld, 0.9) == 0.0
def test_pessimistic_dominates_single_step():
for mu in [0.3, 1.0, 2.0]:
up = gaussian_pld(mu, 0.01)
down = gaussian_pld(mu, 0.01, pessimistic=False)
for e in [0.0, 0.5, 1.0, 2.0]:
exact = gaussian_delta(e, mu)
assert delta_for_epsilon(down, e) <= exact + 1e-12
assert exact <= delta_for_epsilon(up, e) + 1e-12
def test_random_against_brute_force():
rng = random.Random(2106)
for _ in range(500):
n = rng.randint(1, 5)
k = rng.randint(1, 4)
raw = [rng.random() for _ in range(n)]
inf_mass = rng.choice([0.0, 0.0, rng.uniform(0.0, 0.1)])
scale = (1 - inf_mass) / sum(raw)
pld = Pld(rng.randint(-4, 2), tuple(r * scale for r in raw), rng.choice([0.1, 0.25, 0.5]), inf_mass)
epsilon = rng.uniform(0.0, 2.0)
got = numerical_accountant(pld, k, epsilon)
assert got == pytest.approx(brute_delta(pld, k, epsilon), rel=1e-9, abs=1e-12)
History
Before 2018, composition was done with closed-form bounds such as the advanced composition theorem, with Renyi accounting, or, for pure DP steps, with the exact but costly formula of the optimal composition theorem. Meiser and Mohammadi (CCS 2018) showed that the loss distribution itself can be composed numerically, with provable upper and lower bounds, and found that the bounds of the moments accountant were loose. Koskela, Jalko and Honkela (AISTATS 2020) wrote the exact as an integral, evaluated the convolutions with the FFT, and gave error bounds; they applied it to DP-SGD. Gopi, Lee and Wutschitz (NeurIPS 2021) introduced privacy random variables, the PRV accountant, and error bounds that need far fewer grid points, which made the method much faster for long compositions. PLD and PRV accountants are now in the main open source differential privacy libraries.
References
- Sebastian Meiser and Esfandiar Mohammadi, Tight on budget? Tight bounds for r-fold approximate differential privacy, ACM CCS 2018, doi 10.1145/3243734.3243765, privacy buckets: provable upper and lower bounds on the delta of r-fold composition
- Antti Koskela, Joonas Jalko and Antti Honkela, Computing tight differential privacy guarantees using FFT, AISTATS 2020, the integral formula for exact (epsilon, delta), its discretization, the FFT evaluation of the convolutions, and the error bounds
- Sivakanth Gopi, Yin Tat Lee and Lukas Wutschitz, Numerical composition of differential privacy, NeurIPS 2021, privacy loss random variables, the PRV accountant and its error bounds, and the running time for k-fold composition
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag XTW2ZE Edit this page History Report an error Markdown