| 318 | **********************************************************************/ |
| 319 | |
| 320 | inT32 STATS::cluster(float lower, // thresholds |
| 321 | float upper, |
| 322 | float multiple, // distance threshold |
| 323 | inT32 max_clusters, // max no to make |
| 324 | STATS *clusters) { // array of clusters |
| 325 | BOOL8 new_cluster; // added one |
| 326 | float *centres; // cluster centres |
| 327 | inT32 entry; // bucket index |
| 328 | inT32 cluster; // cluster index |
| 329 | inT32 best_cluster; // one to assign to |
| 330 | inT32 new_centre = 0; // residual mode |
| 331 | inT32 new_mode; // pile count of new_centre |
| 332 | inT32 count; // pile to place |
| 333 | float dist; // from cluster |
| 334 | float min_dist; // from best_cluster |
| 335 | inT32 cluster_count; // no of clusters |
| 336 | |
| 337 | if (buckets_ == NULL || max_clusters < 1) |
| 338 | return 0; |
| 339 | centres = new float[max_clusters + 1]; |
| 340 | for (cluster_count = 1; cluster_count <= max_clusters |
| 341 | && clusters[cluster_count].buckets_ != NULL |
| 342 | && clusters[cluster_count].total_count_ > 0; |
| 343 | cluster_count++) { |
| 344 | centres[cluster_count] = |
| 345 | static_cast<float>(clusters[cluster_count].ile(0.5)); |
| 346 | new_centre = clusters[cluster_count].mode(); |
| 347 | for (entry = new_centre - 1; centres[cluster_count] - entry < lower |
| 348 | && entry >= rangemin_ |
| 349 | && pile_count(entry) <= pile_count(entry + 1); |
| 350 | entry--) { |
| 351 | count = pile_count(entry) - clusters[0].pile_count(entry); |
| 352 | if (count > 0) { |
| 353 | clusters[cluster_count].add(entry, count); |
| 354 | clusters[0].add (entry, count); |
| 355 | } |
| 356 | } |
| 357 | for (entry = new_centre + 1; entry - centres[cluster_count] < lower |
| 358 | && entry < rangemax_ |
| 359 | && pile_count(entry) <= pile_count(entry - 1); |
| 360 | entry++) { |
| 361 | count = pile_count(entry) - clusters[0].pile_count(entry); |
| 362 | if (count > 0) { |
| 363 | clusters[cluster_count].add(entry, count); |
| 364 | clusters[0].add(entry, count); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | cluster_count--; |
| 369 | |
| 370 | if (cluster_count == 0) { |
| 371 | clusters[0].set_range(rangemin_, rangemax_); |
| 372 | } |
| 373 | do { |
| 374 | new_cluster = FALSE; |
| 375 | new_mode = 0; |
| 376 | for (entry = 0; entry < rangemax_ - rangemin_; entry++) { |
| 377 | count = buckets_[entry] - clusters[0].buckets_[entry]; |
no test coverage detected