Skip to content

Commit 103c52b

Browse files
author
Bruno Alano
committed
Scikit-learn dont implement the arccos distance, use cosine distance to pairwise distance
1 parent 354e30d commit 103c52b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

hdbscan/dist_metrics.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ cdef class CosineDistance(DistanceMetric):
10521052
norm2 += x2[j] * x2[j]
10531053
return 1.0 - d / sqrt(norm1 * norm2)
10541054

1055+
#------------------------------------------------------------
1056+
# Cosine Distance
1057+
# D(x, y) = arccos(dot(x, y) / (|x| * |y|)) / PI
1058+
10551059
cdef class ArccosDistance(DistanceMetric):
10561060
cdef inline DTYPE_t dist(self, DTYPE_t* x1, DTYPE_t* x2, ITYPE_t size) nogil except -1:
10571061
cdef DTYPE_t d = 0, norm1 = 0, norm2 = 0

hdbscan/hdbscan_.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def _hdbscan_generic(X, min_samples=5, alpha=1.0,
6868
raise ValueError('Minkowski metric with negative p value is not defined!')
6969

7070
distance_matrix = pairwise_distances(X, metric=metric, p=p)
71+
elif metric == 'arccos':
72+
distance_matrix = pairwise_distances(X, metric='cosine', **kwargs)
7173
else:
7274
distance_matrix = pairwise_distances(X, metric=metric, **kwargs)
7375

0 commit comments

Comments
 (0)