28 #include <raft/core/device_coo_matrix.hpp>
29 #include <raft/core/device_mdspan.hpp>
30 #include <raft/core/handle.hpp>
31 #include <raft/core/kvp.hpp>
32 #include <raft/core/resource/thrust_policy.hpp>
33 #include <raft/sparse/coo.hpp>
34 #include <raft/util/cudart_utils.hpp>
36 #include <rmm/device_uvector.hpp>
38 #include <thrust/device_ptr.h>
39 #include <thrust/extrema.h>
40 #include <thrust/gather.h>
41 #include <thrust/scatter.h>
42 #include <thrust/transform.h>
44 #include <cuvs/cluster/agglomerative.hpp>
65 template <
typename value_
idx =
int64_t,
typename value_t =
float>
75 auto stream = handle.get_stream();
76 size_t n_edges = m - 1;
77 cuvs::cluster::agglomerative::helpers::linkage_graph_params::mutual_reachability_params
81 linkage_params.min_samples =
params.min_samples + 1;
82 linkage_params.alpha =
params.alpha;
86 raft::make_device_matrix_view<const value_t, value_idx>(X, m, n),
89 raft::make_device_coo_matrix_view<value_t, value_idx, value_idx, size_t>(
91 raft::make_device_coordinate_structure_view(
93 raft::make_device_matrix_view<value_idx, value_idx>(out.
get_children(), n_edges, 2),
94 raft::make_device_vector_view<value_t, value_idx>(out.
get_deltas(), n_edges),
95 raft::make_device_vector_view<value_idx, value_idx>(out.
get_sizes(), n_edges),
96 std::make_optional<raft::device_vector_view<value_t, value_idx>>(
97 raft::make_device_vector_view<value_t, value_idx>(core_dists, m)));
100 template <
typename value_
idx =
int64_t,
typename value_t =
float>
111 auto stream = handle.get_stream();
112 auto exec_policy = handle.get_thrust_policy();
114 int min_cluster_size =
params.min_cluster_size;
133 rmm::device_uvector<value_t> tree_stabilities(out.
get_condensed_tree().get_n_clusters(),
134 handle.get_stream());
137 handle.get_stream());
138 value_idx n_selected_clusters =
139 detail::Extract::extract_clusters(handle,
143 tree_stabilities.data(),
146 params.cluster_selection_method,
148 params.allow_single_cluster,
150 params.cluster_selection_epsilon);
154 auto lambdas_ptr = thrust::device_pointer_cast(out.
get_condensed_tree().get_lambdas());
155 value_t max_lambda = *(thrust::max_element(
158 detail::Stability::get_stability_scores(handle,
160 tree_stabilities.data(),
176 [label_map = label_map.data()] __device__(value_idx label) {
177 if (label != -1)
return label_map[label];
Definition: hdbscan.hpp:152
Definition: hdbscan.hpp:254
CondensedHierarchy< value_idx, value_t > & get_condensed_tree()
Definition: hdbscan.hpp:296
value_t * get_stabilities()
Definition: hdbscan.hpp:279
rmm::device_uvector< value_idx > & _get_inverse_label_map()
Definition: hdbscan.hpp:282
void set_n_clusters(int n_clusters_)
Definition: hdbscan.hpp:289
value_t * get_probabilities()
Definition: hdbscan.hpp:278
Definition: hdbscan.hpp:164
value_idx * get_sizes()
Definition: hdbscan.hpp:205
value_idx * get_mst_src()
Definition: hdbscan.hpp:207
value_t * get_mst_weights()
Definition: hdbscan.hpp:209
value_idx * get_mst_dst()
Definition: hdbscan.hpp:208
value_idx * get_labels()
Definition: hdbscan.hpp:203
value_t * get_deltas()
Definition: hdbscan.hpp:206
value_idx * get_children()
Definition: hdbscan.hpp:204
Definition: params.hpp:34
void _fit_hdbscan(const raft::handle_t &handle, const value_t *X, size_t m, size_t n, ML::distance::DistanceType metric, Common::HDBSCANParams ¶ms, value_idx *labels, value_t *core_dists, Common::hdbscan_output< value_idx, value_t > &out)
Definition: runner.h:101
void build_linkage(const raft::handle_t &handle, const value_t *X, size_t m, size_t n, ML::distance::DistanceType metric, Common::HDBSCANParams ¶ms, value_t *core_dists, Common::robust_single_linkage_output< value_idx, value_t > &out)
Definition: runner.h:66
DistanceType
Definition: distance_type.hpp:21
void transform(const raft::handle_t &handle, const KMeansParams ¶ms, const float *centroids, const float *X, int n_samples, int n_features, float *X_new)
Transform X to a cluster-distance space.
Definition: dbscan.hpp:29
void build_condensed_hierarchy(const raft::handle_t &handle, const int *children, const float *delta, const int *sizes, int min_cluster_size, int n_leaves, HDBSCAN::Common::CondensedHierarchy< int, float > &condensed_tree)