37void cutree_k(
int n,
const int* merge,
int nclust,
int* labels)
42 if (nclust >
n || nclust < 2)
44 for (j=0; j<
n; j++) labels[j] = 0;
50 std::vector<int> last_merge(
n, 0);
51 for (k=1; k<=(
n-nclust); k++)
58 last_merge[-m1-1] = last_merge[-m2-1] = k;
60 else if (m1 < 0 || m2 < 0)
69 for(l = 0; l <
n; l++)
70 if (last_merge[l] == m1)
78 if( last_merge[l] == m1 || last_merge[l] == m2 )
86 std::vector<int> z(
n,-1);
89 if (last_merge[j] == 0)
95 if (z[last_merge[j]] < 0)
97 z[last_merge[j]] = label++;
99 labels[j] = z[last_merge[j]];
156int hclust_fast(
int n,
double* distmat,
int method,
int* merge,
double* height)
160 cluster_result Z2(
n-1);
164 MST_linkage_core(
n, distmat, Z2);
169 NN_chain_core<METHOD_METR_COMPLETE, t_float>(
n, distmat,
NULL, Z2);
174 double* members =
new double[
n];
175 for (
int i=0; i<
n; i++) members[i] = 1;
176 NN_chain_core<METHOD_METR_AVERAGE, t_float>(
n, distmat, members, Z2);
182 generic_linkage<METHOD_METR_MEDIAN, t_float>(
n, distmat,
NULL, Z2);
189 int* order =
new int[
n];
192 generate_R_dendrogram<true>(merge, height, order, Z2,
n);
196 generate_R_dendrogram<false>(merge, height, order, Z2,
n);