项目作者: LiveRamp

项目描述 :
Union, intersection, and set cardinality in loglog space
高级语言: Java
项目地址: git://github.com/LiveRamp/HyperMinHash-java.git
创建时间: 2018-05-04T02:48:32Z
项目社区:https://github.com/LiveRamp/HyperMinHash-java

开源协议:Other

下载


Build Status

HyperMinHash-java

A Java implementation of the HyperMinHash algorithm, presented by
Yu and Weber.
HyperMinHash allows approximating set unions, intersections, Jaccard Indices,
and cardinalities of very large sets with high accuracy using only loglog space.
It also supports streaming updates and merging sketches, just the same
as HyperLogLog.

This repo implements two flavors of HyperMinHash:
1) HyperMinHash: An implementation based on HyperLogLog with the
addition of the bias correction seen in HyperLogLog++.
2) BetaMinHash: An implementation which uses LogLog-Beta
for the underlying LogLog implementation. Loglog-beta is almost identical in
accuracy to HyperLogLog++, except it performs better on cardinality
estimations for small datasets (n <= 80k), holding memory fixed. Since we use Loglog-Beta,
we refer to our implementation as BetaMinHash. However, our implementation
currently only supports a fixed precision p=14.

If you expect to be dealing with low cardinality datasets (<= 80,000 unique elements),
we recommend using BetaMinHash as it has a smaller memory footprint and is more accurate
than HyperLogLog in the range from 20,000-80,000, holding memory fixed. However, note that
different sketch types are not interchangeable i.e: obtaining the intersection of an
HMH and a BMH is not currently supported.

Both implementations are equipped with serialization/deserialization
capabilities out of the box for sending sketches over the wire or
persisting them to disk.

Usage

Importing via Maven

  1. <dependency>
  2. <groupId>com.liveramp</groupId>
  3. <artifactId>hyperminhash</artifactId>
  4. <version>0.2</version>
  5. </dependency>

Cardinality estimation

  1. Set<byte[]> mySet = getMySet();
  2. BetaMinHash sketch = new BetaMinHash();
  3. for (byte[] element : mySet){
  4. sketch.add(element);
  5. }
  6. long estimatedCardinality = sketch.cardinality();

Merging (unioning) sketches

  1. Collection<BetaMinHash> sketches = getSketches();
  2. SketchCombiner<BetaMinHash> combiner = BetaMinHashCombiner.getInstance();
  3. BetaMinHash combined = combiner.union(sketches);
  4. // to get cardinality of the union
  5. long unionCardinality = combined.cardinality();
  6. // using HyperMinHash instead of BetaMinHash
  7. Collection<HyperMinHash> sketches = getSketches();
  8. SketchCombiner<HyperMinHash> combiner = HyperMinHashCombinre.getInstance();
  9. HyperMinHash combined = combiner.union(sketches);

Cardinality of unions

  1. BetaMinHash combined = combiner.union(sketches);
  2. long estimatedCardinality = combined.cardinality();

Cardinality of intersection

  1. Collection<BetaMinHash> sketches = getSketches();
  2. SketchCombiner<BetaMinHash> combiner = BetaMinHashComber.getInstance();
  3. long intersectionCardinality = combiner.intersectionCardinality(sketches);

Serializing a sketch

To get a byte[] representation of a sketch, use the IntersectionSketch.SerDe interface:

  1. HyperMinHash sketch = getSketch();
  2. HyperMinHashSerde serde = new HyperMinHashSerde();
  3. byte[] serialized = serde.toBytes(sketch);
  4. HyperMinHash deserialized = serde.fromBytes(serialized);
  5. int sizeInBytes = serde.sizeInBytes(sketch);

Maintainers

Commit authorship was lost when merging code. The maintainers of the library, in alphabetical order, are:

1) Christian Hansen (github.com/ChristianHansen)
2) Harry Rackmil (github.com/harryrackmil)
3) Shrif Nada (github.com/sherifnada)

Acknowledgements

Thanks to Seif Lotfy for implementing a
Golang version of HyperMinHash.
We use some of his tests in our library, and our BetaMinHash implementation
references his implementation.