61 for (i = 0; i < n; ++i)
86 for (p = l.
head(); p != 0; p = p->
next())
98 for (i = 0, pi = group.
head(); pi != 0; pi = pi->
next(), ++i)
99 for (j = 0, pj = group.
head(); pj != 0; pj = pj->
next(), ++j)
100 d(group(pi), group(pj)) = 0.0;
123 for (pi = cbk.
head(); pi != 0; pi = pi->
next())
127 for (pj = cbk.
head(); pj != 0; pj = pj->
next())
131 if (pi != 0 && pj != 0) {
138 float min(
float a,
float b)
140 return (a < b) ? a: b;
143 float max(
float a,
float b)
145 return (a > b) ? a: b;
157 cout <<
"Removing row/column " << col << endl;
158 cout <<
"row " <<cbk.
nth(row) << endl;
159 cout <<
"col " <<cbk.
nth(col) << endl;
160 cbk.
nth(row) += cbk.
nth(col);
161 cout <<
"row " <<cbk.
nth(row) << endl;
165 if ((i != row) && (i != col))
169 cout <<
"row " << row <<
" col " << col <<
" left out " << v;
171 for (pi = v.head(); pi != 0; pi = pi->
next())
173 if (method ==
"nearest")
174 fm =
min(d(row,v(pi)),d(col,v(pi)));
175 else if (method ==
"furthest")
176 fm =
max(d(row,v(pi)),d(col,v(pi)));
178 fm =
min(d(row,v(pi)),d(col,v(pi)));
180 cout <<
"writing values to " << v(pi) <<
", " << row <<
" min " 186 d =
sub(d, col, col);
192 static float smallest = 0.0;
199 smallest =
lval(m, smallest, row, col);
200 cout <<
"smallest = " << smallest << endl;
201 cout <<
"row = " << row <<
" col " << col << endl;
206 cout <<
"New matrix\n" << m;
214 static float smallest = 0.0;
220 cout <<
"analysing matrix\n" << m;
221 smallest =
lval(m, smallest, row, col);
222 cout <<
"smallest = " << smallest << endl;
223 cout <<
"row = " << row <<
" col " << col << endl;
228 cout <<
"New matrix\n" << m << endl << endl;
242 for (pi = cbk.
head(); pi != 0; pi = pi->
next(), ++i)
244 for (pj = pi->
next(); pj != 0; pj = pj->
next())
246 smallest =
lowestval(m, cbk(pj), cbk(pi));
255 for (pi = cbk.
head(); pi != 0; pi = pi->
next())
259 cout <<
"Empty entry\n";
277 for (pi = cbk.
head(); pi != 0; pi = pi->
next(), ++i)
279 for (pj = pi->
next(); pj != 0; pj = pj->
next())
290 for (pi = cbk.
head(); pi != 0; pi = pi->
next())
294 cout <<
"Empty entry\n";
305 static int sorttest(
const void *a,
const void *b)
307 float *c = (
float *)a;
308 float *d = (
float *)b;
309 float res = (*c - *d);
312 return (res < 0.0) ? -1 : 1;
325 for (i = 0; i < size; ++i)
328 cout<<
"number of values in EST_FMatrix:" << n_vals <<
" size " << size << endl;
330 v =
new float[n_vals];
332 for (i = k = 0; i < m.
num_rows(); ++i)
335 cout << i <<
" " << j <<
" " << k <<
" " << (i * size) + k << endl;
339 for (i = 0; i < n_vals; ++i)
340 cout <<
"v[" << i <<
"] = " << v[i] << endl;
342 qsort(v, n_vals,
sizeof(
float), sorttest);
345 for (i = 0; i < n_vals; ++i)
358 for (pi = cbk.
head(); pi != 0; pi = pi->
next())
361 for (pj = cbk(pi).
head(); pj != 0; pj = pj->
next())
366 s += names.
nth(cbk.
item(pi).item(pj));
383 for (i = 0; i < n; ++i)
386 for (i = 0; i < n; ++i)
387 cout <<
"n: " << i <<
" " << oldcbk[i] << endl;
390 for (i = 0; i < n; ++i)
391 for (j = i + 1; j < n; ++j)
393 smallest =
lowestval(m, oldcbk[j], oldcbk[i]);
394 cout <<
"smallest = " << smallest <<
" d= " << d << endl << endl;
397 cout <<
"merging " << i <<
" " << j << endl << endl;
403 for (i = 0; i < n; ++i)
404 cout <<
"n: " << i <<
" " << oldcbk[i] << endl;
443 float lowest = 100000.0;
445 cout <<
"list a:" << a <<
"list b:" << b;
447 for (pa = a.
head(); pa != 0; pa = pa->
next())
448 for (pb = b.head(); pb != 0; pb = pb->
next())
451 if (m(a(pa), b(pb)) < lowest)
452 lowest = m(a(pa), b(pb));
467 if ((a(i, j) < lowest) && (a(i, j) > floor))
481 cout <<
"list a:" << a <<
"list b:" << b;
483 for (pa = a.
head(); pa != 0; pa = pa->
next())
484 for (pb = b.head(); pb != 0; pb = pb->
next())
486 if (m(a(pa), b(pb)) > h)
513 for (p = cbk[j].head(); p != 0; p = p->
next())
514 cbk[i].
append(cbk[j].item(p));
525 if (!inf) cerr <<
"Can't open names file " << file << endl;
527 while(inf.getline(inbuf, 1000))
int nn_cluster2(EST_FMatrix &m, EST_CBK &cbk, float d)
EST_Litem * remove_nth(int n)
remove nth item, return pointer to previous item
float highestval(EST_FMatrix &m, EST_TList< int > &a, EST_TList< int > &b)
void qsort(EST_TList< T > &a)
void merge(EST_TList< int > cbk[], int i, int j)
void init_cluster(EST_CBK &cbk, int n)
EST_FMatrix row(const EST_FMatrix &a, ssize_t row)
ssize_t num_columns() const
return number of columns
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
LISP append(LISP l1, LISP l2)
EST_String itoString(int n)
Make a EST_String object from an integer.
ssize_t num_rows() const
return number of rows
T & nth(int n)
return the Nth value
float lval(EST_FMatrix &a, float floor, int &row, int &col)
EST_String ftoString(float n, int pres=3, int width=0, int l=0)
Make a EST_String object from an float, with variable precision.
int contains(EST_TList< int > &l, int n)
float max(float a, float b)
int load_names(EST_String file, EST_TList< EST_String > &names)
float lowestval(EST_FMatrix &m, EST_TList< int > &a, EST_TList< int > &b)
int cluster(EST_FMatrix &m, EST_CBK &cbk, EST_TList< EST_String > &ans, EST_String method, EST_TList< EST_String > &names)
EST_FMatrix sub(const EST_FMatrix &a, ssize_t row, ssize_t col)
float min(float a, float b)
int fn_cluster(EST_FMatrix &m, EST_CBK &cbk, float d)
float nn_cluster3(EST_FMatrix &m, EST_CBK &cbk, EST_String method)
void append(const T &item)
add item onto end of list
void cluster3(EST_FMatrix &m, float d)
EST_String print_codebook(EST_CBK &cbk, float d, EST_TList< EST_String > &names)
void collapse3(EST_FMatrix &d, EST_CBK &cbk, int row, int col, EST_String method)
T & item(const EST_Litem *p)
void remove_distances(EST_FMatrix &d, EST_TList< int > &group)
int nn_cluster(EST_FMatrix &m, EST_CBK &cbk, float d)
EST_FVector sort_matrix(EST_FMatrix &m)
void clear(void)
remove all items in list
EST_Litem * remove(EST_Litem *ptr)
Utility EST_String Functions header file.
void collapse(EST_FMatrix &d, EST_CBK &cbk, int row, int col)