| 30 | }; |
| 31 | |
| 32 | std::vector<assignment> angular_cluster ( |
| 33 | std::vector<matrix<double,0,1> > feats, |
| 34 | const unsigned long num_clusters |
| 35 | ) |
| 36 | { |
| 37 | DLIB_CASSERT(feats.size() != 0, "The dataset can't be empty"); |
| 38 | for (unsigned long i = 0; i < feats.size(); ++i) |
| 39 | { |
| 40 | DLIB_CASSERT(feats[i].size() == feats[0].size(), "All feature vectors must have the same length."); |
| 41 | } |
| 42 | |
| 43 | // find the centroid of feats |
| 44 | const matrix<double,0,1> m = mean(mat(feats)); |
| 45 | |
| 46 | // Now center feats and then project onto the unit sphere. The reason for projecting |
| 47 | // onto the unit sphere is so pick_initial_centers() works in a sensible way. |
| 48 | for (auto& f : feats) |
| 49 | { |
| 50 | f = normalize(f-m); |
| 51 | } |
| 52 | |
| 53 | // now do angular clustering of the points |
| 54 | std::vector<matrix<double,0,1> > centers; |
| 55 | pick_initial_centers(num_clusters, centers, feats, linear_kernel<matrix<double,0,1> >(), 0.05); |
| 56 | find_clusters_using_angular_kmeans(feats, centers); |
| 57 | |
| 58 | // and then report the resulting assignments |
| 59 | std::vector<assignment> assignments; |
| 60 | for (unsigned long i = 0; i < feats.size(); ++i) |
| 61 | { |
| 62 | assignment temp; |
| 63 | temp.c = nearest_center(centers, feats[i]); |
| 64 | temp.dist = length(feats[i] - centers[temp.c]); |
| 65 | temp.idx = i; |
| 66 | assignments.push_back(temp); |
| 67 | } |
| 68 | return assignments; |
| 69 | } |
| 70 | std::vector<assignment> chinese_cluster ( |
| 71 | std::vector<matrix<double,0,1> > feats, |
| 72 | unsigned long &num_clusters |
no test coverage detected