Go to the source code of this file.
|
void | cutree_k (int n, const int *merge, int nclust, int *labels) |
|
void | cutree_cdist (int n, const int *merge, double *height, double cdist, int *labels) |
|
int | hclust_fast (int n, double *distmat, int method, int *merge, double *height) |
|
◆ hclust_fast_methods
Enumerator |
---|
HCLUST_METHOD_SINGLE | |
HCLUST_METHOD_COMPLETE | |
HCLUST_METHOD_AVERAGE | |
HCLUST_METHOD_MEDIAN | |
HCLUST_METHOD_SVF_BEST | |
Definition at line 65 of file fastcluster.h.
◆ cutree_cdist()
void cutree_cdist |
( |
int |
n, |
|
|
const int * |
merge, |
|
|
double * |
height, |
|
|
double |
cdist, |
|
|
int * |
labels |
|
) |
| |
Definition at line 116 of file fastcluster.cpp.
117{
118
119 int k;
120
121 for (k=0; k<(
n-1); k++)
122 {
123 if (height[k] >= cdist)
124 {
125 break;
126 }
127 }
129}
void cutree_k(int n, const int *merge, int nclust, int *labels)
◆ cutree_k()
void cutree_k |
( |
int |
n, |
|
|
const int * |
merge, |
|
|
int |
nclust, |
|
|
int * |
labels |
|
) |
| |
Definition at line 37 of file fastcluster.cpp.
38{
39
40 int k,m1,m2,j,l;
41
42 if (nclust >
n || nclust < 2)
43 {
44 for (j=0; j<
n; j++) labels[j] = 0;
45 return;
46 }
47
48
49
50 std::vector<int> last_merge(
n, 0);
51 for (k=1; k<=(
n-nclust); k++)
52 {
53
54 m1 = merge[k-1];
56 if (m1 < 0 && m2 < 0)
57 {
58 last_merge[-m1-1] = last_merge[-m2-1] = k;
59 }
60 else if (m1 < 0 || m2 < 0)
61 {
62 if(m1 < 0)
63 {
64 j = -m1;
65 m1 = m2;
66 }
67 else j = -m2;
68
69 for(l = 0; l <
n; l++)
70 if (last_merge[l] == m1)
71 last_merge[l] = k;
72 last_merge[j-1] = k;
73 }
74 else
75 {
77 {
78 if( last_merge[l] == m1 || last_merge[l] == m2 )
79 last_merge[l] = k;
80 }
81 }
82 }
83
84
85 int label = 0;
86 std::vector<int> z(
n,-1);
88 {
89 if (last_merge[j] == 0)
90 {
91 labels[j] = label++;
92 }
93 else
94 {
95 if (z[last_merge[j]] < 0)
96 {
97 z[last_merge[j]] = label++;
98 }
99 labels[j] = z[last_merge[j]];
100 }
101 }
102}
◆ hclust_fast()
int hclust_fast |
( |
int |
n, |
|
|
double * |
distmat, |
|
|
int |
method, |
|
|
int * |
merge, |
|
|
double * |
height |
|
) |
| |
Definition at line 156 of file fastcluster.cpp.
157{
158
159
160 cluster_result Z2(
n-1);
162 {
163
164 MST_linkage_core(
n, distmat, Z2);
165 }
167 {
168
169 NN_chain_core<METHOD_METR_COMPLETE, t_float>(
n, distmat,
NULL, Z2);
170 }
172 {
173
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);
177 delete[] members;
178 }
180 {
181
182 generic_linkage<METHOD_METR_MEDIAN, t_float>(
n, distmat,
NULL, Z2);
183 }
184 else
185 {
186 return 1;
187 }
188
189 int* order =
new int[
n];
191 {
192 generate_R_dendrogram<true>(merge, height, order, Z2,
n);
193 }
194 else
195 {
196 generate_R_dendrogram<false>(merge, height, order, Z2,
n);
197 }
198
199 delete[] order;
200
201 return 0;
202}