<p>1) There is a variant of minwise hashing called one permutation hashing (see <a href="http://papers.nips.cc/paper/4778-one-permutation-hashing.pdf" rel="nofollow noreferrer">http://papers.nips.cc/paper/4778-one-permutation-hashing.pdf</a>) that uses only a single hash function. Estimation can be somehow inaccurate for small sets where the number of elements is small compared to the number of bins. However, in this case it is possible to "densify" the hash signature of a set using the technique described in <a href="https://arxiv.org/pdf/1406.4784.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1406.4784.pdf</a>.</p>

<p>2) Bitsets are actually a special case of HyperLogLog sketches as discussed in <a href="https://arxiv.org/pdf/1702.01284.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1702.01284.pdf</a>. This paper also describes a maximum likelihood method that allows more accurate estimation of union and intersections sizes of two HyperLogLog sketches which can be used to finally get an estimate for the Jaccard similarity.</p>
Jaccard similarity algorithm for thousands of huge datasets in runtime
<h2>What I need</h2>

<p>I'm looking for pretty fast and accurate way to find Jaccard similarity among multiple huge sets of data. I could have up to 10.000-20.000 operations of calculating Jaccard similarity. Due to the need to calculate all Jaccard similarities just after dumping of that datasets, I can't calculate them in background with slow algorithms during the quiet winter nights.</p>

<p>I see two possible solutions:</p>

<h2>Solution #1</h2>

<p>Use MinHash algorithm. The problem with this solution is that it's very slow. To get 10% error you need to use 100 hash functions. The only workaround I see here is to hash everything with single "expensive" hash function, and than use 100 "cheap" hash functions over the hash result. But I haven't enough math background to choose them by myself.</p>

<h2>Question #1</h2>

<p><em>How to choose speed efficient set of hash functions for MinHash to get maximum error 10%?</em></p>

<h2>Solution #2</h2>

<p>Use HyperLogLog or BitSet to calculate Jaccard similarity. <br> 
The problem with this approach is that <a href="https://github.com/Volodymyr128/HyperLogLog-vs-MinHash-vs-BitSet-tests/blob/master/src/test/java/algos/JaccardSimilarityHLLvsBitSetTest.java" rel="nofollow noreferrer">for some reasons I get too big errors in some cases</a>. Also the problem with BitSet (even it's sparse data structure) is that it takes too much RAM on huger datasets.</p>

<p>My algorithms:</p>

<ol>
<li>Choose probability cardinality estimation algorithm (HyperLogLog or BitSet)</li>
<li>Calculate probable cardinality of <code>set1</code></li>
<li>Calculate probable cardinality of <code>set2</code></li>
<li>Calculate probable cardinality of <code>set1 union set2</code>. Both HyperLogLog and BitSet support merge operation.</li>
<li>Similarity between <code>set2</code> and <code>set1</code> = <code>(cardinality(set1) + cardinality(set2) - cardinality(set1 union set2)) / cardinality(set2)</code></li>
</ol>

<h2>Question #2</h2>

<p><em>Why do I get the same deviation of Jaccard similarity estimation on both BitSet and HyperLogLog? <a href="https://github.com/Volodymyr128/HyperLogLog-vs-MinHash-vs-BitSet-tests/blob/master/src/test/java/algos/CardinalityHLLvsBitSetTest.java" rel="nofollow noreferrer">BitSet prove better cardinality precision than HLL</a>. I though that if BitSet takes much more space it should have much bigger accuracy, am I wrong?</em></p>

<h2>Question #3</h2>

<p><em>Is that impossible to achieve deviation of Jaccard similarity less than 5% with BitSet and HyperLogLog? What I'm doing wrong?</em></p>

<h2>P.S.</h2>

<p><a href="https://github.com/Volodymyr128/HyperLogLog-vs-MinHash-vs-BitSet-tests/blob/master/src/test/java/algos/JaccardSimilarityHLLvsBitSetTest.java" rel="nofollow noreferrer">Hope this test results would be helpful for you!</a></p>