Skip to content

Commit f2e2af9

Browse files
authored
Fixed all_points_core_distance for clusters with pairwise distances of zero
Previously, all_points_core_distance would return NaN if all points within a cluster had a distance of zero to one another, i.e. were all the same. Now, it returns an array of zeros with length(distance_matrix).
1 parent 523cd86 commit f2e2af9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hdbscan/validity.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ def all_points_core_distance(distance_matrix, d=2.0):
3131
distance_matrix != 0]) ** d
3232
result = distance_matrix.sum(axis=1)
3333
result /= distance_matrix.shape[0] - 1
34-
result **= (-1.0 / d)
34+
35+
if result.sum() == 0:
36+
result = np.zeros(len(distance_matrix))
37+
else:
38+
result **= (-1.0 / d)
3539

3640
return result
3741

0 commit comments

Comments
 (0)