Skip to content

Commit

Permalink
use De-Morgan's laws to optimize jaccard computation
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatYYX committed Jul 30, 2018
1 parent 5c1c05f commit 29e6099
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rltk/similarity/jaccard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ def _jaccard_index(set1, set2):
if len(set1) == 0 or len(set2) == 0:
return 0

return float(len(set1 & set2)) / float(len(set1 | set2))
# return float(len(set1 & set2)) / float(len(set1 | set2))

inter_len = len(set1 & set2)
return float(inter_len) / (len(set1) + len(set2) - inter_len)


def jaccard_index_similarity(set1, set2):
Expand Down

0 comments on commit 29e6099

Please sign in to comment.