4 std::vector<DiagramType> &intermediateDiagrams,
6 std::vector<std::vector<std::vector<MatchingType>>> &all_matchings) {
29 for(
size_t j = 0; j < CTDiagram.size(); ++j) {
40 data_max[i].push_back(t);
41 data_max_idx[i].push_back(j);
46 data_max[i].push_back(t);
47 data_max_idx[i].push_back(j);
52 data_min[i].push_back(t);
53 data_min_idx[i].push_back(j);
60 data_sad[i].push_back(t);
61 data_sad_idx[i].push_back(j);
73 std::vector<std::vector<MatchingType>> matching_min, matching_sad,
76 double total_cost = 0, min_cost = 0, sad_cost = 0, max_cost = 0;
87 printMsg(
"Computing Minima barycenter...");
92 bary_min.setDiagramType(0);
94 bary_min.setGeometricalFactor(
alpha_);
103 bary_min.setDiagrams(&data_min);
105 matching_min = bary_min.execute(barycenter_min);
106 min_cost = bary_min.getCost();
107 total_cost += min_cost;
116 printMsg(
"Computing Saddles barycenter...");
121 bary_sad.setDiagramType(1);
123 bary_sad.setGeometricalFactor(
alpha_);
132 bary_sad.setDiagrams(&data_sad);
134 matching_sad = bary_sad.execute(barycenter_sad);
135 sad_cost = bary_sad.getCost();
136 total_cost += sad_cost;
145 printMsg(
"Computing Maxima barycenter...");
150 bary_max.setDiagramType(2);
152 bary_max.setGeometricalFactor(
alpha_);
161 bary_max.setDiagrams(&data_max);
163 matching_max = bary_max.execute(barycenter_max);
164 max_cost = bary_max.getCost();
165 total_cost += max_cost;
171 all_matchings.resize(1);
176 for(
size_t j = 0; j < matching_min[i].size(); j++) {
178 int const bidder_id = std::get<0>(t);
179 std::get<0>(t) = data_min_idx[i][bidder_id];
180 if(std::get<1>(t) < 0) {
183 all_matchings[0][i].push_back(t);
188 for(
size_t j = 0; j < matching_sad[i].size(); j++) {
190 int const bidder_id = std::get<0>(t);
191 std::get<0>(t) = data_sad_idx[i][bidder_id];
192 if(std::get<1>(t) >= 0) {
193 std::get<1>(t) = std::get<1>(t) + barycenter_min.size();
197 all_matchings[0][i].push_back(t);
202 for(
size_t j = 0; j < matching_max[i].size(); j++) {
204 int const bidder_id = std::get<0>(t);
205 std::get<0>(t) = data_max_idx[i][bidder_id];
206 if(std::get<1>(t) >= 0) {
208 = std::get<1>(t) + barycenter_min.size() + barycenter_sad.size();
212 all_matchings[0][i].push_back(t);
217 for(
size_t j = 0; j < barycenter_min.size(); j++) {
218 const auto &dt = barycenter_min[j];
219 barycenter.push_back(dt);
221 for(
size_t j = 0; j < barycenter_sad.size(); j++) {
222 const auto &dt = barycenter_sad[j];
223 barycenter.push_back(dt);
225 for(
size_t j = 0; j < barycenter_max.size(); j++) {
226 const auto &dt = barycenter_max[j];
227 barycenter.push_back(dt);
231 std::vector<int> number_of_matchings_for_point(barycenter.size());
232 std::vector<float> cords_x1(barycenter.size());
233 std::vector<float> cords_y1(barycenter.size());
234 std::vector<float> cords_z1(barycenter.size());
235 std::vector<float> cords_x2(barycenter.size());
236 std::vector<float> cords_y2(barycenter.size());
237 std::vector<float> cords_z2(barycenter.size());
238 for(
unsigned i = 0; i < barycenter.size(); i++) {
239 number_of_matchings_for_point[i] = 0;
248 for(
unsigned i = 0; i < all_matchings[0].size(); i++) {
250 for(
unsigned j = 0; j < all_matchings[0][i].size(); j++) {
252 int const bidder_id = std::get<0>(t);
253 int const bary_id = std::get<1>(t);
255 const auto &bidder = CTDiagram[bidder_id];
256 number_of_matchings_for_point[bary_id] += 1;
257 cords_x1[bary_id] += bidder.birth.coords[0];
258 cords_y1[bary_id] += bidder.birth.coords[1];
259 cords_z1[bary_id] += bidder.birth.coords[2];
260 cords_x2[bary_id] += bidder.death.coords[0];
261 cords_y2[bary_id] += bidder.death.coords[1];
262 cords_z2[bary_id] += bidder.death.coords[2];
266 for(
unsigned i = 0; i < barycenter.size(); i++) {
267 if(number_of_matchings_for_point[i] > 0) {
268 barycenter[i].birth.coords[0]
269 = cords_x1[i] / number_of_matchings_for_point[i];
270 barycenter[i].birth.coords[1]
271 = cords_y1[i] / number_of_matchings_for_point[i];
272 barycenter[i].birth.coords[2]
273 = cords_z1[i] / number_of_matchings_for_point[i];
274 barycenter[i].death.coords[0]
275 = cords_x2[i] / number_of_matchings_for_point[i];
276 barycenter[i].death.coords[1]
277 = cords_y2[i] / number_of_matchings_for_point[i];
278 barycenter[i].death.coords[2]
279 = cords_z2[i] / number_of_matchings_for_point[i];
283 printMsg(
"Min-saddle cost : " + std::to_string(min_cost));
284 printMsg(
"Saddle-saddle cost : " + std::to_string(sad_cost));
285 printMsg(
"Saddle-max cost : " + std::to_string(max_cost));
286 printMsg(
"Total cost : " + std::to_string(total_cost));