{"id":225,"date":"2026-11-13T12:35:08","date_gmt":"2026-11-13T04:35:08","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-minhash-estimates-a-jaccard-similarity\/"},"modified":"2026-11-13T21:53:10","modified_gmt":"2026-11-13T13:53:10","slug":"how-minhash-estimates-a-jaccard-similarity","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-minhash-estimates-a-jaccard-similarity\/","title":{"rendered":"How MinHash estimates a Jaccard similarity"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>MinHash<\/strong> estimates the Jaccard similarity of two sets. With a random hash, the probability that the element of minimum hash is the same in both sets equals the Jaccard index, the size of the intersection divided by the size of the union. k independent hashes give k trials. The fraction of hashes that agree is an unbiased estimate, and the variance falls as <strong>1\/k<\/strong>. A signature of k minimum hashes replaces each set.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Jaccard similarity needs the intersection and the union. For large sets those scans dominate, and a database of sets needs a pairwise comparison that does not read every element. A random permutation of the universe puts some element first. That first element lands in the intersection exactly when it is the first element of both sets, and the chance of that event is the Jaccard index. The minimum hash simulates the first element of a random permutation.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Several independent minima concentrate the estimate. Locality-sensitive hashing for Jaccard uses bands of this signature so that similar sets collide in a bucket and dissimilar sets usually do not.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Each coordinated minimum is equal with probability exactly equal to the Jaccard index, for a truly random hash, or approximately so for a practical hash family that behaves randomly on the data. The average of k independent trials has variance J(1\u2212J)\/k. Time to build a signature is proportional to the set size times k. Comparing two signatures is O(k). Extra memory is the signature, not the set.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The hashes on the two sets must be the same functions. Independent hashes per set make agreement meaningless. A single hash has variance J(1\u2212J), which is large. k in the hundreds is a common choice when the estimate will be thresholded.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Choose k hash functions, or one hash and k random seeds, and fix them for the whole collection.<\/li>\n<li>For a set, the signature component i is the minimum of hash_i over the elements. Empty sets have no minimum and need a documented sentinel.<\/li>\n<li>The estimated Jaccard similarity is the fraction of components in which two signatures are equal.<\/li>\n<li>Do not compare minima that were produced by different seeds. The coordination is the algorithm.<\/li>\n<li>For a search index, split the signature into bands and hash each band into a bucket. A candidate pair shares a bucket. Verify or re-estimate the candidates.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">The estimate is of Jaccard similarity, not of cosine similarity and not of edit distance. Uncoordinated hashes do not estimate anything useful. The variance formula assumes independent trials. Reusing one hash with correlated prefixes understates the variance reduction. Banding is a retrieval structure on top of the estimate, not a more accurate estimator.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when each set is hashed with a fresh seed<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Draw new hash functions for every set<\/td>\n<td>Equal minima then happen by chance across unrelated functions. The probability is no longer the Jaccard index.<\/td>\n<\/tr>\n<tr>\n<td>Estimate from one minimum and treat it as a stable percentage<\/td>\n<td>One trial is a Bernoulli random variable with variance J(1\u2212J). The percentage needs many trials.<\/td>\n<\/tr>\n<tr>\n<td>Store the minimum of the raw identifiers with no hash<\/td>\n<td>The smallest identifier is one fixed permutation, and it is adversarial if identifiers are assigned by a rule. The permutation has to be random.<\/td>\n<\/tr>\n<tr>\n<td>Use the signature equality fraction as a cosine<\/td>\n<td>The probability identity is specific to Jaccard. Cosine has a different locality-sensitive family.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">A cardinality sketch is HyperLogLog. Membership is a Bloom filter. MinHash is the Jaccard estimator, and banding it is the locality-sensitive index for similar sets.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment estimates Jaccard similarity by the fraction of hash trials whose minimum lands on the same element. Sets {1, 2, 3, 4} and {3, 4, 5, 6} have Jaccard 1\/3. With a seeded family the estimate prints <code>0.32<\/code>.<\/p>\n\n<pre><code class=\"language-python\">import random\na = {1, 2, 3, 4}\nb = {3, 4, 5, 6}\nrng = random.Random(0)\ntrials = 300\nagree = 0\nfor _ in range(trials):\n    salt = rng.randrange(10**9)\n    def h(x):\n        return (x * 1315423911 + salt) % 2**31\n    if min(a, key=h) == min(b, key=h):\n        agree += 1\nest = agree \/ trials\ntruth = len(a &amp; b) \/ len(a | b)\nassert abs(est - truth) &lt; 0.08\nprint(f&quot;{est:.2f}&quot;)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\"><strong>MinHash<\/strong> is Broder&#8217;s sketch for near-duplicate web pages, and the same sketch feeds plagiarism and document-clustering pipelines. The estimate is a Jaccard similarity of the shingles. A full set intersection is exact and does not fit the same memory.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop MinHash when the sets are small enough to compare exactly. Keep coordinated signatures when many pairs must be screened and an unbiased estimate of Jaccard similarity is the score.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for MinHash returns the coordinated minimum and the fact that its collision probability is the Jaccard index. <strong>MinHash estimates Jaccard similarity by the fraction of coordinated minimum hashes that agree, which equals the true index in expectation.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: MinHash estimates the Jaccard similarity of two sets. With a random hash, the probability that the element of minimum hash is the same in both sets equals the Jaccard index, the size of the intersection divided by the size of the union. k independent hashes give k&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,36],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-sketches"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=225"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":624,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/225\/revisions\/624"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}