Skip to content

Commit 23b9f6e

Browse files
committed
Add types to outlier code.
1 parent 6147cb9 commit 23b9f6e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

hdbscan/_hdbscan_tree.pyx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,32 @@ cdef get_probabilities(np.ndarray tree, dict cluster_map, np.ndarray labels):
401401

402402
return result
403403

404-
cpdef outlier_scores(tree):
404+
cpdef np.ndarray[np.double_t, ndim=1] outlier_scores(np.ndarray tree):
405+
406+
cdef np.ndarray[np.double_t, ndim=1] result
407+
cdef np.ndarray[np.double_t, ndim=1] deaths
408+
cdef np.intp_t root_cluster
409+
cdef np.intp_t point
410+
cdef np.intp_t parent
411+
cdef np.intp_t cluster
412+
cdef np.double_t lambda_max
405413

406414
result = np.zeros(labels.shape[0])
407415
deaths = max_lambdas(tree)
408416
root_cluster = tree['parent'].min()
409417

418+
topological_sort_order = np.argsort(tree['parent'])
419+
topologically_sorted_tree = tree[topological_sort_order]
420+
421+
for row in topologically_sorted_tree:
422+
cluster = row['child']
423+
if cluster < root_cluster:
424+
break
425+
426+
parent = row['parent']
427+
if deaths[cluster] > deaths[parent]:
428+
deaths[parent] = deaths[cluster]
429+
410430
for row in tree:
411431
point = row['child']
412432
if point >= root_cluster:

0 commit comments

Comments
 (0)