|
5 | 5 |
|
6 | 6 | #pragma once |
7 | 7 |
|
8 | | -#include <cuml/cluster/single_linkage_output.hpp> |
9 | 8 | #include <cuml/common/distance_type.hpp> |
10 | 9 |
|
11 | 10 | #include <raft/core/handle.hpp> |
12 | 11 |
|
13 | | -namespace raft { |
14 | | -class handle_t; |
15 | | -} |
16 | | - |
17 | 12 | namespace ML { |
| 13 | +namespace linkage { |
18 | 14 |
|
19 | 15 | /** |
20 | 16 | * @brief Computes single-linkage hierarchical clustering on a dense input |
21 | 17 | * feature matrix and outputs the labels, dendrogram, and minimum spanning tree. |
22 | | - * Connectivities are constructed using the full n^2 pairwise distance matrix. |
23 | | - * This can be very fast for smaller datasets when there is enough memory |
24 | | - * available. |
25 | | - * @param[in] handle raft handle to encapsulate expensive resources |
26 | | - * @param[in] X dense feature matrix on device |
27 | | - * @param[in] m number of rows in X |
28 | | - * @param[in] n number of columns in X |
29 | | - * @param[in] metric distance metric to use. Must be supported by the |
30 | | - * dense pairwise distances API. |
31 | | - * @param[out] out container object for output arrays |
32 | | - * @param[out] n_clusters number of clusters to cut from resulting dendrogram |
33 | | - */ |
34 | | -void single_linkage_pairwise(const raft::handle_t& handle, |
35 | | - const float* X, |
36 | | - size_t m, |
37 | | - size_t n, |
38 | | - ML::single_linkage_output<int>* out, |
39 | | - ML::distance::DistanceType metric, |
40 | | - int n_clusters = 5); |
41 | | - |
42 | | -/** |
43 | | - * @brief Computes single-linkage hierarchical clustering on a dense input |
44 | | - * feature matrix and outputs the labels, dendrogram, and minimum spanning tree. |
45 | | - * Connectivities are constructed using a k-nearest neighbors graph. While this |
46 | | - * strategy enables the algorithm to scale to much higher numbers of rows, |
47 | | - * it comes with the downside that additional knn steps may need to be |
48 | | - * executed to connect an otherwise unconnected k-nn graph. |
49 | | - * @param[in] handle raft handle to encapsulate expensive resources |
50 | | - * @param[in] X dense feature matrix on device |
51 | | - * @param[in] m number of rows in X |
52 | | - * @param[in] n number of columns in X |
53 | | - * @param[in] metric distance metric to use. Must be supported by the |
54 | | - * dense pairwise distances API. |
55 | | - * @param[out] out container object for output arrays |
56 | | - * @param[out] c the optimal value of k is guaranteed to be at least log(n) + c |
57 | | - * where c is some constant. This constant can usually be set to a fairly low |
58 | | - * value, like 15, and still maintain good performance. |
59 | | - * @param[out] n_clusters number of clusters to cut from resulting dendrogram |
| 18 | + * |
| 19 | + * @param[in] handle: raft handle to encapsulate expensive resources |
| 20 | + * @param[in] X: dense feature matrix on device, C contiguous |
| 21 | + * @param[in] n_rows: number of rows in X |
| 22 | + * @param[in] n_cols: number of columns in X |
| 23 | + * @param[in] n_clusters: the number of clusters to fit. |
| 24 | + * @param[in] metric: distance metric to use. Must be supported by the |
| 25 | + * dense pairwise distances API. |
| 26 | + * @param[out] children: the output dendrogram, shape=(n_rows - 1, 2), C contiguous |
| 27 | + * @param[out] labels: the output labels, shape=(n_rows,) |
| 28 | + * @param[in] use_knn: whether to construct a knn graph instead of the full |
| 29 | + * n^2 pairwise distance matrix. This can be faster for very large |
| 30 | + * datasets or in cases where lower memory usage is required. |
| 31 | + * @param[in] c: tunes the number of neighbors when `use_knn` is true, where |
| 32 | + * `n_neighbors=log(n_rows) + c`. |
60 | 33 | */ |
61 | | -void single_linkage_neighbors( |
62 | | - const raft::handle_t& handle, |
63 | | - const float* X, |
64 | | - size_t m, |
65 | | - size_t n, |
66 | | - ML::single_linkage_output<int>* out, |
67 | | - ML::distance::DistanceType metric = ML::distance::DistanceType::L2Unexpanded, |
68 | | - int c = 15, |
69 | | - int n_clusters = 5); |
70 | | - |
71 | | -void single_linkage_pairwise(const raft::handle_t& handle, |
72 | | - const float* X, |
73 | | - size_t m, |
74 | | - size_t n, |
75 | | - ML::single_linkage_output<int64_t>* out, |
76 | | - ML::distance::DistanceType metric, |
77 | | - int n_clusters = 5); |
78 | | - |
| 34 | +void single_linkage(const raft::handle_t& handle, |
| 35 | + const float* X, |
| 36 | + int n_rows, |
| 37 | + int n_cols, |
| 38 | + size_t n_clusters, |
| 39 | + ML::distance::DistanceType metric, |
| 40 | + int* children, |
| 41 | + int* labels, |
| 42 | + bool use_knn = false, |
| 43 | + int c = 15); |
| 44 | + |
| 45 | +}; // namespace linkage |
79 | 46 | }; // namespace ML |
0 commit comments