From 0654bfbab17fe16edf90445f0a351454b460028f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 30 May 2017 15:20:29 +0000 Subject: Fix spell checker errors git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2475 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 94422e6f356532b2db4dc5a55cbb851210b3c36d --- src/common/include/gudhi/distance_functions.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/common/include') diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index f6e2ab5a..f683136b 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -48,6 +48,11 @@ class Euclidean_distance { } return std::sqrt(dist); } + template< typename T > + T operator() ( const std::pair< T,T >& f , const std::pair< T,T >& s ) + { + return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); + } }; } // namespace Gudhi -- cgit v1.2.3 From 3a76dcb9f49671b01ae200a13569f47fca57dac0 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 31 May 2017 06:20:04 +0000 Subject: Fix cpplint and cppcheck git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2480 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9ad6fc7b096fff02a8696515c074ddd92980a8e2 --- .../example/persistence_heat_maps.cpp | 1 + .../example/persistence_intervals.cpp | 2 + .../example/persistence_landscape.cpp | 6 ++- .../example/persistence_landscape_on_grid.cpp | 6 ++- .../example/persistence_vectors.cpp | 6 ++- .../include/gudhi/PSSK.h | 9 +++-- .../include/gudhi/Persistence_heat_maps.h | 33 ++++++++-------- .../include/gudhi/Persistence_intervals.h | 7 ++-- .../gudhi/Persistence_intervals_with_distances.h | 4 +- .../include/gudhi/Persistence_landscape.h | 37 +++++++++--------- .../include/gudhi/Persistence_landscape_on_grid.h | 44 +++++++++++----------- .../include/gudhi/Persistence_vectors.h | 18 +++++---- .../gudhi/common_persistence_representations.h | 3 ++ .../include/gudhi/read_persistence_from_file.h | 8 ++-- .../average_persistence_heat_maps.cpp | 1 + .../compute_distance_of_persistence_heat_maps.cpp | 2 + ...ute_scalar_product_of_persistence_heat_maps.cpp | 1 + ...h_m_weighted_by_arctan_of_their_persistence.cpp | 2 + ...te_p_h_m_weighted_by_distance_from_diagonal.cpp | 2 + ...ate_p_h_m_weighted_by_squared_diag_distance.cpp | 2 + .../create_persistence_heat_maps.cpp | 2 + .../persistence_heat_maps/create_pssk.cpp | 2 + ...te_birth_death_range_in_persistence_diagram.cpp | 1 + .../compute_bottleneck_distance.cpp | 2 + .../compute_number_of_dominant_intervals.cpp | 3 ++ .../plot_histogram_of_intervals_lengths.cpp | 3 ++ .../plot_persistence_Betti_numbers.cpp | 3 ++ .../plot_persistence_intervals.cpp | 3 ++ .../persistence_landscapes/average_landscapes.cpp | 1 + .../compute_distance_of_landscapes.cpp | 1 + .../compute_scalar_product_of_landscapes.cpp | 1 + .../compute_distance_of_landscapes_on_grid.cpp | 2 + ...ompute_scalar_product_of_landscapes_on_grid.cpp | 1 + .../create_landscapes_on_grid.cpp | 4 +- .../average_persistence_vectors.cpp | 1 + .../compute_distance_of_persistence_vectors.cpp | 2 + ...mpute_scalar_product_of_persistence_vectors.cpp | 2 + .../create_persistence_vectors.cpp | 2 + src/common/include/gudhi/distance_functions.h | 4 +- 39 files changed, 151 insertions(+), 83 deletions(-) (limited to 'src/common/include') diff --git a/src/Persistence_representations/example/persistence_heat_maps.cpp b/src/Persistence_representations/example/persistence_heat_maps.cpp index 5e3be880..a9ac5df5 100644 --- a/src/Persistence_representations/example/persistence_heat_maps.cpp +++ b/src/Persistence_representations/example/persistence_heat_maps.cpp @@ -25,6 +25,7 @@ #include #include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/example/persistence_intervals.cpp b/src/Persistence_representations/example/persistence_intervals.cpp index 1accfb0c..29cd66f3 100644 --- a/src/Persistence_representations/example/persistence_intervals.cpp +++ b/src/Persistence_representations/example/persistence_intervals.cpp @@ -24,6 +24,8 @@ #include #include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/example/persistence_landscape.cpp b/src/Persistence_representations/example/persistence_landscape.cpp index 4225f83a..1bcc524a 100644 --- a/src/Persistence_representations/example/persistence_landscape.cpp +++ b/src/Persistence_representations/example/persistence_landscape.cpp @@ -22,11 +22,13 @@ #include +#include +#include +#include + using namespace Gudhi; using namespace Gudhi::Persistence_representations; -#include - int main(int argc, char** argv) { // create two simple vectors with birth--death pairs: diff --git a/src/Persistence_representations/example/persistence_landscape_on_grid.cpp b/src/Persistence_representations/example/persistence_landscape_on_grid.cpp index 821fb5b7..0cede07e 100644 --- a/src/Persistence_representations/example/persistence_landscape_on_grid.cpp +++ b/src/Persistence_representations/example/persistence_landscape_on_grid.cpp @@ -22,11 +22,13 @@ #include +#include +#include +#include + using namespace Gudhi; using namespace Gudhi::Persistence_representations; -#include - int main(int argc, char** argv) { // create two simple vectors with birth--death pairs: diff --git a/src/Persistence_representations/example/persistence_vectors.cpp b/src/Persistence_representations/example/persistence_vectors.cpp index bc2f3fe7..c6581039 100644 --- a/src/Persistence_representations/example/persistence_vectors.cpp +++ b/src/Persistence_representations/example/persistence_vectors.cpp @@ -21,12 +21,14 @@ */ #include -#include - #include + +#include #include #include #include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/include/gudhi/PSSK.h b/src/Persistence_representations/include/gudhi/PSSK.h index 59e73af4..53628737 100644 --- a/src/Persistence_representations/include/gudhi/PSSK.h +++ b/src/Persistence_representations/include/gudhi/PSSK.h @@ -26,6 +26,10 @@ // gudhi include #include +#include +#include +#include + namespace Gudhi { namespace Persistence_representations { @@ -117,8 +121,8 @@ void PSSK::construct(const std::vector >& intervals_, for (size_t pt_nr = 0; pt_nr != intervals_.size(); ++pt_nr) { // compute the value of intervals_[pt_nr] in the grid: - int x_grid = (int)((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels); - int y_grid = (int)((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int x_grid = static_cast((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int y_grid = static_cast((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); if (dbg) { std::cerr << "point : " << intervals_[pt_nr].first << " , " << intervals_[pt_nr].second << std::endl; @@ -134,7 +138,6 @@ void PSSK::construct(const std::vector >& intervals_, if (dbg) { std::cerr << "After shift : \n"; - ; std::cerr << "x_grid : " << x_grid << std::endl; std::cerr << "y_grid : " << y_grid << std::endl; std::cerr << "filter.size() : " << filter.size() << std::endl; diff --git a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h index 549c19e7..5ef5129d 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h +++ b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h @@ -23,18 +23,20 @@ #ifndef PERSISTENCE_HEAT_MAPS_H_ #define PERSISTENCE_HEAT_MAPS_H_ +// gudhi include +#include +#include + // standard include #include #include #include #include #include -#include #include - -// gudhi include -#include -#include +#include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -68,8 +70,8 @@ std::vector > create_Gaussian_filter(size_t pixel_radius, do getchar(); } - for (int x = -pixel_radius; x <= (int)pixel_radius; x++) { - for (int y = -pixel_radius; y <= (int)pixel_radius; y++) { + for (int x = -pixel_radius; x <= static_cast(pixel_radius); x++) { + for (int y = -pixel_radius; y <= static_cast(pixel_radius); y++) { double real_x = 2 * sigma * x / pixel_radius; double real_y = 2 * sigma * y / pixel_radius; r = sqrt(real_x * real_x + real_y * real_y); @@ -123,7 +125,7 @@ class constant_scaling_function { class distance_from_diagonal_scaling { public: double operator()(const std::pair& point_in_diagram) { - //(point_in_diagram.first+point_in_diagram.second)/2.0 + // (point_in_diagram.first+point_in_diagram.second)/2.0 return sqrt(pow((point_in_diagram.first - (point_in_diagram.first + point_in_diagram.second) / 2.0), 2) + pow((point_in_diagram.second - (point_in_diagram.first + point_in_diagram.second) / 2.0), 2)); } @@ -194,7 +196,7 @@ class Persistence_heat_maps { this->erase_below_diagonal = false; this->min_ = this->max_ = 0; this->set_up_parameters_for_basic_classes(); - }; + } /** * Construction that takes at the input the following parameters: @@ -580,8 +582,8 @@ void Persistence_heat_maps::construct(const std::vectormin_) / (this->max_ - this->min_) * number_of_pixels); - int y_grid = (int)((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int x_grid = static_cast((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int y_grid = static_cast((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); if (dbg) { std::cerr << "point : " << intervals_[pt_nr].first << " , " << intervals_[pt_nr].second << std::endl; @@ -597,7 +599,6 @@ void Persistence_heat_maps::construct(const std::vector::compute_mean(const std::vector< for (size_t map_no = 0; map_no != maps.size(); ++map_no) { mean += maps[map_no]->heat_map[i][j]; } - heat_maps[i][j] = mean / (double)maps.size(); + heat_maps[i][j] = mean / static_cast(maps.size()); } } this->heat_map = heat_maps; @@ -782,7 +783,7 @@ void Persistence_heat_maps::load_from_file(const char* file // checking if the file exist / if it was open. if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } // now we read the file one by one. @@ -848,7 +849,7 @@ double Persistence_heat_maps::distance(const Persistence_he if (!this->check_if_the_same(second)) { std::cerr << "The persistence images are of non compatible sizes. We cannot therefore compute distance between " "them. The program will now terminate"; - throw "The persistence images are of non compatible sizes. We cannot therefore compute distance between them. The program will now terminate"; + throw "The persistence images are of non compatible sizes. The program will now terminate"; } // if we are here, we know that the two persistence images are defined on the same domain, so we can start computing @@ -897,7 +898,7 @@ double Persistence_heat_maps::compute_scalar_product(const if (!this->check_if_the_same(second)) { std::cerr << "The persistence images are of non compatible sizes. We cannot therefore compute distance between " "them. The program will now terminate"; - throw "The persistence images are of non compatible sizes. We cannot therefore compute distance between them. The program will now terminate"; + throw "The persistence images are of non compatible sizes. The program will now terminate"; } // if we are here, we know that the two persistence images are defined on the same domain, so we can start computing diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h index 939ae274..9e614efd 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h @@ -32,9 +32,10 @@ #include #include #include -#include #include #include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -402,7 +403,7 @@ std::vector Persistence_intervals::characteristic_function_of_diagram(do for (size_t pos = beginIt; pos != endIt; ++pos) { result[pos] += - ((x_max - x_min) / (double)number_of_bins) * (this->intervals[i].second - this->intervals[i].first); + ((x_max - x_min) / static_cast(number_of_bins)) * (this->intervals[i].second - this->intervals[i].first); } if (dbg) { std::cerr << "Result at this stage \n"; @@ -564,6 +565,6 @@ double Persistence_intervals::project_to_R(int number_of_function) const { } } // namespace Persistence_representations -} // namespace gudhi +} // namespace Gudhi #endif // PERSISTENCE_INTERVALS_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h index 0f3920cd..e476d28a 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h @@ -26,6 +26,8 @@ #include #include +#include + namespace Gudhi { namespace Persistence_representations { @@ -56,6 +58,6 @@ class Persistence_intervals_with_distances : public Persistence_intervals { }; } // namespace Persistence_representations -} // namespace gudhi +} // namespace Gudhi #endif // PERSISTENCE_INTERVALS_WITH_DISTANCES_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape.h b/src/Persistence_representations/include/gudhi/Persistence_landscape.h index be7c9e31..c86e68d3 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape.h @@ -23,6 +23,10 @@ #ifndef PERSISTENCE_LANDSCAPE_H_ #define PERSISTENCE_LANDSCAPE_H_ +// gudhi include +#include +#include + // standard include #include #include @@ -31,10 +35,9 @@ #include #include #include - -// gudhi include -#include -#include +#include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -323,7 +326,7 @@ class Persistence_landscape { * Vectorized_topological_data */ std::vector vectorize(int number_of_function) const { - // TODO, think of something smarter over here + // TODO(PD) think of something smarter over here std::vector v; if ((size_t)number_of_function > this->land.size()) { return v; @@ -393,7 +396,7 @@ class Persistence_landscape { nextLevelMerge.swap(nextNextLevelMerge); } (*this) = (*nextLevelMerge[0]); - (*this) *= 1 / ((double)to_average.size()); + (*this) *= 1 / static_cast(to_average.size()); } /** @@ -882,7 +885,7 @@ void Persistence_landscape::load_landscape_from_file(const char* filename) { in.open(filename); if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } std::string line; @@ -971,7 +974,7 @@ Persistence_landscape operation_on_pair_of_landscapes(const Persistence_landscap } lambda_n.push_back( std::make_pair(land1.land[i][p].first, - oper((double)land1.land[i][p].second, + oper(static_cast(land1.land[i][p].second), function_value(land2.land[i][q - 1], land2.land[i][q], land1.land[i][p].first)))); ++p; continue; @@ -1085,8 +1088,8 @@ double compute_maximal_distance_non_symmetric(const Persistence_landscape& pl1, } int p2Count = 0; - for (size_t i = 1; i != pl1.land[level].size() - 1; ++i) // In this case, I consider points at the infinity - { + // In this case, I consider points at the infinity + for (size_t i = 1; i != pl1.land[level].size() - 1; ++i) { while (true) { if ((pl1.land[level][i].first >= pl2.land[level][p2Count].first) && (pl1.land[level][i].first <= pl2.land[level][p2Count + 1].first)) @@ -1142,17 +1145,17 @@ double compute_distance_of_landscapes(const Persistence_landscape& first, const } if (p < std::numeric_limits::max()) { - //\int_{- \infty}^{+\infty}| first-second |^p + // \int_{- \infty}^{+\infty}| first-second |^p double result; if (p != 1) { if (dbg) std::cerr << "Power != 1, compute integral to the power p\n"; - result = lan.compute_integral_of_landscape((double)p); + result = lan.compute_integral_of_landscape(p); } else { if (dbg) std::cerr << "Power = 1, compute integral \n"; result = lan.compute_integral_of_landscape(); } - //(\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) - return pow(result, 1 / (double)p); + // (\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) + return pow(result, 1.0 / p); } else { // p == infty if (dbg) std::cerr << "Power = infty, compute maximum \n"; @@ -1232,9 +1235,9 @@ double compute_inner_product(const Persistence_landscape& l1, const Persistence_ } // we have two intervals in which functions are constant: - //[l1.land[level][l1It].first , l1.land[level][l1It+1].first] + // [l1.land[level][l1It].first , l1.land[level][l1It+1].first] // and - //[l2.land[level][l2It].first , l2.land[level][l2It+1].first] + // [l2.land[level][l2It].first , l2.land[level][l2It+1].first] // We also have an interval [x1,x2]. Since the intervals in the landscapes cover the whole R, then it is clear // that x2 // is either l1.land[level][l1It+1].first of l2.land[level][l2It+1].first or both. Lets test it. @@ -1316,6 +1319,6 @@ void Persistence_landscape::plot(const char* filename, double xRangeBegin, doubl } } // namespace Persistence_representations -} // namespace gudhi +} // namespace Gudhi #endif // PERSISTENCE_LANDSCAPE_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h index bea98f74..6eec26d6 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h @@ -24,6 +24,10 @@ #ifndef PERSISTENCE_LANDSCAPE_ON_GRID_H_ #define PERSISTENCE_LANDSCAPE_ON_GRID_H_ +// gudhi include +#include +#include + // standard include #include #include @@ -32,14 +36,9 @@ #include #include #include -#include -#include #include - -// gudhi include - -#include -#include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -165,7 +164,7 @@ class Persistence_landscape_on_grid { double compute_integral_of_landscape(size_t level) const { bool dbg = false; double result = 0; - double dx = (this->grid_max - this->grid_min) / (double)(this->values_of_landscapes.size() - 1); + double dx = (this->grid_max - this->grid_min) / static_cast(this->values_of_landscapes.size() - 1); if (dbg) { std::cerr << "this->grid_max : " << this->grid_max << std::endl; @@ -220,7 +219,7 @@ class Persistence_landscape_on_grid { bool dbg = false; double result = 0; - double dx = (this->grid_max - this->grid_min) / (double)(this->values_of_landscapes.size() - 1); + double dx = (this->grid_max - this->grid_min) / static_cast(this->values_of_landscapes.size() - 1); double previous_x = this->grid_min; double previous_y = 0; if (this->values_of_landscapes[0].size() > level) previous_y = this->values_of_landscapes[0][level]; @@ -279,7 +278,7 @@ class Persistence_landscape_on_grid { * Shall those points be joined with lines, we will obtain the i-th landscape function. **/ friend std::ostream& operator<<(std::ostream& out, const Persistence_landscape_on_grid& land) { - double dx = (land.grid_max - land.grid_min) / (double)(land.values_of_landscapes.size() - 1); + double dx = (land.grid_max - land.grid_min) / static_cast(land.values_of_landscapes.size() - 1); double x = land.grid_min; for (size_t i = 0; i != land.values_of_landscapes.size(); ++i) { out << x << " : "; @@ -306,7 +305,7 @@ class Persistence_landscape_on_grid { if ((x < this->grid_min) || (x > this->grid_max)) return 0; // find a position of a vector closest to x: - double dx = (this->grid_max - this->grid_min) / (double)(this->values_of_landscapes.size() - 1); + double dx = (this->grid_max - this->grid_min) / static_cast(this->values_of_landscapes.size() - 1); size_t position = size_t((x - this->grid_min) / dx); if (dbg) { @@ -338,7 +337,6 @@ class Persistence_landscape_on_grid { std::make_pair(position * dx + this->grid_min, this->values_of_landscapes[position][level]), std::make_pair((position + 1) * dx + this->grid_min, 0)); } else { - //(this->values_of_landscapes[position+1].size() > level) line = compute_parameters_of_a_line( std::make_pair(position * dx + this->grid_min, 0), std::make_pair((position + 1) * dx + this->grid_min, this->values_of_landscapes[position + 1][level])); @@ -623,7 +621,7 @@ class Persistence_landscape_on_grid { throw "Landscapes are not defined on the same grid, the program will now terminate"; double result = 0; - double dx = (l1.grid_max - l1.grid_min) / (double)(l1.values_of_landscapes.size() - 1); + double dx = (l1.grid_max - l1.grid_min) / static_cast(l1.values_of_landscapes.size() - 1); double previous_x = l1.grid_min - dx; double previous_y_l1 = 0; @@ -737,14 +735,14 @@ class Persistence_landscape_on_grid { } if (p < std::numeric_limits::max()) { - //\int_{- \infty}^{+\infty}| first-second |^p + // \int_{- \infty}^{+\infty}| first-second |^p double result; if (p != 1) { if (dbg) { std::cerr << "p : " << p << std::endl; getchar(); } - result = lan.compute_integral_of_landscape((double)p); + result = lan.compute_integral_of_landscape(p); if (dbg) { std::cerr << "integral : " << result << std::endl; getchar(); @@ -756,8 +754,8 @@ class Persistence_landscape_on_grid { getchar(); } } - //(\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) - return pow(result, 1 / (double)p); + // (\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) + return pow(result, 1.0 / p); } else { // p == infty return lan.compute_maximum(); @@ -789,7 +787,7 @@ class Persistence_landscape_on_grid { * Vectorized_topological_data */ std::vector vectorize(int number_of_function) const { - // TODO, think of something smarter over here + // TODO(PD) think of something smarter over here if ((number_of_function < 0) || ((size_t)number_of_function >= this->values_of_landscapes.size())) { throw "Wrong number of function\n"; } @@ -864,7 +862,7 @@ class Persistence_landscape_on_grid { } // normalizing: for (size_t i = 0; i != this->values_of_landscapes[grid_point].size(); ++i) { - this->values_of_landscapes[grid_point][i] /= (double)to_average.size(); + this->values_of_landscapes[grid_point][i] /= static_cast(to_average.size()); } } } // compute_average @@ -979,10 +977,10 @@ void Persistence_landscape_on_grid::set_up_values_of_landscapes(const std::vecto this->grid_max = grid_max_; if (grid_max_ <= grid_min_) { - throw "Wrong parameters of grid_min and grid_max given to the procedure. The grid have negative, or zero size. The program will now terminate.\n"; + throw "Wrong parameters of grid_min and grid_max given to the procedure. The program will now terminate.\n"; } - double dx = (grid_max_ - grid_min_) / (double)(number_of_points_); + double dx = (grid_max_ - grid_min_) / static_cast(number_of_points_); // for every interval in the diagram: for (size_t int_no = 0; int_no != p.size(); ++int_no) { size_t grid_interval_begin = (p[int_no].first - grid_min_) / dx; @@ -1161,7 +1159,7 @@ void Persistence_landscape_on_grid::load_landscape_from_file(const char* filenam // check if the file exist. if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } size_t number_of_points_in_the_grid = 0; @@ -1223,7 +1221,7 @@ void Persistence_landscape_on_grid::plot(const char* filename, double min_x, dou } size_t number_of_nonzero_levels = this->number_of_nonzero_levels(); - double dx = (this->grid_max - this->grid_min) / ((double)this->values_of_landscapes.size() - 1); + double dx = (this->grid_max - this->grid_min) / static_cast(this->values_of_landscapes.size() - 1); size_t from = 0; if (from_ != std::numeric_limits::max()) { diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h index 282c107d..ad4d3c57 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h +++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h @@ -23,17 +23,19 @@ #ifndef PERSISTENCE_VECTORS_H_ #define PERSISTENCE_VECTORS_H_ +// gudhi include +#include +#include +#include + #include #include #include #include #include #include - -// gudhi include -#include -#include -#include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -66,7 +68,7 @@ class Vector_distances_in_diagram { /** * The default constructor. **/ - Vector_distances_in_diagram(){}; + Vector_distances_in_diagram(){} /** * The constructor that takes as an input a multiset of persistence intervals (given as vector of birth-death @@ -517,7 +519,7 @@ void Vector_distances_in_diagram::compute_average(const std::vector(to_average.size()); } this->sorted_vector_of_distances = av; this->where_to_cut = av.size(); @@ -611,7 +613,7 @@ void Vector_distances_in_diagram::load_from_file(const char* filename) { // check if the file exist. if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } double number; diff --git a/src/Persistence_representations/include/gudhi/common_persistence_representations.h b/src/Persistence_representations/include/gudhi/common_persistence_representations.h index 8f56ad3e..61a3274d 100644 --- a/src/Persistence_representations/include/gudhi/common_persistence_representations.h +++ b/src/Persistence_representations/include/gudhi/common_persistence_representations.h @@ -23,6 +23,9 @@ #ifndef COMMON_PERSISTENCE_REPRESENTATIONS_H_ #define COMMON_PERSISTENCE_REPRESENTATIONS_H_ +#include +#include + namespace Gudhi { namespace Persistence_representations { // this file contain an implementation of some common procedures used in Persistence_representations. diff --git a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h index a5c2b286..ad3d4e83 100644 --- a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h +++ b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h @@ -28,6 +28,8 @@ #include #include #include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -54,7 +56,7 @@ std::vector > read_persistence_intervals_in_one_dimens // checking if the file exist: if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } std::string line; @@ -85,7 +87,7 @@ std::vector > read_persistence_intervals_in_one_dimens while (ss >> number) { this_line.push_back(number); } - number_of_entries_per_line += (int)this_line.size(); + number_of_entries_per_line += static_cast(this_line.size()); if (dbg) { std::cerr << "number_of_entries_per_line : " << number_of_entries_per_line << ". This number was obtained by analyzing this line : " << line << std::endl; @@ -93,7 +95,7 @@ std::vector > read_persistence_intervals_in_one_dimens if ((number_of_entries_per_line < 2) || (number_of_entries_per_line > 4)) { std::cerr << "The input file you have provided have wrong number of numerical entries per line. The program " "will now terminate. \n"; - throw "The input file you have provided have wrong number of numerical entries per line. The program will now terminate. \n"; + throw "Wrong number of numerical entries per line in the input file. The program will now terminate. \n"; } } // In case there is an 'inf' string in this line, we are dealing with this situation in below. diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp index b0ea3a35..b4e2be89 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp @@ -26,6 +26,7 @@ using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include +#include int main(int argc, char** argv) { std::cout << "This program computes average persistence landscape of persistence landscapes created based on " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp index f87530d4..56b2d336 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute distance of persistence heat maps stored in a file (the file needs to be created " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp index f801d056..ec9482f0 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp @@ -27,6 +27,7 @@ using namespace Gudhi::Persistence_representations; #include #include +#include int main(int argc, char** argv) { std::cout << "This program compute scalar product of persistence landscapes stored in a file (the file needs to be " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp index a127996f..68c75059 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp index 371d94a6..a56393a3 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp index e2b9abb1..44115329 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp index 03f1641a..ebc82f82 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence heat map of diagrams provided as an input.\n"; diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp index 004fa90e..7b24bb7c 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates PSSK of diagrams provided as an input.\n"; diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp index 058677d9..72c56e92 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp index f1ccda9f..6a872b7a 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp @@ -28,6 +28,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute the bottleneck distance of persistence diagrams stored in a files. \n"; diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp index 1f7011e1..5fbbef14 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp @@ -24,6 +24,9 @@ #include #include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp index 6bdb0081..b8f96b60 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp @@ -24,6 +24,9 @@ #include #include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp index 206745c1..521621b2 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp @@ -24,6 +24,9 @@ #include #include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp index 971f039e..e76906e9 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp index 1927551d..f885a7a7 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp @@ -26,6 +26,7 @@ using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include +#include int main(int argc, char** argv) { std::cout << "This program computes average persistence landscape of persistence landscapes created based on " diff --git a/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp index a4027fa7..7028b98b 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp @@ -27,6 +27,7 @@ using namespace Gudhi::Persistence_representations; #include #include +#include int main(int argc, char** argv) { std::cout << "This program compute distance of persistence landscapes stored in a file (the file needs to be created " diff --git a/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp index 95d5a998..76a9d433 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp @@ -27,6 +27,7 @@ using namespace Gudhi::Persistence_representations; #include #include +#include int main(int argc, char** argv) { std::cout << "This program compute scalar product of persistence landscapes stored in a file (the file needs to be " diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp index 1ba34762..4694e897 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute distance of persistence landscapes on grid stored in a file (the file needs to be " diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp index 4ec9a740..75c33cb1 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp @@ -27,6 +27,7 @@ using namespace Gudhi::Persistence_representations; #include #include +#include int main(int argc, char** argv) { std::cout << "This program compute scalar product of persistence landscapes on grid stored in a file (the file needs " diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp index 65addbe5..490a1c25 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence landscape on grid of diagrams provided as an input.\n"; @@ -66,7 +68,7 @@ int main(int argc, char** argv) { if ((min_ != -1) || (max_ != -1)) { l = Persistence_landscape_on_grid(filenames[i], min_, max_, size_of_grid, dimension); } else { - //(min_ == -1) && (max_ == -1), in this case the program will find min_ and max_ based on the data. + // (min_ == -1) && (max_ == -1), in this case the program will find min_ and max_ based on the data. l = Persistence_landscape_on_grid(filenames[i], size_of_grid, dimension); } std::stringstream ss; diff --git a/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp index 2bfc4a6d..585f2f61 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp @@ -26,6 +26,7 @@ using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include +#include int main(int argc, char** argv) { std::cout << "This program computes average persistence vector of persistence vectors created based on persistence " diff --git a/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp index a2e27612..79906262 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute distance of persistence vectors stored in a file (the file needs to be created " diff --git a/src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp index 95f2d2ae..a5916ed8 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute scalar product of persistence vectors stored in a file (the file needs to be " diff --git a/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp index 2996f49b..0941308f 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence vectors of diagrams provided as an input. The first parameter of this " diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index f683136b..e52fc611 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -26,6 +26,7 @@ #include // for std::sqrt #include // for std::decay #include // for std::begin, std::end +#include namespace Gudhi { @@ -49,8 +50,7 @@ class Euclidean_distance { return std::sqrt(dist); } template< typename T > - T operator() ( const std::pair< T,T >& f , const std::pair< T,T >& s ) - { + T operator() ( const std::pair< T, T >& f , const std::pair< T, T >& s ) { return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); } }; -- cgit v1.2.3 From 3736caa9ed742f985d743b9c959442d331110050 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 31 May 2017 06:46:24 +0000 Subject: Fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2481 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3e39324360996e408351421a2185c2cd9e6ee1ae --- .../doc/Persistence_representations_doc.h | 321 ++++++++++----------- .../include/gudhi/Persistence_vectors.h | 2 +- .../persistence_landscapes/create_landscapes.cpp | 2 + src/common/include/gudhi/distance_functions.h | 4 +- 4 files changed, 165 insertions(+), 164 deletions(-) (limited to 'src/common/include') diff --git a/src/Persistence_representations/doc/Persistence_representations_doc.h b/src/Persistence_representations/doc/Persistence_representations_doc.h index 7884574d..49a1cdd0 100644 --- a/src/Persistence_representations/doc/Persistence_representations_doc.h +++ b/src/Persistence_representations/doc/Persistence_representations_doc.h @@ -34,223 +34,222 @@ namespace Persistence_representations { * @{ *\section Persistence_representations_idea Idea - *In order to perform most of the statistical tests and machine learning algorithms on a data one need to be able to + In order to perform most of the statistical tests and machine learning algorithms on a data one need to be able to perform only a very limited number of operations on them. Let us fix a representation of - * data of a type A. To perform most of the statistical and machine learning operations one need to be able to compute + data of a type A. To perform most of the statistical and machine learning operations one need to be able to compute average of objects of type A (so that the averaged object is also of a type A), to - * compute distance between objects of a type A, to vectorize object of a type A and to compute scalar product of a pair + compute distance between objects of a type A, to vectorize object of a type A and to compute scalar product of a pair objects of a type A. - * - *To put this statement into a context, let us assume we have two collections \f$ c_1,\ldots,c_n\f$ and + + To put this statement into a context, let us assume we have two collections \f$ c_1,\ldots,c_n\f$ and \f$d_1,...,d_n\f$ of objects of a type A. We want to verify if the average of those two collections - * are different by performing a permutation test. - *First of all, we compute averages of those two collections: C average of \f$ c_1,\ldots,c_n \f$ and D average of + are different by performing a permutation test. + First of all, we compute averages of those two collections: C average of \f$ c_1,\ldots,c_n \f$ and D average of \f$d_1,\ldots,d_n\f$. Note that both C and D are of a type A. Then we compute \f$d(C,D)\f$, - * a distance between C and D. - *Later we put the two collections into one bin: - *\f[B = \{ c_1,...,c_n,d_1,...,d_n \}\f] - *Then we shuffle B, and we divide the shuffled version of B into two classes: \f$B_1\f$ and \f$B_2\f$ (in this case, of + a distance between C and D. + Later we put the two collections into one bin: + \f[B = \{ c_1,...,c_n,d_1,...,d_n \}\f] + Then we shuffle B, and we divide the shuffled version of B into two classes: \f$B_1\f$ and \f$B_2\f$ (in this case, of the same cardinality). Then we compute averages \f$\hat{B_1}\f$ and \f$\hat{B_2}\f$ - * of elements in \f$B_1\f$ and \f$B_2\f$. Note that again, \f$\hat{B_1}\f$ and \f$\hat{B_2}\f$ are of a type A. - *Then we compute their distance \f$d(\hat{B_1},\hat{B_2})\f$. The procedure of shuffling and dividing the set \f$B\f$ + of elements in \f$B_1\f$ and \f$B_2\f$. Note that again, \f$\hat{B_1}\f$ and \f$\hat{B_2}\f$ are of a type A. + Then we compute their distance \f$d(\hat{B_1},\hat{B_2})\f$. The procedure of shuffling and dividing the set \f$B\f$ is repeated \f$N\f$ times (where \f$N\f$ is reasonably large number). - *Then the p-value of a statement that the averages of \f$c_1,...,c_n\f$ and \f$d_1,...,d_n\f$ is approximated by the + Then the p-value of a statement that the averages of \f$c_1,...,c_n\f$ and \f$d_1,...,d_n\f$ is approximated by the number of times \f$d(\hat{B_1},\hat{B_2}) > d(C,D)\f$ divided by \f$N\f$. - * - *The permutation test reminded above can be performed for any type A which can be averaged, and which allows for + + The permutation test reminded above can be performed for any type A which can be averaged, and which allows for computations of distances. - * - *The Persistence\_representations contains a collection of various representations of persistent homology that + + The Persistence\_representations contains a collection of various representations of persistent homology that implements various concepts described below: - * - *\li Concept of a representation of persistence that allows averaging (so that the average object is of the same type). - *\li Concept of representation of persistence that allows computations of distances. - *\li Concept of representation of persistence that allows computations of scalar products. - *\li Concept of representation of persistence that allows vectorization. - *\li Concept of representation of persistence that allows computations of real--valued characteristics of objects. - * - * - *At the moment an implementation of the following representations of persistence are available (further details of + + \li Concept of a representation of persistence that allows averaging (so that the average object is of the same type). + \li Concept of representation of persistence that allows computations of distances. + \li Concept of representation of persistence that allows computations of scalar products. + \li Concept of representation of persistence that allows vectorization. + \li Concept of representation of persistence that allows computations of real--valued characteristics of objects. + + + At the moment an implementation of the following representations of persistence are available (further details of those representations will be discussed later): - * - *\li Exact persistence landscapes (allow averaging, computation of distances, scalar products, vectorizations and real + + \li Exact persistence landscapes (allow averaging, computation of distances, scalar products, vectorizations and real value characteristics). - *\li Persistence landscapes on a grid (allow averaging, computation of distances scalar products, vectorizations and + \li Persistence landscapes on a grid (allow averaging, computation of distances scalar products, vectorizations and real value characteristics). - *\li Persistence heat maps – various representations where one put some weighted or not Gaussian kernel for each point + \li Persistence heat maps – various representations where one put some weighted or not Gaussian kernel for each point of diagram (allow averaging, computation of distances, scalar products, - * vectorizations and real value characteristics). - *\li Persistence vectors (allow averaging, computation of distances, scalar products, vectorizations and real value + vectorizations and real value characteristics). + \li Persistence vectors (allow averaging, computation of distances, scalar products, vectorizations and real value characteristics). - *\li Persistence diagrams / barcodes (allow computation of distances, vectorizations and real value characteristics). - * - * - * Note that at the while functionalities like averaging, distances and scalar products are fixed, there is no canonical + \li Persistence diagrams / barcodes (allow computation of distances, vectorizations and real value characteristics). + + + Note that at the while functionalities like averaging, distances and scalar products are fixed, there is no canonical way of vectorizing and computing real valued characteristics of objects. Therefore the - * vectorizations and computation of real value characteristics procedures are quite likely to evolve in the furthering + vectorizations and computation of real value characteristics procedures are quite likely to evolve in the furthering versions of the library. - * - * The main aim of this implementation is to be able to implement various statistical methods, both on the level of C++ + + The main aim of this implementation is to be able to implement various statistical methods, both on the level of C++ and on the level of python. The methods will operate on the functionalities offered - * by concepts. That means that the statistical and ML methods will be able to operate on any representation that + by concepts. That means that the statistical and ML methods will be able to operate on any representation that implement the required concept (including the ones that are not in the library at the moment). - * That gives provides a framework, that is very easy to extend, for topological statistics. - * - * Below we are discussing the representations which are currently implemented in Persistence\_representations package: - * - * \section sec_persistence_landscapes Persistence Landscapes - * Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape
- * Persistence landscapes were originally proposed by Bubenik in \cite bubenik_landscapes_2015. Efficient algorithms to + That gives provides a framework, that is very easy to extend, for topological statistics. + + Below we are discussing the representations which are currently implemented in Persistence\_representations package: + + \section sec_persistence_landscapes Persistence Landscapes + Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape
+ Persistence landscapes were originally proposed by Bubenik in \cite bubenik_landscapes_2015. Efficient algorithms to compute them rigorously were proposed by Bubenik and Dlotko in \cite bubenik_dlotko_landscapes_2016. The idea of - * persistence landscapes is shortly summarized in below. - * - * To begin with, suppose we are given a point \f$(b,d) \in \mathbb{R}^2\f$ in a - * persistence diagram. With this point, we associate a piecewise - * linear function \f$f_{(b,d)} : \mathbb{R} \rightarrow [0,\infty)\f$, which is - * defined as - * - * \f[f_{(b,d)}(x) = - * \left\{ \begin{array}{ccl} - * 0 & \mbox{ if } & x \not\in (b, d) \; , \\ - * x - b & \mbox{ if } & x \in \left( b, \frac{b+d}{2} - * \right] \; , \\ - * d - x & \mbox{ if } & x \in \left(\frac{b+d}{2}, - * d \right) \; . - * \end{array} \right. - *\f] - * - * A persistence landscape of the birth-death - * pairs \f$(b_i , d_i)\f$, where \f$i = 1,\ldots,m\f$, which constitute the given - * persistence diagram is the sequence of functions \f$\lambda_k : \mathbb{R} \rightarrow [0,\infty)\f$ for \f$k \in + persistence landscapes is shortly summarized in below. + + To begin with, suppose we are given a point \f$(b,d) \in \mathbb{R}^2\f$ in a + persistence diagram. With this point, we associate a piecewise + linear function \f$f_{(b,d)} : \mathbb{R} \rightarrow [0,\infty)\f$, which is + defined as + + \f[f_{(b,d)}(x) = + \left\{ \begin{array}{ccl} + 0 & \mbox{ if } & x \not\in (b, d) \; , \\ + x - b & \mbox{ if } & x \in \left( b, \frac{b+d}{2} + \right] \; , \\ + d - x & \mbox{ if } & x \in \left(\frac{b+d}{2}, + d \right) \; . + \end{array} \right. + \f] + + A persistence landscape of the birth-death + pairs \f$(b_i , d_i)\f$, where \f$i = 1,\ldots,m\f$, which constitute the given + persistence diagram is the sequence of functions \f$\lambda_k : \mathbb{R} \rightarrow [0,\infty)\f$ for \f$k \in \mathbb{N}\f$, where \f$\lambda_k(x)\f$ - * denotes the \f$k^{\rm th}\f$ largest value of the numbers \f$f_{(b_i,d_i)}(x)\f$, - * for \f$i = 1, \ldots, m\f$, and we define \f$\lambda_k(x) = 0\f$ if \f$k > m\f$. - * Equivalently, this sequence of functions can be combined into a single - * function \f$L : \mathbb{N} \times \mathbb{R} \to [0,\infty)\f$ of two - * variables, if we define \f$L(k,t) = \lambda_k(t)\f$. - * - * The detailed description of algorithms used to compute persistence landscapes can be found in \cite - bubenik_dlotko_landscapes_2016. - * Note that this implementation provides exact representation of landscapes. That have many advantages, but also a few + denotes the \f$k^{\rm th}\f$ largest value of the numbers \f$f_{(b_i,d_i)}(x)\f$, + for \f$i = 1, \ldots, m\f$, and we define \f$\lambda_k(x) = 0\f$ if \f$k > m\f$. + Equivalently, this sequence of functions can be combined into a single + function \f$L : \mathbb{N} \times \mathbb{R} \to [0,\infty)\f$ of two + variables, if we define \f$L(k,t) = \lambda_k(t)\f$. + + The detailed description of algorithms used to compute persistence landscapes can be found in + \cite bubenik_dlotko_landscapes_2016. + Note that this implementation provides exact representation of landscapes. That have many advantages, but also a few drawbacks. For instance, as discussed - * in \cite bubenik_dlotko_landscapes_2016, the exact representation of landscape may be of quadratic size with respect + in \cite bubenik_dlotko_landscapes_2016, the exact representation of landscape may be of quadratic size with respect to the input persistence diagram. It may therefore happen - * that, for very large diagrams, using this representation may be memory--prohibitive. In such a case, there are two + that, for very large diagrams, using this representation may be memory--prohibitive. In such a case, there are two possible ways to proceed: - * - *\li Use non exact representation on a grid described in the Section \ref sec_landscapes_on_grid. - *\li Compute just a number of initial nonzero landscapes. This option is available from C++ level. - * - * - * - *\section sec_landscapes_on_grid Persistence Landscapes on a grid - * Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape_on_grid
- * This is an alternative, not--exact, representation of persistence landscapes defined in the Section \ref + + \li Use non exact representation on a grid described in the Section \ref sec_landscapes_on_grid. + \li Compute just a number of initial nonzero landscapes. This option is available from C++ level. + + + + \section sec_landscapes_on_grid Persistence Landscapes on a grid + Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape_on_grid
+ This is an alternative, not--exact, representation of persistence landscapes defined in the Section \ref sec_persistence_landscapes. Unlike in the Section \ref sec_persistence_landscapes we build a - * representation of persistence landscape by sampling its values on a finite, equally distributed grid of points. - * Since, the persistence landscapes that originate from persistence diagrams have slope \f$1\f$ or \f$-1\f$, we have an + representation of persistence landscape by sampling its values on a finite, equally distributed grid of points. + Since, the persistence landscapes that originate from persistence diagrams have slope \f$1\f$ or \f$-1\f$, we have an estimate of a region between the grid points where the landscape cab be located. - * That allows to estimate an error make when performing various operations on landscape. Note that for average + That allows to estimate an error make when performing various operations on landscape. Note that for average landscapes the slope is in range \f$[-1,1]\f$ and similar estimate can be used. - * - * Due to a lack of rigorous description of the algorithms to deal with this non--rigorous representation of persistence + + Due to a lack of rigorous description of the algorithms to deal with this non--rigorous representation of persistence landscapes in the literature, we are providing a short discussion of them in below. - * - *Let us assume that we want to compute persistence landscape on a interval \f$[x,y]\f$. Let us assume that we want to + + Let us assume that we want to compute persistence landscape on a interval \f$[x,y]\f$. Let us assume that we want to use \f$N\f$ grid points for that purpose. - * Then we will sample the persistence landscape on points \f$x_1 = x , x_2 = x + \frac{y-x}{N}, \ldots , x_{N} = y\f$. + Then we will sample the persistence landscape on points \f$x_1 = x , x_2 = x + \frac{y-x}{N}, \ldots , x_{N} = y\f$. Persistence landscapes are represented as a vector of - * vectors of real numbers. Assume that i-th vector consist of \f$n_i\f$ numbers sorted from larger to smaller. They + vectors of real numbers. Assume that i-th vector consist of \f$n_i\f$ numbers sorted from larger to smaller. They represent the values of the functions \f$\lambda_1,\ldots,\lambda_{n_i}\f$ ,\f$\lambda_{n_i+1}\f$ and the functions with larger indices are then zero functions) on the i-th point of a grid, i.e. \f$x + i \frac{y-x}{N}\f$. - * - *When averaging two persistence landscapes represented by a grid we need to make sure that they are defined in a + + When averaging two persistence landscapes represented by a grid we need to make sure that they are defined in a compatible grids. I.e. the intervals \f$[x,y]\f$ on which they are defined are - * the same, and the numbers of grid points \f$N\f$ are the same in both cases. If this is the case, we simply compute + the same, and the numbers of grid points \f$N\f$ are the same in both cases. If this is the case, we simply compute point-wise averages of the entries of corresponding - * vectors (In this whole section we assume that if one vector of numbers is shorter than another, we extend the shorter + vectors (In this whole section we assume that if one vector of numbers is shorter than another, we extend the shorter one with zeros so that they have the same length.) - * - *Computations of distances between two persistence landscapes on a grid is not much different than in the rigorous + + Computations of distances between two persistence landscapes on a grid is not much different than in the rigorous case. In this case, we sum up the distances between the same levels of - * corresponding landscapes. For fixed level, we approximate the landscapes between the corresponding constitutive + corresponding landscapes. For fixed level, we approximate the landscapes between the corresponding constitutive points of landscapes by linear functions, and compute the \f$L^p\f$ distance between them. - * - *Similarly as in case of distance, when computing the scalar product of two persistence landscapes on a grid, we sum up + + Similarly as in case of distance, when computing the scalar product of two persistence landscapes on a grid, we sum up the scalar products of corresponding levels of landscapes. For each level, - * we assume that the persistence landscape on a grid between two grid points is approximated by linear function. + we assume that the persistence landscape on a grid between two grid points is approximated by linear function. Therefore to compute scalar product of two corresponding levels of landscapes, - * we sum up the integrals of products of line segments for every pair of constitutive grid points. - * - *Note that for this representation we need to specify a few parameters: - * - *\li Begin and end point of a grid -- the interval \f$[x,y]\f$ (real numbers). - *\li Number of points in a grid (positive integer \f$N\f$). - * - * - *Note that the same representation is used in TDA R-package \cite Fasy_Kim_Lecci_Maria_tda. - * - *\section sec_persistence_heat_maps Persistence heat maps - * Reference manual: \ref Gudhi::Persistence_representations::Persistence_heat_maps
- *This is a general class of discrete structures which are based on idea of placing a kernel in the points of + we sum up the integrals of products of line segments for every pair of constitutive grid points. + + Note that for this representation we need to specify a few parameters: + + \li Begin and end point of a grid -- the interval \f$[x,y]\f$ (real numbers). + \li Number of points in a grid (positive integer \f$N\f$). + + + Note that the same representation is used in TDA R-package \cite Fasy_Kim_Lecci_Maria_tda. + + \section sec_persistence_heat_maps Persistence heat maps + Reference manual: \ref Gudhi::Persistence_representations::Persistence_heat_maps
+ This is a general class of discrete structures which are based on idea of placing a kernel in the points of persistence diagrams. - *This idea appeared in work by many authors over the last 15 years. As far as we know this idea was firstly described + This idea appeared in work by many authors over the last 15 years. As far as we know this idea was firstly described in the work of Bologna group in \cite Ferri_Frosini_comparision_sheme_1 and \cite Ferri_Frosini_comparision_sheme_2. - *Later it has been described by Colorado State University group in \cite Persistence_Images_2017. The presented paper + Later it has been described by Colorado State University group in \cite Persistence_Images_2017. The presented paper in the first time provide a discussion of stability of the representation. - *Also, the same ideas are used in construction of two recent kernels used for machine learning: \cite - Kusano_Fukumizu_Hiraoka_PWGK and \cite Reininghaus_Huber_ALL_PSSK. Both the kernel's construction uses interesting - ideas to - *ensure stability of the representation with respect to Wasserstein metric. In the kernel presented in \cite - Kusano_Fukumizu_Hiraoka_PWGK, a scaling function is used to multiply the Gaussian kernel in the - *way that the points close to diagonal got low weight and consequently do not have a big influence on the resulting + Also, the same ideas are used in construction of two recent kernels used for machine learning: + \cite Kusano_Fukumizu_Hiraoka_PWGK and \cite Reininghaus_Huber_ALL_PSSK. Both the kernel's construction uses + interesting ideas to ensure stability of the representation with respect to Wasserstein metric. In the kernel + presented in \cite Kusano_Fukumizu_Hiraoka_PWGK, a scaling function is used to multiply the Gaussian kernel in the + way that the points close to diagonal got low weight and consequently do not have a big influence on the resulting distribution. In \cite Reininghaus_Huber_ALL_PSSK for every point \f$(b,d)\f$ two Gaussian kernels - *are added: first, with a weight 1 in a point \f$(b,d)\f$, and the second, with the weight -1 for a point \f$(b,d)\f$. + are added: first, with a weight 1 in a point \f$(b,d)\f$, and the second, with the weight -1 for a point \f$(b,d)\f$. In both cases, the representations are stable with respect to 1-Wasserstein distance. - * - *In Persistence\_representations package we currently implement a discretization of the distributions described above. + + In Persistence\_representations package we currently implement a discretization of the distributions described above. The base of this implementation is 2-dimensional array of pixels. Each pixel have assigned a real value which - * is a sum of values of distributions induced by each point of the persistence diagram. At the moment we compute the + is a sum of values of distributions induced by each point of the persistence diagram. At the moment we compute the sum of values on a center of a pixels. It can be easily extended to any other function - * (like for instance sum of integrals of the intermediate distribution on a pixel). - * - *The parameters that determine the structure are the following: - * - *\li A positive integer k determining the size of the kernel we used (we always assume that the kernels are square). - *\li A filter: in practice a square matrix of a size \f$2k+1 \times 2k+1\f$. By default, this is a discretization of + (like for instance sum of integrals of the intermediate distribution on a pixel). + + The parameters that determine the structure are the following: + + \li A positive integer k determining the size of the kernel we used (we always assume that the kernels are square). + \li A filter: in practice a square matrix of a size \f$2k+1 \times 2k+1\f$. By default, this is a discretization of N(0,1) kernel. - *\li The box \f$[x_0,x_1]\times [y_0,y_1]\f$ bounding the domain of the persistence image. - *\li Scaling function. Each Gaussian kernel at point \f$(p,q)\f$ gets multiplied by the value of this function at the + \li The box \f$[x_0,x_1]\times [y_0,y_1]\f$ bounding the domain of the persistence image. + \li Scaling function. Each Gaussian kernel at point \f$(p,q)\f$ gets multiplied by the value of this function at the point \f$(p,q)\f$. - *\li A boolean value determining if the space below diagonal should be erased or not. To be precise: when points close + \li A boolean value determining if the space below diagonal should be erased or not. To be precise: when points close to diagonal are given then sometimes the kernel have support that reaches the region - *below the diagonal. If the value of this parameter is true, then the values below diagonal can be erased. - * - * - *\section sec_persistence_vectors Persistence vectors - * Reference manual: \ref Gudhi::Persistence_representations::Vector_distances_in_diagram
- *This is a representation of persistent homology in a form of a vector which was designed for an application in 3d + below the diagonal. If the value of this parameter is true, then the values below diagonal can be erased. + + + \section sec_persistence_vectors Persistence vectors + Reference manual: \ref Gudhi::Persistence_representations::Vector_distances_in_diagram
+ This is a representation of persistent homology in a form of a vector which was designed for an application in 3d graphic in \cite Carriere_Oudot_Ovsjanikov_top_signatures_3d. Below we provide a short description of this representation. - * - *Given a persistence diagram \f$D = \{ (b_i,d_i) \}\f$, for every pair of birth--death points \f$(b_1,d_1)\f$ and + + Given a persistence diagram \f$D = \{ (b_i,d_i) \}\f$, for every pair of birth--death points \f$(b_1,d_1)\f$ and \f$(b_2,d_2)\f$ we compute the following three distances: - * - *\li \f$d( (b_1,d_1) , (b_2,d_2) )\f$. - *\li \f$d( (b_1,d_1) , (\frac{b_1,d_1}{2},\frac{b_1,d_1}{2}) )\f$. - *\li \f$d( (b_2,d_2) , (\frac{b_2,d_2}{2},\frac{b_2,d_2}{2}) )\f$. - * - *We pick the smallest of those and add it to a vector. The obtained vector of numbers is then sorted in decreasing + + \li \f$d( (b_1,d_1) , (b_2,d_2) )\f$. + \li \f$d( (b_1,d_1) , (\frac{b_1,d_1}{2},\frac{b_1,d_1}{2}) )\f$. + \li \f$d( (b_2,d_2) , (\frac{b_2,d_2}{2},\frac{b_2,d_2}{2}) )\f$. + + We pick the smallest of those and add it to a vector. The obtained vector of numbers is then sorted in decreasing order. This way we obtain a persistence vector representing the diagram. - * - *Given two persistence vectors, the computation of distances, averages and scalar products is straightforward. Average + + Given two persistence vectors, the computation of distances, averages and scalar products is straightforward. Average is simply a coordinate-wise average of a collection of vectors. In this section we - * assume that the vectors are extended by zeros if they are of a different size. To compute distances we compute + assume that the vectors are extended by zeros if they are of a different size. To compute distances we compute absolute value of differences between coordinates. A scalar product is a sum of products of - * values at the corresponding positions of two vectors. - * - * \copyright GNU General Public License v3. + values at the corresponding positions of two vectors. + + \copyright GNU General Public License v3. */ /** @} */ // end defgroup Persistence_representations diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h index ad4d3c57..0fb49eee 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h +++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h @@ -68,7 +68,7 @@ class Vector_distances_in_diagram { /** * The default constructor. **/ - Vector_distances_in_diagram(){} + Vector_distances_in_diagram() {} /** * The constructor that takes as an input a multiset of persistence intervals (given as vector of birth-death diff --git a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp index 1692c7ac..a6b33225 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence landscapes of diagrams provided as an input. \n"; diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index e52fc611..c556155e 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -50,8 +50,8 @@ class Euclidean_distance { return std::sqrt(dist); } template< typename T > - T operator() ( const std::pair< T, T >& f , const std::pair< T, T >& s ) { - return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); + T operator() (const std::pair< T, T >& f, const std::pair< T, T >& s) { + return sqrt((f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second)); } }; -- cgit v1.2.3 From f583b644e6bb34e6289c17fa33e34f52897a6329 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 13 Jun 2017 15:27:43 +0000 Subject: Merge read_persistence_from_file into persistence_representation_integration git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2539 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2bfc0f855b4814946c5cad892d6314d147db1caf --- src/Bottleneck_distance/example/CMakeLists.txt | 4 ++ .../example/bottleneck_read_file_example.cpp | 36 ++-------- src/common/doc/file_formats.h | 54 +++++++++++++++ src/common/include/gudhi/reader_utils.h | 76 +++++++++++++++++++++- 4 files changed, 139 insertions(+), 31 deletions(-) create mode 100644 src/common/doc/file_formats.h (limited to 'src/common/include') diff --git a/src/Bottleneck_distance/example/CMakeLists.txt b/src/Bottleneck_distance/example/CMakeLists.txt index 0534a2c4..508e57bf 100644 --- a/src/Bottleneck_distance/example/CMakeLists.txt +++ b/src/Bottleneck_distance/example/CMakeLists.txt @@ -19,6 +19,10 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.15" "-m" "0.12" "-d" "3" "-p" "3") + add_test(NAME Bottleneck_read_file_example + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers") + install(TARGETS bottleneck_read_file_example DESTINATION bin) install(TARGETS bottleneck_basic_example DESTINATION bin) install(TARGETS alpha_rips_persistence_bottleneck_distance DESTINATION bin) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index bde05825..238d99ad 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -20,9 +20,8 @@ * along with this program. If not, see . */ -#define CGAL_HAS_THREADS - #include +#include #include #include #include // for pair @@ -30,43 +29,22 @@ #include #include -std::vector< std::pair > read_diagram_from_file(const char* filename) { - std::ifstream in; - in.open(filename); - std::vector< std::pair > result; - if (!in.is_open()) { - std::cerr << "File : " << filename << " do not exist. The program will now terminate \n"; - throw "File do not exist \n"; - } - - std::string line; - while (!in.eof()) { - getline(in, line); - if (line.length() != 0) { - std::stringstream lineSS; - lineSS << line; - double beginn, endd; - lineSS >> beginn; - lineSS >> endd; - result.push_back(std::make_pair(beginn, endd)); - } - } - in.close(); - return result; -} // read_diagram_from_file - int main(int argc, char** argv) { if (argc < 3) { std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file " << "should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << " distance (set by default to zero). The program will now terminate \n"; + return -1; } - std::vector< std::pair< double, double > > diag1 = read_diagram_from_file(argv[1]); - std::vector< std::pair< double, double > > diag2 = read_diagram_from_file(argv[2]); + std::vector> diag1 = read_persistence_intervals_in_dimension(argv[1]); + std::vector> diag2 = read_persistence_intervals_in_dimension(argv[2]); + double tolerance = 0.; if (argc == 4) { tolerance = atof(argv[3]); } double b = Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, tolerance); std::cout << "The distance between the diagrams is : " << b << ". The tolerance is : " << tolerance << std::endl; + + return 0; } diff --git a/src/common/doc/file_formats.h b/src/common/doc/file_formats.h new file mode 100644 index 00000000..c145b271 --- /dev/null +++ b/src/common/doc/file_formats.h @@ -0,0 +1,54 @@ +/* This file is part of the Gudhi Library. The Gudhi library +* (Geometric Understanding in Higher Dimensions) is a generic C++ +* library for computational topology. +* +* Author(s): Clément Jamin +* +* Copyright (C) 2017 INRIA +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef DOC_COMMON_FILE_FORMAT_H_ +#define DOC_COMMON_FILE_FORMAT_H_ + +namespace Gudhi { + +/*! \page fileformats File formats + + \tableofcontents + + \section FileFormatsPers Persistence Diagram + + Such a file, whose extension is usually `.pers`, contains a list of persistence intervals.
+ Lines starting with `#` are ignored (comments).
+ Other lines might contain 2, 3 or 4 values (the number of values on each line must be the same for all lines): + \code{.unparsed} + [[field] dimension] birth death + \endcode + + Here is a simple sample file: + \code{.unparsed} + # Beautiful persistence diagram + 2 2.7 3.7 + 2 9.6 14. + 3 34.2 34.974 + 4 3. inf + \endcode + + Other sample files can be found in the `data/persistence_diagram` folder. +*/ +} // namespace Gudhi + +#endif // DOC_COMMON_FILE_FORMAT_H_ diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 97a87edd..35af09bd 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -2,7 +2,7 @@ * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * - * Author(s): Clement Maria, Pawel Dlotko + * Author(s): Clement Maria, Pawel Dlotko, Clement Jamin * * Copyright (C) 2014 INRIA * @@ -24,6 +24,8 @@ #define READER_UTILS_H_ #include +#include +#include #include @@ -92,7 +94,10 @@ template< typename Graph_t, typename Filtration_value, typename Vertex_handle > Graph_t read_graph(std::string file_name) { std::ifstream in_(file_name.c_str(), std::ios::in); if (!in_.is_open()) { - std::cerr << "Unable to open file " << file_name << std::endl; + std::string error_str("read_graph - Unable to open file "); + error_str.append(file_name); + std::cerr << error_str << std::endl; + throw std::invalid_argument(error_str); } typedef std::pair< Vertex_handle, Vertex_handle > Edge_t; @@ -295,4 +300,71 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from return result; } // read_lower_triangular_matrix_from_csv_file +/** +Reads a file containing persistence intervals. +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death +The output iterator `out` is used this way: `*out++ = std::make_tuple(dim, birth, death);` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +**/ +template +void read_persistence_intervals_and_dimension(std::string const& filename, OutputIterator out) { + + std::ifstream in(filename); + if (!in.is_open()) { + std::string error_str("read_persistence_intervals_and_dimension - Unable to open file "); + error_str.append(filename); + std::cerr << error_str << std::endl; + throw std::invalid_argument(error_str); + } + + while (!in.eof()) { + std::string line; + getline(in, line); + if (line.length() != 0 && line[0] != '#') { + double numbers[4]; + int n = sscanf(line.c_str(), "%lf %lf %lf %lf", &numbers[0], &numbers[1], &numbers[2], &numbers[3]); + if (n >= 2) { + //int field = (n == 4 ? static_cast(numbers[0]) : -1); + int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); + GUDHI_CHECK(numbers[n - 2] <= numbers[n - 1], "Error: birth > death."); + *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]); + } + } + } +} // read_persistence_diagram_from_file + +/** +Reads a file containing persistence intervals. +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death +The return value is an `std::map>>` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +**/ +std::map>> read_persistence_intervals_grouped_by_dimension(std::string const& filename) { + + std::map>> ret; + read_persistence_intervals_and_dimension( + filename, + boost::make_function_output_iterator([&ret](auto t) { ret[get<0>(t)].push_back(std::make_pair(get<1>(t), get<2>(t))); })); + return ret; +} // read_persistence_diagram_from_file + + +/** +Reads a file containing persistence intervals. +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death +If `only_this_dim` = -1, dimension is ignored and all lines are returned. +If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim` +(or where dimension is not specified) are returned. +The return value is an `std::vector>` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +**/ +std::vector> read_persistence_intervals_in_dimension(std::string const& filename, int only_this_dim = -1) { + + std::vector> ret; + read_persistence_intervals_and_dimension( + filename, + boost::make_function_output_iterator([&ret](auto t) { ret.emplace_back(get<1>(t), get<2>(t)); })); + return ret; +} // read_persistence_diagram_from_file + #endif // READER_UTILS_H_ -- cgit v1.2.3 From 9b05f9dadd25f2a5f1051044b2e00ebfc6e9b0a5 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 22 Nov 2017 09:57:46 +0000 Subject: Merge graph_expansion_blocker fix from cech_complex branch git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@2932 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c6397609dbf92cad0fdd6c0fc5365b96657edec9 --- .../example/rips_persistence_step_by_step.cpp | 59 +----- src/Simplex_tree/example/CMakeLists.txt | 10 + .../example/cech_complex_cgal_mini_sphere_3d.cpp | 234 +++++++++++++++++++++ src/Simplex_tree/include/gudhi/Simplex_tree.h | 26 ++- .../include/gudhi/graph_simplicial_complex.h | 63 ++++++ 5 files changed, 323 insertions(+), 69 deletions(-) create mode 100644 src/Simplex_tree/example/cech_complex_cgal_mini_sphere_3d.cpp (limited to 'src/common/include') diff --git a/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp b/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp index 554eeba6..c1de0ef8 100644 --- a/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp +++ b/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp @@ -45,14 +45,7 @@ using Simplex_tree = Gudhi::Simplex_tree; using Vertex_handle = Simplex_tree::Vertex_handle; using Filtration_value = Simplex_tree::Filtration_value; -using Graph_t = boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS -, boost::property < vertex_filtration_t, Filtration_value > -, boost::property < edge_filtration_t, Filtration_value > ->; -using Edge_t = std::pair< Vertex_handle, Vertex_handle >; - -template< typename InputPointRange, typename Distance > -Graph_t compute_proximity_graph(InputPointRange &points, Filtration_value threshold, Distance distance); +using Proximity_graph = Gudhi::Proximity_graph; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; @@ -81,8 +74,9 @@ int main(int argc, char * argv[]) { Points_off_reader off_reader(off_file_points); // Compute the proximity graph of the points - Graph_t prox_graph = compute_proximity_graph(off_reader.get_point_cloud(), threshold - , Gudhi::Euclidean_distance()); + Proximity_graph prox_graph = Gudhi::compute_proximity_graph(off_reader.get_point_cloud(), + threshold, + Gudhi::Euclidean_distance()); // Construct the Rips complex in a Simplex Tree Simplex_tree st; @@ -170,48 +164,3 @@ void program_options(int argc, char * argv[] std::abort(); } } - -/** Output the proximity graph of the points. - * - * If points contains n elements, the proximity graph is the graph - * with n vertices, and an edge [u,v] iff the distance function between - * points u and v is smaller than threshold. - * - * The type PointCloud furnishes .begin() and .end() methods, that return - * iterators with value_type Point. - */ -template< typename InputPointRange, typename Distance > -Graph_t compute_proximity_graph(InputPointRange &points, Filtration_value threshold, Distance distance) { - std::vector< Edge_t > edges; - std::vector< Filtration_value > edges_fil; - - Vertex_handle idx_u, idx_v; - Filtration_value fil; - idx_u = 0; - for (auto it_u = points.begin(); it_u != points.end(); ++it_u) { - idx_v = idx_u + 1; - for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) { - fil = distance(*it_u, *it_v); - if (fil <= threshold) { - edges.emplace_back(idx_u, idx_v); - edges_fil.push_back(fil); - } - } - ++idx_u; - } - - Graph_t skel_graph(edges.begin() - , edges.end() - , edges_fil.begin() - , idx_u); // number of points labeled from 0 to idx_u-1 - - auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); - - boost::graph_traits::vertex_iterator vi, vi_end; - for (std::tie(vi, vi_end) = boost::vertices(skel_graph); - vi != vi_end; ++vi) { - boost::put(vertex_prop, *vi, 0.); - } - - return skel_graph; -} diff --git a/src/Simplex_tree/example/CMakeLists.txt b/src/Simplex_tree/example/CMakeLists.txt index 8bc4ad53..b33b2d05 100644 --- a/src/Simplex_tree/example/CMakeLists.txt +++ b/src/Simplex_tree/example/CMakeLists.txt @@ -34,6 +34,16 @@ if(GMP_FOUND AND CGAL_FOUND) "${CMAKE_SOURCE_DIR}/data/points/bunny_5000.off") install(TARGETS Simplex_tree_example_alpha_shapes_3_from_off DESTINATION bin) + + add_executable ( Simplex_tree_example_cech_complex_cgal_mini_sphere_3d cech_complex_cgal_mini_sphere_3d.cpp ) + target_link_libraries(Simplex_tree_example_cech_complex_cgal_mini_sphere_3d ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CGAL_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(Simplex_tree_example_cech_complex_cgal_mini_sphere_3d ${TBB_LIBRARIES}) + endif() + add_test(NAME Simplex_tree_example_cech_complex_cgal_mini_sphere_3d COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" -r 0.3 -d 3) + + install(TARGETS Simplex_tree_example_alpha_shapes_3_from_off DESTINATION bin) endif() add_executable ( Simplex_tree_example_graph_expansion_with_blocker graph_expansion_with_blocker.cpp ) diff --git a/src/Simplex_tree/example/cech_complex_cgal_mini_sphere_3d.cpp b/src/Simplex_tree/example/cech_complex_cgal_mini_sphere_3d.cpp new file mode 100644 index 00000000..217e251f --- /dev/null +++ b/src/Simplex_tree/example/cech_complex_cgal_mini_sphere_3d.cpp @@ -0,0 +1,234 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include // infinity +#include // for pair +#include + +// ------------------------------------------------------------------------------- +// cech_complex_cgal_mini_sphere_3d is an example of each step that is required to +// build a Cech over a Simplex_tree. Please refer to cech_persistence to see +// how to do the same thing with the Cech_complex wrapper for less detailed +// steps. +// ------------------------------------------------------------------------------- + +// Types definition +using Simplex_tree = Gudhi::Simplex_tree<>; +using Vertex_handle = Simplex_tree::Vertex_handle; +using Simplex_handle = Simplex_tree::Simplex_handle; +using Filtration_value = Simplex_tree::Filtration_value; +using Siblings = Simplex_tree::Siblings; +using Graph_t = boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS +, boost::property < Gudhi::vertex_filtration_t, Filtration_value > +, boost::property < Gudhi::edge_filtration_t, Filtration_value > +>; +using Edge_t = std::pair< Vertex_handle, Vertex_handle >; + +using Kernel = CGAL::Epick_d< CGAL::Dimension_tag<3> >; +using Point = Kernel::Point_d; +using Traits = CGAL::Min_sphere_of_points_d_traits_d; +using Min_sphere = CGAL::Min_sphere_of_spheres_d; + +using Points_off_reader = Gudhi::Points_off_reader; + +class Cech_blocker { + public: + bool operator()(Simplex_handle sh) { + std::vector points; +#if DEBUG_TRACES + std::cout << "Cech_blocker on ["; +#endif // DEBUG_TRACES + for (auto vertex : simplex_tree_.simplex_vertex_range(sh)) { + points.push_back(point_cloud_[vertex]); +#if DEBUG_TRACES + std::cout << vertex << ", "; +#endif // DEBUG_TRACES + } + Min_sphere ms(points.begin(),points.end()); + Filtration_value radius = ms.radius(); +#if DEBUG_TRACES + std::cout << "] - radius = " << radius << " - returns " << (radius > threshold_) << std::endl; +#endif // DEBUG_TRACES + simplex_tree_.assign_filtration(sh, radius); + return (radius > threshold_); + } + Cech_blocker(Simplex_tree& simplex_tree, Filtration_value threshold, const std::vector& point_cloud) + : simplex_tree_(simplex_tree), + threshold_(threshold), + point_cloud_(point_cloud) { } + private: + Simplex_tree simplex_tree_; + Filtration_value threshold_; + std::vector point_cloud_; +}; + +template< typename InputPointRange> +Graph_t compute_proximity_graph(InputPointRange &points, Filtration_value threshold); + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , Filtration_value & threshold + , int & dim_max); + +int main(int argc, char * argv[]) { + std::string off_file_points; + Filtration_value threshold; + int dim_max; + + program_options(argc, argv, off_file_points, threshold, dim_max); + + // Extract the points from the file filepoints + Points_off_reader off_reader(off_file_points); + + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(off_reader.get_point_cloud(), threshold); + + //Min_sphere sph1(off_reader.get_point_cloud()[0], off_reader.get_point_cloud()[1], off_reader.get_point_cloud()[2]); + // Construct the Rips complex in a Simplex Tree + Simplex_tree st; + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion_with_blockers(dim_max, Cech_blocker(st, threshold, off_reader.get_point_cloud())); + + std::cout << "The complex contains " << st.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << st.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + st.initialize_filtration(); + +#if DEBUG_TRACES + std::cout << "********************************************************************\n"; + // Display the Simplex_tree - Can not be done in the middle of 2 inserts + std::cout << "* The complex contains " << st.num_simplices() << " simplices - dimension=" << st.dimension() << "\n"; + std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; + for (auto f_simplex : st.filtration_simplex_range()) { + std::cout << " " << "[" << st.filtration(f_simplex) << "] "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << static_cast(vertex) << " "; + } + std::cout << std::endl; + } +#endif // DEBUG_TRACES + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , Filtration_value & threshold + , int & dim_max) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&off_file_points), + "Name of an OFF file containing a 3d point set.\n"); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Cech complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Cech complex we want to compute."); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Construct a Cech complex defined on a set of input points.\n \n"; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} + +/** Output the proximity graph of the points. + * + * If points contains n elements, the proximity graph is the graph + * with n vertices, and an edge [u,v] iff the distance function between + * points u and v is smaller than threshold. + * + * The type PointCloud furnishes .begin() and .end() methods, that return + * iterators with value_type Point. + */ +template< typename InputPointRange> +Graph_t compute_proximity_graph(InputPointRange &points, Filtration_value threshold) { + std::vector< Edge_t > edges; + std::vector< Filtration_value > edges_fil; + + Kernel k; + Vertex_handle idx_u, idx_v; + Filtration_value fil; + idx_u = 0; + for (auto it_u = points.begin(); it_u != points.end(); ++it_u) { + idx_v = idx_u + 1; + for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) { + fil = k.squared_distance_d_object()(*it_u, *it_v); + // For Cech Complex, threshold is a radius (distance /2) + fil = std::sqrt(fil) / 2.; + if (fil <= threshold) { + edges.emplace_back(idx_u, idx_v); + edges_fil.push_back(fil); + } + } + ++idx_u; + } + + Graph_t skel_graph(edges.begin() + , edges.end() + , edges_fil.begin() + , idx_u); // number of points labeled from 0 to idx_u-1 + + auto vertex_prop = boost::get(Gudhi::vertex_filtration_t(), skel_graph); + + boost::graph_traits::vertex_iterator vi, vi_end; + for (std::tie(vi, vi_end) = boost::vertices(skel_graph); + vi != vi_end; ++vi) { + boost::put(vertex_prop, *vi, 0.); + } + + return skel_graph; +} diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 7da767cb..5d8a90ee 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -1145,7 +1145,7 @@ class Simplex_tree { Siblings * new_sib = new Siblings(siblings, // oncles simplex->first, // parent boost::adaptors::reverse(intersection)); // boost::container::ordered_unique_range_t - std::vector blocked_new_sib_list; + std::vector blocked_new_sib_vertex_list; // As all intersections are inserted, we can call the blocker function on all new_sib members for (auto new_sib_member = new_sib->members().begin(); new_sib_member != new_sib->members().end(); @@ -1153,17 +1153,19 @@ class Simplex_tree { bool blocker_result = block_simplex(new_sib_member); // new_sib member has been blocked by the blocker function // add it to the list to be removed - do not perform it while looping on it - if (blocker_result) - blocked_new_sib_list.push_back(new_sib_member); + if (blocker_result) { + blocked_new_sib_vertex_list.push_back(new_sib_member->first); + } } - bool removed = false; - for (auto& blocked_new_sib_member : blocked_new_sib_list){ - removed = removed || remove_maximal_simplex(blocked_new_sib_member); - } - if (removed) { + if (blocked_new_sib_vertex_list.size() == new_sib->members().size()) { + // Specific case where all have to be deleted + delete new_sib; // ensure the children property simplex->second.assign_children(siblings); } else { + for (auto& blocked_new_sib_member : blocked_new_sib_vertex_list) { + new_sib->members().erase(blocked_new_sib_member); + } // ensure recursive call simplex->second.assign_children(new_sib); siblings_expansion_with_blockers(new_sib, max_dim, k - 1, block_simplex); @@ -1338,16 +1340,14 @@ class Simplex_tree { public: /** \brief Remove a maximal simplex. * @param[in] sh Simplex handle on the maximal simplex to remove. - * @return a boolean value that is an implementation detail, and that the user is supposed to ignore * \pre Please check the simplex has no coface before removing it. * \exception std::invalid_argument In debug mode, if sh has children. - * \post Be aware that removing is shifting data in a flat_map (`initialize_filtration()` to be done). + * \post Be aware that removing is shifting data in a flat_map (initialize_filtration to be done). * \post Note that the dimension of the simplicial complex may be lower after calling `remove_maximal_simplex()` * than it was before. However, `upper_bound_dimension()` will return the old value, which remains a valid upper * bound. If you care, you can call `dimension()` to recompute the exact dimension. - * \internal @return true if the leaf's branch has no other leaves (branch's children has been re-assigned), false otherwise. */ - bool remove_maximal_simplex(Simplex_handle sh) { + void remove_maximal_simplex(Simplex_handle sh) { // Guarantee the simplex has no children GUDHI_CHECK(!has_children(sh), std::invalid_argument("Simplex_tree::remove_maximal_simplex - argument has children")); @@ -1365,9 +1365,7 @@ class Simplex_tree { delete child; // dimension may need to be lowered dimension_to_be_lowered_ = true; - return true; } - return false; } private: diff --git a/src/common/include/gudhi/graph_simplicial_complex.h b/src/common/include/gudhi/graph_simplicial_complex.h index 5fe7c826..d84421b2 100644 --- a/src/common/include/gudhi/graph_simplicial_complex.h +++ b/src/common/include/gudhi/graph_simplicial_complex.h @@ -28,6 +28,9 @@ #include // for pair<> #include #include +#include // for std::tie + +namespace Gudhi { /* Edge tag for Boost PropertyGraph. */ struct edge_filtration_t { @@ -39,4 +42,64 @@ struct vertex_filtration_t { typedef boost::vertex_property_tag kind; }; +template +using Proximity_graph = typename boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS +, boost::property < vertex_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value > +, boost::property < edge_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >>; + +/** \brief Computes the proximity graph of the points. + * + * If points contains n elements, the proximity graph is the graph with n vertices, and an edge [u,v] iff the + * distance function between points u and v is smaller than threshold. + * + * \tparam ForwardPointRange furnishes `.begin()` and `.end()` methods. + * + * \tparam Distance furnishes `operator()(const Point& p1, const Point& p2)`, where + * `Point` is a point from the `ForwardPointRange`, and that returns a `Filtration_value`. + */ +template< typename SimplicialComplexForProximityGraph + , typename ForwardPointRange + , typename Distance > +Proximity_graph compute_proximity_graph( + const ForwardPointRange& points, + typename SimplicialComplexForProximityGraph::Filtration_value threshold, + Distance distance) { + using Vertex_handle = typename SimplicialComplexForProximityGraph::Vertex_handle; + using Filtration_value = typename SimplicialComplexForProximityGraph::Filtration_value; + + std::vector> edges; + std::vector< Filtration_value > edges_fil; + std::map< Vertex_handle, Filtration_value > vertices; + + Vertex_handle idx_u, idx_v; + Filtration_value fil; + idx_u = 0; + for (auto it_u = points.begin(); it_u != points.end(); ++it_u) { + idx_v = idx_u + 1; + for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) { + fil = distance(*it_u, *it_v); + if (fil <= threshold) { + edges.emplace_back(idx_u, idx_v); + edges_fil.push_back(fil); + } + } + ++idx_u; + } + + // Points are labeled from 0 to idx_u-1 + Proximity_graph skel_graph(edges.begin(), edges.end(), edges_fil.begin(), idx_u); + + auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); + + typename boost::graph_traits>::vertex_iterator vi, vi_end; + for (std::tie(vi, vi_end) = boost::vertices(skel_graph); + vi != vi_end; ++vi) { + boost::put(vertex_prop, *vi, 0.); + } + + return skel_graph; +} + +} // namespace Gudhi + #endif // GRAPH_SIMPLICIAL_COMPLEX_H_ -- cgit v1.2.3 From 4cf2e2232a2046590909d78c887a2b96a2af8177 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 2 Dec 2017 13:34:29 +0000 Subject: Cleanup checks in Simplex_tree Rewrite GUDHi_CHECK so we don't get nasty surprises with: if(cond) GUDHI_CHECK(...) else ... where the else would have been matched with the if in GUDHI_CHECK. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST-glisse@3010 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a1385540710d0079567b7e4566766bd0da53c584 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 7 ++++--- src/common/include/gudhi/Debug_utils.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/common/include') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index cb6ab309..81dff00d 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -106,8 +106,9 @@ class Simplex_tree { }; struct Key_simplex_base_dummy { Key_simplex_base_dummy() {} - void assign_key(Simplex_key) { } - Simplex_key key() const { assert(false); return -1; } + // Undefined so it will not link + void assign_key(Simplex_key); + Simplex_key key() const; }; typedef typename std::conditional::type Key_simplex_base; @@ -121,7 +122,7 @@ class Simplex_tree { }; struct Filtration_simplex_base_dummy { Filtration_simplex_base_dummy() {} - void assign_filtration(Filtration_value f) { assert(f == 0); } + void assign_filtration(Filtration_value GUDHI_CHECK_code(f)) { GUDHI_CHECK(f == 0, "filtration value specified for a complex that does not store them"); } Filtration_value filtration() const { return 0; } }; typedef typename std::conditional Date: Tue, 19 Dec 2017 09:52:37 +0000 Subject: Add a function for unitary tests to test floating point values equality w/wo epsilon values git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration_cmake_improvement@3083 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 835037fd6efea4fbfc9a494df3015186232388bf --- src/Alpha_complex/test/Alpha_complex_unit_test.cpp | 19 +++--- .../test/persistence_heat_maps_test.cpp | 72 ++++++++-------------- src/Rips_complex/test/test_rips_complex.cpp | 25 ++++---- src/cmake/modules/GUDHI_test_coverage.cmake | 14 ++++- src/common/include/gudhi/Debug_utils.h | 2 +- src/common/include/gudhi/Unitary_tests_utils.h | 39 ++++++++++++ 6 files changed, 96 insertions(+), 75 deletions(-) create mode 100644 src/common/include/gudhi/Unitary_tests_utils.h (limited to 'src/common/include') diff --git a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp index 166373fe..c3ad1a9c 100644 --- a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp @@ -23,6 +23,7 @@ #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "alpha_complex" #include +#include #include #include @@ -36,7 +37,7 @@ // to construct a simplex_tree from Delaunay_triangulation #include #include -#include +#include // Use dynamic_dimension_tag for the user to be able to set dimension typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Kernel_d; @@ -96,10 +97,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_OFF_file, TestedKernel, list_of BOOST_CHECK(simplex_tree_59.num_simplices() == 23); } -bool are_almost_the_same(float a, float b) { - return std::fabs(a - b) < std::numeric_limits::epsilon(); -} - // Use static dimension_tag for the user not to be able to set dimension typedef CGAL::Epick_d< CGAL::Dimension_tag<4> > Kernel_4; typedef Kernel_4::Point_d Point_4; @@ -166,16 +163,16 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) { for (auto f_simplex : simplex_tree.filtration_simplex_range()) { switch (simplex_tree.dimension(f_simplex)) { case 0: - BOOST_CHECK(are_almost_the_same(simplex_tree.filtration(f_simplex), 0.0)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(simplex_tree.filtration(f_simplex), 0.0); break; case 1: - BOOST_CHECK(are_almost_the_same(simplex_tree.filtration(f_simplex), 1.0/2.0)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(simplex_tree.filtration(f_simplex), 1.0/2.0); break; case 2: - BOOST_CHECK(are_almost_the_same(simplex_tree.filtration(f_simplex), 2.0/3.0)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(simplex_tree.filtration(f_simplex), 2.0/3.0); break; case 3: - BOOST_CHECK(are_almost_the_same(simplex_tree.filtration(f_simplex), 3.0/4.0)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(simplex_tree.filtration(f_simplex), 3.0/4.0); break; default: BOOST_CHECK(false); // Shall not happen @@ -239,10 +236,10 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) { for (auto f_simplex : simplex_tree.filtration_simplex_range()) { switch (simplex_tree.dimension(f_simplex)) { case 0: - BOOST_CHECK(are_almost_the_same(simplex_tree.filtration(f_simplex), 0.0)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(simplex_tree.filtration(f_simplex), 0.0); break; case 1: - BOOST_CHECK(are_almost_the_same(simplex_tree.filtration(f_simplex), 1.0/2.0)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(simplex_tree.filtration(f_simplex), 1.0/2.0); break; default: BOOST_CHECK(false); // Shall not happen diff --git a/src/Persistence_representations/test/persistence_heat_maps_test.cpp b/src/Persistence_representations/test/persistence_heat_maps_test.cpp index 1f1502f5..4da13b86 100644 --- a/src/Persistence_representations/test/persistence_heat_maps_test.cpp +++ b/src/Persistence_representations/test/persistence_heat_maps_test.cpp @@ -25,12 +25,15 @@ #include #include #include +#include #include using namespace Gudhi; using namespace Gudhi::Persistence_representations; +double epsilon = 0.0005; + BOOST_AUTO_TEST_CASE(check_construction_of_heat_maps) { std::vector > filter = create_Gaussian_filter(100, 1); Persistence_heat_maps p("data/file_with_diagram", filter, false, 1000, 0, 1); @@ -139,28 +142,15 @@ BOOST_AUTO_TEST_CASE(check_distance_for_heat_maps) { Persistence_heat_maps q("data/file_with_diagram_1", filter, false, 1000, 0, 1); Persistence_heat_maps r("data/file_with_diagram_2", filter, false, 1000, 0, 1); - // cerr << p.distance( p ) << endl; - // cerr << p.distance( q ) << endl; - // cerr << p.distance( r ) << endl; - // cerr << q.distance( p ) << endl; - // cerr << q.distance( q ) << endl; - // cerr << q.distance( r ) << endl; - // cerr << r.distance( p ) << endl; - // cerr << r.distance( q ) << endl; - // cerr << r.distance( r ) << endl; - // 0 624.183 415.815 - // 624.183 0 528.06Z - // 415.815 528.066 0 - - BOOST_CHECK(fabs(p.distance(p) - 0) < 0.0005); - BOOST_CHECK(fabs(p.distance(q) - 624.183) < 0.0005); - BOOST_CHECK(fabs(p.distance(r) - 415.815) < 0.0005); - BOOST_CHECK(fabs(q.distance(p) - 624.183) < 0.0005); - BOOST_CHECK(fabs(q.distance(q) - 0) < 0.0005); - BOOST_CHECK(fabs(q.distance(r) - 528.066) < 0.0005); - BOOST_CHECK(fabs(r.distance(p) - 415.815) < 0.0005); - BOOST_CHECK(fabs(r.distance(q) - 528.066) < 0.0005); - BOOST_CHECK(fabs(r.distance(r) - 0) < 0.0005); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(p), 0., epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q), 624.183, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(r), 415.815, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.distance(p), 624.183, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.distance(q), 0., epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.distance(r), 528.066, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.distance(p), 415.815, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.distance(q), 528.066, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.distance(r), 0., epsilon); } BOOST_AUTO_TEST_CASE(check_projections_to_R_for_heat_maps) { @@ -169,13 +159,9 @@ BOOST_AUTO_TEST_CASE(check_projections_to_R_for_heat_maps) { Persistence_heat_maps q("data/file_with_diagram_1", filter, false, 1000, 0, 1); Persistence_heat_maps r("data/file_with_diagram_2", filter, false, 1000, 0, 1); - // cerr << p.project_to_R(0) << endl; - // cerr << q.project_to_R(0) << endl; - // cerr << r.project_to_R(0) << endl; - - BOOST_CHECK(fabs(p.project_to_R(0) - 44.3308) < 0.0005); - BOOST_CHECK(fabs(q.project_to_R(0) - 650.568) < 0.0005); - BOOST_CHECK(fabs(r.project_to_R(0) - 429.287) < 0.0005); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.project_to_R(0), 44.3308, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.project_to_R(0), 650.568, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.project_to_R(0), 429.287, epsilon); } BOOST_AUTO_TEST_CASE(check_scalar_products_for_heat_maps) { @@ -184,25 +170,15 @@ BOOST_AUTO_TEST_CASE(check_scalar_products_for_heat_maps) { Persistence_heat_maps q("data/file_with_diagram_1", filter, false, 1000, 0, 1); Persistence_heat_maps r("data/file_with_diagram_2", filter, false, 1000, 0, 1); - // cerr << p.compute_scalar_product( p ) << endl; - // cerr << p.compute_scalar_product( q ) << endl; - // cerr << p.compute_scalar_product( r ) << endl; - // cerr << q.compute_scalar_product( p ) << endl; - // cerr << q.compute_scalar_product( q ) << endl; - // cerr << q.compute_scalar_product( r ) << endl; - // cerr << r.compute_scalar_product( p ) << endl; - // cerr << r.compute_scalar_product( q ) << endl; - // cerr << r.compute_scalar_product( r ) << endl; - - BOOST_CHECK(fabs(p.compute_scalar_product(p) - 0.0345687) < 0.0005); - BOOST_CHECK(fabs(p.compute_scalar_product(q) - 0.0509357) < 0.0005); - BOOST_CHECK(fabs(p.compute_scalar_product(r) - 0.0375608) < 0.0005); - BOOST_CHECK(fabs(q.compute_scalar_product(p) - 0.0509357) < 0.0005); - BOOST_CHECK(fabs(q.compute_scalar_product(q) - 1.31293) < 0.0005); - BOOST_CHECK(fabs(q.compute_scalar_product(r) - 0.536799) < 0.0005); - BOOST_CHECK(fabs(r.compute_scalar_product(p) - 0.0375608) < 0.0005); - BOOST_CHECK(fabs(r.compute_scalar_product(q) - 0.536799) < 0.0005); - BOOST_CHECK(fabs(r.compute_scalar_product(r) - 0.672907) < 0.0005); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(p), 0.0345687, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(q), 0.0509357, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(r), 0.0375608, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.compute_scalar_product(p), 0.0509357, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.compute_scalar_product(q), 1.31293 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.compute_scalar_product(r), 0.536799 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.compute_scalar_product(p), 0.0375608, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.compute_scalar_product(q), 0.536799 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.compute_scalar_product(r), 0.672907 , epsilon); } BOOST_AUTO_TEST_CASE(check_arythmetic_operations_for_heat_maps) { diff --git a/src/Rips_complex/test/test_rips_complex.cpp b/src/Rips_complex/test/test_rips_complex.cpp index fc83f5f7..89afbc25 100644 --- a/src/Rips_complex/test/test_rips_complex.cpp +++ b/src/Rips_complex/test/test_rips_complex.cpp @@ -36,6 +36,7 @@ #include #include #include +#include // Type definitions using Point = std::vector; @@ -44,10 +45,6 @@ using Filtration_value = Simplex_tree::Filtration_value; using Rips_complex = Gudhi::rips_complex::Rips_complex; using Distance_matrix = std::vector>; -bool are_almost_the_same(float a, float b) { - return std::fabs(a - b) < std::numeric_limits::epsilon(); -} - BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) { // ---------------------------------------------------------------------------- // @@ -92,7 +89,7 @@ BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) { std::cout << ") - distance =" << Gudhi::Euclidean_distance()(vp.at(0), vp.at(1)) << " - filtration =" << st.filtration(f_simplex) << std::endl; BOOST_CHECK(vp.size() == 2); - BOOST_CHECK(are_almost_the_same(st.filtration(f_simplex), Gudhi::Euclidean_distance()(vp.at(0), vp.at(1)))); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), Gudhi::Euclidean_distance()(vp.at(0), vp.at(1))); } } @@ -113,14 +110,14 @@ BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) { Simplex_tree::Filtration_value f12 = st2.filtration(st2.find({1, 2})); Simplex_tree::Filtration_value f012 = st2.filtration(st2.find({0, 1, 2})); std::cout << "f012= " << f012 << " | f01= " << f01 << " - f02= " << f02 << " - f12= " << f12 << std::endl; - BOOST_CHECK(are_almost_the_same(f012, std::max(f01, std::max(f02,f12)))); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(f012, std::max(f01, std::max(f02,f12))); Simplex_tree::Filtration_value f45 = st2.filtration(st2.find({4, 5})); Simplex_tree::Filtration_value f56 = st2.filtration(st2.find({5, 6})); Simplex_tree::Filtration_value f46 = st2.filtration(st2.find({4, 6})); Simplex_tree::Filtration_value f456 = st2.filtration(st2.find({4, 5, 6})); std::cout << "f456= " << f456 << " | f45= " << f45 << " - f56= " << f56 << " - f46= " << f46 << std::endl; - BOOST_CHECK(are_almost_the_same(f456, std::max(f45, std::max(f56,f46)))); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(f456, std::max(f45, std::max(f56,f46))); const int DIMENSION_3 = 3; Simplex_tree st3; @@ -140,7 +137,7 @@ BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) { Simplex_tree::Filtration_value f0123 = st3.filtration(st3.find({0, 1, 2, 3})); std::cout << "f0123= " << f0123 << " | f012= " << f012 << " - f123= " << f123 << " - f013= " << f013 << " - f023= " << f023 << std::endl; - BOOST_CHECK(are_almost_the_same(f0123, std::max(f012, std::max(f123, std::max(f013, f023))))); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(f0123, std::max(f012, std::max(f123, std::max(f013, f023)))); } @@ -219,12 +216,12 @@ BOOST_AUTO_TEST_CASE(Rips_complex_from_points) { std::cout << "dimension(" << st.dimension(f_simplex) << ") - f = " << st.filtration(f_simplex) << std::endl; switch (st.dimension(f_simplex)) { case 0: - BOOST_CHECK(are_almost_the_same(st.filtration(f_simplex), 0.0)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), 0.0); break; case 1: case 2: case 3: - BOOST_CHECK(are_almost_the_same(st.filtration(f_simplex), 2.0)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), 2.0); break; default: BOOST_CHECK(false); // Shall not happen @@ -276,7 +273,7 @@ BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) { } std::cout << ") - filtration =" << st.filtration(f_simplex) << std::endl; BOOST_CHECK(vvh.size() == 2); - BOOST_CHECK(are_almost_the_same(st.filtration(f_simplex), distances[vvh.at(0)][vvh.at(1)])); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), distances[vvh.at(0)][vvh.at(1)]); } } @@ -297,14 +294,14 @@ BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) { Simplex_tree::Filtration_value f12 = st2.filtration(st2.find({1, 2})); Simplex_tree::Filtration_value f012 = st2.filtration(st2.find({0, 1, 2})); std::cout << "f012= " << f012 << " | f01= " << f01 << " - f02= " << f02 << " - f12= " << f12 << std::endl; - BOOST_CHECK(are_almost_the_same(f012, std::max(f01, std::max(f02,f12)))); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(f012, std::max(f01, std::max(f02,f12))); Simplex_tree::Filtration_value f45 = st2.filtration(st2.find({4, 5})); Simplex_tree::Filtration_value f56 = st2.filtration(st2.find({5, 6})); Simplex_tree::Filtration_value f46 = st2.filtration(st2.find({4, 6})); Simplex_tree::Filtration_value f456 = st2.filtration(st2.find({4, 5, 6})); std::cout << "f456= " << f456 << " | f45= " << f45 << " - f56= " << f56 << " - f46= " << f46 << std::endl; - BOOST_CHECK(are_almost_the_same(f456, std::max(f45, std::max(f56,f46)))); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(f456, std::max(f45, std::max(f56,f46))); const int DIMENSION_3 = 3; Simplex_tree st3; @@ -324,7 +321,7 @@ BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) { Simplex_tree::Filtration_value f0123 = st3.filtration(st3.find({0, 1, 2, 3})); std::cout << "f0123= " << f0123 << " | f012= " << f012 << " - f123= " << f123 << " - f013= " << f013 << " - f023= " << f023 << std::endl; - BOOST_CHECK(are_almost_the_same(f0123, std::max(f012, std::max(f123, std::max(f013, f023))))); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(f0123, std::max(f012, std::max(f123, std::max(f013, f023)))); } diff --git a/src/cmake/modules/GUDHI_test_coverage.cmake b/src/cmake/modules/GUDHI_test_coverage.cmake index ce171a0e..bea5b2d6 100644 --- a/src/cmake/modules/GUDHI_test_coverage.cmake +++ b/src/cmake/modules/GUDHI_test_coverage.cmake @@ -8,7 +8,19 @@ if (GPROF_PATH) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") endif() +if (DEBUG_TRACES) + # Make CTest more verbose with DEBUG_TRACES - no XML output + set(GUDHI_UT_LOG_LEVEL "--log_level=all") + set(GUDHI_UT_REPORT_LEVEL "--report_level=detailed") +else() + set(GUDHI_UT_LOG_FORMAT "--log_format=XML") + set(GUDHI_UT_LOG_SINK "--log_sink=${CMAKE_BINARY_DIR}/${unitary_test}_UT.xml") + set(GUDHI_UT_LOG_LEVEL "--log_level=test_suite") + set(GUDHI_UT_REPORT_LEVEL "--report_level=no") +endif() + function(gudhi_add_coverage_test unitary_test) add_test(NAME ${unitary_test} COMMAND $ - "--log_format=XML" "--log_sink=${CMAKE_BINARY_DIR}/${unitary_test}_UT.xml" "--log_level=test_suite" "--report_level=no") + ${GUDHI_UT_LOG_FORMAT} ${GUDHI_UT_LOG_SINK} + ${GUDHI_UT_LOG_LEVEL} ${GUDHI_UT_REPORT_LEVEL}) endfunction() diff --git a/src/common/include/gudhi/Debug_utils.h b/src/common/include/gudhi/Debug_utils.h index 8ed3b7b3..f9d9c50c 100644 --- a/src/common/include/gudhi/Debug_utils.h +++ b/src/common/include/gudhi/Debug_utils.h @@ -4,7 +4,7 @@ * * Author(s): David Salinas * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * Copyright (C) 2014 INRIA * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/common/include/gudhi/Unitary_tests_utils.h b/src/common/include/gudhi/Unitary_tests_utils.h new file mode 100644 index 00000000..7ae5d356 --- /dev/null +++ b/src/common/include/gudhi/Unitary_tests_utils.h @@ -0,0 +1,39 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2017 INRIA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef UNITARY_TESTS_UTILS_H_ +#define UNITARY_TESTS_UTILS_H_ + +#include + +#include + +template +void GUDHI_TEST_FLOAT_EQUALITY_CHECK(FloatingType a, FloatingType b, + FloatingType epsilon = std::numeric_limits::epsilon()) { +#ifdef DEBUG_TRACES + std::cout << "GUDHI_TEST_FLOAT_EQUALITY_CHECK - " << a << " versus " << b + << " | diff = " << std::fabs(a - b) << " - epsilon = " << epsilon << std::endl; +#endif + BOOST_CHECK(std::fabs(a - b) < epsilon); +} + +#endif // UNITARY_TESTS_UTILS_H_ -- cgit v1.2.3 From 95cbbd98a9b1dcec7142f1b45555991cf0f94b70 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 22 Dec 2017 14:18:50 +0000 Subject: Cleanups in Euclidean_distance. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/misc-glisse@3102 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 06a14b11149e9c7265b8a3427404a9a0991d51aa --- src/common/include/gudhi/distance_functions.h | 31 +++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/common/include') diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index c556155e..3a5d1fd5 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -23,6 +23,10 @@ #ifndef DISTANCE_FUNCTIONS_H_ #define DISTANCE_FUNCTIONS_H_ +#include + +#include + #include // for std::sqrt #include // for std::decay #include // for std::begin, std::end @@ -38,20 +42,29 @@ namespace Gudhi { * have the same dimension. */ class Euclidean_distance { public: + // boost::range_value is not SFINAE-friendly so we cannot use it in the return type template< typename Point > - auto operator()(const Point& p1, const Point& p2) const -> typename std::decay::type { - auto it1 = p1.begin(); - auto it2 = p2.begin(); - typename Point::value_type dist = 0.; - for (; it1 != p1.end(); ++it1, ++it2) { - typename Point::value_type tmp = (*it1) - (*it2); + typename std::iterator_traits::type>::value_type + operator()(const Point& p1, const Point& p2) const { + auto it1 = std::begin(p1); + auto it2 = std::begin(p2); + typedef typename boost::range_value::type NT; + NT dist = 0; + for (; it1 != std::end(p1); ++it1, ++it2) { + GUDHI_CHECK(it2 != std::end(p2), "inconsistent point dimensions"); + NT tmp = *it1 - *it2; dist += tmp*tmp; } - return std::sqrt(dist); + GUDHI_CHECK(it2 == std::end(p2), "inconsistent point dimensions"); + using std::sqrt; + return sqrt(dist); } template< typename T > - T operator() (const std::pair< T, T >& f, const std::pair< T, T >& s) { - return sqrt((f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second)); + T operator() (const std::pair< T, T >& f, const std::pair< T, T >& s) const { + T dx = f.first - s.first; + T dy = f.second - s.second; + using std::sqrt; + return sqrt(dx*dx + dy*dy); } }; -- cgit v1.2.3 From d8f04fab98dcb46ba7b300048311bf9e8b0ab3d2 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 22 Jan 2018 13:51:28 +0000 Subject: Fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@3149 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e1cc797f8c24015168a1f84430666e8a156ababa --- src/Bottleneck_distance/include/gudhi/Bottleneck.h | 4 +- .../include/gudhi/Neighbors_finder.h | 1 + .../include/gudhi/read_persistence_from_file.h | 15 ++-- .../utilities/rips_distance_matrix_persistence.cpp | 61 +++++++--------- src/Rips_complex/utilities/rips_persistence.cpp | 60 ++++++--------- .../example/cech_complex_cgal_mini_sphere_3d.cpp | 85 +++++++++------------- .../example/graph_expansion_with_blocker.cpp | 40 +++++----- src/Simplex_tree/example/simple_simplex_tree.cpp | 84 +++++++++------------ .../include/gudhi/Kd_tree_search.h | 3 +- .../example/example_strong_witness_complex_off.cpp | 22 +++--- .../example/example_witness_complex_sphere.cpp | 24 +++--- .../utilities/strong_witness_persistence.cpp | 69 +++++++----------- .../utilities/weak_witness_persistence.cpp | 69 +++++++----------- src/common/include/gudhi/Unitary_tests_utils.h | 1 + 14 files changed, 223 insertions(+), 315 deletions(-) (limited to 'src/common/include') diff --git a/src/Bottleneck_distance/include/gudhi/Bottleneck.h b/src/Bottleneck_distance/include/gudhi/Bottleneck.h index 8c97dce9..7aee07bb 100644 --- a/src/Bottleneck_distance/include/gudhi/Bottleneck.h +++ b/src/Bottleneck_distance/include/gudhi/Bottleneck.h @@ -46,7 +46,7 @@ double bottleneck_distance_approx(Persistence_graph& g, double e) { if (step <= b_lower_bound || step >= b_upper_bound) // Avoid precision problem break; m.set_r(step); - while (m.multi_augment()) {}; // compute a maximum matching (in the graph corresponding to the current r) + while (m.multi_augment()) {} // compute a maximum matching (in the graph corresponding to the current r) if (m.perfect()) { m = biggest_unperfect; b_upper_bound = step; @@ -68,7 +68,7 @@ double bottleneck_distance_exact(Persistence_graph& g) { while (lower_bound_i != upper_bound_i) { long step = lower_bound_i + static_cast ((upper_bound_i - lower_bound_i - 1) / alpha); m.set_r(sd.at(step)); - while (m.multi_augment()) {}; // compute a maximum matching (in the graph corresponding to the current r) + while (m.multi_augment()) {} // compute a maximum matching (in the graph corresponding to the current r) if (m.perfect()) { m = biggest_unperfect; upper_bound_i = step; diff --git a/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h b/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h index dc804630..87c7cee5 100644 --- a/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h +++ b/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h @@ -32,6 +32,7 @@ #include #include +#include // for std::max namespace Gudhi { diff --git a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h index 450c223c..83b89d0e 100644 --- a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h +++ b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h @@ -23,6 +23,8 @@ #ifndef READ_PERSISTENCE_FROM_FILE_H_ #define READ_PERSISTENCE_FROM_FILE_H_ +#include + #include #include #include @@ -30,7 +32,7 @@ #include #include #include -#include +#include // for std::numeric_limits<> namespace Gudhi { namespace Persistence_representations { @@ -72,16 +74,9 @@ std::vector > read_persistence_intervals_in_one_dimens std::cout << "COnsidering interval : " << barcode_initial[i].first << " " << barcode_initial[i].second << std::endl; } - // if ( barcode_initial[i].first == barcode_initial[i].second ) - //{ - // if ( dbg )std::cout << "It has zero length \n"; - // continue;//zero length intervals are not relevant, so we skip all of them. - //} - if (barcode_initial[i].first > - barcode_initial[i] - .second) // note that in this case barcode_initial[i].second != std::numeric_limits::infinity() - { + if (barcode_initial[i].first > barcode_initial[i].second) { + // note that in this case barcode_initial[i].second != std::numeric_limits::infinity() if (dbg) std::cout << "Swap and enter \n"; // swap them to make sure that birth < death final_barcode.push_back(std::pair(barcode_initial[i].second, barcode_initial[i].first)); diff --git a/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp b/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp index d38808c7..ca3c0327 100644 --- a/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp +++ b/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp @@ -1,5 +1,5 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * * Author(s): Pawel Dlotko, Vincent Rouvreau @@ -36,18 +36,13 @@ using Simplex_tree = Gudhi::Simplex_tree; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; using Distance_matrix = std::vector>; -void program_options(int argc, char * argv[] - , std::string & csv_matrix_file - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence); +void program_options(int argc, char* argv[], std::string& csv_matrix_file, std::string& filediag, + Filtration_value& threshold, int& dim_max, int& p, Filtration_value& min_persistence); -int main(int argc, char * argv[]) { +int main(int argc, char* argv[]) { std::string csv_matrix_file; std::string filediag; Filtration_value threshold; @@ -88,33 +83,28 @@ int main(int argc, char * argv[]) { return 0; } -void program_options(int argc, char * argv[] - , std::string & csv_matrix_file - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence) { +void program_options(int argc, char* argv[], std::string& csv_matrix_file, std::string& filediag, + Filtration_value& threshold, int& dim_max, int& p, Filtration_value& min_persistence) { namespace po = boost::program_options; po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&csv_matrix_file), - "Name of file containing a distance matrix. Can be square or lower triangular matrix. Separator is ';'."); + hidden.add_options()( + "input-file", po::value(&csv_matrix_file), + "Name of file containing a distance matrix. Can be square or lower triangular matrix. Separator is ';'."); po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + visible.add_options()("help,h", "produce help message")( + "output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Rips complex construction.")( + "cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.")( + "field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals"); po::positional_options_description pos; pos.add("input-file", 1); @@ -123,8 +113,7 @@ void program_options(int argc, char * argv[] all.add(visible).add(hidden); po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); po::notify(vm); if (vm.count("help") || !vm.count("input-file")) { diff --git a/src/Rips_complex/utilities/rips_persistence.cpp b/src/Rips_complex/utilities/rips_persistence.cpp index d504798b..8405c014 100644 --- a/src/Rips_complex/utilities/rips_persistence.cpp +++ b/src/Rips_complex/utilities/rips_persistence.cpp @@ -1,5 +1,5 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * * Author(s): Clément Maria @@ -37,19 +37,14 @@ using Simplex_tree = Gudhi::Simplex_tree; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; using Point = std::vector; using Points_off_reader = Gudhi::Points_off_reader; -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence); +void program_options(int argc, char* argv[], std::string& off_file_points, std::string& filediag, + Filtration_value& threshold, int& dim_max, int& p, Filtration_value& min_persistence); -int main(int argc, char * argv[]) { +int main(int argc, char* argv[]) { std::string off_file_points; std::string filediag; Filtration_value threshold; @@ -91,33 +86,27 @@ int main(int argc, char * argv[]) { return 0; } -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence) { +void program_options(int argc, char* argv[], std::string& off_file_points, std::string& filediag, + Filtration_value& threshold, int& dim_max, int& p, Filtration_value& min_persistence) { namespace po = boost::program_options; po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of an OFF file containing a point set.\n"); + hidden.add_options()("input-file", po::value(&off_file_points), + "Name of an OFF file containing a point set.\n"); po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + visible.add_options()("help,h", "produce help message")( + "output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Rips complex construction.")( + "cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.")( + "field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals"); po::positional_options_description pos; pos.add("input-file", 1); @@ -126,8 +115,7 @@ void program_options(int argc, char * argv[] all.add(visible).add(hidden); po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); po::notify(vm); if (vm.count("help") || !vm.count("input-file")) { diff --git a/src/Simplex_tree/example/cech_complex_cgal_mini_sphere_3d.cpp b/src/Simplex_tree/example/cech_complex_cgal_mini_sphere_3d.cpp index 217e251f..9bd51106 100644 --- a/src/Simplex_tree/example/cech_complex_cgal_mini_sphere_3d.cpp +++ b/src/Simplex_tree/example/cech_complex_cgal_mini_sphere_3d.cpp @@ -1,5 +1,5 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * * Author(s): Clément Maria @@ -33,7 +33,7 @@ #include #include -#include // infinity +#include // infinity #include // for pair #include @@ -50,15 +50,14 @@ using Vertex_handle = Simplex_tree::Vertex_handle; using Simplex_handle = Simplex_tree::Simplex_handle; using Filtration_value = Simplex_tree::Filtration_value; using Siblings = Simplex_tree::Siblings; -using Graph_t = boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS -, boost::property < Gudhi::vertex_filtration_t, Filtration_value > -, boost::property < Gudhi::edge_filtration_t, Filtration_value > ->; -using Edge_t = std::pair< Vertex_handle, Vertex_handle >; +using Graph_t = boost::adjacency_list, + boost::property >; +using Edge_t = std::pair; -using Kernel = CGAL::Epick_d< CGAL::Dimension_tag<3> >; +using Kernel = CGAL::Epick_d >; using Point = Kernel::Point_d; -using Traits = CGAL::Min_sphere_of_points_d_traits_d; +using Traits = CGAL::Min_sphere_of_points_d_traits_d; using Min_sphere = CGAL::Min_sphere_of_spheres_d; using Points_off_reader = Gudhi::Points_off_reader; @@ -76,7 +75,7 @@ class Cech_blocker { std::cout << vertex << ", "; #endif // DEBUG_TRACES } - Min_sphere ms(points.begin(),points.end()); + Min_sphere ms(points.begin(), points.end()); Filtration_value radius = ms.radius(); #if DEBUG_TRACES std::cout << "] - radius = " << radius << " - returns " << (radius > threshold_) << std::endl; @@ -85,24 +84,20 @@ class Cech_blocker { return (radius > threshold_); } Cech_blocker(Simplex_tree& simplex_tree, Filtration_value threshold, const std::vector& point_cloud) - : simplex_tree_(simplex_tree), - threshold_(threshold), - point_cloud_(point_cloud) { } + : simplex_tree_(simplex_tree), threshold_(threshold), point_cloud_(point_cloud) {} + private: Simplex_tree simplex_tree_; Filtration_value threshold_; std::vector point_cloud_; }; -template< typename InputPointRange> -Graph_t compute_proximity_graph(InputPointRange &points, Filtration_value threshold); +template +Graph_t compute_proximity_graph(InputPointRange& points, Filtration_value threshold); -void program_options(int argc, char * argv[] - , std::string & off_file_points - , Filtration_value & threshold - , int & dim_max); +void program_options(int argc, char* argv[], std::string& off_file_points, Filtration_value& threshold, int& dim_max); -int main(int argc, char * argv[]) { +int main(int argc, char* argv[]) { std::string off_file_points; Filtration_value threshold; int dim_max; @@ -115,7 +110,7 @@ int main(int argc, char * argv[]) { // Compute the proximity graph of the points Graph_t prox_graph = compute_proximity_graph(off_reader.get_point_cloud(), threshold); - //Min_sphere sph1(off_reader.get_point_cloud()[0], off_reader.get_point_cloud()[1], off_reader.get_point_cloud()[2]); + // Min_sphere sph1(off_reader.get_point_cloud()[0], off_reader.get_point_cloud()[1], off_reader.get_point_cloud()[2]); // Construct the Rips complex in a Simplex Tree Simplex_tree st; // insert the proximity graph in the simplex tree @@ -135,7 +130,8 @@ int main(int argc, char * argv[]) { std::cout << "* The complex contains " << st.num_simplices() << " simplices - dimension=" << st.dimension() << "\n"; std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; for (auto f_simplex : st.filtration_simplex_range()) { - std::cout << " " << "[" << st.filtration(f_simplex) << "] "; + std::cout << " " + << "[" << st.filtration(f_simplex) << "] "; for (auto vertex : st.simplex_vertex_range(f_simplex)) { std::cout << static_cast(vertex) << " "; } @@ -145,24 +141,19 @@ int main(int argc, char * argv[]) { return 0; } -void program_options(int argc, char * argv[] - , std::string & off_file_points - , Filtration_value & threshold - , int & dim_max) { +void program_options(int argc, char* argv[], std::string& off_file_points, Filtration_value& threshold, int& dim_max) { namespace po = boost::program_options; po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of an OFF file containing a 3d point set.\n"); + hidden.add_options()("input-file", po::value(&off_file_points), + "Name of an OFF file containing a 3d point set.\n"); po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Cech complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Cech complex we want to compute."); + visible.add_options()("help,h", "produce help message")( + "max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Cech complex construction.")( + "cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Cech complex we want to compute."); po::positional_options_description pos; pos.add("input-file", 1); @@ -171,8 +162,7 @@ void program_options(int argc, char * argv[] all.add(visible).add(hidden); po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); po::notify(vm); if (vm.count("help") || !vm.count("input-file")) { @@ -194,10 +184,10 @@ void program_options(int argc, char * argv[] * The type PointCloud furnishes .begin() and .end() methods, that return * iterators with value_type Point. */ -template< typename InputPointRange> -Graph_t compute_proximity_graph(InputPointRange &points, Filtration_value threshold) { - std::vector< Edge_t > edges; - std::vector< Filtration_value > edges_fil; +template +Graph_t compute_proximity_graph(InputPointRange& points, Filtration_value threshold) { + std::vector edges; + std::vector edges_fil; Kernel k; Vertex_handle idx_u, idx_v; @@ -217,16 +207,13 @@ Graph_t compute_proximity_graph(InputPointRange &points, Filtration_value thresh ++idx_u; } - Graph_t skel_graph(edges.begin() - , edges.end() - , edges_fil.begin() - , idx_u); // number of points labeled from 0 to idx_u-1 + Graph_t skel_graph(edges.begin(), edges.end(), edges_fil.begin(), + idx_u); // number of points labeled from 0 to idx_u-1 auto vertex_prop = boost::get(Gudhi::vertex_filtration_t(), skel_graph); boost::graph_traits::vertex_iterator vi, vi_end; - for (std::tie(vi, vi_end) = boost::vertices(skel_graph); - vi != vi_end; ++vi) { + for (std::tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi) { boost::put(vertex_prop, *vi, 0.); } diff --git a/src/Simplex_tree/example/graph_expansion_with_blocker.cpp b/src/Simplex_tree/example/graph_expansion_with_blocker.cpp index 86bfb8cb..0d458cbd 100644 --- a/src/Simplex_tree/example/graph_expansion_with_blocker.cpp +++ b/src/Simplex_tree/example/graph_expansion_with_blocker.cpp @@ -27,8 +27,7 @@ using Simplex_tree = Gudhi::Simplex_tree<>; using Simplex_handle = Simplex_tree::Simplex_handle; -int main(int argc, char * const argv[]) { - +int main(int argc, char* const argv[]) { // Construct the Simplex Tree with a 1-skeleton graph example Simplex_tree simplexTree; @@ -45,33 +44,32 @@ int main(int argc, char * const argv[]) { simplexTree.insert_simplex({5, 6}, 10.); simplexTree.insert_simplex({6}, 10.); - simplexTree.expansion_with_blockers(3, [&](Simplex_handle sh){ - bool result = false; - std::cout << "Blocker on ["; - // User can loop on the vertices from the given simplex_handle i.e. - for (auto vertex : simplexTree.simplex_vertex_range(sh)) { - // We block the expansion, if the vertex '6' is in the given list of vertices - if (vertex == 6) - result = true; - std::cout << vertex << ", "; - } - std::cout << "] ( " << simplexTree.filtration(sh); - // User can re-assign a new filtration value directly in the blocker (default is the maximal value of boudaries) - simplexTree.assign_filtration(sh, simplexTree.filtration(sh) + 1.); + simplexTree.expansion_with_blockers(3, [&](Simplex_handle sh) { + bool result = false; + std::cout << "Blocker on ["; + // User can loop on the vertices from the given simplex_handle i.e. + for (auto vertex : simplexTree.simplex_vertex_range(sh)) { + // We block the expansion, if the vertex '6' is in the given list of vertices + if (vertex == 6) result = true; + std::cout << vertex << ", "; + } + std::cout << "] ( " << simplexTree.filtration(sh); + // User can re-assign a new filtration value directly in the blocker (default is the maximal value of boudaries) + simplexTree.assign_filtration(sh, simplexTree.filtration(sh) + 1.); - std::cout << " + 1. ) = " << result << std::endl; + std::cout << " + 1. ) = " << result << std::endl; - return result; - }); + return result; + }); std::cout << "********************************************************************\n"; std::cout << "* The complex contains " << simplexTree.num_simplices() << " simplices"; std::cout << " - dimension " << simplexTree.dimension() << "\n"; std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; for (auto f_simplex : simplexTree.filtration_simplex_range()) { - std::cout << " " << "[" << simplexTree.filtration(f_simplex) << "] "; - for (auto vertex : simplexTree.simplex_vertex_range(f_simplex)) - std::cout << "(" << vertex << ")"; + std::cout << " " + << "[" << simplexTree.filtration(f_simplex) << "] "; + for (auto vertex : simplexTree.simplex_vertex_range(f_simplex)) std::cout << "(" << vertex << ")"; std::cout << std::endl; } diff --git a/src/Simplex_tree/example/simple_simplex_tree.cpp b/src/Simplex_tree/example/simple_simplex_tree.cpp index b6b65b88..828977c2 100644 --- a/src/Simplex_tree/example/simple_simplex_tree.cpp +++ b/src/Simplex_tree/example/simple_simplex_tree.cpp @@ -30,10 +30,10 @@ using Simplex_tree = Gudhi::Simplex_tree<>; using Vertex_handle = Simplex_tree::Vertex_handle; using Filtration_value = Simplex_tree::Filtration_value; -using typeVectorVertex = std::vector< Vertex_handle >; -using typePairSimplexBool = std::pair< Simplex_tree::Simplex_handle, bool >; +using typeVectorVertex = std::vector; +using typePairSimplexBool = std::pair; -int main(int argc, char * const argv[]) { +int main(int argc, char* const argv[]) { const Filtration_value FIRST_FILTRATION_VALUE = 0.1; const Filtration_value SECOND_FILTRATION_VALUE = 0.2; const Filtration_value THIRD_FILTRATION_VALUE = 0.3; @@ -54,7 +54,7 @@ int main(int argc, char * const argv[]) { // ++ FIRST std::cout << " * INSERT 0" << std::endl; - typeVectorVertex firstSimplexVector = { 0 }; + typeVectorVertex firstSimplexVector = {0}; typePairSimplexBool returnValue = simplexTree.insert_simplex(firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); @@ -66,9 +66,8 @@ int main(int argc, char * const argv[]) { // ++ SECOND std::cout << " * INSERT 1" << std::endl; - typeVectorVertex secondSimplexVector = { 1 }; - returnValue = - simplexTree.insert_simplex(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + typeVectorVertex secondSimplexVector = {1}; + returnValue = simplexTree.insert_simplex(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + 1 INSERTED" << std::endl; @@ -78,9 +77,8 @@ int main(int argc, char * const argv[]) { // ++ THIRD std::cout << " * INSERT (0,1)" << std::endl; - typeVectorVertex thirdSimplexVector = { 0, 1 }; - returnValue = - simplexTree.insert_simplex(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + typeVectorVertex thirdSimplexVector = {0, 1}; + returnValue = simplexTree.insert_simplex(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (0,1) INSERTED" << std::endl; @@ -90,9 +88,8 @@ int main(int argc, char * const argv[]) { // ++ FOURTH std::cout << " * INSERT 2" << std::endl; - typeVectorVertex fourthSimplexVector = { 2 }; - returnValue = - simplexTree.insert_simplex(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + typeVectorVertex fourthSimplexVector = {2}; + returnValue = simplexTree.insert_simplex(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + 2 INSERTED" << std::endl; @@ -102,9 +99,8 @@ int main(int argc, char * const argv[]) { // ++ FIFTH std::cout << " * INSERT (2,0)" << std::endl; - typeVectorVertex fifthSimplexVector = { 2, 0 }; - returnValue = - simplexTree.insert_simplex(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + typeVectorVertex fifthSimplexVector = {2, 0}; + returnValue = simplexTree.insert_simplex(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (2,0) INSERTED" << std::endl; @@ -114,9 +110,8 @@ int main(int argc, char * const argv[]) { // ++ SIXTH std::cout << " * INSERT (2,1)" << std::endl; - typeVectorVertex sixthSimplexVector = { 2, 1 }; - returnValue = - simplexTree.insert_simplex(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + typeVectorVertex sixthSimplexVector = {2, 1}; + returnValue = simplexTree.insert_simplex(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (2,1) INSERTED" << std::endl; @@ -126,9 +121,8 @@ int main(int argc, char * const argv[]) { // ++ SEVENTH std::cout << " * INSERT (2,1,0)" << std::endl; - typeVectorVertex seventhSimplexVector = { 2, 1, 0 }; - returnValue = - simplexTree.insert_simplex(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); + typeVectorVertex seventhSimplexVector = {2, 1, 0}; + returnValue = simplexTree.insert_simplex(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (2,1,0) INSERTED" << std::endl; @@ -138,9 +132,8 @@ int main(int argc, char * const argv[]) { // ++ EIGHTH std::cout << " * INSERT 3" << std::endl; - typeVectorVertex eighthSimplexVector = { 3 }; - returnValue = - simplexTree.insert_simplex(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + typeVectorVertex eighthSimplexVector = {3}; + returnValue = simplexTree.insert_simplex(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + 3 INSERTED" << std::endl; @@ -150,9 +143,8 @@ int main(int argc, char * const argv[]) { // ++ NINETH std::cout << " * INSERT (3,0)" << std::endl; - typeVectorVertex ninethSimplexVector = { 3, 0 }; - returnValue = - simplexTree.insert_simplex(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + typeVectorVertex ninethSimplexVector = {3, 0}; + returnValue = simplexTree.insert_simplex(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (3,0) INSERTED" << std::endl; @@ -162,7 +154,7 @@ int main(int argc, char * const argv[]) { // ++ TENTH std::cout << " * INSERT 0 (already inserted)" << std::endl; - typeVectorVertex tenthSimplexVector = { 0 }; + typeVectorVertex tenthSimplexVector = {0}; // With a different filtration value returnValue = simplexTree.insert_simplex(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); @@ -174,9 +166,8 @@ int main(int argc, char * const argv[]) { // ++ ELEVENTH std::cout << " * INSERT (2,1,0) (already inserted)" << std::endl; - typeVectorVertex eleventhSimplexVector = { 2, 1, 0 }; - returnValue = - simplexTree.insert_simplex(eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); + typeVectorVertex eleventhSimplexVector = {2, 1, 0}; + returnValue = simplexTree.insert_simplex(eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (2,1,0) INSERTED" << std::endl; @@ -192,9 +183,9 @@ int main(int argc, char * const argv[]) { std::cout << " - dimension " << simplexTree.dimension() << "\n"; std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; for (auto f_simplex : simplexTree.filtration_simplex_range()) { - std::cout << " " << "[" << simplexTree.filtration(f_simplex) << "] "; - for (auto vertex : simplexTree.simplex_vertex_range(f_simplex)) - std::cout << "(" << vertex << ")"; + std::cout << " " + << "[" << simplexTree.filtration(f_simplex) << "] "; + for (auto vertex : simplexTree.simplex_vertex_range(f_simplex)) std::cout << "(" << vertex << ")"; std::cout << std::endl; } // [0.1] 0 @@ -217,7 +208,7 @@ int main(int argc, char * const argv[]) { else std::cout << "***- NO IT ISN'T\n"; - typeVectorVertex unknownSimplexVector = { 15 }; + typeVectorVertex unknownSimplexVector = {15}; simplexFound = simplexTree.find(unknownSimplexVector); std::cout << "**************IS THE SIMPLEX {15} IN THE SIMPLEX TREE ?\n"; if (simplexFound != simplexTree.null_simplex()) @@ -232,7 +223,7 @@ int main(int argc, char * const argv[]) { else std::cout << "***- NO IT ISN'T\n"; - typeVectorVertex otherSimplexVector = { 1, 15 }; + typeVectorVertex otherSimplexVector = {1, 15}; simplexFound = simplexTree.find(otherSimplexVector); std::cout << "**************IS THE SIMPLEX {15,1} IN THE SIMPLEX TREE ?\n"; if (simplexFound != simplexTree.null_simplex()) @@ -240,7 +231,7 @@ int main(int argc, char * const argv[]) { else std::cout << "***- NO IT ISN'T\n"; - typeVectorVertex invSimplexVector = { 1, 2, 0 }; + typeVectorVertex invSimplexVector = {1, 2, 0}; simplexFound = simplexTree.find(invSimplexVector); std::cout << "**************IS THE SIMPLEX {1,2,0} IN THE SIMPLEX TREE ?\n"; if (simplexFound != simplexTree.null_simplex()) @@ -248,7 +239,7 @@ int main(int argc, char * const argv[]) { else std::cout << "***- NO IT ISN'T\n"; - simplexFound = simplexTree.find({ 0, 1 }); + simplexFound = simplexTree.find({0, 1}); std::cout << "**************IS THE SIMPLEX {0,1} IN THE SIMPLEX TREE ?\n"; if (simplexFound != simplexTree.null_simplex()) std::cout << "***+ YES IT IS!\n"; @@ -256,23 +247,20 @@ int main(int argc, char * const argv[]) { std::cout << "***- NO IT ISN'T\n"; std::cout << "**************COFACES OF {0,1} IN CODIMENSION 1 ARE\n"; - for (auto& simplex : simplexTree.cofaces_simplex_range(simplexTree.find({0,1}), 1)) { - for (auto vertex : simplexTree.simplex_vertex_range(simplex)) - std::cout << "(" << vertex << ")"; + for (auto& simplex : simplexTree.cofaces_simplex_range(simplexTree.find({0, 1}), 1)) { + for (auto vertex : simplexTree.simplex_vertex_range(simplex)) std::cout << "(" << vertex << ")"; std::cout << std::endl; } std::cout << "**************STARS OF {0,1} ARE\n"; - for (auto& simplex : simplexTree.star_simplex_range(simplexTree.find({0,1}))) { - for (auto vertex : simplexTree.simplex_vertex_range(simplex)) - std::cout << "(" << vertex << ")"; + for (auto& simplex : simplexTree.star_simplex_range(simplexTree.find({0, 1}))) { + for (auto vertex : simplexTree.simplex_vertex_range(simplex)) std::cout << "(" << vertex << ")"; std::cout << std::endl; } std::cout << "**************BOUNDARIES OF {0,1,2} ARE\n"; - for (auto& simplex : simplexTree.boundary_simplex_range(simplexTree.find({0,1,2}))) { - for (auto vertex : simplexTree.simplex_vertex_range(simplex)) - std::cout << "(" << vertex << ")"; + for (auto& simplex : simplexTree.boundary_simplex_range(simplexTree.find({0, 1, 2}))) { + for (auto vertex : simplexTree.simplex_vertex_range(simplex)) std::cout << "(" << vertex << ")"; std::cout << std::endl; } diff --git a/src/Spatial_searching/include/gudhi/Kd_tree_search.h b/src/Spatial_searching/include/gudhi/Kd_tree_search.h index ef428002..96bbeb36 100644 --- a/src/Spatial_searching/include/gudhi/Kd_tree_search.h +++ b/src/Spatial_searching/include/gudhi/Kd_tree_search.h @@ -271,8 +271,7 @@ class Kd_tree_search { m_tree.search(it, Fuzzy_sphere(p, radius, eps, m_tree.traits())); } - int tree_depth() const - { + int tree_depth() const { return m_tree.root()->depth(); } diff --git a/src/Witness_complex/example/example_strong_witness_complex_off.cpp b/src/Witness_complex/example/example_strong_witness_complex_off.cpp index bc069654..346bef6d 100644 --- a/src/Witness_complex/example/example_strong_witness_complex_off.cpp +++ b/src/Witness_complex/example/example_strong_witness_complex_off.cpp @@ -39,10 +39,9 @@ using Point_d = typename K::Point_d; using Witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; using Point_vector = std::vector; -int main(int argc, char * const argv[]) { +int main(int argc, char* const argv[]) { if (argc != 5) { - std::cerr << "Usage: " << argv[0] - << " path_to_point_file number_of_landmarks max_squared_alpha limit_dimension\n"; + std::cerr << "Usage: " << argv[0] << " path_to_point_file number_of_landmarks max_squared_alpha limit_dimension\n"; return 0; } @@ -56,9 +55,9 @@ int main(int argc, char * const argv[]) { Point_vector point_vector, landmarks; Gudhi::Points_off_reader off_reader(file_name); if (!off_reader.is_valid()) { - std::cerr << "Strong witness complex - Unable to read file " << file_name << "\n"; - exit(-1); // ----- >> - } + std::cerr << "Strong witness complex - Unable to read file " << file_name << "\n"; + exit(-1); // ----- >> + } point_vector = Point_vector(off_reader.get_point_cloud()); std::cout << "Successfully read " << point_vector.size() << " points.\n"; @@ -66,16 +65,15 @@ int main(int argc, char * const argv[]) { // Choose landmarks (decomment one of the following two lines) // Gudhi::subsampling::pick_n_random_points(point_vector, nbL, std::back_inserter(landmarks)); - Gudhi::subsampling::choose_n_farthest_points(K(), point_vector, nbL, Gudhi::subsampling::random_starting_point, std::back_inserter(landmarks)); - + Gudhi::subsampling::choose_n_farthest_points(K(), point_vector, nbL, Gudhi::subsampling::random_starting_point, + std::back_inserter(landmarks)); + // Compute witness complex start = clock(); - Witness_complex witness_complex(landmarks, - point_vector); + Witness_complex witness_complex(landmarks, point_vector); witness_complex.create_complex(simplex_tree, alpha2, lim_dim); end = clock(); - std::cout << "Strong witness complex took " - << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; + std::cout << "Strong witness complex took " << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; std::cout << "Number of simplices is: " << simplex_tree.num_simplices() << "\n"; } diff --git a/src/Witness_complex/example/example_witness_complex_sphere.cpp b/src/Witness_complex/example/example_witness_complex_sphere.cpp index a66da3f9..a6e9b11a 100644 --- a/src/Witness_complex/example/example_witness_complex_sphere.cpp +++ b/src/Witness_complex/example/example_witness_complex_sphere.cpp @@ -42,27 +42,25 @@ /** Write a gnuplot readable file. * Data range is a random access range of pairs (arg, value) */ -template < typename Data_range > -void write_data(Data_range & data, std::string filename) { +template +void write_data(Data_range& data, std::string filename) { std::ofstream ofs(filename, std::ofstream::out); - for (auto entry : data) - ofs << entry.first << ", " << entry.second << "\n"; + for (auto entry : data) ofs << entry.first << ", " << entry.second << "\n"; ofs.close(); } -int main(int argc, char * const argv[]) { +int main(int argc, char* const argv[]) { using Kernel = CGAL::Epick_d; using Witness_complex = Gudhi::witness_complex::Euclidean_witness_complex; if (argc != 2) { - std::cerr << "Usage: " << argv[0] - << " number_of_landmarks \n"; + std::cerr << "Usage: " << argv[0] << " number_of_landmarks \n"; return 0; } int number_of_landmarks = atoi(argv[1]); - std::vector< std::pair > l_time; + std::vector > l_time; // Generate points for (int nbP = 500; nbP < 10000; nbP += 500) { @@ -77,16 +75,16 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); // Gudhi::subsampling::pick_n_random_points(point_vector, number_of_landmarks, std::back_inserter(landmarks)); - Gudhi::subsampling::choose_n_farthest_points(K(), point_vector, number_of_landmarks, Gudhi::subsampling::random_starting_point, std::back_inserter(landmarks)); + Gudhi::subsampling::choose_n_farthest_points(K(), point_vector, number_of_landmarks, + Gudhi::subsampling::random_starting_point, + std::back_inserter(landmarks)); // Compute witness complex - Witness_complex witness_complex(landmarks, - point_vector); + Witness_complex witness_complex(landmarks, point_vector); witness_complex.create_complex(simplex_tree, 0); end = clock(); double time = static_cast(end - start) / CLOCKS_PER_SEC; - std::cout << "Witness complex for " << number_of_landmarks << " landmarks took " - << time << " s. \n"; + std::cout << "Witness complex for " << number_of_landmarks << " landmarks took " << time << " s. \n"; std::cout << "Number of simplices is: " << simplex_tree.num_simplices() << "\n"; l_time.push_back(std::make_pair(nbP, time)); } diff --git a/src/Witness_complex/utilities/strong_witness_persistence.cpp b/src/Witness_complex/utilities/strong_witness_persistence.cpp index e3e0c1ee..2fba631b 100644 --- a/src/Witness_complex/utilities/strong_witness_persistence.cpp +++ b/src/Witness_complex/utilities/strong_witness_persistence.cpp @@ -47,16 +47,10 @@ using Filtration_value = SimplexTree::Filtration_value; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { +void program_options(int argc, char* argv[], int& nbL, std::string& file_name, std::string& filediag, + Filtration_value& max_squared_alpha, int& p, int& dim_max, Filtration_value& min_persistence); + +int main(int argc, char* argv[]) { std::string file_name; std::string filediag; Filtration_value max_squared_alpha; @@ -70,8 +64,8 @@ int main(int argc, char * argv[]) { Point_vector witnesses, landmarks; Gudhi::Points_off_reader off_reader(file_name); if (!off_reader.is_valid()) { - std::cerr << "Witness complex - Unable to read file " << file_name << "\n"; - exit(-1); // ----- >> + std::cerr << "Witness complex - Unable to read file " << file_name << "\n"; + exit(-1); // ----- >> } witnesses = Point_vector(off_reader.get_point_cloud()); std::cout << "Successfully read " << witnesses.size() << " points.\n"; @@ -79,11 +73,11 @@ int main(int argc, char * argv[]) { // Choose landmarks (decomment one of the following two lines) // Gudhi::subsampling::pick_n_random_points(point_vector, nbL, std::back_inserter(landmarks)); - Gudhi::subsampling::choose_n_farthest_points(K(), witnesses, nbL, Gudhi::subsampling::random_starting_point, std::back_inserter(landmarks)); + Gudhi::subsampling::choose_n_farthest_points(K(), witnesses, nbL, Gudhi::subsampling::random_starting_point, + std::back_inserter(landmarks)); // Compute witness complex - Strong_witness_complex strong_witness_complex(landmarks, - witnesses); + Strong_witness_complex strong_witness_complex(landmarks, witnesses); strong_witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); @@ -112,37 +106,28 @@ int main(int argc, char * argv[]) { return 0; } -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence) { +void program_options(int argc, char* argv[], int& nbL, std::string& file_name, std::string& filediag, + Filtration_value& max_squared_alpha, int& p, int& dim_max, Filtration_value& min_persistence) { namespace po = boost::program_options; po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&file_name), - "Name of file containing a point set in off format."); + hidden.add_options()("input-file", po::value(&file_name), + "Name of file containing a point set in off format."); po::options_description visible("Allowed options", 100); Filtration_value default_alpha = std::numeric_limits::infinity(); - visible.add_options() - ("help,h", "produce help message") - ("landmarks,l", po::value(&nbL), - "Number of landmarks to choose from the point cloud.") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), - "Maximal squared relaxation parameter.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence)->default_value(0), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") - ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), - "Maximal dimension of the strong witness complex we want to compute."); + visible.add_options()("help,h", "produce help message")("landmarks,l", po::value(&nbL), + "Number of landmarks to choose from the point cloud.")( + "output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), + "Maximal squared relaxation parameter.")( + "field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence)->default_value(0), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals")("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), + "Maximal dimension of the strong witness complex we want to compute."); po::positional_options_description pos; pos.add("input-file", 1); @@ -151,8 +136,7 @@ void program_options(int argc, char * argv[] all.add(visible).add(hidden); po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); po::notify(vm); if (vm.count("help") || !vm.count("input-file")) { @@ -170,4 +154,3 @@ void program_options(int argc, char * argv[] std::abort(); } } - diff --git a/src/Witness_complex/utilities/weak_witness_persistence.cpp b/src/Witness_complex/utilities/weak_witness_persistence.cpp index a63b0837..23fa93aa 100644 --- a/src/Witness_complex/utilities/weak_witness_persistence.cpp +++ b/src/Witness_complex/utilities/weak_witness_persistence.cpp @@ -47,16 +47,10 @@ using Filtration_value = SimplexTree::Filtration_value; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { +void program_options(int argc, char* argv[], int& nbL, std::string& file_name, std::string& filediag, + Filtration_value& max_squared_alpha, int& p, int& dim_max, Filtration_value& min_persistence); + +int main(int argc, char* argv[]) { std::string file_name; std::string filediag; Filtration_value max_squared_alpha; @@ -70,8 +64,8 @@ int main(int argc, char * argv[]) { Point_vector witnesses, landmarks; Gudhi::Points_off_reader off_reader(file_name); if (!off_reader.is_valid()) { - std::cerr << "Witness complex - Unable to read file " << file_name << "\n"; - exit(-1); // ----- >> + std::cerr << "Witness complex - Unable to read file " << file_name << "\n"; + exit(-1); // ----- >> } witnesses = Point_vector(off_reader.get_point_cloud()); std::cout << "Successfully read " << witnesses.size() << " points.\n"; @@ -79,11 +73,11 @@ int main(int argc, char * argv[]) { // Choose landmarks (decomment one of the following two lines) // Gudhi::subsampling::pick_n_random_points(point_vector, nbL, std::back_inserter(landmarks)); - Gudhi::subsampling::choose_n_farthest_points(K(), witnesses, nbL, Gudhi::subsampling::random_starting_point, std::back_inserter(landmarks)); + Gudhi::subsampling::choose_n_farthest_points(K(), witnesses, nbL, Gudhi::subsampling::random_starting_point, + std::back_inserter(landmarks)); // Compute witness complex - Witness_complex witness_complex(landmarks, - witnesses); + Witness_complex witness_complex(landmarks, witnesses); witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); @@ -112,38 +106,28 @@ int main(int argc, char * argv[]) { return 0; } - -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence) { +void program_options(int argc, char* argv[], int& nbL, std::string& file_name, std::string& filediag, + Filtration_value& max_squared_alpha, int& p, int& dim_max, Filtration_value& min_persistence) { namespace po = boost::program_options; po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&file_name), - "Name of file containing a point set in off format."); + hidden.add_options()("input-file", po::value(&file_name), + "Name of file containing a point set in off format."); Filtration_value default_alpha = std::numeric_limits::infinity(); po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("landmarks,l", po::value(&nbL), - "Number of landmarks to choose from the point cloud.") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), - "Maximal squared relaxation parameter.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence)->default_value(0), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") - ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), - "Maximal dimension of the weak witness complex we want to compute."); + visible.add_options()("help,h", "produce help message")("landmarks,l", po::value(&nbL), + "Number of landmarks to choose from the point cloud.")( + "output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), + "Maximal squared relaxation parameter.")( + "field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence)->default_value(0), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals")("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), + "Maximal dimension of the weak witness complex we want to compute."); po::positional_options_description pos; pos.add("input-file", 1); @@ -152,8 +136,7 @@ void program_options(int argc, char * argv[] all.add(visible).add(hidden); po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); po::notify(vm); if (vm.count("help") || !vm.count("input-file")) { diff --git a/src/common/include/gudhi/Unitary_tests_utils.h b/src/common/include/gudhi/Unitary_tests_utils.h index 7ae5d356..8394a062 100644 --- a/src/common/include/gudhi/Unitary_tests_utils.h +++ b/src/common/include/gudhi/Unitary_tests_utils.h @@ -25,6 +25,7 @@ #include #include +#include // for std::numeric_limits<> template void GUDHI_TEST_FLOAT_EQUALITY_CHECK(FloatingType a, FloatingType b, -- cgit v1.2.3