Algorithmadvanced
Anatomy
Also called bucketization.
Releases quasi-identifiers and sensitive values in two tables linked only by group id, with l-diverse groups and no generalization.
- Time
- O(n log m) worst
- Space
- O(n) extra
- Where
- l = the diversity parameter; m = the number of distinct sensitive values; n = the number of tuples
- Model
- Word RAM
- Properties
- deterministicnot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Xiaokui Xiao, Yufei Tao, 2006
Anatomy publishes a table with a sensitive attribute as two tables. The quasi-identifier table (QIT) holds the exact quasi-identifier values of each tuple and a group id. The sensitive table (ST) holds, for each group, the sensitive values and their counts. Nothing joins a tuple to its own sensitive value except the group id, and each group holds at least tuples with distinct sensitive values. Xiao and Tao (VLDB 2006) proved that an attacker who knows a person's quasi-identifier values and knows that the person is in the table then guesses the person's sensitive value with probability at most , the same as for an l-diverse generalized table. But no value is coarsened, so aggregate queries that mix quasi-identifiers and the sensitive attribute are much more accurate. Their algorithm Anatomize builds the groups in time in the word-RAM model, and its reconstruction error is within a factor of the lowest possible. The value of is a policy choice.
In plain words
A hospital wants to publish patient ages and ZIP codes, and also the diseases, without letting anyone link a patient to a disease. Generalization would blur the ages into ranges. Anatomy keeps them exact.
It puts the patients into small groups, and each group must have different diseases. It then publishes two lists. The first list gives each patient's age and ZIP code and the number of the group. The second list gives, for each group number, the diseases in the group, but not who has which one.
If a group has three patients with three different diseases, a neighbour who finds a patient in the first list only learns that the patient has one of three diseases. The groups are formed by taking one patient from each of the most common diseases at a time, so that no disease is left over at the end.
The problem
The input is a table of tuples with quasi-identifier attributes and one categorical sensitive attribute , and an integer . A partition of into groups is l-diverse if in each group , the most frequent sensitive value has (Definition 2 of the paper). The output is the QIT, with one row for each tuple in group , and the ST, with one row for each group and each value in it (Definition 3).
An l-diverse partition exists if and only if at most tuples share a sensitive value; the paper calls this the eligibility condition. It is necessary because each group can hold at most tuples of a value, and these numbers add up to at most . The algorithm below shows that it is also sufficient.
The quality measure of the paper is the reconstruction error. For a tuple with value in group , , the squared distance between the true point of and the distribution that the release gives for it, and . Theorem 2 of the paper proves for every l-diverse partition.
The algorithm
ANATOMIZE(T, l) ▷ at most n/l tuples of T share a sensitive value- 1
QIT ← ∅, ST ← ∅, g ← 0 - 2
hash the tuples of T into buckets by their sensitive value - 3
while at least l buckets are non-empty do - 4
g ← g + 1, G_g ← ∅ - 5
S ← the l buckets that hold the most tuples - 6
for each bucket B in S do - 7
remove one tuple from B and add it to G_g - 8
for each non-empty bucket B do ▷ B holds exactly one tuple - 9
t ← the tuple of B - 10
S' ← the groups that hold no tuple with the sensitive value of t - 11
add t to one group of S' - 12
for j ← 1 to g do - 13
for each tuple t of G_j, insert (t[A_1], ..., t[A_d], j) into QIT - 14
for each distinct value v in G_j, insert (j, v, c_j(v)) into ST - 15
return QIT, ST
Lines L3 to L7 are the group creation phase. Each iteration takes one tuple from each of the largest buckets, so each new group has exactly tuples with distinct values. The phase stops when fewer than buckets are non-empty. Lines L8 to L11 are the residue phase. The eligibility condition guarantees two facts that the paper proves as Properties 1 and 2: at the end of the first phase each non-empty bucket holds exactly one tuple, and each such residue tuple has a group without its value. Lines L12 to L14 write the two tables.
The paper removes "an arbitrary tuple" at line L7 and picks "a random group" at line L11; both choices are free. The code takes the oldest tuple of each bucket, breaks ties between buckets of the same size by the first appearance of their value, and puts a residue tuple into the first group of . Within each group, it writes the QIT rows and the ST rows in sorted order, so that the order of the rows says nothing about which tuple has which value (see Pitfalls).
Example
Take seven synthetic tuples with . Age and ZIP code are the quasi-identifiers and the disease is sensitive. Flu occurs 3 times, and , so the table is eligible.
| tuple | Age | ZIP | disease |
|---|---|---|---|
| 23 | 11001 | flu | |
| 27 | 11002 | gastritis | |
| 35 | 11005 | flu | |
| 59 | 12001 | dyspepsia | |
| 61 | 12003 | flu | |
| 65 | 12004 | gastritis | |
| 70 | 12007 | pneumonia |
Line L2 makes four buckets. Ties of size go to the value that appears first in the table.
| step | buckets before the step (flu, gastritis, dyspepsia, pneumonia) | the largest | new group |
|---|---|---|---|
| iteration 1 | , , , | flu, gastritis | |
| iteration 2 | , , , | flu, gastritis | |
| iteration 3 | , , , | flu, dyspepsia | |
| residue | , , , | one bucket left, | goes to , which has no pneumonia |
The release is the two tables below.
| Age | ZIP | group |
|---|---|---|
| 23 | 11001 | 1 |
| 27 | 11002 | 1 |
| 70 | 12007 | 1 |
| 35 | 11005 | 2 |
| 65 | 12004 | 2 |
| 59 | 12001 | 3 |
| 61 | 12003 | 3 |
| group | disease | count |
|---|---|---|
| 1 | flu | 1 |
| 1 | gastritis | 1 |
| 1 | pneumonia | 1 |
| 2 | flu | 1 |
| 2 | gastritis | 1 |
| 3 | dyspepsia | 1 |
| 3 | flu | 1 |
An attacker who knows that a person aged 23 in ZIP 11001 is in the table finds group 1, and learns only that the person has flu, gastritis or pneumonia, each with probability . A researcher still sees the exact ages. Each tuple is alone with its value in its group, so , and . The lower bound is , and , the worst case of Theorem 4.
Correctness
Let be the number of tuples left in the buckets, the size of the largest bucket and the number of buckets of that size. The group creation phase keeps the invariant: either , or . At the start, it follows from the eligibility condition . When the phase stops, buckets are non-empty, and gives . With this is less than , against the invariant. So each bucket holds at most one tuple (Property 1). The first phase makes groups. A residue value occurs at most times in , and one of these occurrences is the residue tuple, so at most groups hold and is not empty (Property 2). Each group then has at least tuples, all with distinct values (Property 3), so . The full proof is in proofs/correctness.md.
The privacy claim is a theorem of the paper (Lemma 1, Corollary 1 and Theorem 1): if the attacker knows the quasi-identifier values of a person and that the person is in , and treats each assignment of the values of a group to its tuples as equally likely, then the probability that the person has value is .
Proof: Anatomize returns an l-diverse partition of every eligible tablefull
Let have tuples and let . The table is eligible if at most tuples share a sensitive value. A partition is l-diverse if in each group every value has . During the group creation phase (lines L3 to L7), let be the number of tuples left in the buckets, the number of non-empty buckets, the size of the largest bucket and the number of buckets of size .
Claim 0 (eligibility is necessary). If an l-diverse partition exists, the table is eligible.
Proof. For a value , .
Claim 1 (invariant). Before each test of line L3, either or .
Proof. At the start, and . If , then . If , then , so .
Now take an iteration with (if , every bucket still has at most one tuple afterwards, so the claim holds). Line L5 takes the largest buckets and line L7 removes one tuple from each, so .
- If , all chosen buckets have size . Then and , and .
- If , all buckets of size are chosen and drop to , so . Let be the number of buckets of size that are not chosen; then . If , . If , a bucket of size was passed over, so all chosen buckets have size at least , and . Hence .
Claim 2 (Property 1). When line L3 stops the loop, each bucket holds at most one tuple, and groups exist.
Proof. The loop stops with . Suppose . The largest buckets hold tuples and the other hold at most each, so , which contradicts Claim 1. So and . Each iteration removed tuples, so with , which gives .
Claim 3 (Property 2). For each residue tuple , the set of line L10 is not empty.
Proof. Let be the value of . Since and is an integer, . Each group made by lines L4 to L7 takes at most one tuple from each bucket, so it holds at most once, and itself is in no group yet. The residue tuples have distinct values by Claim 2, so no earlier residue tuple added . Hence at most groups hold . Since for an eligible non-empty table (otherwise ), and at least one group lacks .
Claim 4 (Property 3 and correctness). If the table is eligible, the groups form a partition of into groups of at least tuples with pairwise distinct values, so the partition is l-diverse.
Proof. Every tuple leaves its bucket exactly once, at line L7 or at line L9, and joins exactly one group, so the groups partition . Each group starts with tuples from different buckets, so with distinct values, and grows only at line L11, by a tuple whose value it does not hold (Claim 3). So in each group every value occurs once, and . Lines L12 to L14 write exactly the rows of Definition 3 of Xiao and Tao for this partition. With Claim 0, an l-diverse partition exists if and only if the table is eligible, and the code raises an error exactly when it is not.
The error. In a group of size where all counts are 1, each tuple has error , so the group contributes and the release has . Since , this is at most , which is times the lower bound of Theorem 2 of the paper.
Cost. Line L2 is with hashing. The heap holds at most entries, and each of the iterations does pops and at most pushes, so the first phase is . The residue phase handles fewer than tuples and scans at most groups for each, with a set of values per group, which is . Lines L12 to L14 are with the sorting inside groups. The extra space is .
Complexity
The model is the word-RAM, with the sensitive values hashed in expected time.
- Line L2 takes expected time.
- The code keeps the non-empty buckets in a binary heap keyed by size. Each of the iterations pops buckets and pushes back at most , at each, so the first phase takes time.
- At most residue tuples exist, and each scans at most groups with a set of values per group, so the residue phase takes time.
- Lines L12 to L14 take time, or with the sorting of rows inside each group.
- The extra space is for the groups.
In external memory, Theorem 3 of the paper shows I/Os and memory for a page size : the bucket sizes fit in memory, and the groups are written out in the order they are made. Theorem 4 bounds the quality: if divides , then , the lower bound; otherwise is at most times the lower bound. With all counts 1, , whatever group each residue tuple joins.
Properties
- No generalization. The quasi-identifier values are published exactly. The privacy comes from cutting the link between the QIT row and the ST row.
- Groups of size or slightly more. Each group has tuples, and at most groups receive one or more residue tuples.
- Deterministic as coded. The paper allows any choice at lines L7 and L11; the guarantee holds for every choice.
- Membership is not hidden. The QIT shows the exact quasi-identifier values of everyone in the table, so an attacker learns who is in it. A generalized table can hide this when the attacker does not know who is in the table, which the paper discusses as its assumption A2.
Variants and improvements
- Other diversity rules per group. Lines L3 to L7 make each group distinct -diverse with one tuple per value, which also meets the entropy and recursive forms of l-diversity. A group rule based on t-closeness needs a different grouping step.
- Republication. When the table changes and is released again, each release can be l-diverse and the sequence can still leak. m-invariance is the fix of Xiao and Tao for that case; it uses the same group and signature idea.
- More than two tables. Later work cuts the attributes into more than two column groups, each released with a group id, so that correlated quasi-identifiers stay together.
- The same format with a generalized QIT. Some systems combine a coarse generalization of the quasi-identifiers with a separate sensitive table, to hide membership as well.
When to use it
Use anatomy when analysts need the exact quasi-identifier values, for example to run range queries or to fit a model on age and ZIP code together with the sensitive attribute, and when publishing who is in the table is acceptable. If membership itself is sensitive, use a generalization such as Mondrian, or a differentially private release. If the attacker may learn the correlation between quasi-identifiers and the sensitive value from the release itself, the bound does not hold, as the next section explains.
Pitfalls
- Taking any buckets at line L5. If line L5 takes non-empty buckets that are not the largest, values can be stranded. With the values and (eligible, since ), the group leaves the bucket , and the second has no group without . Line L5 must take the largest buckets.
- Placing a residue tuple anywhere at line L11. A residue tuple put into a group that already has its value makes that value occur twice in a group of tuples, and for . Line L10 must restrict the choice to groups without the value.
- Leaking through row order at lines L13 and L14. If the QIT rows of a group are written in the same order as the ST rows, for example both in the order in which line L7 picked the tuples, then the -th row of one table matches the -th row of the other, and the release links every person to a value. Write each group's rows in an order that does not depend on the link, such as sorted by value.
- Skipping the eligibility test. If more than tuples share a value, no l-diverse partition exists. Without the test, the loop of line L3 ends with a bucket of two or more tuples, and line L11 fails. Test first, and suppress tuples of the frequent value or lower .
- Trusting against a learning attacker. The bound assumes that each assignment inside a group is equally likely. Kifer (SIGMOD 2009) showed that an attacker can learn from the whole anatomized release how quasi-identifiers and sensitive values correlate, and then guess single values with probability well above . Anatomy limits what one row reveals, not what the release reveals about the population.
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/anatomy-bucketization/. The authors are listed in prov/Y4WDK2.jsonl.
import heapq
from collections import Counter, deque
from collections.abc import Hashable, Sequence
from fractions import Fraction
Row = Sequence[Hashable]
def anatomize_groups(values: Sequence[Hashable], l: int) -> list[list[int]]:
"""Partition the positions 0..n-1 into l-diverse groups by their sensitive values.
Precondition: l >= 1 and at most n / l positions share a value (the
eligibility condition); otherwise ValueError is raised. Each group gets at
least l positions, all with distinct values. Ties between buckets of the
same size go to the value that appears first, and each bucket gives up its
oldest position first. Cost: O(n log m) time and O(n) extra space for n
values with m distinct ones.
"""
if l < 1:
raise ValueError("l must be at least 1")
n = len(values)
groups: list[list[int]] = [] # @line L1
index: dict[Hashable, int] = {}
queues: list[deque[int]] = []
for i, v in enumerate(values): # @line L2
if v not in index:
index[v] = len(queues)
queues.append(deque())
queues[index[v]].append(i)
if queues and l * max(len(q) for q in queues) > n:
raise ValueError("not eligible: more than n / l tuples share a sensitive value")
heap = [(-len(q), k) for k, q in enumerate(queues)]
heapq.heapify(heap)
while len(heap) >= l: # @line L3
group: list[int] = [] # @line L4
chosen = [heapq.heappop(heap) for _ in range(l)] # @line L5
for neg_size, k in chosen: # @line L6
group.append(queues[k].popleft()) # @line L7
if neg_size + 1 < 0:
heapq.heappush(heap, (neg_size + 1, k))
groups.append(group)
seen = [{values[i] for i in g} for g in groups]
for _, k in sorted(heap, key=lambda e: e[1]): # @line L8
i = queues[k].popleft() # @line L9
v = values[i]
target = next(j for j, vs in enumerate(seen) if v not in vs) # @line L10
groups[target].append(i) # @line L11
seen[target].add(v)
return groups
def anatomize(
table: Sequence[Row], qi: Sequence[int], s: int, l: int
) -> tuple[list[tuple[Hashable, ...]], list[tuple[int, Hashable, int]]]:
"""Return the quasi-identifier table and the sensitive table of an anatomized release.
A QIT row is the quasi-identifier values of a tuple followed by its group
id (from 1). An ST row is (group id, value, count). Inside each group the
rows are sorted, so the row order does not link a QIT row to an ST row.
Precondition: as for anatomize_groups, and the values of each column are
mutually comparable. Cost: O(n log n) time, O(n) extra space.
"""
groups = anatomize_groups([row[s] for row in table], l)
qit: list[tuple[Hashable, ...]] = []
st: list[tuple[int, Hashable, int]] = []
for j, g in enumerate(groups, start=1): # @line L12
qit.extend((*key, j) for key in sorted(tuple(table[i][a] for a in qi) for i in g)) # @line L13
counts = Counter(table[i][s] for i in g)
st.extend((j, v, c) for v, c in sorted(counts.items())) # @line L14
return qit, st # @line L15
def reconstruction_error(groups: Sequence[Sequence[Hashable]]) -> Fraction:
"""Return the RCE of Xiao and Tao for groups given as lists of sensitive values.
For a tuple with value v in group G, the error is (1 - c(v)/|G|)^2 plus the
sum of c(u)^2 / |G|^2 over the other values u of G. Cost: O(n) for n tuples
when each group has O(1) distinct values, O(sum of |G| m_G) in general.
"""
total = Fraction(0)
for g in groups:
size = len(g)
counts = Counter(g)
for v in g:
err = (1 - Fraction(counts[v], size)) ** 2
err += sum((Fraction(c * c, size * size) for u, c in counts.items() if u != v), Fraction(0))
total += err
return total
test_anatomy_bucketization.py 149 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/anatomy-bucketization/. The authors are listed in prov/Y4WDK2.jsonl.
import random
from collections import Counter
from fractions import Fraction
import pytest
from anatomy_bucketization import anatomize, anatomize_groups, reconstruction_error
TABLE = [
(23, 11001, "flu"),
(27, 11002, "gastritis"),
(35, 11005, "flu"),
(59, 12001, "dyspepsia"),
(61, 12003, "flu"),
(65, 12004, "gastritis"),
(70, 12007, "pneumonia"),
]
def test_example() -> None:
values = [r[2] for r in TABLE]
groups = anatomize_groups(values, 2)
assert groups == [[0, 1, 6], [2, 5], [4, 3]]
qit, st = anatomize(TABLE, [0, 1], 2, 2)
assert qit == [
(23, 11001, 1),
(27, 11002, 1),
(70, 12007, 1),
(35, 11005, 2),
(65, 12004, 2),
(59, 12001, 3),
(61, 12003, 3),
]
assert st == [
(1, "flu", 1),
(1, "gastritis", 1),
(1, "pneumonia", 1),
(2, "flu", 1),
(2, "gastritis", 1),
(3, "dyspepsia", 1),
(3, "flu", 1),
]
rce = reconstruction_error([[values[i] for i in g] for g in groups])
assert rce == 4
assert rce / (7 * (1 - Fraction(1, 2))) == Fraction(8, 7)
def test_edges() -> None:
assert anatomize([], [0], 1, 3) == ([], [])
assert anatomize_groups(["a", "b", "a"], 1) == [[0], [2], [1]]
with pytest.raises(ValueError):
anatomize_groups(["a", "a", "b"], 2)
with pytest.raises(ValueError):
anatomize_groups(["a"], 0)
with pytest.raises(ValueError):
anatomize_groups(["a", "b"], 3)
# the largest buckets must be taken first, or the second "a" is stranded
groups = anatomize_groups(["a", "a", "b", "c"], 2)
assert sorted(sorted(g) for g in groups) == [[0, 2], [1, 3]]
def set_partitions(n: int) -> list[list[int]]:
"""Every set partition of range(n) as a restricted growth string."""
out: list[list[int]] = [[]]
for _ in range(n):
out = [s + [b] for s in out for b in range((max(s) + 2) if s else 1)]
return out
PARTITIONS = {n: set_partitions(n) for n in range(1, 7)}
def blocks_of(labels: list[int], values: list[str]) -> list[list[str]]:
out: dict[int, list[str]] = {}
for b, v in zip(labels, values):
out.setdefault(b, []).append(v)
return list(out.values())
def diverse(block: list[str], l: int) -> bool:
return l * max(Counter(block).values()) <= len(block)
def rce_closed_form(blocks: list[list[str]]) -> Fraction:
# summing the per-tuple error over a block of size g gives g - (sum of c^2) / g
return sum(
(Fraction(len(b) ** 2 - sum(c * c for c in Counter(b).values()), len(b)) for b in blocks),
Fraction(0),
)
def check_groups(groups: list[list[int]], values: list[str], l: int) -> None:
n = len(values)
assert sorted(i for g in groups for i in g) == list(range(n))
assert len(groups) == n // l
for g in groups:
assert len(g) >= l
assert len({values[i] for i in g}) == len(g)
def test_against_brute_force() -> None:
rng = random.Random(7)
for _ in range(500):
n = rng.randint(1, 6)
l = rng.randint(1, 3)
values = [rng.choice("abcd"[: rng.randint(1, 4)]) for _ in range(n)]
best = None
for labels in PARTITIONS[n]:
blocks = blocks_of(labels, values)
if all(diverse(b, l) for b in blocks):
rce = rce_closed_form(blocks)
best = rce if best is None or rce < best else best
eligible = l * max(Counter(values).values()) <= n
assert eligible == (best is not None)
if not eligible:
with pytest.raises(ValueError):
anatomize_groups(values, l)
continue
groups = anatomize_groups(values, l)
check_groups(groups, values, l)
got = reconstruction_error([[values[i] for i in g] for g in groups])
assert got == rce_closed_form([[values[i] for i in g] for g in groups])
assert best >= n * (1 - Fraction(1, l))
assert best <= got <= (1 + Fraction(1, n)) * best
def test_large_random() -> None:
rng = random.Random(8)
for _ in range(500):
n = rng.randint(0, 30)
l = rng.randint(1, 5)
m = rng.randint(1, 8)
values = [rng.choice("abcdefgh"[:m]) for _ in range(n)]
if n and l * max(Counter(values).values()) > n:
with pytest.raises(ValueError):
anatomize_groups(values, l)
continue
groups = anatomize_groups(values, l)
check_groups(groups, values, l)
got = reconstruction_error([[values[i] for i in g] for g in groups])
assert got == n - n // l
table = [(rng.randint(0, 9), v) for v in values]
qit, st = anatomize(table, [0], 1, l)
assert len(qit) == n
assert sum(c for _, _, c in st) == n
assert Counter(v for _, v, _ in st) == Counter(v for g in groups for v in {values[i] for i in g})
History
Xiao and Tao presented anatomy at VLDB 2006, with the l-diverse partition, the two-table release, the lower bound on the reconstruction error and the linear I/O algorithm. Their running example compared anatomy with a generalized table of the same data and showed much smaller errors on aggregate queries. The same release format, a table of group ids next to a table of sensitive values, is often called bucketization in later work. Kifer's 2009 deFinetti attack showed the limits of the bound when the attacker learns from the release, and the same authors' m-invariance of 2007 extended the group and signature idea to tables that change over time.
References
- Xiaokui Xiao and Yufei Tao, Anatomy: simple and effective privacy preservation, 32nd International Conference on Very Large Data Bases (VLDB 2006), pages 139-150, Section 3 (Definitions 2 and 3, Lemma 1, Corollary 1 and Theorem 1 on the breach probability 1/l, and the assumptions A1 and A2), Section 4 (the reconstruction error), Section 5.1 (Theorem 2), Section 5.2 (Figure 3 and Properties 1 to 3) and Section 5.3 (Theorems 3 and 4)
- Daniel Kifer, Attacks on privacy and deFinetti's theorem, ACM SIGMOD 2009, pages 127-138, the attack that learns the correlation between quasi-identifiers and sensitive values from an anatomized release and uses it against single records
- Ashwin Machanavajjhala, Johannes Gehrke, Daniel Kifer and Muthuramakrishnan Venkitasubramaniam, l-diversity: privacy beyond k-anonymity, ICDE 2006, page 24, the l-diversity principle that anatomy enforces on each group
- Benjamin C. M. Fung, Ke Wang, Rui Chen and Philip S. Yu, Privacy-preserving data publishing: a survey of recent developments, ACM Computing Surveys 42(4), article 14, 2010, the anonymization operations, where anatomy is compared with generalization, suppression and perturbation
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 Y4WDK2 Edit this page History Report an error Markdown