Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix distance_valid for jaccard
  • Loading branch information
cjz18001 committed Jun 18, 2020
1 parent 7216d02 commit c0da55d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions ann_benchmarks/distance.py
Expand Up @@ -4,7 +4,6 @@ from scipy.spatial.distance import pdist as scipy_pdist
def pdist(a, b, metric):
return scipy_pdist([a, b], metric=metric)[0]

# Need own implementation of jaccard because numpy's implementation is different
def jaccard(a, b):
if len(a) == 0 or len(b) == 0:
return 0
Expand All @@ -31,7 +30,7 @@ def jaccard(a, b):
# 'distance_valid' : lambda a: True
# }
# }
# Chunjiang Modified 20190216

metrics = {
'hamming': {
'distance' : lambda a, b: pdist(a, b, "hamming"),
Expand All @@ -40,7 +39,7 @@ metrics = {
# return 1 - jaccard similarity, because smaller distances are better.
'jaccard': {
'distance' : lambda a, b: pdist(a, b, "jaccard"),
'distance_valid' : lambda a: a < 1 - 1e-5
'distance_valid' : lambda a: a < 1 + 1e-5
},
'euclidean': {
'distance' : lambda a, b: pdist(a, b, "euclidean"),
Expand Down

0 comments on commit c0da55d

Please sign in to comment.