void cluster(point ps[], int n, int k, int cs[]) { ld **distances; // all the edge weights void *clusters[n]; // array of pointers to clusters. // note that the indexes of the array are // the same as the indexes of the points int point1, point2; // temporary variables that should store // the next pair of closest points // allocate memory for the arrays distances = (ld **) smalloc(sizeof(ld *) * n); // pre-calculate all the edge weights (distances // between every point and every other point) get_distances(distances, ps, n); // initialize each cluster to have just 1 point for(int i = 0; i < n; i++) { clusters[i] = create_cluster(i); } // keep merging clusters until we're down to k clusters for(int num_clusters = n; num_clusters > k; num_clusters--) { // find the 2 closest clusters that aren't connected next_shortest_edge(&point1, &point2, distances, n, clusters); // merge them merge_clusters(clusters[point1], clusters[point2]); } // convert the crazy cluster numbers to normal ones normalize_clusters(cs, n, clusters); }
void hb_buffer_t::delete_glyph () { unsigned int cluster = info[idx].cluster; if (idx + 1 < len && cluster == info[idx + 1].cluster) { /* Cluster survives; do nothing. */ goto done; } if (out_len) { /* Merge cluster backward. */ if (cluster < out_info[out_len - 1].cluster) { unsigned int old_cluster = out_info[out_len - 1].cluster; for (unsigned i = out_len; i && out_info[i - 1].cluster == old_cluster; i--) out_info[i - 1].cluster = cluster; } goto done; } if (idx + 1 < len) { /* Merge cluster forward. */ merge_clusters (idx, idx + 2); goto done; } done: skip_glyph (); }
void Main::check_results() { // Function that checks how many cluster canidates // have been detected. if (clusters.size() > 0) merge_clusters(); else std::cout<<"No clusters deteced in sample!"<<std::endl; }
void merge(cluster* clusters, sim_metric* dist, int* mask, const unsigned int nel, const unsigned int c1, const unsigned int c2) { #pragma omp parallel num_threads(omp_get_num_procs()) { #pragma omp single nowait { merge_clusters(clusters, c1, c2); } merge_dist(dist, mask, nel, c1, c2); } // disattiva c2 sulla maschera *mask = *mask & ~(0x01 << c2); }
// virtual function derived from class DBSCAN void DBSCAN_Grid::fit(){ prepare_labels(cl_d.size1()); float begin; begin = get_clock(); hash_construct_grid(); cout<<get_clock() - begin<<endl; begin = get_clock(); determine_core_point_grid(); cout<<get_clock() - begin<<endl; begin = get_clock(); merge_clusters(); cout<<get_clock() - begin<<endl; determine_boarder_point(); }
void cluster_builder::calc(const std::vector<cv::Point2f> &pts0, std::vector<std::vector<cv::Point2f> > &result) { std::vector<cv::Point2f> pts = pts0; std::vector<Cluster> clusters; double threshold = threshold_; while (!pts.empty()) { once(pts, clusters, threshold); threshold /= 2; // 增加创建新的 cluster 的机会 .... } merge_clusters(clusters); // 合并 .. for (std::vector<Cluster>::const_iterator it = clusters.begin(); it != clusters.end(); ++it) { result.push_back(it->pts); } }
void hb_buffer_t::sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *)) { assert (!have_positions); for (unsigned int i = start + 1; i < end; i++) { unsigned int j = i; while (j > start && compar (&info[j - 1], &info[i]) > 0) j--; if (i == j) continue; /* Move item i to occupy place for item j, shift what's in between. */ merge_clusters (j, i + 1); { hb_glyph_info_t t = info[i]; memmove (&info[j + 1], &info[j], (i - j) * sizeof (hb_glyph_info_t)); info[j] = t; } } }
void hb_buffer_t::replace_glyphs (unsigned int num_in, unsigned int num_out, const uint32_t *glyph_data) { if (unlikely (!make_room_for (num_in, num_out))) return; merge_clusters (idx, idx + num_in); hb_glyph_info_t orig_info = info[idx]; hb_glyph_info_t *pinfo = &out_info[out_len]; for (unsigned int i = 0; i < num_out; i++) { *pinfo = orig_info; pinfo->codepoint = glyph_data[i]; pinfo++; } idx += num_in; out_len += num_out; }