37 void cutree_k(
int n,
const int *merge,
int nclust,
int *labels)
42 if (nclust > n || nclust < 2) {
43 for (j = 0; j < n; j++)
50 std::vector<int> last_merge(n, 0);
51 for (k = 1; k <= (n - nclust); k++) {
54 m2 = merge[n - 1 + k - 1];
55 if (m1 < 0 && m2 < 0) {
56 last_merge[-m1 - 1] = last_merge[-m2 - 1] = k;
57 }
else if (m1 < 0 || m2 < 0) {
64 for (l = 0; l < n; l++)
65 if (last_merge[l] == m1)
67 last_merge[j - 1] = k;
69 for (l = 0; l < n; l++) {
70 if (last_merge[l] == m1 || last_merge[l] == m2)
78 std::vector<int> z(n, -1);
79 for (j = 0; j < n; j++) {
80 if (last_merge[j] == 0) {
83 if (z[last_merge[j]] < 0) {
84 z[last_merge[j]] = label++;
86 labels[j] = z[last_merge[j]];
103 void cutree_cdist(
int n,
const int *merge,
double *height,
double cdist,
int *labels)
108 for (k = 0; k < (n - 1); k++) {
109 if (height[k] >= cdist) {
140 int hclust_fast(
int n,
double *distmat,
int method,
int *merge,
double *height)
147 MST_linkage_core(n, distmat, Z2);
150 NN_chain_core<METHOD_METR_COMPLETE, t_float>(n, distmat, NULL, Z2);
153 double *members =
new double[n];
154 for (
int i = 0; i < n; i++)
156 NN_chain_core<METHOD_METR_AVERAGE, t_float>(n, distmat, members, Z2);
160 generic_linkage<METHOD_METR_MEDIAN, t_float>(n, distmat, NULL, Z2);
165 int *order =
new int[n];
167 generate_R_dendrogram<true>(merge, height, order, Z2, n);
169 generate_R_dendrogram<false>(merge, height, order, Z2, n);