Skip to content

Commit

Permalink
Fixed all_points_core_distance for clusters with pairwise distances o…
Browse files Browse the repository at this point in the history
…f 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).
  • Loading branch information
tadorfer committed Aug 23, 2022
1 parent 523cd86 commit f2e2af9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hdbscan/validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def all_points_core_distance(distance_matrix, d=2.0):
distance_matrix != 0]) ** d
result = distance_matrix.sum(axis=1)
result /= distance_matrix.shape[0] - 1
result **= (-1.0 / d)

if result.sum() == 0:
result = np.zeros(len(distance_matrix))
else:
result **= (-1.0 / d)

return result

Expand Down

0 comments on commit f2e2af9

Please sign in to comment.