Static Value-Flow Analysis
Loading...
Searching...
No Matches
Enumerations | Functions
fastcluster.h File Reference

Go to the source code of this file.

Enumerations

enum  hclust_fast_methods {
  HCLUST_METHOD_SINGLE = 0 , HCLUST_METHOD_COMPLETE = 1 , HCLUST_METHOD_AVERAGE = 2 , HCLUST_METHOD_MEDIAN = 3 ,
  HCLUST_METHOD_SVF_BEST = 4
}
 

Functions

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)
 

Enumeration Type Documentation

◆ 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.

66{
67 // single link with the minimum spanning tree algorithm (Rohlf, 1973)
69 // complete link with the nearest-neighbor-chain algorithm (Murtagh, 1984)
71 // complete link with the nearest-neighbor-chain algorithm (Murtagh, 1984)
73 // median link with the generic algorithm (Müllner, 2011)
75 // To indicate to try all methods and pick the best.
77};
@ HCLUST_METHOD_AVERAGE
Definition fastcluster.h:72
@ HCLUST_METHOD_COMPLETE
Definition fastcluster.h:70
@ HCLUST_METHOD_SVF_BEST
Definition fastcluster.h:76
@ HCLUST_METHOD_MEDIAN
Definition fastcluster.h:74
@ HCLUST_METHOD_SINGLE
Definition fastcluster.h:68

Function Documentation

◆ 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 }
128 cutree_k(n, merge, n-k, labels);
129}
cJSON * n
Definition cJSON.cpp:2558
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 // assign to each observable the number of its last merge step
49 // beware: indices of observables in merge start at 1 (R convention)
50 std::vector<int> last_merge(n, 0);
51 for (k=1; k<=(n-nclust); k++)
52 {
53 // (m1,m2) = merge[k,]
54 m1 = merge[k-1];
55 m2 = merge[n-1+k-1];
56 if (m1 < 0 && m2 < 0) // both single observables
57 {
58 last_merge[-m1-1] = last_merge[-m2-1] = k;
59 }
60 else if (m1 < 0 || m2 < 0) // one is a cluster
61 {
62 if(m1 < 0)
63 {
64 j = -m1;
65 m1 = m2;
66 }
67 else j = -m2;
68 // merging single observable and cluster
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 // both cluster
75 {
76 for(l=0; l < n; l++)
77 {
78 if( last_merge[l] == m1 || last_merge[l] == m2 )
79 last_merge[l] = k;
80 }
81 }
82 }
83
84 // assign cluster labels
85 int label = 0;
86 std::vector<int> z(n,-1);
87 for (j=0; j<n; j++)
88 {
89 if (last_merge[j] == 0) // still singleton
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 // call appropriate clustering function
160 cluster_result Z2(n-1);
161 if (method == HCLUST_METHOD_SINGLE)
162 {
163 // single link
164 MST_linkage_core(n, distmat, Z2);
165 }
166 else if (method == HCLUST_METHOD_COMPLETE)
167 {
168 // complete link
169 NN_chain_core<METHOD_METR_COMPLETE, t_float>(n, distmat, NULL, Z2);
170 }
171 else if (method == HCLUST_METHOD_AVERAGE)
172 {
173 // best average distance
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 }
179 else if (method == HCLUST_METHOD_MEDIAN)
180 {
181 // best median distance (beware: O(n^3))
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];
190 if (method == HCLUST_METHOD_MEDIAN)
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; // only needed for visualization
200
201 return 0;
202}
#define NULL
Definition extapi.c:2