LexisMinhash::Similarity
Similarity measures for comparing documents
This module provides various similarity metrics for comparing document representations, including weighted overlap for TF-IDF or other weighted document representations. Similarity contains similarity and overlap measures useful for comparing MinHash signatures and weighted document vectors.
Class methods
Optimized overlap coefficient using two-pointer scan for sorted Slices (UInt32)
Input slices MUST be sorted in ascending order.
Computes the Jaccard similarity coefficient between two sets
The Jaccard similarity measures similarity between two sets as |A ∩ B| / |A ∪ B|. Returns a value between 0.0 (no overlap) and 1.0 (identical sets).
a = Set{1, 2, 3}
b = Set{2, 3, 4}
LexisMinhash::Similarity.jaccard(a, b) # => 0.5 (intersection: 2, union: 4)
Computes the weighted overlap coefficient between two weighted document representations
The weighted overlap coefficient measures similarity as the sum of minimum weights for intersecting terms, normalized by the smaller total weight. This is useful for comparing weighted document representations like TF-IDF vectors.
doc_a = {"machine" => 0.8, "learning" => 0.9, "data" => 0.5}
doc_b = {"machine" => 0.8, "learning" => 0.6, "model" => 0.7}
LexisMinhash::Similarity.weighted_overlap(doc_a, doc_b) # => ~0.736
NOTE: Keys are case-sensitive; ensure both hashes use consistent casing.