4 std::vector<DiagramType> &intermediateDiagrams,
5 std::vector<DiagramType> &final_centroids,
6 std::vector<std::vector<std::vector<MatchingType>>> &all_matchings) {
8 const int numberOfInputs_ = intermediateDiagrams.size();
11 printMsg(
"Clustering " + std::to_string(numberOfInputs_) +
" diagrams in "
14 std::vector<DiagramType> data_min(numberOfInputs_);
15 std::vector<DiagramType> data_sad(numberOfInputs_);
16 std::vector<DiagramType> data_max(numberOfInputs_);
18 std::vector<std::vector<int>> data_min_idx(numberOfInputs_);
19 std::vector<std::vector<int>> data_sad_idx(numberOfInputs_);
20 std::vector<std::vector<int>> data_max_idx(numberOfInputs_);
22 std::vector<int> inv_clustering(numberOfInputs_);
29 for(
int i = 0; i < numberOfInputs_; i++) {
32 for(
size_t j = 0; j < CTDiagram.size(); ++j) {
33 auto &t = CTDiagram[j];
38 double const dt = t.persistence();
44 data_max[i].push_back(t);
45 data_max_idx[i].push_back(j);
48 data_min[i].push_back(t);
49 data_min_idx[i].push_back(j);
55 data_max[i].push_back(t);
56 data_max_idx[i].push_back(j);
61 data_min[i].push_back(t);
62 data_min_idx[i].push_back(j);
69 data_sad[i].push_back(t);
70 data_sad_idx[i].push_back(j);
78 std::stringstream msg;
81 msg <<
"Only MIN-SAD Pairs";
86 msg <<
"Only SAD-SAD Pairs";
91 msg <<
"Only SAD-MAX Pairs";
96 msg <<
"All critical pairs: "
102 std::vector<std::vector<std::vector<std::vector<MatchingType>>>>
103 all_matchings_per_type_and_cluster;
109 KMeans.setUseKDTree(
true);
111 KMeans.setGeometricalFactor(
Alpha);
121 KMeans.setDiagrams(&data_min, &data_sad, &data_max);
122 KMeans.setDos(do_min, do_sad, do_max);
125 = KMeans.execute(final_centroids, all_matchings_per_type_and_cluster);
126 std::vector<std::vector<int>> centroids_sizes = KMeans.get_centroids_sizes();
132 std::vector<int> cluster_size;
133 std::vector<int> idxInCluster(numberOfInputs_);
135 for(
int j = 0; j < numberOfInputs_; ++j) {
136 size_t const c = inv_clustering[j];
137 if(c + 1 > cluster_size.size()) {
138 cluster_size.resize(c + 1);
143 idxInCluster[j] = cluster_size[c] - 1;
147 bool removeDuplicateGlobalPair =
false;
149 removeDuplicateGlobalPair =
true;
154 all_matchings[c].resize(numberOfInputs_);
155 if(removeDuplicateGlobalPair) {
156 centroids_sizes[c][0] -= 1;
159 for(
int i = 0; i < numberOfInputs_; i++) {
160 size_t const c = inv_clustering[i];
164 j < all_matchings_per_type_and_cluster[c][0][idxInCluster[i]].size();
167 = all_matchings_per_type_and_cluster[c][0][idxInCluster[i]][j];
168 int const bidder_id = std::get<0>(t);
169 if(bidder_id < (
int)data_min[i].size()) {
173 std::get<0>(t) = data_min_idx[i][bidder_id];
176 if(std::get<1>(t) < 0) {
179 all_matchings[inv_clustering[i]][i].push_back(t);
186 j < all_matchings_per_type_and_cluster[c][1][idxInCluster[i]].size();
189 = all_matchings_per_type_and_cluster[c][1][idxInCluster[i]][j];
190 int const bidder_id = std::get<0>(t);
191 if(bidder_id < (
int)data_sad[i].size()) {
195 std::get<0>(t) = data_sad_idx[i][bidder_id];
197 if(std::get<1>(t) >= 0) {
198 std::get<1>(t) = std::get<1>(t) + centroids_sizes[c][0];
202 all_matchings[inv_clustering[i]][i].push_back(t);
209 j < all_matchings_per_type_and_cluster[c][2][idxInCluster[i]].size();
212 = all_matchings_per_type_and_cluster[c][2][idxInCluster[i]][j];
213 int const bidder_id = std::get<0>(t);
214 if(bidder_id < (
int)data_max[i].size()) {
218 std::get<0>(t) = data_max_idx[i][bidder_id];
221 if(std::get<1>(t) > 0) {
223 = std::get<1>(t) + centroids_sizes[c][0] + centroids_sizes[c][1];
224 }
else if(std::get<1>(t) == 0) {
225 if(!removeDuplicateGlobalPair) {
226 std::get<1>(t) = std::get<1>(t) + centroids_sizes[c][0]
227 + centroids_sizes[c][1];
232 all_matchings[inv_clustering[i]][i].push_back(t);
239 return inv_clustering;