From 1e6ac8d38d00862a8ff8697c787de02beb6f8fe4 Mon Sep 17 00:00:00 2001 From: Keanu Sisouk Date: Thu, 21 Sep 2023 16:09:40 +0200 Subject: [PATCH] Resolving conflict in PersistenceDiagramClustering --- .../PDBarycenter.cpp | 95 +++--- .../PDClustering.cpp | 295 +++++++++--------- .../PersistenceDiagramBarycenter.cpp | 18 +- .../PersistenceDiagramClustering.cpp | 16 +- 4 files changed, 214 insertions(+), 210 deletions(-) diff --git a/core/base/persistenceDiagramClustering/PDBarycenter.cpp b/core/base/persistenceDiagramClustering/PDBarycenter.cpp index 674effdbb6..7e024c4d7f 100644 --- a/core/base/persistenceDiagramClustering/PDBarycenter.cpp +++ b/core/base/persistenceDiagramClustering/PDBarycenter.cpp @@ -34,14 +34,14 @@ void ttk::PDBarycenter::runMatching( std::vector> *all_matchings, bool use_kdt, bool actual_distance) { - Timer time_matchings; + Timer const time_matchings; double local_cost = *total_cost; #ifdef TTK_ENABLE_OPENMP #pragma omp parallel for num_threads(threadNumber_) schedule(dynamic, 1) reduction(+:local_cost) #endif for(int i = 0; i < numberOfInputs_; i++) { - double delta_lim = 0.01; + double const delta_lim = 0.01; PersistenceDiagramAuction auction( current_bidder_diagrams_[i], barycenter_goods_[i], wasserstein_, geometrical_factor_, lambda_, delta_lim, kdt, correspondence_kdt_map, @@ -56,7 +56,7 @@ void ttk::PDBarycenter::runMatching( min_diag_price->at(i) = auction.getMinimalDiagonalPrice(); min_price->at(i) = getMinimalPrice(i); std::vector matchings; - double cost = auction.getMatchingsAndDistance(matchings, true); + double const cost = auction.getMatchingsAndDistance(matchings, true); all_matchings->at(i) = matchings; if(actual_distance) { local_cost += sqrt(cost); @@ -64,7 +64,8 @@ void ttk::PDBarycenter::runMatching( local_cost += cost; } - double quotient = epsilon * auction.getAugmentedNumberOfBidders() / cost; + double const quotient + = epsilon * auction.getAugmentedNumberOfBidders() / cost; precision_[i] = quotient < 1 ? 1. / sqrt(1 - quotient) - 1 : 10; if(auction.getRelativePrecision() == 0) precision_[i] = 0; @@ -95,7 +96,7 @@ void ttk::PDBarycenter::runMatchingAuction( geometrical_factor_, lambda_, 0.01, kdt, correspondence_kdt_map, 0, (*min_diag_price)[i], use_kdt); std::vector matchings; - double cost = auction.run(matchings, i); + double const cost = auction.run(matchings, i); all_matchings->at(i) = matchings; if(actual_distance) { local_cost += sqrt(cost); @@ -140,7 +141,7 @@ std::vector> ttk::PDBarycenter::correctMatchings( // 1. Invert the current_bidder_ids_ vector std::vector new_to_old_id(current_bidder_diagrams_[i].size()); for(size_t j = 0; j < current_bidder_ids_[i].size(); j++) { - int new_id = current_bidder_ids_[i][j]; + int const new_id = current_bidder_ids_[i][j]; if(new_id >= 0) { new_to_old_id[new_id] = j; } @@ -149,7 +150,7 @@ std::vector> ttk::PDBarycenter::correctMatchings( std::vector matchings_diagram_i; for(size_t j = 0; j < previous_matchings[i].size(); j++) { MatchingType m = previous_matchings[i][j]; - int new_id = std::get<0>(m); + int const new_id = std::get<0>(m); if(new_id >= 0 && std::get<1>(m) >= 0) { std::get<0>(m) = new_to_old_id[new_id]; matchings_diagram_i.push_back(m); @@ -163,10 +164,10 @@ std::vector> ttk::PDBarycenter::correctMatchings( double ttk::PDBarycenter::updateBarycenter( std::vector> &matchings) { // 1. Initialize variables used in the sequel - Timer t_update; - size_t n_goods = barycenter_goods_[0].size(); + Timer const t_update; + size_t const n_goods = barycenter_goods_[0].size(); - size_t n_diagrams = current_bidder_diagrams_.size(); + size_t const n_diagrams = current_bidder_diagrams_.size(); points_added_ = 0; points_deleted_ = 0; double max_shift = 0; @@ -203,8 +204,8 @@ double ttk::PDBarycenter::updateBarycenter( for(size_t j = 0; j < matchings.size(); j++) { double weight = useCustomWeights_ ? (*customWeights_)[j] : 0.0; for(size_t i = 0; i < matchings[j].size(); i++) { - int bidder_id = std::get<0>(matchings[j][i]); - int good_id = std::get<1>(matchings[j][i]); + int const bidder_id = std::get<0>(matchings[j][i]); + int const good_id = std::get<1>(matchings[j][i]); if(good_id < 0 && bidder_id >= 0) { // Future new barycenter point points_to_append.emplace_back( @@ -282,19 +283,19 @@ double ttk::PDBarycenter::updateBarycenter( } // TODO Weight by persistence - double new_crit_coord_x + double const new_crit_coord_x = crit_coords_x[i] / (double)(n_diagrams - count_diag_matchings[i]); - double new_crit_coord_y + double const new_crit_coord_y = crit_coords_y[i] / (double)(n_diagrams - count_diag_matchings[i]); - double new_crit_coord_z + double const new_crit_coord_z = crit_coords_z[i] / (double)(n_diagrams - count_diag_matchings[i]); // 3.3 Compute and store how much the point has shifted // TODO adjust shift with geometrical_factor_ - double dx = barycenter_goods_[0].at(i).x_ - new_x; - double dy = barycenter_goods_[0].at(i).y_ - new_y; - double shift = Geometry::pow(std::abs(dx), wasserstein_) - + Geometry::pow(std::abs(dy), wasserstein_); + double const dx = barycenter_goods_[0].at(i).x_ - new_x; + double const dy = barycenter_goods_[0].at(i).y_ - new_y; + double const shift = Geometry::pow(std::abs(dx), wasserstein_) + + Geometry::pow(std::abs(dy), wasserstein_); if(shift > max_shift) { max_shift = shift; } @@ -323,7 +324,7 @@ double ttk::PDBarycenter::updateBarycenter( for(size_t i = 0; i < n_goods; i++) { if(count_diag_matchings[i] == n_diagrams) { points_deleted_ += 1; - double shift + double const shift = 2 * Geometry::pow( barycenter_goods_[0].at(i).getPersistence() / 2., wasserstein_); @@ -360,7 +361,7 @@ double ttk::PDBarycenter::updateBarycenter( std::get<2>(critical_coordinates)); } barycenter_goods_[j].emplace_back(g); - double shift + double const shift = 2 * Geometry::pow( barycenter_goods_[j].at(g.id_).getPersistence() / 2., wasserstein_); @@ -440,7 +441,7 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams( max_diagram_size = current_bidder_diagrams_[i].size(); } } - int max_points_to_add = std::max( + int const max_points_to_add = std::max( min_points_to_add, min_points_to_add + (int)(max_diagram_size / 10)); // 2. Get which points can be added, deduce the new minimal persistence @@ -450,8 +451,8 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams( std::vector persistences; for(size_t j = 0; j < bidder_diagrams_[i].size(); j++) { - Bidder b = bidder_diagrams_[i].at(j); - double persistence = b.getPersistence(); + Bidder const b = bidder_diagrams_[i].at(j); + double const persistence = b.getPersistence(); if(persistence >= min_persistence && persistence < previous_min_persistence) { candidates_to_be_added[i].push_back(j); @@ -463,9 +464,9 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams( return ((persistences[a] > persistences[b]) || ((persistences[a] == persistences[b]) && (a > b))); }); - int size = candidates_to_be_added[i].size(); + int const size = candidates_to_be_added[i].size(); if(size >= max_points_to_add) { - double last_persistence_added + double const last_persistence_added = persistences[idx[i][max_points_to_add - 1]]; if(last_persistence_added > new_min_persistence) { new_min_persistence = last_persistence_added; @@ -479,7 +480,7 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams( int compteur_for_adding_points = 0; for(int i = 0; i < numberOfInputs_; i++) { - int size = candidates_to_be_added[i].size(); + int const size = candidates_to_be_added[i].size(); for(int j = 0; j < std::min(max_points_to_add, size); j++) { Bidder b = bidder_diagrams_[i].at(candidates_to_be_added[i][idx[i][j]]); if(b.getPersistence() >= new_min_persistence) { @@ -491,7 +492,7 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams( current_bidder_ids_[i][candidates_to_be_added[i][idx[i][j]]] = current_bidder_diagrams_[i].size() - 1; - int to_be_added_to_barycenter + int const to_be_added_to_barycenter = deterministic_ ? compteur_for_adding_points % numberOfInputs_ : rand() % numberOfInputs_; // We add the bidder as a good with probability 1/n_diagrams @@ -516,8 +517,8 @@ double ttk::PDBarycenter::getMaxPersistence() { BidderDiagram &D = bidder_diagrams_[i]; for(size_t j = 0; j < D.size(); j++) { // Add bidder to bidders - Bidder &b = D.at(j); - double persistence = b.getPersistence(); + Bidder const &b = D.at(j); + double const persistence = b.getPersistence(); if(persistence > max_persistence) { max_persistence = persistence; } @@ -534,8 +535,8 @@ double ttk::PDBarycenter::getMinimalPrice(int i) { return 0; } for(size_t j = 0; j < D.size(); j++) { - Good &b = D.at(j); - double price = b.getPrice(); + Good const &b = D.at(j); + double const price = b.getPrice(); if(price < min_price) { min_price = price; } @@ -552,8 +553,8 @@ double ttk::PDBarycenter::getLowestPersistence() { BidderDiagram &D = bidder_diagrams_[i]; for(size_t j = 0; j < D.size(); j++) { // Add bidder to bidders - Bidder &b = D.at(j); - double persistence = b.getPersistence(); + Bidder const &b = D.at(j); + double const persistence = b.getPersistence(); if(persistence < lowest_persistence && persistence > 0) { lowest_persistence = persistence; } @@ -579,7 +580,7 @@ void ttk::PDBarycenter::setInitialBarycenter(double min_persistence) { int count = 0; for(size_t j = 0; j < CTDiagram->size(); j++) { // Add bidder to bidders - Good g = Good((*CTDiagram)[j], count, lambda_); + Good const g = Good((*CTDiagram)[j], count, lambda_); if(g.getPersistence() >= min_persistence) { goods.emplace_back(g); count++; @@ -617,7 +618,7 @@ typename ttk::PDBarycenter::KDTreePair ttk::PDBarycenter::getKDTree() const { } for(size_t idx = 0; idx < barycenter_goods_.size(); idx++) { - std::vector empty_weights; + std::vector const empty_weights; weights.push_back(empty_weights); for(size_t i = 0; i < barycenter_goods_[idx].size(); i++) { const Good &g = barycenter_goods_[idx].at(i); @@ -638,7 +639,7 @@ std::vector> ttk::PDBarycenter::executeAuctionBarycenter(DiagramType &barycenter) { std::vector> previous_matchings; - double min_persistence = 0; + double const min_persistence = 0; double min_cost = std::numeric_limits::max(); int last_min_cost_obtained = 0; @@ -646,7 +647,7 @@ std::vector> this->setInitialBarycenter( min_persistence); // false for a determinist initialization - double max_persistence = getMaxPersistence(); + double const max_persistence = getMaxPersistence(); std::vector min_diag_price(numberOfInputs_); std::vector min_price(numberOfInputs_); @@ -655,7 +656,7 @@ std::vector> min_price[i] = 0; } - int min_points_to_add = std::numeric_limits::max(); + int const min_points_to_add = std::numeric_limits::max(); this->enrichCurrentBidderDiagrams(2 * max_persistence, min_persistence, min_diag_price, min_price, min_points_to_add, false); @@ -665,7 +666,7 @@ std::vector> double total_cost; while(!finished) { - Timer tm; + Timer const tm; std::pair, std::vector> pair; bool use_kdt = false; @@ -686,13 +687,13 @@ std::vector> barycenter.clear(); for(size_t j = 0; j < barycenter_goods_[0].size(); j++) { - Good &g = barycenter_goods_[0].at(j); + Good const &g = barycenter_goods_[0].at(j); barycenter.emplace_back(PersistencePair{CriticalVertex{0, nt1_, g.x_, {}}, CriticalVertex{0, nt2_, g.y_, {}}, diagramType_, true}); } - bool actual_distance = (numberOfInputs_ == 2); + bool const actual_distance = (numberOfInputs_ == 2); runMatchingAuction(&total_cost, sizes, *pair.first, pair.second, &min_diag_price, &all_matchings, use_kdt, actual_distance); @@ -737,7 +738,7 @@ std::vector> } barycenter.resize(0); for(size_t j = 0; j < barycenter_goods_[0].size(); j++) { - Good &g = barycenter_goods_[0].at(j); + Good const &g = barycenter_goods_[0].at(j); barycenter.emplace_back(PersistencePair{CriticalVertex{0, nt1_, g.x_, {}}, CriticalVertex{0, nt2_, g.y_, {}}, diagramType_, true}); @@ -755,10 +756,10 @@ double ttk::PDBarycenter::computeRealCost() { for(int i = 0; i < numberOfInputs_; i++) { PersistenceDiagramAuction auction( wasserstein_, geometrical_factor_, lambda_, 0.01, true); - GoodDiagram current_barycenter = barycenter_goods_[0]; - BidderDiagram current_bidder_diagram = bidder_diagrams_[i]; + GoodDiagram const current_barycenter = barycenter_goods_[0]; + BidderDiagram const current_bidder_diagram = bidder_diagrams_[i]; auction.BuildAuctionDiagrams(current_bidder_diagram, current_barycenter); - double cost = auction.run(fake_matchings); + double const cost = auction.run(fake_matchings); total_real_cost += cost * cost; } return sqrt(total_real_cost); @@ -773,7 +774,7 @@ bool ttk::PDBarycenter::isPrecisionObjectiveMet(double precision_objective, } } } else if(mode == 1) { // AVERAGE PRECISION - double average_precision + double const average_precision = std::accumulate(precision_.begin(), precision_.end(), 0.0) / numberOfInputs_; if(average_precision > precision_objective) { diff --git a/core/base/persistenceDiagramClustering/PDClustering.cpp b/core/base/persistenceDiagramClustering/PDClustering.cpp index 7464af1e05..f8c8eb308d 100644 --- a/core/base/persistenceDiagramClustering/PDClustering.cpp +++ b/core/base/persistenceDiagramClustering/PDClustering.cpp @@ -34,7 +34,7 @@ std::vector ttk::PDClustering::execute( } } int matchings_only = false; - Timer tm; + Timer const tm; { // PARTICULARITIES FOR THE CASE OF ONE UNIQUE CLUSTER if(k_ <= 1) { @@ -285,7 +285,7 @@ std::vector ttk::PDClustering::execute( precision_criterion_ = precision_min_ && precision_sad_ && precision_max_; - bool precision_criterion_reached = precision_criterion_; + bool const precision_criterion_reached = precision_criterion_; this->printMsg("Iteration " + std::to_string(n_iterations_) + " epsilon " + std::to_string(epsilon_[0]) + " " @@ -375,7 +375,7 @@ std::vector ttk::PDClustering::execute( resetDosToOriginalValues(); // display results - std::vector> rows{ + std::vector> const rows{ {" Min-saddle cost", std::to_string(cost_min_)}, {" Saddle-saddle cost", std::to_string(cost_sad_)}, {" Saddle-max cost", std::to_string(cost_max_)}, @@ -419,14 +419,14 @@ std::vector ttk::PDClustering::execute( // if NumberOfClusters > 1, the global pair was duplicated // and needs to be removed from the min-saddle problem // It is the first pair. - int removeFirstPairMin + int const removeFirstPairMin = (k_ > 1 and original_dos[0] and original_dos[2]) ? 1 : 0; int addedFirstPairMax = 0; int addedFirstPairMin = removeFirstPairMin; // min-max Pair if(removeFirstPairMin or (!do_min_ and do_max_)) { - Good &g = centroids_max_[c].at(0); + Good const &g = centroids_max_[c].at(0); const auto &critCoords = g.GetCriticalCoordinates(); final_centroids[c].emplace_back(PersistencePair{ CriticalVertex{0, CriticalType::Local_minimum, g.x_, critCoords}, @@ -434,7 +434,7 @@ std::vector ttk::PDClustering::execute( false}); addedFirstPairMax = 1; } else if(do_min_) { - Good &g = centroids_min_[c].at(0); + Good const &g = centroids_min_[c].at(0); const auto &critCoords = g.GetCriticalCoordinates(); final_centroids[c].emplace_back(PersistencePair{ CriticalVertex{0, CriticalType::Local_minimum, g.x_, critCoords}, @@ -445,7 +445,7 @@ std::vector ttk::PDClustering::execute( if(do_min_) { for(size_t i = addedFirstPairMin; i < centroids_min_[c].size(); ++i) { - Good &g = centroids_min_[c].at(i); + Good const &g = centroids_min_[c].at(i); const auto &critCoords = g.GetCriticalCoordinates(); final_centroids[c].emplace_back(PersistencePair{ CriticalVertex{0, CriticalType::Local_minimum, g.x_, critCoords}, @@ -459,7 +459,7 @@ std::vector ttk::PDClustering::execute( if(do_sad_) { for(size_t i = 0; i < centroids_saddle_[c].size(); ++i) { - Good &g = centroids_saddle_[c].at(i); + Good const &g = centroids_saddle_[c].at(i); const auto &critCoords = g.GetCriticalCoordinates(); final_centroids[c].emplace_back(PersistencePair{ CriticalVertex{0, CriticalType::Saddle1, g.x_, critCoords}, @@ -473,7 +473,7 @@ std::vector ttk::PDClustering::execute( if(do_max_) { for(size_t i = addedFirstPairMax; i < centroids_max_[c].size(); ++i) { - Good &g = centroids_max_[c].at(i); + Good const &g = centroids_max_[c].at(i); const auto &critCoords = g.GetCriticalCoordinates(); ttk::CriticalType saddle_type; if(do_sad_) @@ -508,13 +508,13 @@ void ttk::PDClustering::correctMatchings( &previous_matchings) { for(int c = 0; c < k_; c++) { for(size_t i = 0; i < clustering_[c].size(); i++) { - int diagram_id = clustering_[c][i]; + int const diagram_id = clustering_[c][i]; if(original_dos[0]) { // 1. Invert the current_bidder_ids_ vector std::vector new_to_old_id( current_bidder_diagrams_min_[diagram_id].size(), -1); for(size_t j = 0; j < current_bidder_ids_min_[diagram_id].size(); j++) { - int new_id = current_bidder_ids_min_[diagram_id][j]; + int const new_id = current_bidder_ids_min_[diagram_id][j]; if(new_id >= 0) { new_to_old_id[new_id] = j; } @@ -523,7 +523,7 @@ void ttk::PDClustering::correctMatchings( std::vector matchings_diagram_i; for(size_t j = 0; j < previous_matchings[c][0][i].size(); j++) { MatchingType m = previous_matchings[c][0][i][j]; - int new_id = std::get<0>(m); + int const new_id = std::get<0>(m); if(new_id >= 0 && std::get<1>(m) >= 0) { std::get<0>(m) = new_to_old_id[new_id]; matchings_diagram_i.emplace_back(m); @@ -541,7 +541,7 @@ void ttk::PDClustering::correctMatchings( std::vector new_to_old_id( current_bidder_diagrams_saddle_[diagram_id].size()); for(size_t j = 0; j < current_bidder_ids_sad_[diagram_id].size(); j++) { - int new_id = current_bidder_ids_sad_[diagram_id][j]; + int const new_id = current_bidder_ids_sad_[diagram_id][j]; if(new_id >= 0) { new_to_old_id[new_id] = j; } @@ -551,9 +551,9 @@ void ttk::PDClustering::correctMatchings( std::vector matchings_diagram_i; for(size_t j = 0; j < previous_matchings[c][1][i].size(); j++) { MatchingType m = previous_matchings[c][1][i][j]; - int new_id = std::get<0>(m); + int const new_id = std::get<0>(m); if(new_id >= 0 && std::get<1>(m) >= 0) { - int old_id = new_to_old_id[new_id]; + int const old_id = new_to_old_id[new_id]; if(old_id > 0) { std::get<0>(m) = old_id; matchings_diagram_i.emplace_back(m); @@ -578,7 +578,7 @@ void ttk::PDClustering::correctMatchings( std::vector new_to_old_id( current_bidder_diagrams_max_[diagram_id].size()); for(size_t j = 0; j < current_bidder_ids_max_[diagram_id].size(); j++) { - int new_id = current_bidder_ids_max_[diagram_id][j]; + int const new_id = current_bidder_ids_max_[diagram_id][j]; if(new_id >= 0) { new_to_old_id[new_id] = j; } @@ -592,7 +592,7 @@ void ttk::PDClustering::correctMatchings( // std::cout<<"processing matching "<(m)<<" // "<(m)<<" "<(m)<<" "<= 0 && std::get<1>(m) >= 0) { - int old_id = new_to_old_id[new_id]; + int const old_id = new_to_old_id[new_id]; if(old_id > 0) { std::get<0>(m) = old_id; matchings_diagram_i.emplace_back(m); @@ -645,8 +645,8 @@ double ttk::PDClustering::getMostPersistent(int type) { if(do_min_ && (type == -1 || type == 0)) { for(size_t i = 0; i < bidder_diagrams_min_.size(); ++i) { for(size_t j = 0; j < bidder_diagrams_min_[i].size(); ++j) { - Bidder b = bidder_diagrams_min_[i].at(j); - double persistence = b.getPersistence(); + Bidder const b = bidder_diagrams_min_[i].at(j); + double const persistence = b.getPersistence(); if(persistence > max_persistence) { max_persistence = persistence; } @@ -657,8 +657,8 @@ double ttk::PDClustering::getMostPersistent(int type) { if(do_sad_ && (type == -1 || type == 1)) { for(size_t i = 0; i < bidder_diagrams_saddle_.size(); ++i) { for(size_t j = 0; j < bidder_diagrams_saddle_[i].size(); ++j) { - Bidder b = bidder_diagrams_saddle_[i].at(j); - double persistence = b.getPersistence(); + Bidder const b = bidder_diagrams_saddle_[i].at(j); + double const persistence = b.getPersistence(); if(persistence > max_persistence) { max_persistence = persistence; } @@ -669,8 +669,8 @@ double ttk::PDClustering::getMostPersistent(int type) { if(do_max_ && (type == -1 || type == 2)) { for(size_t i = 0; i < bidder_diagrams_max_.size(); ++i) { for(size_t j = 0; j < bidder_diagrams_max_[i].size(); ++j) { - Bidder b = bidder_diagrams_max_[i].at(j); - double persistence = b.getPersistence(); + Bidder const b = bidder_diagrams_max_[i].at(j); + double const persistence = b.getPersistence(); if(persistence > max_persistence) { max_persistence = persistence; } @@ -688,8 +688,8 @@ double ttk::PDClustering::getLessPersistent(int type) { if(do_min_ && (type == -1 || type == 0)) { for(size_t i = 0; i < bidder_diagrams_min_.size(); ++i) { for(size_t j = 0; j < bidder_diagrams_min_[i].size(); ++j) { - Bidder b = bidder_diagrams_min_[i].at(j); - double persistence = b.getPersistence(); + Bidder const b = bidder_diagrams_min_[i].at(j); + double const persistence = b.getPersistence(); if(persistence < min_persistence) { min_persistence = persistence; } @@ -700,8 +700,8 @@ double ttk::PDClustering::getLessPersistent(int type) { if(do_sad_ && (type == -1 || type == 1)) { for(size_t i = 0; i < bidder_diagrams_saddle_.size(); ++i) { for(size_t j = 0; j < bidder_diagrams_saddle_[i].size(); ++j) { - Bidder b = bidder_diagrams_saddle_[i].at(j); - double persistence = b.getPersistence(); + Bidder const b = bidder_diagrams_saddle_[i].at(j); + double const persistence = b.getPersistence(); if(persistence < min_persistence) { min_persistence = persistence; } @@ -712,8 +712,8 @@ double ttk::PDClustering::getLessPersistent(int type) { if(do_max_ && (type == -1 || type == 2)) { for(size_t i = 0; i < bidder_diagrams_max_.size(); ++i) { for(size_t j = 0; j < bidder_diagrams_max_[i].size(); ++j) { - Bidder b = bidder_diagrams_max_[i].at(j); - double persistence = b.getPersistence(); + Bidder const b = bidder_diagrams_max_[i].at(j); + double const persistence = b.getPersistence(); if(persistence < min_persistence) { min_persistence = persistence; } @@ -730,8 +730,8 @@ std::vector> ttk::PDClustering::getMinPrices() { for(int i = 0; i < numberOfInputs_; ++i) { min_prices[0].emplace_back(std::numeric_limits::max()); for(size_t j = 0; j < centroids_with_price_min_[i].size(); ++j) { - Good g = centroids_with_price_min_[i].at(j); - double price = g.getPrice(); + Good const g = centroids_with_price_min_[i].at(j); + double const price = g.getPrice(); if(price < min_prices[0][i]) { min_prices[0][i] = price; } @@ -743,8 +743,8 @@ std::vector> ttk::PDClustering::getMinPrices() { for(int i = 0; i < numberOfInputs_; ++i) { min_prices[1].emplace_back(std::numeric_limits::max()); for(size_t j = 0; j < centroids_with_price_saddle_[i].size(); ++j) { - Good g = centroids_with_price_saddle_[i].at(j); - double price = g.getPrice(); + Good const g = centroids_with_price_saddle_[i].at(j); + double const price = g.getPrice(); if(price < min_prices[1][i]) { min_prices[1][i] = price; } @@ -756,8 +756,8 @@ std::vector> ttk::PDClustering::getMinPrices() { for(int i = 0; i < numberOfInputs_; ++i) { min_prices[2].emplace_back(std::numeric_limits::max()); for(size_t j = 0; j < centroids_with_price_max_[i].size(); ++j) { - Good g = centroids_with_price_max_[i].at(j); - double price = g.getPrice(); + Good const g = centroids_with_price_max_[i].at(j); + double const price = g.getPrice(); if(price < min_prices[2][i]) { min_prices[2][i] = price; } @@ -774,8 +774,8 @@ std::vector> ttk::PDClustering::getMinDiagonalPrices() { for(int i = 0; i < numberOfInputs_; ++i) { min_prices[0].emplace_back(std::numeric_limits::max()); for(size_t j = 0; j < current_bidder_diagrams_min_[i].size(); ++j) { - Bidder b = current_bidder_diagrams_min_[i].at(j); - double price = b.diagonal_price_; + Bidder const b = current_bidder_diagrams_min_[i].at(j); + double const price = b.diagonal_price_; if(price < min_prices[0][i]) { min_prices[0][i] = price; } @@ -790,8 +790,8 @@ std::vector> ttk::PDClustering::getMinDiagonalPrices() { for(int i = 0; i < numberOfInputs_; ++i) { min_prices[1].emplace_back(std::numeric_limits::max()); for(size_t j = 0; j < current_bidder_diagrams_saddle_[i].size(); ++j) { - Bidder b = current_bidder_diagrams_saddle_[i].at(j); - double price = b.diagonal_price_; + Bidder const b = current_bidder_diagrams_saddle_[i].at(j); + double const price = b.diagonal_price_; if(price < min_prices[1][i]) { min_prices[1][i] = price; } @@ -806,8 +806,8 @@ std::vector> ttk::PDClustering::getMinDiagonalPrices() { for(int i = 0; i < numberOfInputs_; ++i) { min_prices[2].emplace_back(std::numeric_limits::max()); for(size_t j = 0; j < current_bidder_diagrams_max_[i].size(); ++j) { - Bidder b = current_bidder_diagrams_max_[i].at(j); - double price = b.diagonal_price_; + Bidder const b = current_bidder_diagrams_max_[i].at(j); + double const price = b.diagonal_price_; if(price < min_prices[2][i]) { min_prices[2][i] = price; } @@ -823,7 +823,7 @@ std::vector> ttk::PDClustering::getMinDiagonalPrices() { double ttk::PDClustering::computeDistance(const BidderDiagram &D1, const BidderDiagram &D2, const double delta_lim) { - GoodDiagram D2_bis = diagramToCentroid(D2); + GoodDiagram const D2_bis = diagramToCentroid(D2); return computeDistance(D1, D2_bis, delta_lim); } @@ -835,7 +835,7 @@ double ttk::PDClustering::computeDistance(const BidderDiagram &D1, PersistenceDiagramAuction auction( wasserstein_, geometrical_factor_, lambda_, delta_lim, use_kdtree_); auction.BuildAuctionDiagrams(D1, D2_bis); - double cost = auction.run(matchings); + double const cost = auction.run(matchings); return cost; } @@ -845,9 +845,9 @@ double ttk::PDClustering::computeDistance(BidderDiagram *const D1, std::vector matchings; PersistenceDiagramAuction auction( wasserstein_, geometrical_factor_, lambda_, delta_lim, use_kdtree_); - int size1 = D1->size(); + int const size1 = D1->size(); auction.BuildAuctionDiagrams(*D1, *D2); - double cost = auction.run(matchings); + double const cost = auction.run(matchings); // Diagonal Points were added in the original diagram. The following line // removes them. D1->resize(size1); @@ -857,7 +857,7 @@ double ttk::PDClustering::computeDistance(BidderDiagram *const D1, double ttk::PDClustering::computeDistance(const GoodDiagram &D1, const GoodDiagram &D2, const double delta_lim) { - BidderDiagram D1_bis = centroidToDiagram(D1); + BidderDiagram const D1_bis = centroidToDiagram(D1); return computeDistance(D1_bis, D2, delta_lim); } @@ -927,17 +927,17 @@ void ttk::PDClustering::initializeCentroids() { for(int c = 0; c < k_; c++) { if(do_min_) { - GoodDiagram centroid_min + GoodDiagram const centroid_min = diagramToCentroid(current_bidder_diagrams_min_[idx[c]]); centroids_min_.emplace_back(centroid_min); } if(do_sad_) { - GoodDiagram centroid_sad + GoodDiagram const centroid_sad = diagramToCentroid(current_bidder_diagrams_saddle_[idx[c]]); centroids_saddle_.emplace_back(centroid_sad); } if(do_max_) { - GoodDiagram centroid_max + GoodDiagram const centroid_max = diagramToCentroid(current_bidder_diagrams_max_[idx[c]]); centroids_max_.emplace_back(centroid_max); } @@ -946,21 +946,21 @@ void ttk::PDClustering::initializeCentroids() { void ttk::PDClustering::initializeCentroidsKMeanspp() { std::vector indexes_clusters; - int random_idx = deterministic_ ? 0 : rand() % numberOfInputs_; + int const random_idx = deterministic_ ? 0 : rand() % numberOfInputs_; indexes_clusters.emplace_back(random_idx); if(do_min_) { - GoodDiagram centroid_min + GoodDiagram const centroid_min = diagramToCentroid(current_bidder_diagrams_min_[random_idx]); centroids_min_.emplace_back(centroid_min); } if(do_sad_) { - GoodDiagram centroid_sad + GoodDiagram const centroid_sad = diagramToCentroid(current_bidder_diagrams_saddle_[random_idx]); centroids_saddle_.emplace_back(centroid_sad); } if(do_max_) { - GoodDiagram centroid_max + GoodDiagram const centroid_max = diagramToCentroid(current_bidder_diagrams_max_[random_idx]); centroids_max_.emplace_back(centroid_max); } @@ -988,19 +988,19 @@ void ttk::PDClustering::initializeCentroidsKMeanspp() { double distance = 0; if(do_min_) { - GoodDiagram centroid_min + GoodDiagram const centroid_min = centroidWithZeroPrices(centroids_min_[j]); distance += computeDistance( current_bidder_diagrams_min_[i], centroid_min, 0.01); } if(do_sad_) { - GoodDiagram centroid_saddle + GoodDiagram const centroid_saddle = centroidWithZeroPrices(centroids_saddle_[j]); distance += computeDistance( current_bidder_diagrams_saddle_[i], centroid_saddle, 0.01); } if(do_max_) { - GoodDiagram centroid_max + GoodDiagram const centroid_max = centroidWithZeroPrices(centroids_max_[j]); distance += computeDistance( current_bidder_diagrams_max_[i], centroid_max, 0.01); @@ -1031,17 +1031,17 @@ void ttk::PDClustering::initializeCentroidsKMeanspp() { indexes_clusters.emplace_back(candidate_centroid); if(do_min_) { - GoodDiagram centroid_min + GoodDiagram const centroid_min = diagramToCentroid(current_bidder_diagrams_min_[candidate_centroid]); centroids_min_.emplace_back(centroid_min); } if(do_sad_) { - GoodDiagram centroid_sad = diagramToCentroid( + GoodDiagram const centroid_sad = diagramToCentroid( current_bidder_diagrams_saddle_[candidate_centroid]); centroids_saddle_.emplace_back(centroid_sad); } if(do_max_) { - GoodDiagram centroid_max + GoodDiagram const centroid_max = diagramToCentroid(current_bidder_diagrams_max_[candidate_centroid]); centroids_max_.emplace_back(centroid_max); } @@ -1152,25 +1152,27 @@ void ttk::PDClustering::computeDistanceToCentroid() { distanceToCentroid_.resize(numberOfInputs_); for(int i = 0; i < numberOfInputs_; ++i) { - double delta_lim{0.01}; + double const delta_lim{0.01}; double distance{}; auto c = inv_clustering_[i]; if(original_dos[0]) { - GoodDiagram centroid_min = centroidWithZeroPrices(centroids_min_[c]); - BidderDiagram bidder_diag + GoodDiagram const centroid_min + = centroidWithZeroPrices(centroids_min_[c]); + BidderDiagram const bidder_diag = diagramWithZeroPrices(current_bidder_diagrams_min_[i]); distance += computeDistance(bidder_diag, centroid_min, delta_lim); } if(original_dos[1]) { - GoodDiagram centroid_saddle + GoodDiagram const centroid_saddle = centroidWithZeroPrices(centroids_saddle_[c]); - BidderDiagram bidder_diag + BidderDiagram const bidder_diag = diagramWithZeroPrices(current_bidder_diagrams_saddle_[i]); distance += computeDistance(bidder_diag, centroid_saddle, delta_lim); } if(original_dos[2]) { - GoodDiagram centroid_max = centroidWithZeroPrices(centroids_max_[c]); - BidderDiagram bidder_diag + GoodDiagram const centroid_max + = centroidWithZeroPrices(centroids_max_[c]); + BidderDiagram const bidder_diag = diagramWithZeroPrices(current_bidder_diagrams_max_[i]); distance += computeDistance(bidder_diag, centroid_max, delta_lim); } @@ -1256,7 +1258,7 @@ void ttk::PDClustering::invertClusters() { // Fill in the clusters for(int c = 0; c < k_; ++c) { for(size_t j = 0; j < clustering_[c].size(); ++j) { - int idx = clustering_[c][j]; + int const idx = clustering_[c][j]; inv_clustering_[idx] = c; } } @@ -1284,9 +1286,9 @@ void ttk::PDClustering::acceleratedUpdateClusters() { // self.old_clusters = copy.copy(self.clusters) invertClusters(); initializeEmptyClusters(); - bool do_min = original_dos[0]; - bool do_sad = original_dos[1]; - bool do_max = original_dos[2]; + bool const do_min = original_dos[0]; + bool const do_sad = original_dos[1]; + bool const do_max = original_dos[2]; for(int i = 0; i < numberOfInputs_; ++i) { // Step 3 find potential changes of clusters @@ -1422,7 +1424,7 @@ void ttk::PDClustering::acceleratedUpdateClusters() { if(inv_clustering_[idx] < k_ && inv_clustering_[idx] >= 0 && clustering_[inv_clustering_[idx]].size() > 1) { idx_acceptable = true; - int cluster_removal = inv_clustering_[idx]; + int const cluster_removal = inv_clustering_[idx]; // Removing the index to remove clustering_[cluster_removal].erase( std::remove(clustering_[cluster_removal].begin(), @@ -1443,7 +1445,7 @@ void ttk::PDClustering::acceleratedUpdateClusters() { idx = clustering_[cluster_max][0]; } } - int cluster_removal = inv_clustering_[idx]; + int const cluster_removal = inv_clustering_[idx]; clustering_[cluster_removal].erase( std::remove(clustering_[cluster_removal].begin(), clustering_[cluster_removal].end(), idx), @@ -1498,9 +1500,9 @@ std::vector ttk::PDClustering::updateCentroidsPosition( bool precision_sad = true; bool precision_max = true; cost_ = 0; - double sq_dist_min = cost_min_; - double sq_dist_sad = cost_sad_; - double sq_dist_max = cost_max_; + double const sq_dist_min = cost_min_; + double const sq_dist_sad = cost_sad_; + double const sq_dist_max = cost_max_; if(do_min_) { cost_min_ = 0; } @@ -1516,14 +1518,14 @@ std::vector ttk::PDClustering::updateCentroidsPosition( std::vector centroids_with_price_min, centroids_with_price_sad, centroids_with_price_max; int count = 0; - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { // Timer time_first_thing; // Find the position of diagrams[idx] in old cluster c - std::vector::iterator i = std::find( + std::vector::iterator const i = std::find( old_clustering_[c].begin(), old_clustering_[c].end(), idx); - int pos = (i == old_clustering_[c].end()) - ? -1 - : std::distance(old_clustering_[c].begin(), i); + int const pos = (i == old_clustering_[c].end()) + ? -1 + : std::distance(old_clustering_[c].begin(), i); if(pos >= 0) { // Diagram was already linked to this centroid before if(do_min_) { @@ -1633,10 +1635,10 @@ std::vector ttk::PDClustering::updateCentroidsPosition( if(do_min_) { std::vector> all_matchings; std::vector sizes; - Timer time_preprocess_bary; + Timer const time_preprocess_bary; std::vector diagrams_c_min; if(barycenter_inputs_reset_flag) { - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { diagrams_c_min.emplace_back(current_bidder_diagrams_min_[idx]); } sizes.resize(diagrams_c_min.size()); @@ -1690,7 +1692,7 @@ std::vector ttk::PDClustering::updateCentroidsPosition( precision_min = barycenter_computer_min_[c].isPrecisionObjectiveMet(deltaLim_, 0); cost_min_ += total_cost; - Timer time_update; + Timer const time_update; if(!only_matchings) { max_shift_c_min = barycenter_computer_min_[c].updateBarycenter(all_matchings); @@ -1706,13 +1708,13 @@ std::vector ttk::PDClustering::updateCentroidsPosition( centroids_with_price_min = barycenter_computer_min_[c].getCurrentBarycenter(); int i = 0; - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { current_bidder_diagrams_min_[idx] = diagrams_c_min[i]; centroids_with_price_min_[idx] = centroids_with_price_min[i]; i++; } - GoodDiagram old_centroid = centroids_min_[c]; + GoodDiagram const old_centroid = centroids_min_[c]; centroids_min_[c] = centroidWithZeroPrices( centroids_with_price_min_[clustering_[c][0]]); @@ -1729,7 +1731,7 @@ std::vector ttk::PDClustering::updateCentroidsPosition( std::vector diagrams_c_min; if(barycenter_inputs_reset_flag) { - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { diagrams_c_min.emplace_back(current_bidder_diagrams_saddle_[idx]); } sizes.resize(diagrams_c_min.size()); @@ -1798,12 +1800,12 @@ std::vector ttk::PDClustering::updateCentroidsPosition( centroids_with_price_sad = barycenter_computer_sad_[c].getCurrentBarycenter(); int i = 0; - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { current_bidder_diagrams_saddle_[idx] = diagrams_c_min[i]; centroids_with_price_saddle_[idx] = centroids_with_price_sad[i]; i++; } - GoodDiagram old_centroid = centroids_saddle_[c]; + GoodDiagram const old_centroid = centroids_saddle_[c]; centroids_saddle_[c] = centroidWithZeroPrices( centroids_with_price_saddle_[clustering_[c][0]]); if(use_accelerated_) @@ -1813,12 +1815,12 @@ std::vector ttk::PDClustering::updateCentroidsPosition( if(do_max_) { std::vector> all_matchings; - Timer time_preprocess_bary; + Timer const time_preprocess_bary; total_cost = 0; std::vector sizes; std::vector diagrams_c_min; if(barycenter_inputs_reset_flag) { - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { diagrams_c_min.emplace_back(current_bidder_diagrams_max_[idx]); } sizes.resize(diagrams_c_min.size()); @@ -1872,7 +1874,7 @@ std::vector ttk::PDClustering::updateCentroidsPosition( = barycenter_computer_max_[c].isPrecisionObjectiveMet(deltaLim_, 0); cost_max_ += total_cost; - Timer time_update; + Timer const time_update; if(!only_matchings) { max_shift_c_max = barycenter_computer_max_[c].updateBarycenter(all_matchings); @@ -1887,12 +1889,12 @@ std::vector ttk::PDClustering::updateCentroidsPosition( centroids_with_price_max = barycenter_computer_max_[c].getCurrentBarycenter(); int i = 0; - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { current_bidder_diagrams_max_[idx] = diagrams_c_min[i]; centroids_with_price_max_[idx] = centroids_with_price_max[i]; i++; } - GoodDiagram old_centroid = centroids_max_[c]; + GoodDiagram const old_centroid = centroids_max_[c]; centroids_max_[c] = centroidWithZeroPrices( centroids_with_price_max_[clustering_[c][0]]); if(use_accelerated_) { @@ -1917,7 +1919,7 @@ std::vector ttk::PDClustering::updateCentroidsPosition( l_[i][c] = 0; } } - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { // Step 6, update the upper bound on the distance to the centroid // thanks to the triangle inequality u_[idx] = Geometry::pow( @@ -1957,8 +1959,8 @@ void ttk::PDClustering::setBidderDiagrams() { } } bidder_diagrams_min_.emplace_back(bidders); - current_bidder_diagrams_min_.emplace_back(BidderDiagram()); - centroids_with_price_min_.emplace_back(GoodDiagram()); + current_bidder_diagrams_min_.emplace_back(); + centroids_with_price_min_.emplace_back(); std::vector ids(bidders.size()); for(size_t j = 0; j < ids.size(); j++) { ids[j] = -1; @@ -1981,8 +1983,8 @@ void ttk::PDClustering::setBidderDiagrams() { } } bidder_diagrams_saddle_.emplace_back(bidders); - current_bidder_diagrams_saddle_.emplace_back(BidderDiagram()); - centroids_with_price_saddle_.emplace_back(GoodDiagram()); + current_bidder_diagrams_saddle_.emplace_back(); + centroids_with_price_saddle_.emplace_back(); std::vector ids(bidders.size()); for(size_t j = 0; j < ids.size(); j++) { ids[j] = -1; @@ -2005,8 +2007,8 @@ void ttk::PDClustering::setBidderDiagrams() { } } bidder_diagrams_max_.emplace_back(bidders); - current_bidder_diagrams_max_.emplace_back(BidderDiagram()); - centroids_with_price_max_.emplace_back(GoodDiagram()); + current_bidder_diagrams_max_.emplace_back(); + centroids_with_price_max_.emplace_back(); std::vector ids(bidders.size()); for(size_t j = 0; j < ids.size(); j++) { ids[j] = -1; @@ -2064,13 +2066,13 @@ std::vector ttk::PDClustering::enrichCurrentBidderDiagrams( } } } - int max_points_to_add_min + int const max_points_to_add_min = std::max(min_points_to_add[0], min_points_to_add[0] + (int)(max_diagram_size_min / 10)); - int max_points_to_add_sad + int const max_points_to_add_sad = std::max(min_points_to_add[1], min_points_to_add[1] + (int)(max_diagram_size_sad / 10)); - int max_points_to_add_max + int const max_points_to_add_max = std::max(min_points_to_add[2], min_points_to_add[2] + (int)(max_diagram_size_max / 10)); @@ -2221,7 +2223,7 @@ std::vector ttk::PDClustering::enrichCurrentBidderDiagrams( if(do_min_) { int compteur_for_adding_points = 0; for(int i = 0; i < numberOfInputs_; i++) { - int size = candidates_to_be_added_min[i].size(); + int const size = candidates_to_be_added_min[i].size(); for(int j = 0; j < std::min(max_points_to_add_min, size); j++) { Bidder b = bidder_diagrams_min_[i].at( candidates_to_be_added_min[i][idx_min[i][j]]); @@ -2254,7 +2256,7 @@ std::vector ttk::PDClustering::enrichCurrentBidderDiagrams( wasserstein_); r_[i] = true; } - int to_be_added_to_barycenter + int const to_be_added_to_barycenter = deterministic_ ? compteur_for_adding_points % numberOfInputs_ : rand() % numberOfInputs_; if(to_be_added_to_barycenter == 0 && add_points_to_barycenter) { @@ -2281,7 +2283,7 @@ std::vector ttk::PDClustering::enrichCurrentBidderDiagrams( if(do_sad_) { int compteur_for_adding_points = 0; for(int i = 0; i < numberOfInputs_; i++) { - int size = candidates_to_be_added_sad[i].size(); + int const size = candidates_to_be_added_sad[i].size(); for(int j = 0; j < std::min(max_points_to_add_sad, size); j++) { Bidder b = bidder_diagrams_saddle_[i].at( candidates_to_be_added_sad[i][idx_sad[i][j]]); @@ -2314,7 +2316,7 @@ std::vector ttk::PDClustering::enrichCurrentBidderDiagrams( wasserstein_); r_[i] = true; } - int to_be_added_to_barycenter + int const to_be_added_to_barycenter = deterministic_ ? compteur_for_adding_points % numberOfInputs_ : rand() % numberOfInputs_; if(to_be_added_to_barycenter == 0 && add_points_to_barycenter) { @@ -2337,7 +2339,7 @@ std::vector ttk::PDClustering::enrichCurrentBidderDiagrams( if(do_max_) { int compteur_for_adding_points = 0; for(int i = 0; i < numberOfInputs_; i++) { - int size = candidates_to_be_added_max[i].size(); + int const size = candidates_to_be_added_max[i].size(); for(int j = 0; j < std::min(max_points_to_add_max, size); j++) { Bidder b = bidder_diagrams_max_[i].at( candidates_to_be_added_max[i][idx_max[i][j]]); @@ -2370,7 +2372,7 @@ std::vector ttk::PDClustering::enrichCurrentBidderDiagrams( wasserstein_); r_[i] = true; } - int to_be_added_to_barycenter + int const to_be_added_to_barycenter = deterministic_ ? compteur_for_adding_points % numberOfInputs_ : rand() % numberOfInputs_; if(to_be_added_to_barycenter == 0 && add_points_to_barycenter) { @@ -2405,7 +2407,7 @@ void ttk::PDClustering::initializeBarycenterComputers( barycenter_computer_min_.resize(k_); for(int c = 0; c < k_; c++) { std::vector diagrams_c; - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { diagrams_c.emplace_back(current_bidder_diagrams_min_[idx]); } barycenter_computer_min_[c] = {}; @@ -2434,7 +2436,7 @@ void ttk::PDClustering::initializeBarycenterComputers( barycenter_computer_sad_.resize(k_); for(int c = 0; c < k_; c++) { std::vector diagrams_c; - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { diagrams_c.emplace_back(current_bidder_diagrams_saddle_[idx]); } barycenter_computer_sad_[c] = {}; @@ -2471,7 +2473,7 @@ void ttk::PDClustering::initializeBarycenterComputers( barycenter_computer_max_.resize(k_); for(int c = 0; c < k_; c++) { std::vector diagrams_c; - for(int idx : clustering_[c]) { + for(int const idx : clustering_[c]) { diagrams_c.emplace_back(current_bidder_diagrams_max_[idx]); } barycenter_computer_max_[c] = {}; @@ -2522,7 +2524,7 @@ void ttk::PDClustering::printDistancesToFile() { } for(int c = 0; c < k_; c++) { - for(int i : clustering_[c]) { + for(int const i : clustering_[c]) { approx_file << (u_[i] + l_[i][c]) / 2 << " "; } approx_file << "\n"; @@ -2537,7 +2539,7 @@ void ttk::PDClustering::printRealDistancesToFile() { std::ofstream file("a_real_mat.txt"); if(file.is_open()) { for(int c = 0; c < k_; c++) { - for(int i : clustering_[c]) { + for(int const i : clustering_[c]) { file << distanceToCentroid_[i] << " "; } file << "\n"; @@ -2557,7 +2559,7 @@ void ttk::PDClustering::printPricesToFile(int iteration) { file << "\ncentroid " << i << std::endl; for(size_t j = 0; j < centroids_with_price_max_[i].size(); j++) { - Good g = centroids_with_price_max_[i].at(j); + Good const g = centroids_with_price_max_[i].at(j); file << g.getPrice() << " "; } } @@ -2574,7 +2576,7 @@ double ttk::PDClustering::computeRealCost() { for(int c = 0; c < k_; c++) { double real_cost_cluster = 0; for(int i = 0; i < numberOfInputs_; i++) { - GoodDiagram current_barycenter + GoodDiagram const current_barycenter = centroidWithZeroPrices(centroids_min_[c]); sq_distance = computeDistance(bidder_diagrams_min_[i], current_barycenter, 0.01); @@ -2587,7 +2589,7 @@ double ttk::PDClustering::computeRealCost() { for(int c = 0; c < k_; c++) { double real_cost_cluster = 0; for(int i = 0; i < numberOfInputs_; i++) { - GoodDiagram current_barycenter + GoodDiagram const current_barycenter = centroidWithZeroPrices(centroids_saddle_[c]); sq_distance = computeDistance( bidder_diagrams_saddle_[i], current_barycenter, 0.01); @@ -2600,7 +2602,7 @@ double ttk::PDClustering::computeRealCost() { for(int c = 0; c < k_; c++) { double real_cost_cluster = 0; for(int i = 0; i < numberOfInputs_; i++) { - GoodDiagram current_barycenter + GoodDiagram const current_barycenter = centroidWithZeroPrices(centroids_max_[c]); sq_distance = computeDistance(bidder_diagrams_max_[i], current_barycenter, 0.01); @@ -2654,7 +2656,7 @@ void ttk::PDClustering::computeBarycenterForTwo( std::vector new_to_old_id(current_diagram1.size()); // 1. Invert the current_bidder_ids_ vector for(size_t j = 0; j < ids1.size(); j++) { - int new_id = ids1[j]; + int const new_id = ids1[j]; if(new_id >= 0) { new_to_old_id[new_id] = j; } @@ -2665,17 +2667,17 @@ void ttk::PDClustering::computeBarycenterForTwo( for(size_t i = 0; i < matchings1.size(); i++) { MatchingType &t = matchings1[i]; - int bidderId = std::get<0>(t); - int goodId = std::get<1>(t); + int const bidderId = std::get<0>(t); + int const goodId = std::get<1>(t); if(bidderId >= 0) { - Bidder b = diagram1.at(new_to_old_id[bidderId]); - double bx = b.x_; - double by = b.y_; + Bidder const b = diagram1.at(new_to_old_id[bidderId]); + double const bx = b.x_; + double const by = b.y_; if(goodId >= 0) { - Good g = barycenter.at(goodId); - double gx = g.x_; - double gy = g.y_; + Good const g = barycenter.at(goodId); + double const gx = g.x_; + double const gy = g.y_; barycenter.at(goodId).x_ = (bx + gx) / 2; barycenter.at(goodId).y_ = (by + gy) / 2; // divide by 4 in order to display the cost of the half matching @@ -2687,11 +2689,12 @@ void ttk::PDClustering::computeBarycenterForTwo( double gy = (bx + by) / 2; gx = (gx + bx) / 2; gy = (gy + by) / 2; - double cost = Geometry::pow((gx - bx), wasserstein_) - + Geometry::pow((gy - by), wasserstein_); - MatchingType t2 = std::make_tuple(bidderId, barycenter.size(), cost); - MatchingType t3 = std::make_tuple(-1, barycenter.size(), cost); - Good g = Good(gx, gy, false, barycenter.size()); + double const cost = Geometry::pow((gx - bx), wasserstein_) + + Geometry::pow((gy - by), wasserstein_); + MatchingType const t2 + = std::make_tuple(bidderId, barycenter.size(), cost); + MatchingType const t3 = std::make_tuple(-1, barycenter.size(), cost); + Good const g = Good(gx, gy, false, barycenter.size()); // g.SetCriticalCoordinates(b.coords_[0], b.coords_[1], b.coords_[2]); barycenter.emplace_back(g); matching_to_add.emplace_back(t2); @@ -2699,9 +2702,9 @@ void ttk::PDClustering::computeBarycenterForTwo( } } else { if(goodId >= 0) { - Good g = barycenter.at(goodId); - double gx = (g.x_ + g.y_) / 2; - double gy = (g.x_ + g.y_) / 2; + Good const g = barycenter.at(goodId); + double const gx = (g.x_ + g.y_) / 2; + double const gy = (g.x_ + g.y_) / 2; barycenter.at(goodId).x_ = (gx + g.x_) / 2; barycenter.at(goodId).y_ = (gy + g.y_) / 2; std::get<2>(t) /= 4; @@ -2721,7 +2724,7 @@ void ttk::PDClustering::computeBarycenterForTwo( std::vector new_to_old_id2(current_diagram0.size()); // 1. Invert the current_bidder_ids_ vector for(size_t j = 0; j < ids0.size(); j++) { - int new_id = ids0[j]; + int const new_id = ids0[j]; if(new_id >= 0) { new_to_old_id2[new_id] = j; } @@ -2729,18 +2732,18 @@ void ttk::PDClustering::computeBarycenterForTwo( for(size_t i = 0; i < matchings0.size(); i++) { MatchingType &t = matchings0[i]; - int bidderId = std::get<0>(t); - int goodId = std::get<1>(t); + int const bidderId = std::get<0>(t); + int const goodId = std::get<1>(t); if(bidderId >= 0 and goodId >= 0) { - Bidder b = diagram0.at(new_to_old_id2[bidderId]); - double bx = b.x_; - double by = b.y_; - Good g = barycenter.at(goodId); - double gx = g.x_; - double gy = g.y_; - double cost = Geometry::pow((gx - bx), wasserstein_) - + Geometry::pow((gy - by), wasserstein_); + Bidder const b = diagram0.at(new_to_old_id2[bidderId]); + double const bx = b.x_; + double const by = b.y_; + Good const g = barycenter.at(goodId); + double const gx = g.x_; + double const gy = g.y_; + double const cost = Geometry::pow((gx - bx), wasserstein_) + + Geometry::pow((gy - by), wasserstein_); std::get<2>(t) = cost; } } diff --git a/core/base/persistenceDiagramClustering/PersistenceDiagramBarycenter.cpp b/core/base/persistenceDiagramClustering/PersistenceDiagramBarycenter.cpp index 70095e2905..8cecd95775 100644 --- a/core/base/persistenceDiagramClustering/PersistenceDiagramBarycenter.cpp +++ b/core/base/persistenceDiagramClustering/PersistenceDiagramBarycenter.cpp @@ -27,12 +27,12 @@ void ttk::PersistenceDiagramBarycenter::execute( DiagramType &CTDiagram = intermediateDiagrams[i]; for(size_t j = 0; j < CTDiagram.size(); ++j) { - PersistencePair &t = CTDiagram[j]; + PersistencePair const &t = CTDiagram[j]; - ttk::CriticalType nt1 = t.birth.type; - ttk::CriticalType nt2 = t.death.type; + ttk::CriticalType const nt1 = t.birth.type; + ttk::CriticalType const nt2 = t.death.type; - double dt = t.persistence(); + double const dt = t.persistence(); // if (abs(dt) < zeroThresh) continue; if(dt > 0) { if(nt1 == ttk::CriticalType::Local_minimum @@ -169,7 +169,7 @@ void ttk::PersistenceDiagramBarycenter::execute( if(do_min) { for(size_t j = 0; j < matching_min[i].size(); j++) { MatchingType t = matching_min[i][j]; - int bidder_id = std::get<0>(t); + int const bidder_id = std::get<0>(t); std::get<0>(t) = data_min_idx[i][bidder_id]; if(std::get<1>(t) < 0) { std::get<1>(t) = -1; @@ -181,7 +181,7 @@ void ttk::PersistenceDiagramBarycenter::execute( if(do_sad) { for(size_t j = 0; j < matching_sad[i].size(); j++) { MatchingType t = matching_sad[i][j]; - int bidder_id = std::get<0>(t); + int const bidder_id = std::get<0>(t); std::get<0>(t) = data_sad_idx[i][bidder_id]; if(std::get<1>(t) >= 0) { std::get<1>(t) = std::get<1>(t) + barycenter_min.size(); @@ -195,7 +195,7 @@ void ttk::PersistenceDiagramBarycenter::execute( if(do_max) { for(size_t j = 0; j < matching_max[i].size(); j++) { MatchingType t = matching_max[i][j]; - int bidder_id = std::get<0>(t); + int const bidder_id = std::get<0>(t); std::get<0>(t) = data_max_idx[i][bidder_id]; if(std::get<1>(t) >= 0) { std::get<1>(t) @@ -243,8 +243,8 @@ void ttk::PersistenceDiagramBarycenter::execute( DiagramType &CTDiagram = intermediateDiagrams[i]; for(unsigned j = 0; j < all_matchings[0][i].size(); j++) { MatchingType t = all_matchings[0][i][j]; - int bidder_id = std::get<0>(t); - int bary_id = std::get<1>(t); + int const bidder_id = std::get<0>(t); + int const bary_id = std::get<1>(t); const auto &bidder = CTDiagram[bidder_id]; number_of_matchings_for_point[bary_id] += 1; diff --git a/core/base/persistenceDiagramClustering/PersistenceDiagramClustering.cpp b/core/base/persistenceDiagramClustering/PersistenceDiagramClustering.cpp index f77864209b..bb30a9fd53 100644 --- a/core/base/persistenceDiagramClustering/PersistenceDiagramClustering.cpp +++ b/core/base/persistenceDiagramClustering/PersistenceDiagramClustering.cpp @@ -84,10 +84,10 @@ std::vector ttk::PersistenceDiagramClustering::execute( for(size_t j = 0; j < CTDiagram.size(); ++j) { auto &t = CTDiagram[j]; - ttk::CriticalType nt1 = t.birth.type; - ttk::CriticalType nt2 = t.death.type; + ttk::CriticalType const nt1 = t.birth.type; + ttk::CriticalType const nt2 = t.death.type; - double dt = t.persistence(); + double const dt = t.persistence(); // if (abs(dt) < zeroThresh) continue; if(dt > 0) { if(nt1 == ttk::CriticalType::Local_minimum @@ -188,7 +188,7 @@ std::vector ttk::PersistenceDiagramClustering::execute( std::vector idxInCluster(numberOfInputs_); for(int j = 0; j < numberOfInputs_; ++j) { - size_t c = inv_clustering[j]; + size_t const c = inv_clustering[j]; if(c + 1 > cluster_size.size()) { cluster_size.resize(c + 1); cluster_size[c] = 1; @@ -212,7 +212,7 @@ std::vector ttk::PersistenceDiagramClustering::execute( } } for(int i = 0; i < numberOfInputs_; i++) { - size_t c = inv_clustering[i]; + size_t const c = inv_clustering[i]; if(do_min) { for(size_t j = 0; @@ -220,7 +220,7 @@ std::vector ttk::PersistenceDiagramClustering::execute( j++) { MatchingType t = all_matchings_per_type_and_cluster[c][0][idxInCluster[i]][j]; - int bidder_id = std::get<0>(t); + int const bidder_id = std::get<0>(t); if(bidder_id < (int)data_min[i].size()) { if(bidder_id < 0) { // matching with a diagonal point std::get<0>(t) = -1; @@ -242,7 +242,7 @@ std::vector ttk::PersistenceDiagramClustering::execute( j++) { MatchingType t = all_matchings_per_type_and_cluster[c][1][idxInCluster[i]][j]; - int bidder_id = std::get<0>(t); + int const bidder_id = std::get<0>(t); if(bidder_id < (int)data_sad[i].size()) { if(bidder_id < 0) { // matching with a diagonal point std::get<0>(t) = -1; @@ -265,7 +265,7 @@ std::vector ttk::PersistenceDiagramClustering::execute( j++) { MatchingType t = all_matchings_per_type_and_cluster[c][2][idxInCluster[i]][j]; - int bidder_id = std::get<0>(t); + int const bidder_id = std::get<0>(t); if(bidder_id < (int)data_max[i].size()) { if(bidder_id < 0) { // matching with a diagonal point std::get<0>(t) = -1;