C-M IN H ASH : I MPROVING M INWISE H ASHING WITH C IRCULANT P ERMUTATION
Anonymous authors
Paper under double-blind review
A BSTRACT
Minwise hashing (MinHash) is an important and practical algorithm for generating random hashes to approximate the Jaccard (resemblance) similarity in massive binary (0/1) data.
The basic theory of MinHash requires applying hundreds or even thousands of independent random permutations to each data vector in the dataset, in order to obtain reliable results for (e g.,) building large-scale learning models or approximate near neighbor search in massive data.
In this paper, we propose Circulant MinHash (C-MinHash) and provide the surprising theoretical results that using only two independent random permutations in a circulant manner leads to uniformly smaller Jaccard estimation variance than that of the classical MinHash with K independent permutations.
Experiments are conducted to show the effectiveness of the proposed method.
We also analyze a more convenient C-MinHash variant which reduces two permutations to just one, with extensive numerical results to validate that it achieves essentially the same estimation accuracy as using two permutations with rigorous theory.
I NTRODUCTION
Given two D -dimensional binary vectors v , w ∈ { 0 , 1 } D , the Jaccard similarity is deﬁned as
[Equation]
(1) which is a commonly used similarity metric in machine learning and web search applications.
The vectors v and w can also be viewed as two sets of items (which represent the locations of non-zero entries), the Jaccard similarity can be equivalently viewed as the size of set intersection over the size of set union.
The well-known method of “minwise hashing” (MinHash) (Broder, 1997; Broder et al., 1997; 1998; Li & Church, 2005; Li & König, 2011) is a standard technique for computing/estimating the Jaccard similarity in massive binary datasets, with numerous applications such as near neighbor search, duplicate detection, malware detection, web search, clustering, large-scale learning, social networks, computer vision, etc.
(Charikar, 2002; Fetterly et al., 2003; Henzinger, 2006; Das et al., 2007; Buehrer & Chellapilla, 2008; Bendersky & Croft, 2009; Chierichetti et al., 2009; Lee et al., 2010; Li et al., 2011; Deng et al., 2012; Chum & Matas, 2012; Shrivastava & Li, 2012; He et al., 2013; Tamersoy et al., 2014; Shrivastava & Li, 2014; Zamora et al., 2016).
1. A R EVIEW OF M INWISE H ASHING (M IN H ASH ) Algorithm 1 Minwise-hashing (MinHash)
Input: Binary data vector
K independent permutations π 1 , ..., π K : [ D ] → [ D ] .
Output:
For k = 1 to K h k ( v ) ← min i : v i (cid:54) =
π k ( i )
End For
For simplicity, Algorithm 1 considers just one vector v ∈ { 0 , 1 } D .
In order to generate K hash values for v , we assume K independent permutations: π 1 , ..., π K : [ D ] (cid:55)→ [ D ] .
For each permutation, the hash value is the ﬁrst non-zero location in the permuted vector, i.e., h k ( v ) =
min i : v i (cid:54) =
π k ( i ) , ∀ k
= 1 , ..., K .
Similarly, for another binary vector w ∈ { 0 , 1 } D , using the same K permutations, we can also obtain K hash values, h k ( w ) .
The estimator of J ( v , w ) is simply
[Equation]
where 1 {·} is the indicator function.
By fundamental probability and the independence among the permutations, it is easy to show that
[Equation]
How large is K ?
The answer depends on the application domains.
For example, for training largescale machine learning models, it appears that K = 512 or K = 1024 might be sufﬁcient (Li et al., 2011).
However, for approximate near neighbor search using many hash tables (Indyk & Motwani, 1998), it is likely that K might have to be much larger than 1024 (Shrivastava & Li, 2012; 2014).
In the early work of MinHash (Broder, 1997; Broder et al., 1997), actually only one permutation was used by storing the ﬁrst K non-zero locations after the permutation.
Later Li & Church (2005) proposed better estimators to improve the estimation accuracy.
The major drawback of the original scheme was that the hashed values did not form a metric space (e.g., satisfying the triangle inequality) and hence could not be used in many algorithms/applications.
We believe this was the main reason why the original authors moved to using K permutations (Broder et al., 1998).
1. O UTLINE OF M AIN R ESULTS
From K Permutations to two.
The main idea of this work, is to replace the independent permutations in MinHash with “circulant” permutations.
Thus, we name the proposed framework CMinHash (circulant MinHash).
The “circulant” trick was used in the literature of random projections.
For example, Yu et al.
(2017) showed that using circulant projections hurts the estimation accuracy, but not by too much when the data are sparse.
In Section 3, we present some (perhaps surprising) theoretical ﬁndings that we just need 2 permutations in MinHash and the results (estimation variances) are even more accurate.
Basically, with the initial permutation (denoted by σ ), we randomly shufﬂe the data to break whatever structure which might exist in the original data, and then the second permutation (denoted by π ) is applied and re-used K times to generate K hash values, via circulation.
This method is called C-MinHash- ( σ, π ) .
Before that, in Section 2, we analyze a simpler variant C-MinHash- (0 , π ) without initial permutation σ .
Although it is not our recommended method, our analysis for C-MinHash- (0 , π ) provides the necessary preparation for later methods and the intuition to understand the need for the initial permutation.
From Two Permutations to one.
In Section 5, we provide a more convenient variant, C-MinHash- ( π, π ) , that only needs one permutation π for both pre-processing and hashing.
Although the theoretical analysis becomes very complicated, we are able to explicitly write down the expectation of the estimator, which is no longer unbiased but the bias is extremely small and has essentially no impact on the estimation accuracy (mean square errors).
Extensive experiments are provided to verify that this variant has same estimation accuracy as C-MinHash- ( σ, π ) using two permutations.
In this paper, we mainly focus on presenting the fundamental idea of C-MinHash and the theoretical analysis on its uniform variance reduction with non-trivial efforts.
Besides improving the Jaccard estimation accuracy when directly implemented in place of MinHash, the proposed C-MinHash mechanism can also be conveniently used as a tool to improve more MinHash based algorithms, for example, the One Permutation Hashing (OPH, Li et al.
When combined with OPH, CMinHash can reduce the required one permutation to effectively 1 /K permutation only.
Since such combination is a research direction which requires independent introduction and efforts, we present the work in a separate manuscript (which could be anonymously shared with Referees if needed).
Input: Binary data vector v ∈ { 0 , 1 } D ,
Permutation vector π : [ D ] → [ D ]
Output: Hash values h 1 ( v ) , ..., h K ( v )
For k = 1 to K
Shift π circulantly rightwards by k units: π k = π
→ k h k ( v ) ← min i : v i (cid:54) =
π → k ( i )
End For
Circular
Shift 𝟏𝝅 →𝒌 = {𝟓, 𝟖, 𝟏, 𝟕, 𝟑, 𝟒, 𝟔, 𝟐}  𝒗    𝝅 →𝒌+𝟏 = {𝟐, 𝟓, 𝟖, 𝟏, 𝟕, 𝟑, 𝟒, 𝟔}  𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗
C-M IN H ASH - (0 , π ) WITHOUT I NITIAL P ERMUTATION
As shown in Algorithm 2, the C-MinHash algorithm has similar operations as MinHash.
The difference lies in the permutations used in the hashing process.
To generate each hash h k ( v ) , we permute the data vector using π → k , which is the permutation shifted k units circulantly towards right based on π .
For example, π = [3 , 1 , 2 , 4] , π → 1 = [4 , 3 , 1 , 2] , π → 2 = [2 , 4 , 3 , 1] , etc.
Conceptually, we may think of circulation as concatenating the ﬁrst and last elements of a vector to form a circle; see Figure 1.
We set the hash value h k ( v ) as the position of the ﬁrst non-zero after being permuted by π → k .
Analogously, we deﬁne the C-MinHash- (0 , π ) estimator of the Jaccard similarity J ( v , w ) as
[Equation]
where h is the hash value output by Algorithm 2.
In this paper, for simplicity, we assume K ≤ D .
Next, we present the theoretical analysis for Algorithm 2, in terms of the expectation (mean) and the variance of the estimator ˆ J 0 ,π .
Our results reveal that the estimation accuracy depends on the initial data distribution, which may lead to undesirable performance behaviors when real-world datasets exhibit various structures.
On the other hand, while it is not our recommended method, the analysis serves a preparation (and insight) for the C-MinHash- ( σ, π ) which will soon be described.
First, we introduce some notations and deﬁnitions.
Given v , w ∈ { 0 , 1 } D , we deﬁne a and f as
[Equation]
We say that ( v , w ) is a ( D, f, a ) -data pair , whose Jaccard similarity can also be written as J = a/f .
Deﬁnition 2.1.
Consider v , w ∈ { 0 , 1 } D .
Deﬁne the location vector as x ∈ { O, × , −} D , with x i being “ O ”, “ × ”, “ − ”, when v i =
w i = 1 , v i + w i =
and v i =
w i = 0 , respectively.
The location vector x can fully characterize a hash collision.
When a permutation π → k is applied, the hashes h k ( v ) and h k ( w ) would collide if after permutation, the ﬁrst “ O ” is placed before the ﬁrst “ × ” (counting from small to large).
This observation will be the key in our theoretical analysis.
Deﬁnition 2.2.
For A, B ∈ { O, × , −} , let { ( A, B ) |(cid:52)} denote the set { ( i, j ) : ( x i , x j ) =
( A, B ) , j − i =
(cid:52)} .
For each 1 ≤ (cid:52) ≤ K − 1 , deﬁne [Equation] [Equation] O
[Equation]
Remark 2.1.
For the ease of notation, by circulation we write x j = x j − D when D < j < 2 D .
Deﬁnition 2.2 measures the relative location of different types of points in the location vector, for a speciﬁc pair of data vectors.
One can easily verify that for ∀ 1 ≤ (cid:52) ≤ K −
[Equation]
(6) which is the intrinsic constraints on the size of above sets.
We are now ready to analyze the expectation and variance of ˆ J 0 ,π .
It is easy to see that ˆ J 0 ,π is still unbiased, i.e., E [ ˆ J 0 ,π ] =
J , by linearity of expectation.
Lemma 2.1 provides an important quantity that leads to V ar [ ˆ J 0 ,π ] as in Theorem 2.2.
Lemma 2.1.
For any 1 ≤ s < t ≤ K with t − s = (cid:52) , we have
[Equation]
where the sets are deﬁned in Deﬁnition 2.2 and h s , h t are the hash values as in Algorithm 2.
Theorem 2.2.
Under the same setting as in Lemma 2.1, the variance of ˆ J 0 ,π is
[Equation]
where Θ (cid:52) (cid:44) E π (cid:2) 1 { h s ( v ) = h s ( w ) } 1 { h t ( v ) =
h t ( w ) } (cid:3) as in Lemma 2.1 with any t − s = (cid:52) .
From Theorem 2.2, we see that the variance of ˆ J 0 ,π depends on a , f , and the size of sets L ’s and
G ’s as in Deﬁnition 2.1, which is determined by the location vector x .
Since we use the original data vectors without randomly permuting the entries beforehand, V ar [ ˆ J 0 ,π ] is called “ locationdependent ” as it is dependent on the location of non-zero entries of the original data.
C-M IN H ASH - ( σ, π ) WITH I NDEPENDENT I NITIAL P ERMUTATION
Algorithm
Input: Binary data vector v ∈ { 0 , 1 } D ,
Permutation vectors π and σ : [ D ] → [ D ]
Output: Hash values h 1 ( v ) , ..., h K ( v )
Initial permutation: v (cid:48)
= σ ( v )
For k = 1 to K
Shift π circulantly rightwards by k units: π k = π
→ k h k ( v ) ← min i : v (cid:48)
i (cid:54) =
π → k ( i )
End For
The method C-MinHash- ( σ, π ) is summarized in Algorithm 3, which is very similar to Algorithm 2.
This time, as pre-processing, we apply an initial permutation σ | =
π on the data to break whatever structures which might exist.
Similarly, we deﬁne the C-MinHash- ( σ, π ) estimator of J as
[Equation]
where h k ’s are the hash values output by Algorithm 3.
We will present our detailed theoretical analysis and the main result (Theorem 3.5).
First, by linearity of expectation and that σ and π are independent, ˆ J σ,π is still an unbiased estimator E [ ˆ J σ,π ] = E [ 1 { h i ( v ) = h i ( w ) } ]
= J . To provide an immediate intuition, the following proposition emphasizes that the collision indicator variables in (7) are pairwise negatively correlated , which intuitively explains the source of variance reduction. Proposition 3.1. In (7), Cov ( 1 { h i ( v ) =
h i ( w ) } , 1 { h j ( v ) =
h j ( w ) } ) < 0 , ∀ i (cid:54) =
j .
Proof.
Denote ˜ E
= E i (cid:54) =
j [ 1 { h i ( v ) =
h i ( w ) } 1 { h j ( v ) =
h j ( w ) } ] , for i (cid:54) =
j .
The task is then to show that Cov ( 1 { h i ( v )
=
h i ( w ) } , 1 { h j ( v ) =
h j ( w ) } ) =
˜
E − J 2 < 0 .
By Theorem 3.5,
V ar [ ˆ J MH ] < V ar [ ˆ J σ,π ] , where V ar [ ˆ J MH ]
= J (1 − J ) K and
[Equation]
=
E   (cid:32)
K
[Equation]
[Equation]
( w ) } (cid:33) 2 
[Equation]
w
[Equation]
[Equation]
{ h i
[Equation]
v )
[Equation]
h
i
[Equation]
w )
[Equation]
1 { h
[Equation]
v )
[Equation]
h
[Equation]
( w ) } ]
K
[Equation]
− J
[Equation]
v
[Equation]
h
[Equation]
w
[Equation]
h
[Equation]
( v )
[Equation]
h
[Equation]
w ) } ]
K− J 2 , where i (cid:54) = j =
[Equation]
Next, we formally present the path to our main result.
The next Theorem gives the variance of ˆ J σ,π .
Theorem 3.2.
Let a, f be deﬁned as in (5).
When 0 < a < f ≤ D ( J / ∈ { 0 , 1 } ), we have
[Equation]
where with l = max(0 , D − 2 f + a )
[Equation]
and ˜
[Equation]
The feasible set { l 0 , l 2 , g 0 , g 1 } satisﬁes the intrinsic constraints (6) [Equation] and
[Equation]
{+n 3 = l 2 − g 
+}
+ ( D − f − s − g 1 ) , n 4 = l 1 − ( D − f − s − g 1 ) .
Also, when a = 0 or f = a ( J = 0 or J = 1 ), we have V ar [ ˆ J σ,π ] = 0 .
Since the original locational structure of the data is broken by the initial permutation σ , V ar [ ˆ J σ,π ] only depends on the value of ( D, f, a ), i.e., it is “location-independent” .
This would make the performance of C-MinHash- ( σ, π ) consistent in different tasks.
Same as MinHash, Proposition 3. states that given D and f , the variance of ˆ J σ,π is symmetric about J = 0 .
5 , as illustrated in Figure 2, which also shows that the variance of ˆ J σ,π is smaller than the variance of the original MinHash.
Proposition 3.3 (Symmetry) .
V ar [ ˆ J σ,π ] is the same for the ( D, f, a ) -data pair and the ( D, f,
f − a ) -data pair, ∀ 0 ≤ a ≤ f ≤ D .
[Figure] [Figure]
[Figure]
[Figure]
J
[Figure] [Figure] [Figure] [Figure]
[Figure]
J [Figure]
f
[Figure]
D 1010 -
J = 0. J = 0.
J = 0. J = 0.
f = 0.
1 J
V a r i an c e R a t i o 0.2 0.
f/D = 0.
1 K/D
V a r i an c e R a t i o f/D = 0.
f/D = 1 D =
A rigorous comparison of V ar [ ˆ J σ,π ] and V ar [ ˆ J MH ] appears to be a challenging task given the complicated combinatorial form of V ar [ ˆ J σ,π ] .
The following lemma characterizes an important property of ˜ E in (9), that it is monotone in D when a and f are ﬁxed, as illustrated in Figure 3 (left).
Lemma 3.4 (Increasing Increment) .
Assume f > a > 0 are arbitrary and ﬁxed.
Denote ˜ E D as in (9) in Theorem 3.2, with D treated as a parameter.
Then we have ˜ E D +1 > ˜ E D for ∀ D ≥ f .
Equipped with Lemma 3.4, we arrive at the following main theoretical result of this work, on the uniform variance reduction of C-MinHash- ( σ, π ) .
Theorem 3.5 (Uniform Superiority) .
For any two binary vectors v , w ∈ { 0 , 1 } D with J (cid:54) = 0 or 1 , it holds that V ar [ ˆ J σ,π ( v , w )] <
V ar [ ˆ J MH ( v , w )] .
That is, using merely two permutations as C-MinHash- ( σ, π ) improves the Jaccard estimation variance of classical MinHash, in all cases.
Next, in Figure 3 (mid) and Theorem 3.6, we show that interestingly, the relative improvement is actually the same for any J , for given D, f and K .
Proposition 3.6 (Consistent Improvement) .
Suppose f is ﬁxed.
In terms of a , the variance ratio
V ar [ ˆ J MH ( v , w )] V ar [ ˆ J σ,π ( v , w )] is constant for any 0 < a < f .
How is the improvement affected by the sparsity (i.e., f ) and the number of hashes K ?
In Figure(right), we plot the variance ratio V ar [ ˆ J MH ]
V ar [ ˆ J σ,π ] with different f and K , given ﬁxed D .
We see that the improvement in variance increases with K (more hashes) and f (more non-zero entries).
Note that, by Proposition 3.6, here we do not need to consider a which does not affect the variance ratio.
The results in Figure 3 again verify Theorem 3.5, as the variance ratio is always greater than 1.
N UMERICAL E XPERIMENTS
In this section, we provide numerical experiments to validate our theoretical ﬁndings and demonstrate that C-MinHash can indeed lead to smaller Jaccard estimation errors.
4. S ANITY C HECK : A S IMULATION S TUDY
A simulation study is conducted on synthetic data to verify the theoretical variances given by Theorem 2.2 and Theorem 3.2.
We simulate D = 128 dimensional binary vector pairs ( v , w ) with different f and a , which have a special locational structure that the location vector x is such that a “ O ”’s are followed by ( f − a ) “ × ”’s and then followed by ( D − f ) “ − ”’s sequentially.
We plot the empirical and theoretical mean square errors (MSE = variance + bias 2 ) in Figure 4:
• The theoretical variance agrees with the empirical observation, as the curves overlap, conﬁrming Theorem 2.2 and Theorem 3.2.
The variance reduction increases with larger K .
• V ar [ ˆ J σ,π ] (C-MinHash- ( σ, π ) ) is always smaller than V ar [ ˆ J MH ] , as stated by Theorem 3.5.
In contrast, V ar [ ˆ J 0 ,π ] (C-MinHash- (0 , π ) ) varies signiﬁcantly depending on different data structures, as mentioned in Section 2. [Figure] [Figure]
4. J ACCARD E STIMATION ON T EXT AND I MAGE D ATASETS
We test C-MinHash on four datasets, including two text datasets: the NIPS full paper dataset from
UCI repository (Dua & Graff, 2017), and the BBC News dataset (Greene & Cunningham, 2006), and two popular image datasets: the MNIST dataset (LeCun et al., 1998) with hand-written digits, and the CIFAR dataset (Krizhevsky, 2009) containing natural images.
All the datasets are processed to be binary.
For each dataset with n data vectors, there are in total n ( n − 1) / 2 data vector pairs.
We estimate the Jaccard similarities for all the pairs and report the mean absolute errors (MAE).
The results are averaged over 10 independent repetitions, for each dataset, as shown in Figure 5:
• The MAE of C-MinHash- ( σ, π ) is consistently smaller than that of MinHash, again conﬁrming Theorem 3.5 on the beneﬁt of the improved variance.
The improvements become more substantial with larger K , which is consistent with the trend in Figure 3.
• Without the initial permutation σ , the accuracy of C-MinHash- (0 , π ) is affected by the distribution of the original data, and it is worse than C- MinHash- ( σ, π ) on all these four datasets.
Also, the performance of C-MinHash- (0 , π ) on image data seems much worse than that on text data, which we believe is because the image datasets contain more structural patterns.
This again suggests that the initial permutation σ might be needed in practice.
In summary, the simulation study has veriﬁed the correctness of our theoretical ﬁndings in Theorem 2.2 and Theorem 3.2.
The experiments with Jaccard estimation on four datasets conﬁrm that
C-MinHash is more accurate than the original MinHash.
The initial permutation σ is recommended.
C-M IN H ASH - ( π, π ) : P RACTICALLY R EDUCING TO O NE P ERMUTATION
We propose a more convenient variant, C-MinHash- ( π, π ) , which only requires one permutation.
That is, π is used for both pre-processing and circulant hashing.
The procedure is the same as Algorithm 3, except that the initial permutation σ is replaced by π .
Denote the Jaccard estimator ˆ J π,π .
The complicated dependency between π (initial permutation) and π → k (hashing) makes the theoretical analysis challenging.
In the following, we provide the mean of each hash collision indicator.
Theorem 5.1.
Assume K ≤ D and let a, f be deﬁned as (5).
The location vector x is deﬁned in
Deﬁnition 2.1.
Denote B 1 = { i : x i = O } , B 2 = { i : x i = ×} and B 3 = { i : x i = −} .
For a ≤ j ≤ D and 1 ≤ k ≤ K , deﬁne
[Equation]
Let n − , 1 ( j )
=
|{ x i
=
O : i ∈
A − ( j ) }| be the number of “ O ” points in A − ( j ) .
Analogously let n − , 2 ( j ) , n − , 3 ( j ) be the number of “ × ” and “ − ” points in A − ( j ) , and n + , 1 ( j ) , n + , 2 ( j ) , n + , 3 ( j ) be the number of “ O ”, “ × ” and “ − ” points in A + ( j ) .
Then, for the k -th C-MinHash- ( π, π ) hash, E [
[Equation]
where P j ( Z ) is the density function of Z
= ( z − ,k | 31 , z + ,k | 31 ) which follows hyper( D, D − f, n − ,k
( j ) | 31 , n + ,k ( j ) | 31 ), with domain Θ j .
For q = 1 , 2 , 3 , denote 1 # q = 1 { j # ∈ B q } , and Ψ q ( j ) = (cid:88) i
[Equation]
q ,
[Equation]
i
[Equation]
(cid:88)
[Equation]
(cid:105) ˜
P q J
[Equation]
, where i ∗ =
( i + k − 1 mod D ) + 1 ,
i # =
( i − k − 1 mod D ) + 1 , ∀ i .
Deﬁne J ∗ =
a − r 1 f − r 1 − r 2 , and ˜ P 1 = ˜ P 2 =
[Equation]
− 1 { q =
[Equation]
D [Equation] where b 0 = (cid:80) 3 k =
z
+ ,k , r 1 = a − z − , 1 − z
+ , 1 , r 2 = f − a − z − , 2 − z + , 2 and r
=
D − f − z − , 3 − z + , 3 .
Theorem 5.1 says that E [ 1 { h k ( v )
=
h k ( w ) } ] would be different for different k .
Figure 6 presents numerical examples to validate the theory and demonstrate the magnitude of bias 2 (recall MSE = bias 2 + variance), where the simulations match perfectly Theorem 5.1.
As the bias of E [ 1 { h k ( v ) =
[Figure]
[Figure] [Figure] [Figure] [Figure]
[Figure] M ea n E s t i m a t e (D,f,a) = (64,4,1) SimulationTheoryTrue
[Figure]
M ean
E s t i m a t e (
[Figure]
SimulationTheoryTrue J
[Figure]
M ean
E s t i m a t e (64,32,16)
SimulationTheoryTrue J h k ( w ) } ] can be positive or negative, the overall bias of ˆ J π,π would approach 0 as K increases.
From the 2nd row, we see that bias 2 is very small ( 10 − 5 or even smaller) and indeed converges to 0 with more hashes, i.e., the averaging effect.
Also, from the proof (see Appendix A.8)
we can know that when a and f are ﬁxed, as D increases, E [ ˆ J π,π ] would converge to J .
We found through extensive numerical experiments that, the MSE of ˆ J π,π is essentially the same as ˆ J σ,π .
Figure 7 (1st row) compares the empirical of C-MinHash- ( π, π ) with the theoretical variances of C-MinHash- ( σ, π ) , where the simulated data has the same special locational structure as in
Section 4.1.
In the 2nd row, we present the MAE comparison on real datasets, where we see that the curves for these two estimators ( ˆ J σ,π and ˆ J π,π ) match well.
In all ﬁgures, the overlapping MSE curves verify our claim that we just need one permutation π .
Due to the space limitation, we provide more empirical justiﬁcations in Appendix B. [Figure] A [Figure]
o l u t e
[Figure]
o r
[Figure]
C ONCLUSION
The method of minwise hashing (MinHash), from the seminal works of Broder and his colleagues, has become standard in industrial practice.
One fundamental reason for its wide applicability is that the binary (0/1) high-dimensional representation is convenient and suitable for a wide range of practical scenarios.
The so-called Jaccard similarity is a popular measure of similarity in binary data.
To estimate the Jaccard similarity J , standard MinHash requires to use K independent permutations, where K , the number of hashes, can be several hundreds or even thousands in practice.
In this paper, we proposed Circulant MinHash (C-MinHash) present the surprising theoretical results that, with merely 2 permutations, we still obtain an unbiased estimate of the Jaccard similarity with the variance strictly smaller than that of the original MinHash, as conﬁrmed by numerical experiments on simulated and real datasets.
The initial permutation is applied to break whatever structure the original data may exhibit.
The second permutation is re-used K times in a circulant shifting fashion.
Moreover, we analyze a more convenient C-MinHash variance which uses only 1 permutation for both pre-processing and circulant hashing.
We derive the complicated mean estimation, and validate through extensive experiments that it has the same Jaccard estimation accuracy as usingpermutations with strict theoretical guarantee.
Practically speaking, our theoretical results may reveal a useful direction for designing hashing methods.
For example, in many applications, using permutation vectors of length (e.g.,) 2 30 might be sufﬁcient.
While it is perhaps unrealistic to store (e.g.,) K = 1024 such permutation vectors in the memory, one can afford to store two such permutations (even in GPU memory).
Using perfectly random permutations in lieu of approximate permutations would simplify the design and analysis of randomized algorithms and ensure that the practical performance strictly matches the theory.
Finally, we mention that our work can be used as a building block to improve Li et al.
(2012), reducing the required one permutation to effectively 1 /K permutation only.
If needed, we would be happy to anonymously share the technical manuscript with the related results.
A P ROOFS OF T ECHNICAL R ESULTS
Notations.
In our analysis, we will use 1 s to denote 1 { h s ( v ) =
h s ( w ) } in for ∀ 1 ≤ s ≤ K , where h is the hash value.
Given two data vectors v , w ∈ { 0 , 1 } D .
Recall in (5): a = (cid:80) Di
=1 1 { v i = 1 and w i = 1 } , f = (cid:80) Di
=1 1 { v i = 1 or w i = 1 } .
Thus, the Jaccard similarity J = a/f .
We also deﬁne ˜
J
= ( a − 1) / ( f − 1) .
Deﬁnition A.1.
Let v , w ∈ { 0 , 1 } D .
Deﬁne the location vector as x ∈ { O, × , −} D , with x i being “ O ”, “ × ”, “ − ” when v i =
w i = 1 , v i + w i =
and v i =
w i = 0 , respectively.
Deﬁnition A.2.
For A, B ∈ { O, × , −} , let { ( i, j ) :
( A, B ) |(cid:52)} denote a pair of indices { ( i, j ) :
( x i , x j ) =
( A, B ) , j − i =
(cid:52)} .
Deﬁne
L 0 ( (cid:52) )
= { ( i, j ) :
( O, O ) |(cid:52)} , L 1 ( (cid:52) )
= { ( i, j ) :
( O, × ) |(cid:52)} , L 2 ( (cid:52) )
= { ( i, j ) : ( O, − ) |(cid:52)} ,
G 0 ( (cid:52) )
= { ( i, j ) : ( − , O ) |(cid:52)} , G 1 ( (cid:52) )
= { ( i, j ) : ( − , × ) |(cid:52)} , G 2 ( (cid:52) )
= { ( i, j ) : ( − , − ) |(cid:52)} ,
H
( (cid:52) )
= { ( i, j ) : ( × , O ) |(cid:52)} , H 1 ( (cid:52) ) = { ( i, j ) : ( × , × ) |(cid:52)} , H 2 ( (cid:52) )
= { ( i, j ) : ( × , − ) |(cid:52)} .
Remark A.1.
For the ease of notation, by circulation we write x j = x j − D when D < j < 2 D .
One can easily verify that given ﬁxed a, f, D , it holds that for ∀ 1 ≤ (cid:52) ≤ K − 1 , |L
( (cid:52) )
| + |L 1 ( (cid:52) )
| + |L 2 ( (cid:52) ) | = |L
( (cid:52) )
| + |G 0 ( (cid:52) ) | + |H
( (cid:52) )
| = a, |G 0 ( (cid:52) ) | + |G 1 ( (cid:52) ) | + |G 2 ( (cid:52) )
| = |L 2 ( (cid:52) )
| + |G 2 ( (cid:52) ) | + |H 2 ( (cid:52) )
| =
D − f, |H
( (cid:52) ) | + |H 1 ( (cid:52) )
| + |H 2 ( (cid:52) )
| = |L 1 ( (cid:52) )
| + |G 1 ( (cid:52) ) | + |H 1 ( (cid:52) )
| = f − a.
We will refer this as the intrinsic constraints on the size of above sets.
A. P ROOF OF L EMMA 2.
Lemma 2.1.
For any 1 ≤ s < t ≤ K with t − s = (cid:52) , we have
[Equation]
where the sets are deﬁned in Deﬁnition 2.2 and h s , h t are the hash values as in Algorithm 2.
Proof.
To check whether a hash sample generated by MinHash collides (under some permutation π ), it sufﬁces to look at the permuted location vector x .
If a collision happens, after permuted by π , type “ O ” point must appear before the ﬁrst “ × ” point.
That said, the minimal permutation index of “ O ” elements must be smaller than that of “ × ” elements.
If the hash sample does not collide, then the ﬁrst “ × ” must appear before the ﬁrst “ O ”.
Note that “ − ” points does not affect the collision.
To compute the variance of the estimator, it sufﬁces to compute E [ 1 s 1 t ] .
Let L , G and H be the union of L ’s, G ’s and H ’s, respectively.
In the following, we say that an index i belongs to a set if i is the ﬁrst term of an element in that set.
We have
[Equation]
One key observation is that, for a pair ( i, j ) in above sets, the hash index π s ( i ) will be the hash index of π t ( j ) .
We begin by decomposing the expectation into
[Equation]
where i ∗ s is the location of the original “ O ” in vector x that collides for s -th hash sample.
It is different from the exact location of collision in x ( π s ) .
Note that the permutation is totally random, so the location of collision is independent of 1 s , and uniformly distributed among all type “ O ” pairs.
When i ∗ s ∈ L
In this case , the minimum index of the type “ O ” pair in x ( π s ) , π s ( i ∗ s ) , is shifted to another type “ O ” pair in x ( π t ) .
Therefore, the indices of pairs with the ﬁrst element being “ O ” or “ × ” originally in x ( π s ) will still be greater than π t ( i ∗ s ) .
If sample s collides at i ∗ s , hash sample t will collide when
All the points in G 1 , after permutation π s , is greater than π s ( i ∗ s ) .
In this case, regardless of the permuted G 0 , hash t will always collide.
There exist points in G 1 after permutation π s smaller than π s ( i ∗ s ) , and also points in G 0 that is smaller than the minimum of permuted G 1 .
Consequently, we have for i ∗ s ∈ L 0 ,
P [ collision s at i ∗ s , collision t ]
[Equation]
and min
[Equation]
This probability holds for ∀ i ∗ s ∈ L 0 .
2) When i ∗ s ∈ L 1 .
Similarly, we consider the condition where i ∗ s ∈ L 1 , and both hash samples collide.
In this case, π s ( i ∗ s ) would be shifted to a “ × ” pair in x ( π t ) .
That is, the indices of pairs with the ﬁrst element being “ O ” or “ × ” originally in x ( π s ) will all become greater than π s ( i ∗ s ) , which now is the location of a “ × ” pair in x ( π t ) .
Thus, to make hash t collide, we will need:
• At least one point from G 0 is smaller than any other points in H ∪ L ∪ G 1 after permutation π s .
Therefore, for any i ∗ s ∈ L 1 ,
P [ collision s at i ∗ s , collision t ]
[Equation]
which is true for ∀ i ∗ s ∈ L 1 .
3) When i ∗ s ∈ L 2 .
In this scenario, π s ( i ∗ s ) would be shifted to a “ − ” pair in x ( π t ) .
Therefore, if hash s collides, hash t will also collide when:
• After applying π s , the minimum of L 0 ∪ H 0 ∪ G 0 is smaller than the minimum of L 1 ∪ H 1 ∪ G 1 .
Thus, we obtain that for any i ∗ s ∈ L 2 ,
P [ collision s at i ∗ s , collision t ] = P [ π s ( i ∗ s ) <
π s ( i ) , ∀ i ∈ H ∪ L /i ∗ s , and[-min j ∈L 0 ∪G 0 ∪H 
-]
[Equation] (cid:44) P [Ω] .
Let 1 s,i ∗ s denote the event { π s ( i ∗ s ) <
π s ( i ) , ∀ i ∈ H ∪ L /i ∗ s } .
Then Ω can be separated into the following several cases:
Ω 1 : 1 s,i ∗ s , min j ∈L 0 ∪H
π s ( j ) < min j ∈L 1 ∪H 1 π s ( j ) , and min j ∈L 0 ∪H
π s ( j ) < min
j ∈G 1 π s ( j ) .
Ω 2 : 1 s,i ∗ s , min j ∈L 0 ∪H
π s ( j ) < min j ∈L 1 ∪H 1 π s ( j ) , and min j ∈L 0 ∪H
π s ( j ) > min j ∈G 1 π s ( j ) > min j ∈G 0 π s ( j ) >
π s ( i ∗ s ) .
Ω 3 : 1 s,i ∗ s , min j ∈L 0 ∪H
π s ( j ) < min j ∈L 1 ∪H 1 π s ( j ) , and min j ∈L 0 ∪H
π s ( j ) > min j ∈G 1 π s ( j ) >
π s ( i ∗ s ) >
min j ∈G
π s ( j ) .
Ω 4 : 1 s,i ∗ s , min j ∈L 0 ∪H
π s ( j ) < min j ∈L 1 ∪H 1 π s ( j ) , and min j ∈L 0 ∪H
π s ( j ) > π s ( i ∗ s ) >
min j ∈G 1 π s ( j ) > min j ∈G
π s ( j ) .
Ω 5 : 1 s,i ∗ s , min j ∈L 0 ∪H
π s ( j ) >
min j ∈L 1 ∪H 1 π s ( j ) , and π s ( i ∗ s ) <
min j ∈G
π s ( j ) < min j ∈L 1 ∪H 1 ∪G 1 π s ( j ) .
Ω 6 : 1 s,i ∗ s , min j ∈L 0 ∪H
π s ( j ) >
min j ∈L 1 ∪H 1 π s ( j ) , and min j ∈G
π s ( j ) <
π s ( i ∗ s ) <
min j ∈L 1 ∪H 1 ∪G 1 π s ( j ) .
We can compute the probability of each event as
[Equation] a [Equation] | =
[Equation]
f
[Equation]
| [Equation] |
[Equation]
a
[Equation]
| [Equation] =
[Equation]
P [Ω [Equation] [Equation] [Equation]
|
[Equation]
|
[Equation]
|L 0 |
[-P [Ω 2 ] = 1 a · a f + |G 0 | + |G 1 | · |G 0 | |G 0 | + |G 1 | + |L 0 | + |H 0 | + |L 1 | + |H 1 | · |G 1 | |L 0 | + |H 0 | + |L 1 | + |H 1 | + |G 1 | · |L 0 | + |H 0 | |L 0 | + |H 0 | + |L 1 | + |H 1 | = f + |G 0 | + |G 1 | · |G 0 | f · |G 1 | f − |G 0 | · a − |G 0 | f − |G 0 | − |G 1 | = |G 0 | · |G 1 | · ( a − |G 0 | ) ( f + |G 0 | + |G 1 | )( f − |G 0 | )( f − |G 0 | − |G 1 | ) f , P [Ω 3 ] = |G 0 | f + |G 0 | + |G 1 | · f + |G 1 | · |G 1 | |L 0 | + |H 
-][Equation]
| |L 0 | + |H {+
+} | + |L 1 | + |H 1 | = |G 
 |
[Equation] |G 1 | [-|L 0 | + |H 
-]· [Equation]
a [Equation] |G 0 | ) ( f + |G 0 | + |G 1 | )( f + |G 1 | )( f − |G 0 | )( f − |G 0 | − |G 1 | ) ,
P [Ω 4 ] = |G 0 | f + |G 0 | + |G 1 | · |G 1 | f + |G 1 | · f · |L 0 | + |H 0 | |L 0 | + |H
| + |L 1 | + |H 1 | = |G 0 | · |G 1 | · ( a − |G 0 | ) ( f + |G 0 | + |G 1 | )( f + |G 1 | )( f − |G 0 | − |G 1 | ) f ,
P [Ω 5 ] = f + |G 0 | + |G 1 | · |G 0 | |G 0 | + |G 1 | + |L 0 | + |H 0 | + |L 1 | + |H 1 | · |L 1 | + |H 1 | |L
| + |H
| + |L 1 | + |H 1 | = |G 0 | · ( f − a − |G 1 | ) ( f + |G 0 | + |G 1 | )( f − |G 0 | − |G 1 | ) f ,
P [Ω 6 ] = |G 0 | f + |G 0 | + |G 1 | · f · |L 1 | + |H 1 | |L
| + |H
| + |L 1 | + |H 1 | = |G 0 | · ( f − a − |G 1 | ) ( f + |G 0 | + |G 1 | )( f − |G 0 | − |G 1 | ) f .
Note that
[Equation]
Summing up all the terms together
[Equation]
we obtain P [Ω] as
[Equation] [Equation]
which holds for ∀ i ∗ s ∈ L 2 .
Now combining (12), (13), (14) with (11), we obtain
E
[Equation] [Equation]
Here, recall that the sets are associated with all 1 ≤ s < t ≤ K such that (cid:52) =
t − s .
Using the intrinsic constraints (10), after some calculation we can simplify (15) as
[Equation]
which completes the proof.
A. P ROOF OF T HEOREM 2.
Theorem 2.2.
Under the same setting as in Lemma 2.1, the variance of ˆ J 0 ,π is
[Equation]
where Θ (cid:52) (cid:44) E π (cid:2) 1 { h s ( v ) = h s ( w ) } 1 { h t ( v ) =
h t ( w ) } (cid:3) as in Lemma 2.1 with any t − s = (cid:52) .
Proof.
By the expansion of variance formula, since E [ 1 2 s ] =
E [ 1 s ] =
J , we have
[Equation]
Note here that for ∀ t > s , the t -th hash sample uses π t as the permutation, which is shifted rightwards by (cid:52) =
t − s from π s .
Thus, we have E [ 1 s 1 t ] =
E [ 1 s − i 1 t − i ] for ∀ 0 <
i < s ∧ t , which implies E [ 1 s 1 t ] =
E [ 1 1 1 t − s +1 ] , ∀ s < t .
Since by assumption K ≤ D , we have
K (cid:88) s
K
[Equation]
[Equation]
Finally, integrating (16), (17) and Lemma 2.1 completes the proof
[Equation]
A. P ROOF OF T HEOREM 3.
Theorem 3.2.
Let a, f be deﬁned as in (5).
When 0 < a < f ≤ D ( J / ∈ { 0 , 1 } )
[Equation]
we have
[Equation]
where with l = max(0 , D − 2 f + a )
[Equation]
and ˜ E =
[Equation]
The feasible set { l 0 , l 2 , g 0 , g 1 } satisﬁes the intrinsic constraints (6)
[Equation]
and
[Equation]
Also, when a = 0 or f = a ( J = 0 or J = 1 ), we have V ar [ ˆ J σ,π ] = 0 .
Proof.
Similar to the proof of Theorem 2.2, we denote Θ (cid:52) =
E σ,π [ 1 s 1 t ] with | t − s | = (cid:52) .
Note that now the expectation is taken w.r.t.
both two independent permutations σ and π .
Since σ is random, we know that Θ
=
Θ 2 = · · · = Θ K − 1 .
Then by the variance formula, we have
[Equation]
Hence, it sufﬁces to consider Θ 1 .
In this proof, we will set (cid:52) = 1 and drop the notation (cid:52) for conciseness, and denote ˜ E =
Θ 1 from now on.
First, we note that Lemma 2.1 gives the desired quantity conditional on σ .
By the law of total probability, we have
[Equation]
where the sizes of sets are random depending on the initial permutation σ (i.e. counted after permuting by σ ).
As a result, the problem turns into deriving the distribution of |L 0 | , |L 1 | , |L 2 | , |G 0 | and |G 1 | under random permutation σ , and then taking expectation of (21) with respect to this additional randomness.
When a = 0 , we know that |L
| = |L 2 | = |G 0 | = 0 , hence the expectation ˜
E is trivially 0.
Thus, the
V ar [ ˆ J σ,π ] = 0 .
When f = a , |G 1 | = 0 , and the constraint on the sets becomes
[Equation]
Then (21) becomes
[Equation]
[Equation]
Therefore, when f = a , we also have V ar [ ˆ J σ,π ] = 0 .
Next, we will consider the general case where 0 < a < f ≤ D .
This can be considered as a combinatorial problem where we randomly arrange a type “ O ”, ( f − a ) type “ × ” and ( D − f ) type “ − ” points in a circle.
We are interested in the distribution of the number of { O, O } , { O, ×} , { O, −} , {− , O } and {− , ×} pairs of consecutive points in clockwise direction.
We consider this procedure in two steps, where we ﬁrst place “ × ” and “ − ” points, and then place “ O ” points.
Step 1.
Randomly place “ × ” and “ − ” points on the circle.
In this step, four types of pairs may appear: {− , −} , {− , ×} , {× , ×} and {× , −} .
Denote C 1 , C 2 ,
C 3 and C 4 as the collections of above pairs.
Since
[Equation]
knowing the size of one set gives information on the size of all the sets.
Thus, we can characterize the joint distribution by analyzing the distribution of |C 1 | .
First, placing ( D − f ) “ − ” points on a circle leads to ( D − f ) number of {− , −} pairs.
This ( D − f ) elements can be regarded as the borders that split the circle into ( D − f ) bins.
Now, we randomly throw ( f − a ) number of “ × ” points into these bins.
If at least one “ × ” falls into one bin, then the number of {− , −} pairs ( |C 1 | ) would reduce by 1 , while |C 2 | and |C 4 | would increase by 1 .
If z “ × ” points fall into one bin, then the number of {× , ×} ( |C 3 | ) would increase by ( z − 1) .
Notice that since s ≤ D − f and D − f − s ≤ f − a , we have max(0 , D − 2 f + a ) ≤ s ≤ D − f .
Consequently, for s in this range, we have
[Equation]
The second line is due to the stars and bars problem that the number of ways to place n unlabeled balls in m distinct bins such that each bin has at least one ball is (cid:0) n − 1 m − 1 (cid:1) .
For |C 1 | = s , we need n = f − a (number of “ × ”) and m =
|C 2 | =
D − f − s .
Moreover, the number of ways to place n balls in m distinct bins is (cid:0) n + m − 1 m − 1 (cid:1) .
When counting the total number of possibilities, we have n = f − a and m =
D − f .
This gives the denominator.
We notice that (22) is actually a hyper-geometric distribution.
Step 2.
Randomly place “ O ” points on the circle.
We have the probability mass function
P
[Equation]
Now it remains to compute the distribution conditional on |C 1 | .
Here we drop |L
| because it is intrinsically determined by |L 1 | and |L 2 | .
Again, given a placement of all “ × ” and “ − ” points, each consecutive pair can be regarded as a distinct bin.
Therefore, now the problem is to randomly throw a type “ O ” points into that ( D − a ) bins, given that we have placed type “ × ” and “ − ” points on the circle with |C 1 | =
s (and thus |C 2 | =
|C 3 |
= D − f − s and |C 4 | = f − a − ( D − f − s ) are also determined correspondingly).
In the following, we count the number of “ O ” points that fall in C i , i = 1 , 2 , 3 , 4 , to make the event Ψ happen.
Note that
• When at least one “ O ” point falls into C 1 (between {− , −} ), |L 2 | and |G
| increase by
. • When at least one “ O ” point falls into C 2 (between {− , ×} ), |L 1 | and |G
| increase by 1 , while |G 1 | decreases by 1 .
• When at least one “ O ” point falls into C 3 (between {× , −} ), |L 2 | increases by 1 .
• When at least one “ O ” point falls into C 4 (between {× , ×} ), |L 1 | increases by 1 .
We denote the number of bins in C i , i = 1 , 2 , 3 , 4 that contain at least one “ O ” point as n 1 , n 2 , n 3 , n 4 , respectively.
As a result of above reasoning, in the event Ψ , we have
[Equation]
Solving the equations gives
[Equation]
Note that (cid:80) 4 i =1 n i = l 1 + l 2 .
Therefore, event Ψ is equivalent to randomly pick n 1 , n 2 , n 3 and n 4 bins in C 1 ,..., C 4 , and then distribute a type “ O ” points in these ( l 1 + l 2 ) bins such that each bin contains at least one “ O ”.
Hence, we obtain
P (cid:110)
|
[Equation]
which is also multi-variate hyper-geometric distributed.
Now combining (22), (23) and (24)
[Equation]
we obtain the joint distribution of |L
|
[Equation]
|L 1 | , |L 2 | , |G 0 | and |G 1 | as
[Equation]
Now let Ξ be the feasible set of ( l 0 , l 1 , g 0 , g 1 , g 2 ) that satisﬁes the intrinsic constraints (10).
The desired expectation w.r.t.
both π and σ can thus be written as ˜
[Equation]
The desired result can then follows by (20).
A. P ROOF OF P ROPOSITION 3.
Proposition 3.3 (Symmetry) .
V ar [ ˆ J σ,π ] is the same for the ( D, f, a ) -data pair and the ( D, f,
f − a ) -data pair, ∀ 0 ≤ a ≤ f ≤ D .
Proof.
For ﬁxed a, f, D , let ˜ E 1 be the expectation deﬁned in Theorem 3.2 for ( v 1 , w 1 ) , and ˜ E 2 be that for ( v 2 , w 2 ) .
From Theorem 3.2 we know that
[Equation]
where ( l 0 , l 2 , g 0 , g 1 ) follows the distribution of ( |L 0 | , |L 2 | , |G 0 | , |G 1 | ) associated with the location vector x 1 of ( v 1 , v 2 ) .
For data pair ( v 2 , w 2 ) , we can consider its location vector x 2 as swapping the “ O ” and “ × ” entries of x 1 .
Now we denote the size of the corresponding sets (Deﬁnition 2.2) of x 2 as l (cid:48)
i s, g (cid:48)
i s, h (cid:48)
i s , for i = 0 , 1 , 2 .
Since σ is applied before hashing, by symmetry there is a one-to-one correspondence between the two location vectors.
More speciﬁcally, l (cid:48) 0 corresponds to h 1 , g (cid:48)
corresponds to g 1 , g (cid:48) 1 corresponds to g 0 , and l (cid:48) 2 corresponds to h 2 .
Therefore, in probability we can write
[Equation]
Consequently, we have
[Equation]
In the sequel, the subscript of expectation is suppressed for conciseness.
Exploiting the constraints (10) [Equation]
we deduce that h 1 = ( f − a ) − l 1 − g 1 , h [-
-]2 = l 0 + g 0 + l 1 + g 1 − a and l 0 + l 1 = a − l 2 .
Using these facts we obtain
[Equation]
Comparing the variances of ˆ J σ,π ( v 1 , w 1 ) and ˆ J σ,π ( v 2 , w 2 ) [Equation] we derive
[Equation]
This completes the proof.
A. P ROOF OF L EMMA 3.
Lemma 3.4 (Increasing Increment) .
Assume a > 0 and f > a are arbitrary and ﬁxed.
Denote ˜ E D as in (19) in Theorem 3.2, with D treated as a parameter.
Then we have ˜ E D +1 > ˜ E D for ∀ D ≥ f .
Proof.
Let the probability mass function (25) with a , f and dimension D be P a,f,D
( l 0 , l 2 , g 0 , g 1 ) .
Conditional on l 0 , l 2 , g 0 , g 1 with D elements, the possible values l [Equation] [Equation] [Equation]
[Equation]
g
[Equation]
1 when adding a “ − ” are
• g (cid:48)
= g 0 + 1 , l (cid:48)
= l 0 , l (cid:48) 2 = l 2 , g (cid:48)
= g 1 .
This is true when the new elements falls between a pair of ( × , O ) , with probability l 1 + l 2 − g
D
• g (cid:48)
= g 1 + 1 , l (cid:48)
= l 0 , l (cid:48) 2 = l 2 , g (cid:48)
= g 0 , when the new elements falls between a pair of ( × , × ) , with probability f − a − l 1 − g 1 D
• g (cid:48)
= g 1 + 1 , l (cid:48)
= l 2 + 1 , l (cid:48)
= l 0 , g (cid:48)
= g 0 , when the new elements falls between a pair of ( O, × ) , with probability l 1 D .
• l (cid:48)
= l 0 − 1 , l (cid:48) 2 = l 2 + 1 , g (cid:48)
= g 0 + 1 , g (cid:48)
= g 1 , when the new elements falls between a pair of ( O, O ) , with probability l 0 D .
• All values unchanged, when the “ − ” falls between other types of pairs, with probability D − f + g 0 + gD .
Denote Ξ D as the feasible set satisfying (10) with dimension D ≥ f .
Above reasoning builds a correspondence between Ξ D and Ξ D +1 .
More precisely, we have
[Equation]
1 + l 2 − g
D
P a,f,D ( l 0 , l 2 , g 0 , g 1 ) + (cid:16) lf + g 0 + g 1 + 1 + a ( g 0 + l 2 ) ( f + g 0 + g 1 + 1) f (cid:17)
f − a − l 1 − g
D
P a,f,D ( l 0 , l 2 , g 0 , g 1 ) + (cid:16) lf + g 0 + g 1 + 1 + a ( g 0 + l 2 + 1) ( f + g 0 + g 1 + 1) f (cid:17) l 1 DP a,f,D ( l 0 , l 2 , g 0 , g 1 ) + (cid:16) l 0 −f + g 0 + g 1 + 1 + a ( g 0 + l 2 + 2) ( f + g 0 + g 1 + 1) f (cid:17) l 0 DP a,f,D ( l 0 , l 2 , g 0 , g 1 ) + (cid:16) lf + g 0 + g 1 + a ( g 0 + l 2 ) ( f + g 0 + g 1 ) f (cid:17) D − f + g 0 + g
D
P a,f,D ( l 0 , l 2 , g 0 , g 1 ) (cid:27) .
The increment can be computed as ˜
[Equation]
˜
[Equation]
=
[Equation]
Ξ D
[Equation]
a ( f − a − l 1 − g 1 )
[Equation] [Equation]
( f
[Equation]
g
[Equation]
g 1 + 1) (cid:27)
P a,f,D ( l 0 , l 2 , g 0 , g 1 ) = (cid:88)
Ξ D (cid:26) ( f
[Equation]
g
[Equation]
g 1 )
[ a ( f + g 1 − l 2 ) − fl 0 ]
Df (
[Equation] [Equation]
[Equation]
g 0 + g
[Equation] [Equation]
( f − a ) l
[Equation]
a
[Equation]
f
[Equation]
[Equation] [Equation]
g
[Equation] [Equation]
1) (cid:27)
P a
[Equation]
f
[Equation]
l
[Equation]
l
[Equation]
, g 0 , g 1 )
= (cid:88)
Ξ D
[Equation] [Equation]
) =
E
[Equation]
af ( l
[Equation]
g 1 )
[Equation]
f ( f
[Equation]
a ) l
[Equation]
a ( f
[Equation]
a )
[Equation] [Equation]
[Equation]
= E (cid:104)
[Equation]
h 1 )
[Equation]
a
[Equation] [Equation]
( f
[Equation]
a
[Equation] [Equation]
[Equation]
f )
[Equation]
f
[Equation]
[Equation] [Equation]
= E (cid:104)
[Equation]
[Equation] [Equation]
where
[Equation] [Equation]
Note that here the expectations are taken w.r.t.
the set size distribution with a, f, D .
We can expand the terms of density function (25) to derive
P
[Equation]
a !
( f − a
[Equation]
( D
[Equation]
f −
[Equation]
( D − 1)! .
Denote a (cid:48) =
a − 1 , f (cid:48) =
f − 1 , D (cid:48)
=
D − 1 and l (cid:48)
= l 0 − 1 .
We have
[Equation] [Equation]
− 1)!
[Equation]
Here the subscript means that we are taking expectation w.r.t the set sizes when the number of “ O ”, “ × ” and “ − ” points is ( a − 1 , f − 1 , D − 1) .
By symmetry, it can be shown similarly that
[Equation]
Substituting above results into (26), we obtain
[Equation]
To compute E 0 , note that with a, f and D , variable g 2 is distributed as hyper( D − 1 , D − f, D − f − 1 ).
For ¯ E , the distribution becomes hyper( D − 2 , D − f, D − f − 1 ).
Since f + g
+
g 1 =
D − g 2 , we deduce
[Equation]
and
[Equation]
For ∀ D ≥ f , we have
[Equation]
Consequently, we have ˜ δ D > 2 a ( f − a ) E (cid:104)
D
[Equation]
g 1 )( f + g 0 + g 1 + 1) − f − g 0 − g
Df ( f + g 0 + g 1 )( f + g 0 + g 1 + 1) − f + g 0 + g
Df ( f + g 0 + g 1 )( f + g 0 + g 1 + 1) (cid:105) = 0 , and note that this holds for ∀ D ≥ K .
The proof is complete.
A. P ROOF OF T HEOREM 3.
Theorem 3.5 (Uniform Superiority) .
For any two binary vectors v , w ∈ { 0 , 1 } D with J (cid:54) = 0 or 1 , it holds that V ar [ ˆ J σ,π ( v , w )] <
V ar [ ˆ J MH ( v , w )] .
Proof.
By assumption we have 0 < a < f .
To compare V ar [ ˆ J σ,π ] with V ar [ ˆ J MH ]
= J (1 − J ) K =
JK + ( K − 1) J 2 K − J 2 , it sufﬁces to compare ˜ E with J 2 .
When D = f , we know that the location vector x of ( v , w ) contains no “ − ” elements.
It is easy to verify that in this case, |G 0 | =
|G 1 | = |L 2 | = 0 , and |L
| follows hyper( f − 1 , a, a − 1 ).
By Theorem 3.2, it follows that when D = f ,
[Equation]
Recall the deﬁnition ˜
J
= a − 1 f − 1 , which is always less than J .
On the other hand, as D → ∞ , we have |L 0 | → 0 , |L 2 | → a , |G 0 | → a and |G 1 | → f − a .
We can easily show that
[Equation]
, as D → ∞ .
By Lemma 3.4, the sequence ( ˜ E f , ˜ E f +1 , ˜ E f +2 , ... ) is strictly increasing.
Since it is convergent with limit J 2 , by the Monotone Convergence Theorem we know that ˜ E D < J 2 , ∀ D ≥ f .
A. P ROOF OF P ROPOSITION 3.
Proposition 3.6 (Consistent Improvement) .
Suppose f is ﬁxed.
In terms of a , the variance ratio ρ ( a ) =
V ar
[ ˆ J MH ( v , w )] V ar [ ˆ J σ,π ( v , w )] is constant for any 0 < a < f .
Proof.
Let ˜ E be deﬁned as in Theorem 3.2.
Assume that D and f are ﬁxed and a is variable.
Firstly, we can write the variance ratio explicitly as
[Equation]
We now show that the term J − ˜ E J = C (1 − J ) , where C is some constant independent of J (i.e., a ).
Then, for ﬁxed D and f , by cancellation ρ ( a ) would be constant for all 0 < a < f .
We have
[Equation]
where we use the constraints (10) that l 0 + l 1 + l 2 = a and l 1 + g 1 + h 1 = f − a .
We now study the three terms respectively.
We have
[Equation]
We have shown in the proof of Lemma 3.4 that
[Equation]
and by symmetry it holds that
[Equation]
Note that Since f is ﬁxed, ( |G 0 | + |G 1 | ) is distributed independent of a .
Consequently, E (cid:48) and E ∗ are both independent of a .
Next, we obtain
[Equation]
and
[Equation]
Summing up the terms and substituting into (27), we derive
[Equation]
where C = − E (cid:48)
+ ( f − f ( f − 2) D − 1 ) E ∗ , which is independent of a .
Taking into ρ ( a ) , we get
[Equation]
a
[Equation]
1) C , which is a constant only depending on f , D and K .
This completes the proof.
A. P ROOF OF T HEOREM 5.
Proof.
Denote E [ 1 k ] :=
E [ 1 { h k ( v ) =
h k ( w ) } ] for any 1 ≤ k ≤ K .
We ﬁrst recall some notations.
We have v , w ∈ { 0 , 1 } D , and a and f are deﬁned in (5).
Denote B 1 = { i : x i = O } , B 2 = { i : x i = ×} and B 3 = { i : x i = −} as the sets of three types of points, respectively.
For a ≤ j ≤ D and 1 ≤ k ≤ K , deﬁne
[Equation]
Let n − , 1 ( j )
=
|{ x i
=
O : i ∈
A − ( j ) }| be the number of “ O ” points in A − ( j ) .
Analogously let n − , 2 ( j ) , n − , 3 ( j ) be the number of “ × ” and “ − ” points in A − ( j ) , and n + , 1 ( j ) , n + , 2 ( j ) , n + , 3 ( j ) be the number of “ O ”, “ × ” and “ − ” points in A + ( j ) .
For any i , denote i ∗ =
( i + k − 1 mod D ) + 1 ,
i # =
( i − k − 1 mod D )
+ 1 .
Our analysis starts with the decomposition of hash collision probability,
[Equation] [Equation]
where recall h ( · ) is the hash sample.
Consider the process for generating the hash.
As before, we look at the location vector x .
In Method 2, we ﬁrst permute x by π to get π ( x ) .
Then the k -th hash samples collide if the minimum of π → k ( π ( x )) is “ O ”.
One key observation is that, when applying π → k , the random index for the i -th element in π ( x ) is exactly the one used for x i # (shifted backwards) in the initial permutation.
A toy example in provided in Figure 8 to help understand the reasoning.
Further denote set M = { π ( i ) : π ( i ) / ∈ B 3 } be the collection of indices of initially permuted vector π ( x ) that are not “ − ” points, and M ← k = ( M − k − 1 mod D ) + 1 be the corresponding indices shifted backwards.
In Figure 8, M = { 2 , 5 , 8 , 11 } .
Also, π (6) = 4 , and the permutation maps are described by the red arrows.
Consequently, in π → k ( π ( x )) , the 8 -th element (“ O ”) in π ( x ) will be permuted to the same index of the 8 − 2 = 6 -th element in x , which equals to 4 .
It is important to notice that, when considering the k -th collision, only points in M ← k matters.
Hence, we deduct:
• (Collision condition)
Denote i =
arg min t ∈M ← k π ( x t ) be the location of minimal permutation index in M ← k .
The k -th collision occurs at j i
f
f. π ( i ) =
j , and the i ∗ -th element in π ( x )
must be a “O” point
Recall the deﬁnition i ∗ =
( i + k − 1 mod D ) +
In Figure 8, consider i = 6 and j = 4 for example.
Above condition means that the i = 6 -th element in x (“ − ” in red bold border) is permuted to the j = 4 -th position, and it is above all other permuted elements with red bold borders.
Meanwhile, the i + k
= 6 + 2 = 8 -th element in π ( x ) must be a “ O ”.
Figure 8 exactly satisﬁes the condition, so it depicts a collision.
Mathematically, we have
[Equation]
where i = arg min t ∈M ← k π ( x t ) .
In this expression, everything is random of π , except for the set
B 1 which is ﬁxed given the data.
Now we will focus on deriving the probability for a ﬁxed i and j in (29).
Our analysis will be conditional on the collection of variables Z which is deﬁned as follows.
Let z − , 1 , z − , 2 and z − , 3 be the number of “ O ”, “ × ” and “ − ” points in A − ( j ) ∩ M c ← k , and z + , 1 , z + , 2 and z + , 3 be the number of “ O ”, “ × ” and “ − ” points in A + ( j )
∩M c ← k , respectively.
Here M c ← k represents the complement of M ← k .
Notice that Z (and its density function) depends on different j since A − ( j ) and A + ( j ) depends on j .
For the ease of notation we suppress the information of j in Z (and z ’s).
It is easy to see that Z
= ( z − ,k | 31 , z + ,k | 31 ) follows hyper( D, D − f, n − ,k
( j ) | 31 , n + ,k ( j ) | 31 ).
Denote the domain of
Z and Θ j .
Conditional on Z , we obtain
[Equation]
with i = arg min t ∈M ← k π ( x t ) .
We will carefully compute the probabilities in the summation.
Basically, the key is that elements in M need to be controlled, i.e. smaller than j , and other positions can be arbitrary.
Given Z , this means that we need to put r 1 = a − z − , 1 − z + , 1 type “ O ” points, r 2 = f − a − z − , 2 − z + , 2 type “ × ” points and r 3 = D − f − z − , 3 − z + , 3 type “ − ” points no smaller than j , with π ( i ) =
j exactly.
Also note that there are ﬁxed b 0 = (cid:80) 3 k =
z
+ ,k type “ − ” points no smaller than j .
With all these deﬁnitions and reasoning, we are ready to proceed with the proof.
Based on x i , we have three general cases.
1) x i ∈ B 1 .
The ﬁrst case is that x i
= O .
Case 1a)
j < i ∗ .
Firstly, we consider the case where j < i ∗ .
By combinatorial theory we have
[Equation]
where the second probability is that the j -th element in π ( x ) is not “ − ”.
Conditional on Z , the probability is dependent on j # :
[Equation]
Combining with (31) we obtain
[Equation]
Next we compute P [ π − 1 ( i ∗ ) ∈
B 1 | π ( i ) =
j, Z ] .
Note that given the conditions, π − 1 ( i ∗ ) has two cases: 1) it comes from M ← k (i
[Equation]
e. it is one of the elements with red bold border); 2) Otherwise.
We then can write
[Equation]
Combining (32) and (33)
[Equation]
we obtain when i ∈ B 1 and j < i ∗ ,
[Equation]
Case 1b)
j = i ∗ .
Similarly approach also applies to the situation with j = i ∗ .
In this case,
[Equation]
The equations are because ( i ∗ )
# = i ∈ B 1 , and equivalently, π − 1 ( i ∗ ) =
π − 1 ( j ) =
i ∈ B 1 .
Case 1c)
j > i ∗ .
I this case, we still have
[Equation]
but the probability of π − 1 ( i ∗ ) being “ O ” is different.
Since j > i ∗ , this event now depends on z − ,p , p = 1 , 2 , 3 .
More speciﬁcally,
[Equation]
Therefore, when i ∈ B 1 and j > j ∗ , it holds that
[Equation]
2) x i ∈ B 2 .
The case where x i ∈ B 2 can be analyzed using similar arguments.
For conciseness, we mainly present the ﬁnal results.
Case 2a)
j < i ∗ .
The calculation ends up in the same form.
We have
[Equation]
with ˜ P 2 = ˜ P 1 .
In addition,
[Equation]
where ¯ J 2 = r
[Equation]
−
[Equation]
b
[Equation]
+ (1 − r 1 + r 2 −
[Equation]
− j − b 0 ) J ∗ .
Hence, when x i ∈ B 2 and j < i ∗ , we have
[Equation]
i
[Equation]
Case 2b)
j = i ∗ .
In this case, Γ( i, j ) simply equals to 0 , since π − 1 ( i ∗ ) =
π − 1 ( j ) ∈ B 2 .
The probability of π − 1 ( i ∗ ) being “ O ” is 0 .
Case 2c)
j > i ∗ .
Omitting the details, we have
[Equation]
2) x i ∈ B 3 .
Case 3a)
j < i ∗ .
The expression is different from previous two, in that we need π − 1 ( j ) ∈ B 3 .
[Equation]
where
[Equation]
Moreover
[Equation]
we have
[Equation]
with ¯ J 3 =
[Equation]
) J ∗ .
Combining parts together we obtain
[Equation]
Case 3b)
j = i ∗ .
By same reasoning as Case 2a), Γ( i, j ) = 0 .
Case 3c)
j > i ∗ .
We have in this case
[Equation]
Finally, combining (30), (34), (35), (36), (37), (38), (39) and (40) and re-organizing terms, the proof is complete.
B M ORE N UMERICAL J USTIFICATION ON C-M IN H ASH - ( π, π )
The “Words” dataset (Li & Church, 2005) (which is publicly available) contains a large number of word vectors, with the i -th entry indicating whether this word appears in the i -th document, for a total of D = 2 16 documents.
The key statistics of the 120 selected word pairs are presented in
Table 1.
Those 120 pairs of words are more or less randomly selected except that we make sure they cover a wide spectrum of data distributions.
Denote d as the number of non-zero entries in the vector.
Table 1 reports the density ˜
d
= d/D for each word vector, ranging from 0.0006 to 0.6.
The
Jaccard similarity J ranges from 0.002 to 0.95.
In Figures 9 - 16, we plot the empirical MSE along with the empirical bias 2 for ˆ J π,π , as well as the empirical MSE for ˆ J σ,π .
Note that for D this large, it is numerically difﬁcult to evaluate the theoretical variance formulas.
From the results in the Figures, we can observe
• For all the data pairs, the MSE of C-MinHash- ( π, π ) estimator overlaps with the empirical MSE of C-MinHash- ( σ, π ) estimator for all K from 1 up to 4096.
• The bias 2 is several orders of magnitudes smaller than the MSE, in all data pairs.
This veriﬁes that the bias of ˆ J π,π is extremely small in practice and can be safely neglected.
We have many more plots on more data pairs.
Nevertheless, we believe the current set of experiments on this “Words” dataset should be sufﬁcient to verify that, the proposed C-MinHash- ( π, π ) could give indistinguishable Jaccard estimation accuracy in practice compared with C-MinHash- ( σ, π ) .
[Table]
ABOUT
[Table]
INTO
[Table]
LIKE
[Table] [Table]
[Table]
AND
[Table]
PROBLEM
[Table]
NAME
[Table]
BRAZIL
[Table]
OH
[Table]
MANY
[Table]
SHOWS
[Table]
PEOPLE - BY 0.
0.228 CALORIES - MICROSOFT 0.
PEOPLE - INFO 0.
0.117 CAN - FROM 0.
PICKS - BOOST 0.
0.007 CAN - SEARCH 0.
PLANET - REWARD 0.
0.018 COMMITTED - PRODUCTIVE 0.
PLEASE - MAKE 0.
0.195 CONTEMPORARY - FLASH 0.
PREFER - PUEDE 0.
0.0001 CONVENIENTLY - INDUSTRIES 0.
PRIVACY - FOUND 0.
0.053 COPYRIGHT - AN 0.
PROSECUTION - MAXIMIZE 0.
0.006 CREDIT - CARD 0.
RECENTLY - INT 0.
0.014 DE - WEB 0.
REPLY - ACHIEVE 0.
0.023 DO - GOOD 0.
RESERVED - BEEN 0.
0.108 EARTH - GROUPS 0.
RIGHTS - FIND 0.
0.166 EXPRESSED - FRUSTRATED 0.
RIGHTS - RESERVED 0.
0.877 FIND - HAS 0.
SCENE - ABOUT 0.
0.029 FIND - SITE 0.
SEE - ALSO 0.
0.291 FIXED - SPECIFIC 0.
SEIZE - ANYTHING 0.
0.012 FLIGHT - TRANSPORTATION 0.
SHOULDERS - GORGEOUS 0.
0.028 FOUND - DE 0.
SICK - FELL 0.
0.085 FRANCISCO - SAN 0.
SITE - CELLULAR 0.
0.010 GOOD - BACK 0.
SOLD - LIVE 0.
0.055 GROUPS - ORDERED 0.
SOLO - CLAIMS 0.
0.007 HAPPY - CONCEPT 0.
SOON - ADVANCE 0.
0.057 HAVE - FIRST 0.
SPECIALIZES - ACTUAL 0.
0.008 HAVE - US 0.
STATE - OF 0.
0.165 HILL - ASSURED 0.
STATES - UNITED 0.
0.591 HOME - SYNTHESIS 0.
TATTOO - JEANS 0.
0.035 HONG - KONG 0.
THAT - ALSO 0.
0.376 HOSTED - DRUGS 0.
THIS - CITY 0.
0.132 INTERVIEWS - FOURTH 0.
THEIR - SUPPORT 0.
0.189 KANSAS - PROPERTY 0.
THEIR - VIEW 0.
0.151 KIRIBATI - GAMBIA 0.
THEM - OF 0.
0.187 LAST - THIS 0.
THEN - NEW 0.
0.192 LEAST - ROMANCE 0.
THINKS - LOT 0.
0.079 LIME - REGISTERED 0.
TIME - OUT 0.
0.366 LINKS - TAKE 0.
TIME - WELL 0.
0.299 LINKS - THAN 0.
TOP - AS 0.
0.217 MAIL - AND 0.
TOP - COPYRIGHT 0.
0.149 MAIL - BACK 0.
TOP - NEWS 0.
0.192 MAKE - LIKE 0.
UP - AND 0.
0.334 MANAGING - LOCK 0.
UP - HAS 0.
0.312 MANY - US 0.
US - BE 0.
0.335 MASS - DREAM 0.
VIEW - IN 0.
0.153 MAY - HELP 0.
VIEW - PEOPLE 0.
0.138 MOST - HOME 0.
WALKED - ANTIVIRUS 0.
0.002 NAME - IN 0.
WEB - GO 0.
0.138 NEITHER - FIGURE 0.
WELL - INFO 0.
0.110 NET - SO 0.
WELL - NEWS 0.
0.161 NEW - PLEASE 0.
WEEKS - LONDON 0.
[Figure]
AFTER
[Table]
OR
[Figure]
[Figure] [Figure]
- AN
[Figure] [Figure]
[Figure]
HAVE
[Figure]
FIRST
[Figure] [Figure]
[Figure]
THIS
[Figure]
LINKS - TAKE
[Figure]
- BACK
[Figure] [Figure]
[Figure]
NOTORIOUSLY - LOCK
[Figure] [Figure]
[Figure] [Figure]
[Figure]
SOON - ADVANCE
[Figure]
[Figure] [Figure]
THEM
[Figure] [Figure]