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