diff --git a/Makefile b/Makefile index 3c03dd2..6055929 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ SOURCE = fog # Commands all: lint test test: unit -publish: upload clean +publish: lint test upload clean clean: rm -rf *.egg-info .pytest_cache build dist diff --git a/fog/metrics/cosine.py b/fog/metrics/cosine.py index aa912a1..8d34deb 100644 --- a/fog/metrics/cosine.py +++ b/fog/metrics/cosine.py @@ -6,6 +6,10 @@ # import math +# TODO: test one of the two counters is empty +# TODO: test both are empty +# TODO: test 1 dimension (identical + different) + def sparse_cosine_similarity(A, B, key=lambda x: x): """ @@ -35,8 +39,10 @@ def sparse_cosine_similarity(A, B, key=lambda x: x): weight = key(v) xx += weight ** 2 - if k in B: - xy += weight * key(B[k]) + v2 = B.get(k) + + if v2 is not None: + xy += weight * key(v2) for v in B.values(): weight = key(v)