Algorithmadvanced
Propose-test-release
Also called PTR.
Proposes a bound on the local sensitivity, tests with noise that the data is far from any dataset that breaks it, and only then releases the answer with noise for that bound.
- Time
- O(n^2) worst
- Space
- O(n) extra
- Where
- n = the number of values
- Model
- Real RAM
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Cynthia Dwork, Jing Lei, 2009
Propose-test-release (PTR) is a way to add noise for the typical case and not the worst case. The analyst proposes a bound on the local sensitivity of a function . The mechanism computes how many records of must change before the local sensitivity is above , adds Laplace noise to that distance, and compares it with . If the noisy distance is too small it outputs , "no answer". Otherwise it releases . The result is -differentially private for every and . For the median of dense data the noise is far smaller than the global sensitivity requires.
In plain words
You want to publish the middle value of a list and you guess that one change can move it by at most . The guess may be wrong for this list, or for a list close to it.
So first count how many values you must change to make the guess wrong. If that count is large, the guess is safe here and also for all lists close to this one. Add noise to the count and compare it with a safety margin. If the noisy count is too small, say nothing. If it is large, publish the middle value with noise for the guess . The noise on the count hides each value, and the margin makes a wrong answer very unlikely.
The problem
A dataset is a list of values in , with odd and public. Two datasets are neighbors if one value is replaced by another (replace), so is fixed, and is the number of replacements from to . The median is with , its local sensitivity is , and its global sensitivity is . The distance to instability is . The goal is an -DP estimate of , or .
Notation: has the density , the variance and .
The algorithm
This is the form of Vadhan (2017, Proposition 3.2), with the median as . Sort and set for and for .
PTR-MEDIAN(x₁ ≤ ... ≤ xₙ, Λ, b, ε, δ)- 1
γ ← min{k ≥ 0 : max_{0≤t≤k+1} (x_{m+t} − x_{m+t−k−1}) > b} ▷ ∞ if no k works - 2
γ̂ ← γ + Lap(1/ε) ▷ γ has sensitivity 1 - 3
if γ̂ ≤ ln(1/δ)/ε then output ⊥ and halt - 4
output x_m + Lap(b/ε)
Line L1 is the distance to instability. The inner maximum is the largest local sensitivity of the median within replacements, from the closed form of Nissim, Raskhodnikova and Smith (2007, Proposition 3.4). It grows with , so the first above is the distance. Line L2 is the Laplace mechanism on . Line L3 is the test. Line L4 is the release with the proposed bound.
Example
Take values , with , and , so the threshold in line L3 is . Each gap is 1, so changes move the median by at most , and for whole numbers . From the code:
| P(the test passes) | noise in line L4 | median absolute error | ||
|---|---|---|---|---|
| 5 | 5 | 0.00007 | Lap(5) | 3.5 |
| 10 | 10 | 0.011 | Lap(10) | 6.9 |
| 15 | 15 | 0.847 | Lap(15) | 10.4 |
| 20 | 20 | 0.999 | Lap(20) | 13.9 |
| 30 | 30 | 1.000 | Lap(30) | 20.8 |
A small gives small noise but the test fails, and a large always passes but adds more noise. With the release is -DP with the median absolute error 13.9. The Laplace mechanism with the global sensitivity 100 at needs , with the median absolute error 34.7. These values are exact for the noise laws (a theorem), not a measurement.
Correctness
Line L1 is the distance (a theorem). By NRS Proposition 3.4, the inner maximum is , so the least with a value above is . The test file checks line L1 against a breadth-first search over all small datasets.
has sensitivity 1 (a theorem). is a metric, so for neighbors.
Privacy (Vadhan Proposition 3.2, a theorem). The test of lines L2 and L3 is -DP. If , then , so line L4 is -DP for this pair, and the total is . If , the test passes with probability . So the output is -DP. Vadhan states ; the same proof gives .
Utility (a theorem). If , the test passes with probability at least .
The full proofs are in proofs/correctness.md.
Proof: Propose-test-release for the median computes the distance to instability and is (2 epsilon, delta)-DPfull
We use the pseudocode of the page. A dataset is a list of values in , with odd and . We sort it and set for and for . Two datasets are neighbors if one value is replaced by another, and is the number of replacements from to . The median is , and is its local sensitivity. The proposed bound is , the threshold is , and the output means "no answer".
Claim 1 (line L1). Let , with if no has . Then , with .
Proof. By Nissim, Raskhodnikova and Smith (2007, Proposition 3.4), . The proof is on the smooth sensitivity page. So exactly when some with has , and the least such is . For every dataset is within replacements and , so exactly when , and the loop can stop at . The test file checks line L1 against a breadth-first search over the grid for and .
Claim 2 (sensitivity of ). For neighbors , , and exactly when .
Proof. is a metric, so for every . Take the minimum over the with : , and the same with and swapped. The set does not depend on , so it is empty for both or for neither.
Claim 3 (privacy; Vadhan Proposition 3.2). The output is -DP, so it is -DP.
Proof. Fix neighbors and a set of outputs. Write with , and . Lines L2 and L3 are the Laplace mechanism on , which has sensitivity 1 by Claim 2, followed by a test. So by post-processing, and . If both are infinite, the test passes for both, and the case below with applies.
Case . Then , so . Let and let be the law of . Then , and
Case . Then , and
In both cases .
Vadhan states the result with . The proof gives because for the Laplace law. The test file computes the exact output law for every pair of neighbors with and , and checks the hockey-stick divergence at against by a fine numerical integration.
Claim 4 (utility). If with , the test passes with probability at least , and then the output is , whose error is above with probability .
Proof. The test fails when , which has probability . The second part is the tail of the Laplace law.
Cost. Sorting takes . Line L1 tries and each try takes , so it takes after the sort. Lines L2 to L4 take . The total is time in the worst case and extra space.
Complexity
In the real-RAM model, sorting takes . Line L1 tries and each try scans terms, so it takes . Lines L2 to L4 take . The total is time in the worst case and extra space. For a general , line L1 can be hard to compute, and this is the main limit of PTR.
Properties
- Any function. The privacy proof uses only the sensitivity 1 of and the bound when . It works for every and .
- Approximate DP only. The output is -DP and not pure DP, because a dataset with still passes with probability . Bun and Steinke note that it is also not zero-concentrated DP.
- A private "no". The output is itself private: it tells only that the data is close to an unstable dataset.
- Data-dependent error. When the test passes, the error is that of , set by the proposal and not by .
Variants and improvements
- Release of stable values. If is constant on all datasets within distance , line L4 can output with no noise (Vadhan Proposition 3.3; Dwork and Roth Algorithm 13). This gives a private mode and the stability-based histogram.
- Scale first. Dwork and Lei, and Dwork and Roth Algorithm 12, first estimate the interquartile range with PTR on a log scale, and then use it as the proposal for the median. Dwork and Roth Theorem 7.1 gives -DP for the scale step.
- Many proposals. Try and stop at the first pass. With the sparse vector technique the cost of the failed tests is small.
- Smooth sensitivity. Smooth sensitivity scales the noise to the local sensitivity near without a test, and it can give pure DP with heavy-tailed noise.
When to use it
Use PTR when a statistic has a large global sensitivity but is stable on typical data, and when a "no answer" output is acceptable: a median, a quantile, a mode, or a robust regression estimate on a large sample. Use the Laplace mechanism when the global sensitivity is small. Use subsample and aggregate when the distance to instability is hard to compute.
Pitfalls
- Release without the test. Skipping line L3, or releasing itself, breaks privacy. The proposal alone is not a bound on the local sensitivity of every dataset.
- No noise in line L2. A test on the exact leaks whether is above the threshold, which can single out one record. The noise is required.
- A data-dependent proposal. The bound must not depend on , unless it comes from a private step whose cost is counted, as in the scale step of Dwork and Lei. A read from the data makes line L4 leak.
- The wrong distance. Line L1 must be the distance to the nearest dataset with , not itself. A dataset with can have a neighbor with a large .
- The privacy cost. The total is , not . Count both lines L2 and L4 in the budget.
- Float noise. The code uses
random.Randomand float noise, for tests only. A deployment needs a cryptographic source of randomness and exact sampling (Mironov 2012; Canonne, Kamath and Steinke 2020).
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
# 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
propose_test_release.py 106 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/propose-test-release/. The authors are listed in prov/DV793R.jsonl.
"""Propose-test-release (PTR) of Dwork and Lei (2009), in the form of
Vadhan (2017, Proposition 3.2), for the median of values in [0, lam].
Neighbors replace one value by another, so n is fixed. The analyst proposes
a bound b on the local sensitivity. The mechanism computes the distance
from x to the nearest dataset whose local sensitivity is above b, tests a
noisy copy of it against ln(1/delta)/epsilon, and releases the median with
Lap(b/epsilon) noise only if the test passes. Otherwise it outputs None
(the symbol "no answer"). The whole run is (2 epsilon, delta)-DP.
The code uses random.Random so that the tests can be repeated, and float
noise. A real release needs a cryptographic source of randomness and exact
sampling (Mironov 2012; Canonne, Kamath and Steinke 2020).
"""
from __future__ import annotations
import math
import random
from typing import Optional, Sequence
def median(xs: Sequence[float]) -> float:
"""The median x_m of an odd number of values, m = (n + 1)/2 in 1-based order. Cost: O(n log n)."""
if len(xs) % 2 == 0 or not xs:
raise ValueError("n must be odd")
return sorted(xs)[len(xs) // 2]
def ball_sensitivity(xs: Sequence[float], k: int, lam: float) -> float:
"""A(k, x) = max over t = 0..k+1 of x_{m+t} - x_{m+t-k-1}, with x_i = 0 for i <= 0 and lam for i > n.
This is the largest local sensitivity of the median over the datasets within k replacements
of x (Nissim, Raskhodnikova and Smith 2007, Proposition 3.4). Cost: O(n log n + k).
"""
return _ball(_padded(xs, lam), (len(xs) + 1) // 2, k)
def _padded(xs: Sequence[float], lam: float) -> list[float]:
# Index i of the list is x_{i - n - 1}: n zeros, the sorted values, then n + 2 copies of lam.
n = len(xs)
return [0.0] * (n + 1) + [float(v) for v in sorted(xs)] + [float(lam)] * (n + 2)
def _ball(p: list[float], m: int, k: int) -> float:
off = (len(p) - 1) // 3 # the offset of x_0 in the padded list
return max(p[off + m + t] - p[off + m + t - k - 1] for t in range(k + 2))
def distance_to_instability(xs: Sequence[float], b: float, lam: float) -> float:
"""The number of replacements from x to the nearest dataset whose local sensitivity is above b.
It is the least k with A(k, x) > b, because A(k, x) grows with k. It is infinite when b >= lam.
Precondition: n odd, values in [0, lam]. Cost: O(n log n + gamma^2).
"""
p = _padded(xs, lam)
m = (len(xs) + 1) // 2
for k in range(len(xs) + 1):
if _ball(p, m, k) > b:
return float(k)
return math.inf
def laplace_noise(b: float, rng: random.Random) -> float:
"""One draw of Lap(b), the density (1/(2b)) exp(-|z|/b), by the inverse CDF. Cost: O(1)."""
u = rng.random() - 0.5
while u == -0.5:
u = rng.random() - 0.5
s = (u > 0) - (u < 0)
return -b * s * math.log(1.0 - 2.0 * abs(u))
def laplace_cdf(t: float, b: float) -> float:
"""P(Lap(b) <= t). Cost: O(1)."""
if t < 0:
return 0.5 * math.exp(t / b)
return 1.0 - 0.5 * math.exp(-t / b)
def pass_probability(gamma: float, epsilon: float, delta: float) -> float:
"""P(gamma + Lap(1/epsilon) > ln(1/delta)/epsilon), the chance that the test of line L3 passes. Cost: O(1)."""
if math.isinf(gamma):
return 1.0
return 1.0 - laplace_cdf(math.log(1.0 / delta) / epsilon - gamma, 1.0 / epsilon)
def propose_test_release_median(
xs: Sequence[float], lam: float, b: float, epsilon: float, delta: float, rng: random.Random
) -> Optional[float]:
"""PTR for the median. Returns None for "no answer", else median(x) + Lap(b/epsilon).
Precondition: n odd, values in [0, lam], b > 0, epsilon > 0, 0 < delta < 1.
Guarantee: (2 epsilon, delta)-DP for replace neighbors (Vadhan, Proposition 3.2).
Cost: O(n^2) time and O(n) extra space.
"""
if epsilon <= 0 or not 0 < delta < 1 or b <= 0:
raise ValueError("need epsilon > 0, 0 < delta < 1 and b > 0")
if len(xs) % 2 == 0:
raise ValueError("n must be odd")
gamma = distance_to_instability(xs, b, lam) # @line L1
noisy = gamma + laplace_noise(1.0 / epsilon, rng) # @line L2
if noisy <= math.log(1.0 / delta) / epsilon: # @line L3
return None
return median(xs) + laplace_noise(b / epsilon, rng) # @line L4
test_propose_test_release.py 162 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/propose-test-release/. The authors are listed in prov/DV793R.jsonl.
import itertools
import math
import random
import dpkit
from propose_test_release import (
distance_to_instability,
laplace_noise,
median,
pass_probability,
propose_test_release_median,
)
def _local_sensitivity(xs, lam):
# Brute force: replace one value by 0 or lam (the extremes move the median the most).
med = median(xs)
best = 0.0
for i in range(len(xs)):
for v in (0, lam):
ys = list(xs)
ys[i] = v
best = max(best, abs(median(ys) - med))
return best
def _bfs_distance(xs, b, lam):
# Breadth-first search over the multisets of the grid {0..lam}^n, one replacement for each step.
start = tuple(sorted(xs))
seen = {start}
frontier = [start]
dist = 0
while frontier:
if any(_local_sensitivity(y, lam) > b for y in frontier):
return float(dist)
nxt = []
for y in frontier:
for i in range(len(y)):
for v in range(lam + 1):
z = tuple(sorted(y[:i] + (v,) + y[i + 1:]))
if z not in seen:
seen.add(z)
nxt.append(z)
frontier = nxt
dist += 1
return math.inf
def test_distance_matches_breadth_first_search() -> None:
count = 0
for n in (1, 3, 5):
for lam in (1, 2, 4):
for xs in itertools.combinations_with_replacement(range(lam + 1), n):
for b in (0, 0.5, 1, 2, lam):
assert distance_to_instability(xs, b, lam) == _bfs_distance(xs, b, lam)
count += 1
assert count >= 500
def test_distance_has_sensitivity_one() -> None:
rng = random.Random(1)
for _ in range(500):
n, lam = rng.choice([3, 5, 9, 21]), 30
b = rng.choice([1, 2, 4, 8])
xs = [rng.randrange(lam + 1) for _ in range(n)]
ys = list(xs)
ys[rng.randrange(n)] = rng.randrange(lam + 1)
assert abs(distance_to_instability(xs, b, lam) - distance_to_instability(ys, b, lam)) <= 1
def test_distance_zero_means_unstable() -> None:
rng = random.Random(2)
for _ in range(500):
n, lam = rng.choice([1, 3, 5, 7]), 10
b = rng.choice([0.5, 1, 3])
xs = [rng.randrange(lam + 1) for _ in range(n)]
assert (distance_to_instability(xs, b, lam) == 0) == (_local_sensitivity(xs, lam) > b)
def _output_law(xs, lam, b, epsilon, delta, grid, h):
# The exact law of the output: the mass of "no answer" and the density on a grid times h.
p = pass_probability(distance_to_instability(xs, b, lam), epsilon, delta)
c, s = median(xs), b / epsilon
return 1.0 - p, [p * h * math.exp(-abs(z - c) / s) / (2 * s) for z in grid]
def test_two_epsilon_delta_dp_by_hockey_stick() -> None:
# Vadhan Proposition 3.2: (2 epsilon, delta)-DP. The proof gives delta/2; we check delta/2.
lam, b, epsilon, delta = 4, 1.0, 0.5, 0.1
h = 0.05
grid = [-40 + h * (i + 0.5) for i in range(int(84 / h))]
universe = range(lam + 1)
laws = {}
for xs in itertools.combinations_with_replacement(universe, 3):
laws[xs] = _output_law(xs, lam, b, epsilon, delta, grid, h)
worst = 0.0
worst_one = 0.0
for xs in laws:
for ys in dpkit.neighbors_replace(xs, universe):
ys = tuple(sorted(ys))
(bx, dx), (by, dy) = laws[xs], laws[ys]
for eps, store in ((2 * epsilon, "two"), (epsilon, "one")):
e = math.exp(eps)
hs = max(0.0, bx - e * by) + sum(max(0.0, a - e * c) for a, c in zip(dx, dy))
if store == "two":
worst = max(worst, hs)
else:
worst_one = max(worst_one, hs)
assert bx <= math.exp(epsilon) * by + 1e-12
assert worst <= delta / 2 + 1e-3
assert worst_one > worst # the test and the release each spend epsilon
def test_pass_probability_formula_and_sampling() -> None:
rng = random.Random(3)
xs = [rng.randrange(101) for _ in range(31)]
for b, epsilon, delta in ((10, 1.0, 1e-3), (20, 0.5, 1e-2), (40, 1.0, 1e-6)):
p = pass_probability(distance_to_instability(xs, b, 100), epsilon, delta)
n = 3000
hits = sum(propose_test_release_median(xs, 100, b, epsilon, delta, rng) is not None for _ in range(n))
assert abs(hits / n - p) <= dpkit.hoeffding_margin(n, 1e-6)
def test_released_value_is_median_plus_laplace() -> None:
rng = random.Random(4)
xs = list(range(51)) # distance 25 to instability for b = 30, so the test passes
outs = [propose_test_release_median(xs, 100, 30, 1.0, 1e-6, rng) for _ in range(3000)]
assert all(o is not None for o in outs)
n = len(outs)
frac = sum(abs(o - 25) > 30 for o in outs) / n
assert abs(frac - math.exp(-1.0)) <= dpkit.hoeffding_margin(n, 1e-6)
def test_example_values() -> None:
xs = list(range(101))
got = [(b, distance_to_instability(xs, b, 100)) for b in (5, 10, 15, 20, 30)]
assert got == [(5, 5), (10, 10), (15, 15), (20, 20), (30, 30)]
probs = [pass_probability(g, 1.0, 1e-6) for _, g in got]
assert probs[0] < 1e-4 and 0.010 < probs[1] < 0.012 and 0.84 < probs[2] < 0.85
assert probs[3] > 0.998 and probs[4] > 0.999999
assert distance_to_instability(xs, 100, 100) == math.inf
def test_laplace_tail() -> None:
rng = random.Random(5)
n = 20000
frac = sum(abs(laplace_noise(2.0, rng)) > 3.0 for _ in range(n)) / n
assert abs(frac - math.exp(-1.5)) <= dpkit.hoeffding_margin(n, 1e-6)
def test_bad_parameters() -> None:
rng = random.Random(6)
for args in (([1], 1, 1.0, 0.0, 0.1), ([1], 1, 1.0, 1.0, 0.0), ([1], 1, 0.0, 1.0, 0.1), ([1, 2], 2, 1.0, 1.0, 0.1)):
try:
propose_test_release_median(*args, rng)
except ValueError:
pass
else:
raise AssertionError("expected ValueError")
History
Nissim, Raskhodnikova and Smith (STOC 2007) showed that noise scaled to the local sensitivity is not safe and gave smooth sensitivity. Dwork and Lei (STOC 2009) gave propose-test-release and used it to make robust estimators of scale, location and regression private. Dwork and Roth (2014) and Vadhan (2017) gave the general form used here, and Vadhan used the stable-value form for private histograms over large universes.
References
- Salil Vadhan, The complexity of differential privacy, in Tutorials on the Foundations of Cryptography, Springer, 2017, pages 347 to 450, Section 3: Proposition 3.2 (propose-test-release, (2 epsilon, delta)-DP) and Proposition 3.3 (releasing stable values)
- Cynthia Dwork and Aaron Roth, The Algorithmic Foundations of Differential Privacy, Foundations and Trends in Theoretical Computer Science 9(3-4), 2014, Section 7: Algorithm 12 (Scale, the interquartile range) with Theorem 7.1 ((4 epsilon, delta)-DP), and Algorithm 13 (A_dist, release based on the distance to instability)
- Cynthia Dwork and Jing Lei, Differential privacy and robust statistics, STOC 2009, the propose-test-release framework and its use for scale, location and regression
- Ilya Mironov, On significance of the least significant bits for differential privacy, ACM CCS 2012, the attack on floating-point noise and the snapping defense
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 DV793R Edit this page History Report an error Markdown