Definitionadvanced
km-anonymity
Also called transaction k-anonymity.
For set-valued data, requires that any m items an attacker knows of a transaction match at least k transactions.
-anonymity is a privacy condition for set-valued data, such as shopping baskets, search logs or lists of diagnoses, where each record is a set of items of any size. An attacker often knows a few items of a person's record, for example some of the things the person bought, and wants to find the whole record. Terrovitis, Mamoulis and Kalnis (PVLDB 2008) defined a database as -anonymous if no attacker who knows up to items of a transaction can narrow the candidates down to fewer than transactions. Every item can be part of the attacker's knowledge, so there is no fixed set of quasi-identifiers, and every item can also be the thing the attacker wants to learn. Both and are policy choices: models how much the attacker is assumed to know. The condition is a property of the published database, and it says nothing about attackers who know more than items.
Definition
A transaction is a non-empty subset of a domain of items, and a database is a multiset of transactions. The support of an itemset is the number of transactions with .
Definition (Terrovitis, Mamoulis and Kalnis, Definition 1). A database is -anonymous if no attacker with background knowledge of up to items of a transaction can use these items to identify fewer than transactions of . Equivalently, every itemset with has support 0 or at least .
An itemset with support 0 is safe: knowing it matches no transaction. The knowledge is modelled as a subset query, the set of transactions that contain the known items.
To make a database -anonymous, the paper uses a generalization hierarchy over and global recoding: a cut of the hierarchy maps each item to one ancestor in all transactions, such as "skim milk" to "milk". Transactions keep set semantics, so two items that map to the same ancestor become one item (Definition 2 and Figure 2 of the paper). The cost of a cut is measured by the normalized certainty penalty (NCP), which charges each generalized item by the share of the domain it covers.
Facts, each a theorem:
- Support is anti-monotone. If , the support of is at least that of . So -anonymity implies -anonymity for every , and -anonymity with a larger implies it with a smaller one.
- Whole-transaction anonymity is stronger. If every transaction occurs at least times in , then is -anonymous for every , because an itemset is contained in all the copies of . The converse is false, as the example below shows.
- Coarser cuts stay anonymous (Property 1 of the paper, monotonicity of cuts). If a cut gives a -anonymous database, so does every more general cut. The reason: an itemset of size at most over the coarser items that some transaction contains comes from an itemset of size at most over the finer items in that transaction, picking one item below each element of , and every transaction that contains contains after the coarser recoding. So the support of is at least the support of , which is 0 or at least , and it is not 0.
The anti-monotone support gives a direct test: count every itemset of size at most that occurs in some transaction, and check the counts. proofs/correctness.md proves that the test is exact.
KM-ANONYMOUS(D, k, m)- 1
C ← an empty map from itemsets to counts - 2
for each transaction t in D do - 3
for each subset I of t with 1 ≤ |I| ≤ m do - 4
C[I] ← C[I] + 1 - 5
for each itemset I in C do - 6
if C[I] < k then return false - 7
return true
If each transaction has at most items, lines L2 to L4 do map updates per transaction, which is in total for a fixed , with hashing in the word-RAM model. The paper stores the same counts in a count-tree, a prefix tree like the FP-tree, and builds it in steps (Section 4.1). The cost grows fast with , which is one reason is small in practice.
Finding the cut with the least information loss is hard in general. The paper gives an optimal algorithm (OA) that searches the lattice of cuts bottom-up in the manner of Incognito, and two heuristics: direct anonymization (DA), which fixes the itemsets of size that break the condition, and apriori anonymization (AA), which fixes itemsets of size in turn, so that each level has fewer combinations to check.
Examples and non-examples
The database is the one of Figure 2 of the paper, with four synthetic transactions over and the hierarchy , , . Take .
| id | original | cut | cut |
|---|---|---|---|
- is -anonymous but not -anonymous. Each single item has support at least 2: has 2, and , and have 3. But the pair has support 1: an attacker who knows that a person bought and finds and learns that the person also bought .
- The cut gives a -anonymous database. The supports are : 4, : 3, : 3, : 3, : 3, : 2. It is also -anonymous, since has support 2.
- -anonymous but not 2-anonymous as whole transactions. In the same recoded database, and each occur once as a whole transaction. An attacker who knew every item of and knew that the basket had no other items would find it. -anonymity does not protect against that much knowledge, by design.
- Non-example: the cut . The supports of , and are 2, 3 and 4, and has 2 and has 3, but has support 1, in . Generalizing the wrong items does not help.
- Coarser is safe. The cut that maps all four items to gives four copies of , which is -anonymous for every and useless, as Property 1 predicts.
Related definitions
- k-anonymity: the condition for tables with a fixed set of quasi-identifier attributes. -anonymity bounds the attacker's knowledge by a number of items instead of a set of attributes.
- Quasi-identifier: in set-valued data any combination of up to items can play this role.
- Sparse dataset de-anonymization: Narayanan and Shmatikov showed that a few known items re-identify records in large sparse datasets, which is the threat that -anonymity bounds when is at least the number of items the attacker knows.
- l-diversity: protects sensitive values once a record is narrowed down to a group. Terrovitis et al. treat every item as both a possible quasi-identifier and possibly sensitive, so -anonymity alone does not stop an attacker from learning an item that all matching transactions share.
- Generalization and suppression: the operations used to reach -anonymity; here generalization follows an item hierarchy and is global.
- Differential privacy: a guarantee that does not depend on a bound on the attacker's knowledge.
Proof: The counting test decides km-anonymity exactlyfull
Let be a finite multiset of transactions, each a finite set of items, and let and . The support of an itemset is the number of transactions , counted with multiplicity, with . is -anonymous if every non-empty itemset with has or .
Claim 1 (the counts). After lines L1 to L4, the map holds exactly the itemsets with and , and for each of them.
Proof. Line L1 starts with an empty map. Line L3 lists each subset of of size 1 to exactly once, because the items of are distinct, and line L4 adds 1 to its count. So after all transactions, is the number of transactions for which is one of the listed subsets, that is, with and . This number is . An itemset is a key of exactly when it was listed at least once, that is, when .
Claim 2 (the test). KM-ANONYMOUS returns true if and only if is -anonymous.
Proof. If is not -anonymous, some with has . By Claim 1, is a key of with , so lines L5 and L6 return false when they reach it, or earlier for another such itemset. If is -anonymous, every key of has , so , line L6 never returns, and line L7 returns true.
Anti-monotone support. If , every transaction that contains contains , so . Hence -anonymity implies -anonymity for : the itemsets of size at most are among those of size at most .
Coarser cuts. Let map items to items, applied with set semantics: . Suppose is -anonymous and is an itemset with and . Take a transaction with , and for each pick one with . The set has and , so . Every transaction has , so . So is -anonymous.
Cost. A transaction with items has subsets of size 1 to , each built and hashed in time. Lines L5 to L7 read each key once. For a fixed the total is map operations.
Code
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/km-anonymity/. The authors are listed in prov/YFDA8G.jsonl.
from collections.abc import Hashable, Iterable, Mapping, Sequence
from itertools import combinations
def is_km_anonymous(transactions: Sequence[Iterable[Hashable]], k: int, m: int) -> bool:
"""Return True if every itemset of at most m items has support 0 or at least k.
Each transaction is read as a set of items. Precondition: k >= 1, m >= 0.
Cost: O(sum over transactions t of C(|t|, 1) + ... + C(|t|, m)) hash map
updates, which is O(|D| tau^m) for transactions of at most tau items.
"""
counts: dict[frozenset[Hashable], int] = {} # @line L1
for t in transactions: # @line L2
items = list(set(t))
for size in range(1, m + 1):
for subset in combinations(items, size): # @line L3
key = frozenset(subset)
counts[key] = counts.get(key, 0) + 1 # @line L4
for c in counts.values(): # @line L5
if c < k: # @line L6
return False
return True # @line L7
def generalize(transactions: Sequence[Iterable[Hashable]], cut: Mapping[Hashable, Hashable]) -> list[frozenset[Hashable]]:
"""Apply a global recoding: replace each item by cut[item] (or keep it if absent), with set semantics.
Cost: O(total number of items).
"""
return [frozenset(cut.get(x, x) for x in t) for t in transactions]
test_km_anonymity.py 84 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/km-anonymity/. The authors are listed in prov/YFDA8G.jsonl.
import random
from collections import Counter
from itertools import combinations
from km_anonymity import generalize, is_km_anonymous
D = [{"a1", "b1", "b2"}, {"a2", "b1"}, {"a2", "b1", "b2"}, {"a1", "a2", "b2"}]
TO_A = {"a1": "A", "a2": "A"}
TO_B = {"b1": "B", "b2": "B"}
def test_example() -> None:
assert is_km_anonymous(D, 2, 1)
assert not is_km_anonymous(D, 2, 2)
da = generalize(D, TO_A)
assert da == [frozenset("A b1 b2".split()), frozenset({"A", "b1"}), frozenset("A b1 b2".split()), frozenset({"A", "b2"})]
assert is_km_anonymous(da, 2, 2)
assert is_km_anonymous(da, 2, 3)
# not 2-anonymous as whole transactions
assert min(Counter(da).values()) == 1
assert not is_km_anonymous(generalize(D, TO_B), 2, 2)
everything = {x: "ALL" for x in ["a1", "a2", "b1", "b2"]}
assert generalize(D, everything) == [frozenset({"ALL"})] * 4
assert is_km_anonymous(generalize(D, everything), 2, 4)
def test_edges() -> None:
assert is_km_anonymous([], 5, 3)
assert is_km_anonymous([{"x"}], 1, 2)
assert not is_km_anonymous([{"x"}], 2, 1)
assert is_km_anonymous([{"x"}], 2, 0)
assert is_km_anonymous([["x", "x"], ["x"]], 2, 2)
def oracle(db: list[set[str]], k: int, m: int) -> bool:
universe = sorted(set().union(*db)) if db else []
for size in range(1, m + 1):
for subset in combinations(universe, size):
s = set(subset)
support = sum(1 for t in db if s <= t)
if 0 < support < k:
return False
return True
def random_db(rng: random.Random) -> list[set[str]]:
items = "abcdef"[: rng.randint(1, 6)]
return [set(rng.sample(items, rng.randint(1, len(items)))) for _ in range(rng.randint(0, 10))]
def test_against_oracle() -> None:
rng = random.Random(31)
for _ in range(600):
db = random_db(rng)
k = rng.randint(1, 4)
m = rng.randint(1, 4)
assert is_km_anonymous(db, k, m) == oracle(db, k, m)
def test_theorems() -> None:
rng = random.Random(32)
parent = {"a": "X", "b": "X", "c": "Y", "d": "Y", "e": "Z", "f": "Z"}
top = {"X": "ALL", "Y": "ALL", "Z": "ALL"}
for _ in range(500):
db = random_db(rng)
k = rng.randint(1, 4)
m = rng.randint(1, 4)
ok = is_km_anonymous(db, k, m)
# anti-monotone in m and in k
if ok:
assert is_km_anonymous(db, k, m - 1)
assert is_km_anonymous(db, k - 1 or 1, m)
# coarser cuts stay anonymous
coarse = generalize(db, parent)
if ok:
assert is_km_anonymous(coarse, k, m)
if is_km_anonymous(coarse, k, m):
assert is_km_anonymous(generalize(coarse, top), k, m)
# whole-transaction k-anonymity implies km-anonymity for every m
copies = [t for t in db for _ in range(k)]
assert is_km_anonymous(copies, k, 6)
References
- Manolis Terrovitis, Nikos Mamoulis and Panos Kalnis, Privacy-preserving anonymization of set-valued data, PVLDB 1(1), 2008, pages 115-125, Section 1 (the shopping-bag example), Section 3 (Definition 1, the subset queries), Section 3.1 (the generalization hierarchy of Figure 1, Definition 2 and the example of Figure 2), Section 3.2 (cuts and global recoding), Section 3.3 (NCP), Section 3.4 (Property 1, monotonicity of cuts) and Section 4 (the count-tree and the OA, DA and AA algorithms)
- Arvind Narayanan and Vitaly Shmatikov, Robust de-anonymization of large sparse datasets, IEEE Symposium on Security and Privacy 2008, pages 111-125, the re-identification of records in sparse data from a few known items, which motivates protection against partial knowledge
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 | H2 full proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag YFDA8G Edit this page History Report an error Markdown