|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
MinHash signature generator. More...
#include <minhash.H>
Public Member Functions | |
| MinHash (size_t k=128) | |
| Construct with signature size. | |
| MinHash (const MinHash &other)=default | |
| Copy the size and the signature of another MinHash. | |
| MinHash (MinHash &&other) | |
| Take the signature of another MinHash, which is left as an empty one of the same size. | |
| MinHash & | operator= (const MinHash &other)=default |
| Copy the size and the signature of another MinHash. | |
| MinHash & | operator= (MinHash &&other) noexcept |
| Exchange this MinHash with another, which is left with the previous state of this one. | |
| void | swap (MinHash &other) noexcept |
| Exchange in O(1) the state of this MinHash and another. | |
| void | update (const T &val) |
| Add an element to the set. | |
| template<std::input_iterator Itor> | |
| void | update (Itor beg, const Itor &end) |
| Add all elements in a range to the MinHash signature. | |
| double | similarity (const MinHash &other) const |
| Estimate Jaccard similarity with another signature. | |
| const Array< uint64_t > & | get_signature () const noexcept |
| Returns the current signature. | |
| void | clear () |
| Reset the signature to the initial all-maximum state. | |
| MinHash & | merge (const MinHash &other) |
| Merge another MinHash signature into this one. | |
| size_t | size () const noexcept |
| Number of hash functions used in the signature. | |
Private Attributes | |
| size_t | k_ |
| Signature size. | |
| Array< uint64_t > | signature_ |
| Minimized hash values. | |
| Array< uint32_t > | seeds_ |
| Random seeds for hash functions. | |
MinHash signature generator.
Maintain a signature of size k representing a set. The Jaccard similarity between two sets can be estimated by the fraction of positions where their MinHash signatures agree.
| T | Element type. |
|
inlineexplicit |
Construct with signature size.
| [in] | k | Number of hashes to use (higher k -> better precision). |
| std::domain_error | if k == 0. |
Definition at line 75 of file minhash.H.
References ah_domain_error_if, Aleph::Array< T >::append(), Aleph::dft_hash_fct(), k, Aleph::MinHash< T >::k_, Aleph::Array< T >::reserve(), Aleph::MinHash< T >::seeds_, and Aleph::MinHash< T >::signature_.
Take the signature of another MinHash, which is left as an empty one of the same size.
The implicit move took the signature but copied its size: the moved-from MinHash then read and wrote hashes that it no longer had, and its clear() wrote through a null buffer.
| [in,out] | other | MinHash to move from. |
| std::bad_alloc | if the signature left to other cannot be allocated; other is then unchanged. |
other. Definition at line 108 of file minhash.H.
References Aleph::MinHash< T >::swap().
|
inline |
Reset the signature to the initial all-maximum state.
| none |
Definition at line 206 of file minhash.H.
References Aleph::MinHash< T >::k_, and Aleph::MinHash< T >::signature_.
Referenced by assertMinHashContracts(), and TEST().
|
inlinenoexcept |
Returns the current signature.
| none |
Definition at line 197 of file minhash.H.
References Aleph::MinHash< T >::signature_.
Referenced by assertMinHashContracts(), and TEST().
Merge another MinHash signature into this one.
Combines two MinHash signatures by taking the element-wise minimum, which corresponds to the union of the underlying sets.
| [in] | other | Another MinHash with the same number of hashes. |
*this after the merge. | std::domain_error | if signature sizes differ. |
Definition at line 222 of file minhash.H.
References ah_domain_error_if, Aleph::MinHash< T >::k_, and Aleph::MinHash< T >::signature_.
|
inline |
Estimate Jaccard similarity with another signature.
| [in] | other | The MinHash signature to compare against. |
| std::domain_error | if signature sizes mismatch. |
Definition at line 179 of file minhash.H.
References ah_domain_error_if, Aleph::MinHash< T >::k_, and Aleph::MinHash< T >::signature_.
|
inlinenoexcept |
Number of hash functions used in the signature.
| none |
Definition at line 237 of file minhash.H.
References Aleph::MinHash< T >::k_.
Referenced by assertMinHashContracts(), TEST(), and TEST().
|
inlinenoexcept |
Exchange in O(1) the state of this MinHash and another.
| [in,out] | other | MinHash to exchange with. |
Definition at line 135 of file minhash.H.
References Aleph::MinHash< T >::k_, Aleph::MinHash< T >::seeds_, Aleph::MinHash< T >::signature_, and Aleph::Array< T >::swap().
Referenced by Aleph::MinHash< T >::MinHash(), and Aleph::MinHash< T >::operator=().
|
inline |
Add an element to the set.
| [in] | val | The element to incorporate into the signature. |
| none |
Definition at line 147 of file minhash.H.
References h, Aleph::MinHash< T >::k_, Aleph::murmur3hash(), Aleph::MinHash< T >::seeds_, and Aleph::MinHash< T >::signature_.
Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), and Aleph::MinHash< T >::update().
|
inline |
Add all elements in a range to the MinHash signature.
Calls update(val) for each element in [beg, end).
| Itor | Iterator whose value type is compatible with update(const T&). |
| [in] | beg | Iterator to the first element. |
| [in] | end | Past-the-end iterator. |
| none |
Definition at line 165 of file minhash.H.
References Aleph::MinHash< T >::update().
|
private |
Signature size.
Definition at line 66 of file minhash.H.
Referenced by Aleph::MinHash< T >::MinHash(), Aleph::MinHash< T >::clear(), Aleph::MinHash< T >::merge(), Aleph::MinHash< T >::similarity(), Aleph::MinHash< T >::size(), Aleph::MinHash< T >::swap(), and Aleph::MinHash< T >::update().
|
private |
Random seeds for hash functions.
Definition at line 68 of file minhash.H.
Referenced by Aleph::MinHash< T >::MinHash(), Aleph::MinHash< T >::swap(), and Aleph::MinHash< T >::update().
|
private |
Minimized hash values.
Definition at line 67 of file minhash.H.
Referenced by Aleph::MinHash< T >::MinHash(), Aleph::MinHash< T >::clear(), Aleph::MinHash< T >::get_signature(), Aleph::MinHash< T >::merge(), Aleph::MinHash< T >::similarity(), Aleph::MinHash< T >::swap(), and Aleph::MinHash< T >::update().