Skip to content

Commit eefcb5b

Browse files
author
Jouni Helske
committed
stabler softmax
1 parent 8d97a02 commit eefcb5b

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

hdbscan/_prediction_utils.pyx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ cpdef np.ndarray[np.float64_t, ndim=1] dist_membership_vector(
7777

7878
if softmax:
7979
for i in range(vector.shape[0]):
80-
if vector[i] != 0:
81-
result[i] = np.exp(1.0 / vector[i])
82-
else:
83-
result[i] = DBL_MAX / vector.shape[0]
84-
sum += result[i]
80+
result[i] = 1.0 / vector[i]
81+
result = np.exp(result - np.nanmax(result))
82+
sum = np.sum(result)
8583

8684
else:
8785
for i in range(vector.shape[0]):

0 commit comments

Comments
 (0)