The MinHash estimate is unbiased and concentrated around the Jaccard similarity full
This proof shows: correctness.
We use the names of the pseudocode on the page. Fix two finite sets A,B⊆U, not both empty, and write C=A∪B and J=∣A∩B∣/∣C∣.
Assumption (R). The functions h1,…,hk are independent. Each hi is injective on C, and the order that hi induces on C is uniform over the ∣C∣! orders. A uniformly random permutation of a finite universe U has this property for every C.
Lemma 1 (the signature). For each i, MINHASH-SIGNATURE sets sig[i]=mina∈Ahi(a), with min∅=∞.
Proof. Fix i. Line L2 sets sig[i]=∞. Invariant of the loop of line L3: after the elements a1,…,aj of A have been seen, sig[i]=min(∞,hi(a1),…,hi(aj)). It holds for j=0, and line L4 keeps it, since min(min(X),y)=min(X∪{y}). At the end j=∣A∣. The loop over i does not change sig[i′] for i′=i. □
Lemma 2 (one position). Let Xi=1 if sigA[i]=sigB[i] and Xi=0 otherwise. Under (R), Pr[Xi=1]=J.
Proof. If one of the sets is empty, say B, then J=0, sigB[i]=∞ and sigA[i] is finite, so Xi=0. Now let both be nonempty. Let u∈C be the element with the least value hi(u); it is unique since hi is injective on C. Under (R), each element of C is first in a uniform order with the same probability, so Pr[u=c]=1/∣C∣ for each c∈C.
- If u∈A∩B, then hi(u)≤hi(a) for each a∈A⊆C, so by Lemma 1, sigA[i]=hi(u), and in the same way sigB[i]=hi(u). So Xi=1.
- If u∈A∖B, then sigA[i]=hi(u). Each b∈B is in C and differs from u, so hi(b)>hi(u) by injectivity, and sigB[i]>hi(u). So Xi=0. The case u∈B∖A is the same.
So Xi=1 exactly when u∈A∩B, which has probability ∣A∩B∣/∣C∣=J. □
Theorem. Let J^ be the value that ESTIMATE returns for the signatures of A and B. Under (R),
- E[J^]=J;
- Var[J^]=J(1−J)/k≤1/(4k);
- for each ε>0, Pr[∣J^−J∣≥ε]≤2e−2kε2.
Proof. Lines L6 to L8 count the positions with equal entries, so line L9 returns J^=k1∑i=1kXi. Each Xi depends only on hi, so the Xi are independent, and by Lemma 2 each is a Bernoulli variable with mean J.
- By linearity of expectation, E[J^]=k1∑iE[Xi]=J.
- A Bernoulli variable with mean J has variance J(1−J). The variance of a sum of independent variables is the sum of their variances, so Var[J^]=k21⋅kJ(1−J)=J(1−J)/k. Since J(1−J)≤1/4 for 0≤J≤1, the bound follows.
- The Hoeffding inequality for k independent variables with values in [0,1] gives Pr[k1∑iXi−J≥ε]≤e−2kε2, and the same bound for the lower tail. A union bound over the two tails gives the claim. ■
Corollary. For 0<δ<1 and k≥ln(2/δ)/(2ε2), Pr[∣J^−J∣≥ε]≤δ, since then 2e−2kε2≤2e−ln(2/δ)=δ.
Termination and cost. The loops of lines L1, L3 and L7 run over finite ranges, k, ∣A∣ and k times, so both procedures stop after k∣A∣ and k steps of O(1) time on the word RAM.