diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-01-08 13:34:18 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-01-08 13:34:18 +0000 |
commit | 8ce961c5d86845613a196e2a5b1e3ea724698d88 (patch) | |
tree | 2bf3b92950a6e1fedc9aa44a24e096cf96bcf821 | |
parent | 7cf0599b211bc6cd5e8a64a75550cdf40b3fbb14 (diff) | |
parent | 22ab936a67cdf649091599526f239bdb263100f9 (diff) |
Merge of branch persistence_representation_integration_cmake_improvement
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@3117 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 673143bd16e06d990aeb104a506cfd71f91a8717
60 files changed, 727 insertions, 936 deletions
diff --git a/data/persistence_diagram/simple_diagram.txt b/data/persistence_diagram/simple_diagram.txt deleted file mode 100644 index 2f199fd4..00000000 --- a/data/persistence_diagram/simple_diagram.txt +++ /dev/null @@ -1,4 +0,0 @@ -1 2 -3 4 -5 6 -7 8
\ No newline at end of file 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 <boost/test/unit_test.hpp> +#include <boost/mpl/list.hpp> #include <CGAL/Delaunay_triangulation.h> #include <CGAL/Epick_d.h> @@ -36,7 +37,7 @@ // to construct a simplex_tree from Delaunay_triangulation #include <gudhi/graph_simplicial_complex.h> #include <gudhi/Simplex_tree.h> -#include <boost/mpl/list.hpp> +#include <gudhi/Unitary_tests_utils.h> // 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<float>::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/example/CMakeLists.txt b/src/Persistence_representations/example/CMakeLists.txt index 7788b603..b8ce8ea6 100644 --- a/src/Persistence_representations/example/CMakeLists.txt +++ b/src/Persistence_representations/example/CMakeLists.txt @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 2.6) project(Persistence_representations_example) -file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") - add_executable ( Persistence_representations_example_landscape_on_grid persistence_landscape_on_grid.cpp ) target_link_libraries(Persistence_representations_example_landscape_on_grid ${Boost_SYSTEM_LIBRARY}) add_test(NAME Persistence_representations_example_landscape_on_grid @@ -17,7 +15,7 @@ add_executable ( Persistence_representations_example_intervals persistence_inter target_link_libraries(Persistence_representations_example_intervals ${Boost_SYSTEM_LIBRARY}) add_test(NAME Persistence_representations_example_intervals COMMAND $<TARGET_FILE:Persistence_representations_example_intervals> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") + "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers") add_executable ( Persistence_representations_example_vectors persistence_vectors.cpp ) target_link_libraries(Persistence_representations_example_vectors ${Boost_SYSTEM_LIBRARY}) diff --git a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h index fb741642..a80c3c40 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h +++ b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h @@ -743,10 +743,10 @@ void Persistence_heat_maps<Scalling_of_kernels>::compute_percentage_of_active( template <typename Scalling_of_kernels> void Persistence_heat_maps<Scalling_of_kernels>::plot(const char* filename) const { std::ofstream out; - std::stringstream ss; - ss << filename << "_GnuplotScript"; + std::stringstream gnuplot_script; + gnuplot_script << filename << "_GnuplotScript"; - out.open(ss.str().c_str()); + out.open(gnuplot_script.str().c_str()); out << "plot '-' matrix with image" << std::endl; for (size_t i = 0; i != this->heat_map.size(); ++i) { for (size_t j = 0; j != this->heat_map[i].size(); ++j) { @@ -755,8 +755,8 @@ void Persistence_heat_maps<Scalling_of_kernels>::plot(const char* filename) cons out << std::endl; } out.close(); - std::cout << "Gnuplot script have been created. Open gnuplot and type load \'" << ss.str().c_str() - << "\' to see the picture." << std::endl; + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; } template <typename Scalling_of_kernels> diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h index a3f963cf..3d04d8b7 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h @@ -167,10 +167,10 @@ class Persistence_intervals { // this program create a gnuplot script file that allows to plot persistence diagram. std::ofstream out; - std::ostringstream nameSS; - nameSS << filename << "_GnuplotScript"; - std::string nameStr = nameSS.str(); - out.open(nameStr); + std::stringstream gnuplot_script; + gnuplot_script << filename << "_GnuplotScript"; + + out.open(gnuplot_script.str().c_str()); std::pair<double, double> min_max_values = this->get_x_range(); if (min_x == max_x) { @@ -195,8 +195,8 @@ class Persistence_intervals { out.close(); - std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '" - << nameStr << "' in gnuplot to visualize." << std::endl; + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; } /** 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 e476d28a..79908883 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h @@ -46,7 +46,7 @@ class Persistence_intervals_with_distances : public Persistence_intervals { * The last parameter, tolerance, it is an additiv error of the approimation, set by default to zero. **/ double distance(const Persistence_intervals_with_distances& second, double power = std::numeric_limits<double>::max(), - double tolerance = 0) const { + double tolerance = (std::numeric_limits<double>::min)()) const { if (power >= std::numeric_limits<double>::max()) { return Gudhi::persistence_diagram::bottleneck_distance(this->intervals, second.intervals, tolerance); } else { diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape.h b/src/Persistence_representations/include/gudhi/Persistence_landscape.h index 2d83dcc3..c5aa7867 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape.h @@ -1331,10 +1331,9 @@ void Persistence_landscape::plot(const char* filename, double xRangeBegin, doubl // this program create a gnuplot script file that allows to plot persistence diagram. std::ofstream out; - std::ostringstream nameSS; - nameSS << filename << "_GnuplotScript"; - std::string nameStr = nameSS.str(); - out.open(nameStr); + std::ostringstream gnuplot_script; + gnuplot_script << filename << "_GnuplotScript"; + out.open(gnuplot_script.str().c_str()); if ((xRangeBegin != std::numeric_limits<double>::max()) || (xRangeEnd != std::numeric_limits<double>::max()) || (yRangeBegin != std::numeric_limits<double>::max()) || (yRangeEnd != std::numeric_limits<double>::max())) { @@ -1367,8 +1366,8 @@ void Persistence_landscape::plot(const char* filename, double xRangeBegin, doubl } out << "EOF" << std::endl; } - std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '" - << nameStr << "' in gnuplot to visualize." << std::endl; + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; } } // namespace Persistence_representations 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 4ceb9bf6..84fd22ed 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h @@ -1207,10 +1207,9 @@ void Persistence_landscape_on_grid::plot(const char* filename, double min_x, dou // this program create a gnuplot script file that allows to plot persistence diagram. std::ofstream out; - std::ostringstream nameSS; - nameSS << filename << "_GnuplotScript"; - std::string nameStr = nameSS.str(); - out.open(nameStr); + std::ostringstream gnuplot_script; + gnuplot_script << filename << "_GnuplotScript"; + out.open(gnuplot_script.str().c_str()); if (min_x == max_x) { std::pair<double, double> min_max = compute_minimum_maximum(); @@ -1241,7 +1240,6 @@ void Persistence_landscape_on_grid::plot(const char* filename, double min_x, dou out << "plot "; for (size_t lambda = from; lambda != to; ++lambda) { - // out << " '-' using 1:2 title 'l" << lambda << "' with lp"; out << " '-' using 1:2 notitle with lp"; if (lambda + 1 != to) { out << ", \\"; @@ -1261,8 +1259,8 @@ void Persistence_landscape_on_grid::plot(const char* filename, double min_x, dou } out << "EOF" << std::endl; } - std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '" - << nameStr << "' in gnuplot to visualize." << std::endl; + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; } template <typename T> diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h index aed48b73..63577e46 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h +++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h @@ -201,7 +201,8 @@ class Vector_distances_in_diagram { } out << std::endl; out.close(); - std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; } /** 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 <boost/test/unit_test.hpp> #include <gudhi/reader_utils.h> #include <gudhi/Persistence_heat_maps.h> +#include <gudhi/Unitary_tests_utils.h> #include <iostream> using namespace Gudhi; using namespace Gudhi::Persistence_representations; +double epsilon = 0.0005; + BOOST_AUTO_TEST_CASE(check_construction_of_heat_maps) { std::vector<std::vector<double> > filter = create_Gaussian_filter(100, 1); Persistence_heat_maps<constant_scaling_function> 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<constant_scaling_function> q("data/file_with_diagram_1", filter, false, 1000, 0, 1); Persistence_heat_maps<constant_scaling_function> 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<constant_scaling_function> q("data/file_with_diagram_1", filter, false, 1000, 0, 1); Persistence_heat_maps<constant_scaling_function> 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<constant_scaling_function> q("data/file_with_diagram_1", filter, false, 1000, 0, 1); Persistence_heat_maps<constant_scaling_function> 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/Persistence_representations/test/persistence_intervals_test.cpp b/src/Persistence_representations/test/persistence_intervals_test.cpp index 545330c4..c8f67966 100644 --- a/src/Persistence_representations/test/persistence_intervals_test.cpp +++ b/src/Persistence_representations/test/persistence_intervals_test.cpp @@ -25,25 +25,20 @@ #include <boost/test/unit_test.hpp> #include <gudhi/reader_utils.h> #include "gudhi/Persistence_intervals.h" +#include <gudhi/common_persistence_representations.h> +#include <gudhi/Unitary_tests_utils.h> #include <iostream> using namespace Gudhi; using namespace Gudhi::Persistence_representations; -double epsilon = 0.0000005; - -// cout << "Left most end of the interval : " << min_max_.first << std::endl; -// cout << "Right most end of the interval : " << min_max_.second << std::endl; BOOST_AUTO_TEST_CASE(check_min_max_function) { - std::cerr << "First test \n"; Persistence_intervals p("data/file_with_diagram"); std::pair<double, double> min_max_ = p.get_x_range(); - // cout << min_max_.first << " " << min_max_.second << std::endl;getchar(); - - BOOST_CHECK(fabs(min_max_.first - 0.0290362) <= epsilon); - BOOST_CHECK(fabs(min_max_.second - 0.994537) <= epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(min_max_.first, 0.0290362, Gudhi::Persistence_representations::epsi); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(min_max_.second, 0.994537, Gudhi::Persistence_representations::epsi); } BOOST_AUTO_TEST_CASE(check_length_of_dominant_intervals) { @@ -61,7 +56,8 @@ BOOST_AUTO_TEST_CASE(check_length_of_dominant_intervals) { dominant_intervals_length.push_back(0.700468); dominant_intervals_length.push_back(0.622177); for (size_t i = 0; i != dominant_ten_intervals_length.size(); ++i) { - BOOST_CHECK(fabs(dominant_ten_intervals_length[i] - dominant_intervals_length[i]) <= epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(dominant_ten_intervals_length[i], dominant_intervals_length[i], + Gudhi::Persistence_representations::epsi); } } BOOST_AUTO_TEST_CASE(check_dominant_intervals) { @@ -81,8 +77,10 @@ BOOST_AUTO_TEST_CASE(check_dominant_intervals) { templ.push_back(std::pair<double, double>(0.267421, 0.889597)); for (size_t i = 0; i != ten_dominant_intervals.size(); ++i) { - BOOST_CHECK(fabs(ten_dominant_intervals[i].first - templ[i].first) <= epsilon); - BOOST_CHECK(fabs(ten_dominant_intervals[i].second - templ[i].second) <= epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(ten_dominant_intervals[i].first, templ[i].first, + Gudhi::Persistence_representations::epsi); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(ten_dominant_intervals[i].second, templ[i].second, + Gudhi::Persistence_representations::epsi); } } @@ -102,7 +100,7 @@ BOOST_AUTO_TEST_CASE(check_histogram_of_lengths) { template_histogram.push_back(1); template_histogram.push_back(1); for (size_t i = 0; i != histogram.size(); ++i) { - BOOST_CHECK(fabs(histogram[i] - template_histogram[i]) <= epsilon); + BOOST_CHECK(histogram[i] == template_histogram[i]); } } @@ -123,7 +121,7 @@ BOOST_AUTO_TEST_CASE(check_cumulative_histograms_of_lengths) { template_cumulative_histogram.push_back(45); for (size_t i = 0; i != cumulative_histogram.size(); ++i) { - BOOST_CHECK(fabs(cumulative_histogram[i] - template_cumulative_histogram[i]) <= epsilon); + BOOST_CHECK(cumulative_histogram[i] == template_cumulative_histogram[i]); } } BOOST_AUTO_TEST_CASE(check_characteristic_function_of_diagram) { @@ -143,15 +141,8 @@ BOOST_AUTO_TEST_CASE(check_characteristic_function_of_diagram) { template_char_funct_diag.push_back(0.0676303); for (size_t i = 0; i != char_funct_diag.size(); ++i) { - // cout << char_funct_diag[i] << std::endl; - if (fabs(char_funct_diag[i] - template_char_funct_diag[i]) >= 0.0001) { - std::cout << "Boost test fail check_characteristic_function_of_diagram : " << std::endl; - std::cerr << char_funct_diag[i] << " " << template_char_funct_diag[i] << std::endl; - std::cerr << fabs(char_funct_diag[i] - template_char_funct_diag[i]) << std::endl; - std::cerr << 0.0001 << std::endl; - //getchar(); - } - BOOST_CHECK(fabs(char_funct_diag[i] - template_char_funct_diag[i]) <= 0.0001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(char_funct_diag[i], template_char_funct_diag[i], + Gudhi::Persistence_representations::epsi); } } @@ -174,110 +165,110 @@ BOOST_AUTO_TEST_CASE(check_cumulative_characteristic_function_of_diagram) { template_char_funct_diag_cumul.push_back(9.48386); for (size_t i = 0; i != cumul_char_funct_diag.size(); ++i) { - // cout << cumul_char_funct_diag[i] << std::endl; - BOOST_CHECK(fabs(cumul_char_funct_diag[i] - template_char_funct_diag_cumul[i]) <= 0.0001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(cumul_char_funct_diag[i], template_char_funct_diag_cumul[i], + Gudhi::Persistence_representations::epsi); } } BOOST_AUTO_TEST_CASE(check_compute_persistent_betti_numbers) { Persistence_intervals p("data/file_with_diagram"); - std::vector<std::pair<double, double> > pbns; - pbns.push_back(std::pair<double, double>(0.0290362, 1)); - pbns.push_back(std::pair<double, double>(0.0307676, 2)); - pbns.push_back(std::pair<double, double>(0.0366312, 3)); - pbns.push_back(std::pair<double, double>(0.0544614, 4)); - pbns.push_back(std::pair<double, double>(0.0920033, 5)); - pbns.push_back(std::pair<double, double>(0.104599, 6)); - pbns.push_back(std::pair<double, double>(0.114718, 7)); - pbns.push_back(std::pair<double, double>(0.117379, 8)); - pbns.push_back(std::pair<double, double>(0.123493, 9)); - pbns.push_back(std::pair<double, double>(0.133638, 10)); - pbns.push_back(std::pair<double, double>(0.137798, 9)); - pbns.push_back(std::pair<double, double>(0.149798, 10)); - pbns.push_back(std::pair<double, double>(0.155421, 11)); - pbns.push_back(std::pair<double, double>(0.158443, 12)); - pbns.push_back(std::pair<double, double>(0.176956, 13)); - pbns.push_back(std::pair<double, double>(0.183234, 12)); - pbns.push_back(std::pair<double, double>(0.191069, 13)); - pbns.push_back(std::pair<double, double>(0.191333, 14)); - pbns.push_back(std::pair<double, double>(0.191836, 15)); - pbns.push_back(std::pair<double, double>(0.192675, 16)); - pbns.push_back(std::pair<double, double>(0.208564, 17)); - pbns.push_back(std::pair<double, double>(0.218425, 18)); - pbns.push_back(std::pair<double, double>(0.219902, 17)); - pbns.push_back(std::pair<double, double>(0.23233, 16)); - pbns.push_back(std::pair<double, double>(0.234558, 17)); - pbns.push_back(std::pair<double, double>(0.237166, 16)); - pbns.push_back(std::pair<double, double>(0.247352, 17)); - pbns.push_back(std::pair<double, double>(0.267421, 18)); - pbns.push_back(std::pair<double, double>(0.268093, 19)); - pbns.push_back(std::pair<double, double>(0.278734, 18)); - pbns.push_back(std::pair<double, double>(0.284722, 19)); - pbns.push_back(std::pair<double, double>(0.284998, 20)); - pbns.push_back(std::pair<double, double>(0.294069, 21)); - pbns.push_back(std::pair<double, double>(0.306293, 22)); - pbns.push_back(std::pair<double, double>(0.322361, 21)); - pbns.push_back(std::pair<double, double>(0.323152, 22)); - pbns.push_back(std::pair<double, double>(0.371021, 23)); - pbns.push_back(std::pair<double, double>(0.372395, 24)); - pbns.push_back(std::pair<double, double>(0.387744, 25)); - pbns.push_back(std::pair<double, double>(0.435537, 26)); - pbns.push_back(std::pair<double, double>(0.462911, 25)); - pbns.push_back(std::pair<double, double>(0.483569, 26)); - pbns.push_back(std::pair<double, double>(0.489209, 25)); - pbns.push_back(std::pair<double, double>(0.517115, 24)); - pbns.push_back(std::pair<double, double>(0.522197, 23)); - pbns.push_back(std::pair<double, double>(0.532665, 22)); - pbns.push_back(std::pair<double, double>(0.545262, 23)); - pbns.push_back(std::pair<double, double>(0.587227, 22)); - pbns.push_back(std::pair<double, double>(0.593036, 23)); - pbns.push_back(std::pair<double, double>(0.602647, 24)); - pbns.push_back(std::pair<double, double>(0.605044, 25)); - pbns.push_back(std::pair<double, double>(0.621962, 24)); - pbns.push_back(std::pair<double, double>(0.629449, 23)); - pbns.push_back(std::pair<double, double>(0.636719, 22)); - pbns.push_back(std::pair<double, double>(0.64957, 21)); - pbns.push_back(std::pair<double, double>(0.650781, 22)); - pbns.push_back(std::pair<double, double>(0.654951, 23)); - pbns.push_back(std::pair<double, double>(0.683489, 24)); - pbns.push_back(std::pair<double, double>(0.687172, 23)); - pbns.push_back(std::pair<double, double>(0.69703, 22)); - pbns.push_back(std::pair<double, double>(0.701174, 21)); - pbns.push_back(std::pair<double, double>(0.717623, 22)); - pbns.push_back(std::pair<double, double>(0.722023, 21)); - pbns.push_back(std::pair<double, double>(0.722298, 20)); - pbns.push_back(std::pair<double, double>(0.725347, 19)); - pbns.push_back(std::pair<double, double>(0.73071, 18)); - pbns.push_back(std::pair<double, double>(0.758355, 17)); - pbns.push_back(std::pair<double, double>(0.770913, 18)); - pbns.push_back(std::pair<double, double>(0.790833, 17)); - pbns.push_back(std::pair<double, double>(0.821211, 16)); - pbns.push_back(std::pair<double, double>(0.849305, 17)); - pbns.push_back(std::pair<double, double>(0.853669, 16)); - pbns.push_back(std::pair<double, double>(0.866659, 15)); - pbns.push_back(std::pair<double, double>(0.872896, 16)); - pbns.push_back(std::pair<double, double>(0.889597, 15)); - pbns.push_back(std::pair<double, double>(0.900231, 14)); - pbns.push_back(std::pair<double, double>(0.903847, 13)); - pbns.push_back(std::pair<double, double>(0.906299, 12)); - pbns.push_back(std::pair<double, double>(0.910852, 11)); - pbns.push_back(std::pair<double, double>(0.93453, 10)); - pbns.push_back(std::pair<double, double>(0.944757, 9)); - pbns.push_back(std::pair<double, double>(0.947812, 8)); - pbns.push_back(std::pair<double, double>(0.959154, 7)); - pbns.push_back(std::pair<double, double>(0.975654, 6)); - pbns.push_back(std::pair<double, double>(0.976719, 5)); - pbns.push_back(std::pair<double, double>(0.977343, 4)); - pbns.push_back(std::pair<double, double>(0.980129, 3)); - pbns.push_back(std::pair<double, double>(0.987842, 2)); - pbns.push_back(std::pair<double, double>(0.990127, 1)); - pbns.push_back(std::pair<double, double>(0.994537, 0)); + std::vector<std::pair<double, size_t> > pbns; + pbns.push_back(std::pair<double, size_t>(0.0290362, 1)); + pbns.push_back(std::pair<double, size_t>(0.0307676, 2)); + pbns.push_back(std::pair<double, size_t>(0.0366312, 3)); + pbns.push_back(std::pair<double, size_t>(0.0544614, 4)); + pbns.push_back(std::pair<double, size_t>(0.0920033, 5)); + pbns.push_back(std::pair<double, size_t>(0.104599, 6)); + pbns.push_back(std::pair<double, size_t>(0.114718, 7)); + pbns.push_back(std::pair<double, size_t>(0.117379, 8)); + pbns.push_back(std::pair<double, size_t>(0.123493, 9)); + pbns.push_back(std::pair<double, size_t>(0.133638, 10)); + pbns.push_back(std::pair<double, size_t>(0.137798, 9)); + pbns.push_back(std::pair<double, size_t>(0.149798, 10)); + pbns.push_back(std::pair<double, size_t>(0.155421, 11)); + pbns.push_back(std::pair<double, size_t>(0.158443, 12)); + pbns.push_back(std::pair<double, size_t>(0.176956, 13)); + pbns.push_back(std::pair<double, size_t>(0.183234, 12)); + pbns.push_back(std::pair<double, size_t>(0.191069, 13)); + pbns.push_back(std::pair<double, size_t>(0.191333, 14)); + pbns.push_back(std::pair<double, size_t>(0.191836, 15)); + pbns.push_back(std::pair<double, size_t>(0.192675, 16)); + pbns.push_back(std::pair<double, size_t>(0.208564, 17)); + pbns.push_back(std::pair<double, size_t>(0.218425, 18)); + pbns.push_back(std::pair<double, size_t>(0.219902, 17)); + pbns.push_back(std::pair<double, size_t>(0.23233, 16)); + pbns.push_back(std::pair<double, size_t>(0.234558, 17)); + pbns.push_back(std::pair<double, size_t>(0.237166, 16)); + pbns.push_back(std::pair<double, size_t>(0.247352, 17)); + pbns.push_back(std::pair<double, size_t>(0.267421, 18)); + pbns.push_back(std::pair<double, size_t>(0.268093, 19)); + pbns.push_back(std::pair<double, size_t>(0.278734, 18)); + pbns.push_back(std::pair<double, size_t>(0.284722, 19)); + pbns.push_back(std::pair<double, size_t>(0.284998, 20)); + pbns.push_back(std::pair<double, size_t>(0.294069, 21)); + pbns.push_back(std::pair<double, size_t>(0.306293, 22)); + pbns.push_back(std::pair<double, size_t>(0.322361, 21)); + pbns.push_back(std::pair<double, size_t>(0.323152, 22)); + pbns.push_back(std::pair<double, size_t>(0.371021, 23)); + pbns.push_back(std::pair<double, size_t>(0.372395, 24)); + pbns.push_back(std::pair<double, size_t>(0.387744, 25)); + pbns.push_back(std::pair<double, size_t>(0.435537, 26)); + pbns.push_back(std::pair<double, size_t>(0.462911, 25)); + pbns.push_back(std::pair<double, size_t>(0.483569, 26)); + pbns.push_back(std::pair<double, size_t>(0.489209, 25)); + pbns.push_back(std::pair<double, size_t>(0.517115, 24)); + pbns.push_back(std::pair<double, size_t>(0.522197, 23)); + pbns.push_back(std::pair<double, size_t>(0.532665, 22)); + pbns.push_back(std::pair<double, size_t>(0.545262, 23)); + pbns.push_back(std::pair<double, size_t>(0.587227, 22)); + pbns.push_back(std::pair<double, size_t>(0.593036, 23)); + pbns.push_back(std::pair<double, size_t>(0.602647, 24)); + pbns.push_back(std::pair<double, size_t>(0.605044, 25)); + pbns.push_back(std::pair<double, size_t>(0.621962, 24)); + pbns.push_back(std::pair<double, size_t>(0.629449, 23)); + pbns.push_back(std::pair<double, size_t>(0.636719, 22)); + pbns.push_back(std::pair<double, size_t>(0.64957, 21)); + pbns.push_back(std::pair<double, size_t>(0.650781, 22)); + pbns.push_back(std::pair<double, size_t>(0.654951, 23)); + pbns.push_back(std::pair<double, size_t>(0.683489, 24)); + pbns.push_back(std::pair<double, size_t>(0.687172, 23)); + pbns.push_back(std::pair<double, size_t>(0.69703, 22)); + pbns.push_back(std::pair<double, size_t>(0.701174, 21)); + pbns.push_back(std::pair<double, size_t>(0.717623, 22)); + pbns.push_back(std::pair<double, size_t>(0.722023, 21)); + pbns.push_back(std::pair<double, size_t>(0.722298, 20)); + pbns.push_back(std::pair<double, size_t>(0.725347, 19)); + pbns.push_back(std::pair<double, size_t>(0.73071, 18)); + pbns.push_back(std::pair<double, size_t>(0.758355, 17)); + pbns.push_back(std::pair<double, size_t>(0.770913, 18)); + pbns.push_back(std::pair<double, size_t>(0.790833, 17)); + pbns.push_back(std::pair<double, size_t>(0.821211, 16)); + pbns.push_back(std::pair<double, size_t>(0.849305, 17)); + pbns.push_back(std::pair<double, size_t>(0.853669, 16)); + pbns.push_back(std::pair<double, size_t>(0.866659, 15)); + pbns.push_back(std::pair<double, size_t>(0.872896, 16)); + pbns.push_back(std::pair<double, size_t>(0.889597, 15)); + pbns.push_back(std::pair<double, size_t>(0.900231, 14)); + pbns.push_back(std::pair<double, size_t>(0.903847, 13)); + pbns.push_back(std::pair<double, size_t>(0.906299, 12)); + pbns.push_back(std::pair<double, size_t>(0.910852, 11)); + pbns.push_back(std::pair<double, size_t>(0.93453, 10)); + pbns.push_back(std::pair<double, size_t>(0.944757, 9)); + pbns.push_back(std::pair<double, size_t>(0.947812, 8)); + pbns.push_back(std::pair<double, size_t>(0.959154, 7)); + pbns.push_back(std::pair<double, size_t>(0.975654, 6)); + pbns.push_back(std::pair<double, size_t>(0.976719, 5)); + pbns.push_back(std::pair<double, size_t>(0.977343, 4)); + pbns.push_back(std::pair<double, size_t>(0.980129, 3)); + pbns.push_back(std::pair<double, size_t>(0.987842, 2)); + pbns.push_back(std::pair<double, size_t>(0.990127, 1)); + pbns.push_back(std::pair<double, size_t>(0.994537, 0)); std::vector<std::pair<double, size_t> > pbns_new = p.compute_persistent_betti_numbers(); for (size_t i = 0; i != pbns.size(); ++i) { - // cout << pbns_new[i].first << "," << pbns_new[i].second << std::endl; - BOOST_CHECK(fabs(pbns[i].first - pbns_new[i].first) <= epsilon); - BOOST_CHECK(fabs(pbns[i].second - pbns_new[i].second) <= epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(pbns[i].first, pbns_new[i].first, + Gudhi::Persistence_representations::epsi); + BOOST_CHECK(pbns[i].second == pbns_new[i].second); } } @@ -297,7 +288,7 @@ BOOST_AUTO_TEST_CASE(check_k_n_n) { knn_template.push_back(0.786945); for (size_t i = 0; i != knn.size(); ++i) { - // cout << knn[i] << std::endl; - BOOST_CHECK(fabs(knn[i] - knn_template[i]) <= 0.000005); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(knn[i], knn_template[i], + Gudhi::Persistence_representations::epsi); } } diff --git a/src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp b/src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp index 7b70eee3..631e4d70 100644 --- a/src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp +++ b/src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp @@ -24,8 +24,9 @@ #define BOOST_TEST_MODULE "Persistence_intervals_with_distances_test" #include <boost/test/unit_test.hpp> #include <gudhi/reader_utils.h> -#include "gudhi/Persistence_intervals_with_distances.h" -#include "gudhi/common_persistence_representations.h" +#include <gudhi/Persistence_intervals_with_distances.h> +#include <gudhi/common_persistence_representations.h> +#include <gudhi/Unitary_tests_utils.h> #include <iostream> @@ -38,9 +39,7 @@ BOOST_AUTO_TEST_CASE(check_bottleneck_distances_computation) { double dist = p.distance(q); - // std::cout << "dist : " << dist << std::endl; - - BOOST_CHECK(almost_equal(dist, 0.389043)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(dist, 0.389043, Gudhi::Persistence_representations::epsi); } BOOST_AUTO_TEST_CASE(check_default_parameters_in_distance) { @@ -51,11 +50,7 @@ BOOST_AUTO_TEST_CASE(check_default_parameters_in_distance) { double max_parameter_distance = p.distance(q, std::numeric_limits<double>::max()); double inf_parameter_distance = p.distance(q, std::numeric_limits<double>::infinity()); - // std::cout << "default_parameter_distance : " << default_parameter_distance << std::endl; - // std::cout << "max_parameter_distance : " << max_parameter_distance << std::endl; - // std::cout << "inf_parameter_distance : " << inf_parameter_distance << std::endl; - - BOOST_CHECK(default_parameter_distance == max_parameter_distance); - BOOST_CHECK(inf_parameter_distance == max_parameter_distance); - BOOST_CHECK(inf_parameter_distance == max_parameter_distance); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(default_parameter_distance, max_parameter_distance); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(inf_parameter_distance, max_parameter_distance); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(inf_parameter_distance, max_parameter_distance); } diff --git a/src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp b/src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp index 6b1608fe..8e2808d0 100644 --- a/src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp +++ b/src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp @@ -25,12 +25,15 @@ #include <boost/test/unit_test.hpp> #include <gudhi/reader_utils.h> #include <gudhi/Persistence_landscape_on_grid.h> +#include <gudhi/Unitary_tests_utils.h> #include <iostream> using namespace Gudhi; using namespace Gudhi::Persistence_representations; +double epsilon = 0.0005; + BOOST_AUTO_TEST_CASE(check_construction_of_landscape) { Persistence_landscape_on_grid l("data/file_with_diagram_1", 100, std::numeric_limits<unsigned short>::max()); l.print_to_file("landscape_from_file_with_diagram_1"); @@ -53,16 +56,14 @@ BOOST_AUTO_TEST_CASE(check_construction_of_landscape_using_only_ten_levels) { std::vector<double> v2 = g.vectorize(level); BOOST_CHECK(v1.size() == v2.size()); for (size_t i = 0; i != v1.size(); ++i) { - BOOST_CHECK(v1[i] == v2[i]); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(v1[i], v2[i]); } } } BOOST_AUTO_TEST_CASE(check_computations_of_integrals) { Persistence_landscape_on_grid p("data/file_with_diagram_1", 100, std::numeric_limits<unsigned short>::max()); - double integral = p.compute_integral_of_landscape(); - // cerr << "integral : " << integral << endl;getchar(); - BOOST_CHECK(fabs(integral - 27.343) <= 0.00005); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape(), 27.343, epsilon); } BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) { @@ -92,9 +93,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) integrals_fir_different_levels.push_back(0.202633); for (size_t level = 0; level != integrals_fir_different_levels.size(); ++level) { - double integral = p.compute_integral_of_landscape(level); - // cerr << integral << endl; - BOOST_CHECK(fabs(integral - integrals_fir_different_levels[level]) <= 0.00005); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape(level), integrals_fir_different_levels[level], + epsilon); } } @@ -109,9 +109,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_of_powers_of_landscape) { integrals_fir_different_powers.push_back(0.23011); for (size_t power = 0; power != 5; ++power) { - double integral = p.compute_integral_of_landscape(power); - // cerr << integral << endl; - BOOST_CHECK(fabs(integral - integrals_fir_different_powers[power]) <= 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape(power), integrals_fir_different_powers[power], + epsilon); } } @@ -145,8 +144,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_values_on_different_points) { double x = 0.0012321; double dx = 0.05212; for (size_t i = 0; i != 10; ++i) { - BOOST_CHECK(almost_equal(p.compute_value_at_a_given_point(0, x), results_level_0[i])); - BOOST_CHECK(almost_equal(p.compute_value_at_a_given_point(10, x), results_level_10[i])); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(0, x), results_level_0[i], epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(10, x), results_level_10[i], epsilon); x += dx; } } @@ -179,22 +178,14 @@ BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) { Persistence_landscape_on_grid second("data/file_with_diagram_2", 0., 1., 100); Persistence_landscape_on_grid sum = p + second; - // cerr << p.compute_maximum() << endl; - // cerr << p.compute_norm_of_landscape(1) << endl; - // cerr << p.compute_norm_of_landscape(2) << endl; - // cerr << p.compute_norm_of_landscape(3) << endl; - // cerr << compute_distance_of_landscapes_on_grid(p,sum,1) << endl; - // cerr << compute_distance_of_landscapes_on_grid(p,sum,2) << endl; - // cerr << compute_distance_of_landscapes_on_grid(p,sum,std::numeric_limits<double>::max()) << endl; - - BOOST_CHECK(fabs(p.compute_maximum() - 0.46) <= 0.00001); - BOOST_CHECK(fabs(p.compute_norm_of_landscape(1) - 27.3373) <= 0.00001); - BOOST_CHECK(fabs(p.compute_norm_of_landscape(2) - 1.84143) <= 0.00001); - BOOST_CHECK(fabs(p.compute_norm_of_landscape(3) - 0.927067) <= 0.00001); - BOOST_CHECK(fabs(compute_distance_of_landscapes_on_grid(p, sum, 1) - 16.8519) <= 0.00005); - BOOST_CHECK(fabs(compute_distance_of_landscapes_on_grid(p, sum, 2) - 1.44542) <= 0.00001); - BOOST_CHECK(fabs(compute_distance_of_landscapes_on_grid(p, sum, std::numeric_limits<double>::max()) - 0.45) <= - 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_maximum(), 0.46, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(1), 27.3373 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(2), 1.84143 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(3), 0.927067, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes_on_grid(p, sum, 1), 16.8519, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes_on_grid(p, sum, 2), 1.44542, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes_on_grid(p, sum, std::numeric_limits<double>::max()), + 0.45, epsilon); } BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances) { @@ -209,7 +200,7 @@ BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances) { double dist_numeric_limit_max = p.distance(q, std::numeric_limits<double>::max()); double dist_infinity = p.distance(q, std::numeric_limits<double>::infinity()); - BOOST_CHECK(dist_numeric_limit_max == dist_infinity); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(dist_numeric_limit_max, dist_infinity); } BOOST_AUTO_TEST_CASE(check_computations_of_averages) { @@ -226,16 +217,15 @@ BOOST_AUTO_TEST_CASE(check_computations_of_averages) { BOOST_AUTO_TEST_CASE(check_computations_of_distances) { Persistence_landscape_on_grid p("data/file_with_diagram", 0., 1., 10000); Persistence_landscape_on_grid q("data/file_with_diagram_1", 0., 1., 10000); - BOOST_CHECK(fabs(p.distance(q) - 25.5779) <= 0.00005); - BOOST_CHECK(fabs(p.distance(q, 2) - 2.04891) <= 0.00001); - BOOST_CHECK(fabs(p.distance(q, std::numeric_limits<double>::max()) - 0.359) <= 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q), 25.5779, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q, 2), 2.04891, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q, std::numeric_limits<double>::max()), 0.359, epsilon); } BOOST_AUTO_TEST_CASE(check_computations_of_scalar_product) { Persistence_landscape_on_grid p("data/file_with_diagram", 0., 1., 10000); Persistence_landscape_on_grid q("data/file_with_diagram_1", 0., 1., 10000); - // std::cerr << p.compute_scalar_product( q ) << std::endl; - BOOST_CHECK(almost_equal(p.compute_scalar_product(q), 0.754367)); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(q), 0.754367, epsilon); } // Below I am storing the code used to generate tests for that functionality. diff --git a/src/Persistence_representations/test/persistence_lanscapes_test.cpp b/src/Persistence_representations/test/persistence_lanscapes_test.cpp index 81adb6fa..e7267bec 100644 --- a/src/Persistence_representations/test/persistence_lanscapes_test.cpp +++ b/src/Persistence_representations/test/persistence_lanscapes_test.cpp @@ -25,6 +25,7 @@ #include <boost/test/unit_test.hpp> #include <gudhi/reader_utils.h> #include <gudhi/Persistence_landscape.h> +#include <gudhi/Unitary_tests_utils.h> #include <iostream> #include <limits> @@ -32,7 +33,7 @@ using namespace Gudhi; using namespace Gudhi::Persistence_representations; -double epsilon = 0.0000005; +double epsilon = 0.0005; BOOST_AUTO_TEST_CASE(check_construction_of_landscape) { std::vector<std::pair<double, double> > diag = @@ -57,9 +58,7 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals) { std::vector<std::pair<double, double> > diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram"); Persistence_landscape p(diag); - double integral = p.compute_integral_of_landscape(); - // cerr << integral << " " << 2.34992 << endl; - BOOST_CHECK(fabs(integral - 2.34992) <= 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape(), 2.34992, epsilon); } BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) { @@ -67,37 +66,37 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram"); Persistence_landscape p(diag); - std::vector<double> integrals_fir_different_levels; - integrals_fir_different_levels.push_back(0.216432); - integrals_fir_different_levels.push_back(0.204763); - integrals_fir_different_levels.push_back(0.188793); - integrals_fir_different_levels.push_back(0.178856); - integrals_fir_different_levels.push_back(0.163142); - integrals_fir_different_levels.push_back(0.155015); - integrals_fir_different_levels.push_back(0.143046); - integrals_fir_different_levels.push_back(0.133765); - integrals_fir_different_levels.push_back(0.123531); - integrals_fir_different_levels.push_back(0.117393); - integrals_fir_different_levels.push_back(0.111269); - integrals_fir_different_levels.push_back(0.104283); - integrals_fir_different_levels.push_back(0.0941308); - integrals_fir_different_levels.push_back(0.0811208); - integrals_fir_different_levels.push_back(0.0679001); - integrals_fir_different_levels.push_back(0.0580801); - integrals_fir_different_levels.push_back(0.0489647); - integrals_fir_different_levels.push_back(0.0407936); - integrals_fir_different_levels.push_back(0.0342599); - integrals_fir_different_levels.push_back(0.02896); - integrals_fir_different_levels.push_back(0.0239881); - integrals_fir_different_levels.push_back(0.0171792); - integrals_fir_different_levels.push_back(0.0071511); - integrals_fir_different_levels.push_back(0.00462067); - integrals_fir_different_levels.push_back(0.00229033); - integrals_fir_different_levels.push_back(0.000195296); + std::vector<double> integrals_for_different_levels; + integrals_for_different_levels.push_back(0.216432); + integrals_for_different_levels.push_back(0.204763); + integrals_for_different_levels.push_back(0.188793); + integrals_for_different_levels.push_back(0.178856); + integrals_for_different_levels.push_back(0.163142); + integrals_for_different_levels.push_back(0.155015); + integrals_for_different_levels.push_back(0.143046); + integrals_for_different_levels.push_back(0.133765); + integrals_for_different_levels.push_back(0.123531); + integrals_for_different_levels.push_back(0.117393); + integrals_for_different_levels.push_back(0.111269); + integrals_for_different_levels.push_back(0.104283); + integrals_for_different_levels.push_back(0.0941308); + integrals_for_different_levels.push_back(0.0811208); + integrals_for_different_levels.push_back(0.0679001); + integrals_for_different_levels.push_back(0.0580801); + integrals_for_different_levels.push_back(0.0489647); + integrals_for_different_levels.push_back(0.0407936); + integrals_for_different_levels.push_back(0.0342599); + integrals_for_different_levels.push_back(0.02896); + integrals_for_different_levels.push_back(0.0239881); + integrals_for_different_levels.push_back(0.0171792); + integrals_for_different_levels.push_back(0.0071511); + integrals_for_different_levels.push_back(0.00462067); + integrals_for_different_levels.push_back(0.00229033); + integrals_for_different_levels.push_back(0.000195296); for (size_t level = 0; level != p.size(); ++level) { - double integral = p.compute_integral_of_a_level_of_a_landscape(level); - BOOST_CHECK(fabs(integral - integrals_fir_different_levels[level]) <= 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_a_level_of_a_landscape(level), + integrals_for_different_levels[level], epsilon); } } @@ -106,16 +105,16 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_of_powers_of_landscape) { read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram"); Persistence_landscape p(diag); - std::vector<double> integrals_fir_different_powers; - integrals_fir_different_powers.push_back(17.1692); - integrals_fir_different_powers.push_back(2.34992); - integrals_fir_different_powers.push_back(0.49857); - integrals_fir_different_powers.push_back(0.126405); - integrals_fir_different_powers.push_back(0.0355235); + std::vector<double> integrals_for_different_powers; + integrals_for_different_powers.push_back(17.1692); + integrals_for_different_powers.push_back(2.34992); + integrals_for_different_powers.push_back(0.49857); + integrals_for_different_powers.push_back(0.126405); + integrals_for_different_powers.push_back(0.0355235); for (size_t power = 0; power != 5; ++power) { - double integral = p.compute_integral_of_landscape((double)power); - BOOST_CHECK(fabs(integral - integrals_fir_different_powers[power]) <= 0.00005); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape((double)power), + integrals_for_different_powers[power], epsilon); } } @@ -124,18 +123,18 @@ BOOST_AUTO_TEST_CASE(check_computations_of_values_on_different_points) { read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram"); Persistence_landscape p(diag); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(1, 0.0)) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(1, 0.1) - 0.0692324) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(1, 0.2) - 0.163369) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(1, 0.3) - 0.217115) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(2, 0.0)) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(2, 0.1) - 0.0633688) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(2, 0.2) - 0.122361) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(2, 0.3) - 0.195401) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(3, 0.0)) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(3, 0.1) - 0.0455386) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(3, 0.2) - 0.0954012) <= 0.00001); - BOOST_CHECK(fabs(p.compute_value_at_a_given_point(3, 0.3) - 0.185282) <= 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(1, 0.0), 0. , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(1, 0.1), 0.0692324, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(1, 0.2), 0.163369 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(1, 0.3), 0.217115 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(2, 0.0), 0. , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(2, 0.1), 0.0633688, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(2, 0.2), 0.122361 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(2, 0.3), 0.195401 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(3, 0.0), 0. , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(3, 0.1), 0.0455386, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(3, 0.2), 0.0954012, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(3, 0.3), 0.185282 , epsilon); } BOOST_AUTO_TEST_CASE(check_computations_sum_differences_and_multiplications) { @@ -171,13 +170,14 @@ BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) { second.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram_1"); Persistence_landscape sum = p + second; - BOOST_CHECK(fabs(p.compute_maximum() - 0.431313) <= 0.00001); - BOOST_CHECK(fabs(p.compute_norm_of_landscape(1) - 2.34992) <= 0.00001); - BOOST_CHECK(fabs(p.compute_norm_of_landscape(2) - 0.706095) <= 0.00001); - BOOST_CHECK(fabs(p.compute_norm_of_landscape(3) - 0.501867) <= 0.00001); - BOOST_CHECK(fabs(compute_distance_of_landscapes(p, sum, 1) - 27.9323) <= 0.00005); - BOOST_CHECK(fabs(compute_distance_of_landscapes(p, sum, 2) - 2.35199) <= 0.00001); - BOOST_CHECK(fabs(compute_distance_of_landscapes(p, sum, std::numeric_limits<double>::max()) - 0.464478) <= 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_maximum() , 0.431313, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(1), 2.34992 , epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(2), 0.706095, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(3), 0.501867, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes(p, sum, 1), 27.9323, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes(p, sum, 2), 2.35199, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes(p, sum, std::numeric_limits<double>::max()), + 0.464478, epsilon); } BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances) { @@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances) { double dist_numeric_limit_max = p.distance(q, std::numeric_limits<double>::max()); double dist_infinity = p.distance(q, std::numeric_limits<double>::infinity()); - BOOST_CHECK(dist_numeric_limit_max == dist_infinity); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(dist_numeric_limit_max, dist_infinity); } BOOST_AUTO_TEST_CASE(check_computations_of_averages) { @@ -217,13 +217,9 @@ BOOST_AUTO_TEST_CASE(check_computations_of_distances) { std::vector<std::pair<double, double> > diag2 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1"); Persistence_landscape q(diag2); - std::cout << "p.distance(q) = " << p.distance(q) << std::endl; - BOOST_CHECK(fabs(p.distance(q) - 25.5824) <= 0.00005); - std::cout << "p.distance(q, 2) = " << p.distance(q, 2) << std::endl; - BOOST_CHECK(fabs(p.distance(q, 2) - 2.1264) <= 0.0001); - std::cout << "p.distance(q, std::numeric_limits<double>::max()) = " << - p.distance(q, std::numeric_limits<double>::max()) << std::endl; - BOOST_CHECK(fabs(p.distance(q, std::numeric_limits<double>::max()) - 0.359068) <= 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q), 25.5824, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q, 2), 2.1264, epsilon); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q, std::numeric_limits<double>::max()), 0.359068, epsilon); } BOOST_AUTO_TEST_CASE(check_computations_of_scalar_product) { @@ -233,7 +229,7 @@ BOOST_AUTO_TEST_CASE(check_computations_of_scalar_product) { std::vector<std::pair<double, double> > diag2 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1"); Persistence_landscape q(diag2); - BOOST_CHECK(fabs(p.compute_scalar_product(q) - 0.754498) <= 0.00001); + GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(q), 0.754498, epsilon); } diff --git a/src/Persistence_representations/test/read_persistence_from_file_test.cpp b/src/Persistence_representations/test/read_persistence_from_file_test.cpp index 76d7cdb0..afdc822c 100644 --- a/src/Persistence_representations/test/read_persistence_from_file_test.cpp +++ b/src/Persistence_representations/test/read_persistence_from_file_test.cpp @@ -21,7 +21,7 @@ */ #define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "Persistence_representations" +#define BOOST_TEST_MODULE "read_persistence_from_file_test" #include <boost/test/unit_test.hpp> #include <gudhi/read_persistence_from_file.h> diff --git a/src/Persistence_representations/test/vector_representation_test.cpp b/src/Persistence_representations/test/vector_representation_test.cpp index 3f3e2abe..7e4ce3ee 100644 --- a/src/Persistence_representations/test/vector_representation_test.cpp +++ b/src/Persistence_representations/test/vector_representation_test.cpp @@ -26,7 +26,7 @@ #include <iostream> #define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "Persistence_representations" +#define BOOST_TEST_MODULE "vector_representation_test" #include <boost/test/unit_test.hpp> #include <gudhi/reader_utils.h> #include <vector> diff --git a/src/Persistence_representations/utilities/CMakeLists.txt b/src/Persistence_representations/utilities/CMakeLists.txt index 66524666..137eb0c1 100644 --- a/src/Persistence_representations/utilities/CMakeLists.txt +++ b/src/Persistence_representations/utilities/CMakeLists.txt @@ -1,6 +1,53 @@ +# Copy files, otherwise result files are created in sources +file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") +file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") + +function(add_persistence_representation_creation_utility creation_utility) + add_executable ( ${creation_utility} ${creation_utility}.cpp ) + + # as the function is called in a subdirectory level, need to '../' to find persistence files + # ARGN will add all the other arguments (except creation_utility) sent to the CMake functions + add_test(NAME Persistence_representation_utilities_${creation_utility} COMMAND $<TARGET_FILE:${creation_utility}> + ${ARGN} "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" + "${CMAKE_CURRENT_BINARY_DIR}/../second.pers") +endfunction(add_persistence_representation_creation_utility) + +function(add_persistence_representation_plot_utility plot_utility tool_extension) + add_executable ( ${plot_utility} ${plot_utility}.cpp ) + + # as the function is called in a subdirectory level, need to '../' to find persistence heat maps files + add_test(NAME Persistence_representation_utilities_${plot_utility}_first COMMAND $<TARGET_FILE:${plot_utility}> + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers${tool_extension}") + #add_test(NAME Persistence_representation_utilities_${plot_utility}_second COMMAND $<TARGET_FILE:${plot_utility}> + # "${CMAKE_CURRENT_BINARY_DIR}/../second.pers${tool_extension}") + if(GNUPLOT_PATH) + add_test(NAME Persistence_representation_utilities_${plot_utility}_first_gnuplot COMMAND ${GNUPLOT_PATH} + "-e" "load '${CMAKE_CURRENT_BINARY_DIR}/../first.pers${tool_extension}_GnuplotScript'") + #add_test(NAME Persistence_representation_utilities_${plot_utility}_second_gnuplot COMMAND ${GNUPLOT_PATH} + # "-e" "load '${CMAKE_CURRENT_BINARY_DIR}/../second.pers${tool_extension}_GnuplotScript'") + endif() +endfunction(add_persistence_representation_plot_utility) + +function(add_persistence_representation_function_utility function_utility tool_extension) + add_executable ( ${function_utility} ${function_utility}.cpp ) + + # ARGV2 is an optional argument + if (${ARGV2}) + # as the function is called in a subdirectory level, need to '../' to find persistence heat maps files + add_test(NAME Persistence_representation_utilities_${function_utility} COMMAND $<TARGET_FILE:${function_utility}> + "${ARGV2}" + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers${tool_extension}" + "${CMAKE_CURRENT_BINARY_DIR}/../second.pers${tool_extension}") + else() + # as the function is called in a subdirectory level, need to '../' to find persistence heat maps files + add_test(NAME Persistence_representation_utilities_${function_utility} COMMAND $<TARGET_FILE:${function_utility}> + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers${tool_extension}" + "${CMAKE_CURRENT_BINARY_DIR}/../second.pers${tool_extension}") + endif() +endfunction(add_persistence_representation_function_utility) + add_subdirectory(persistence_heat_maps) add_subdirectory(persistence_intervals) add_subdirectory(persistence_landscapes) add_subdirectory(persistence_landscapes_on_grid) add_subdirectory(persistence_vectors) - diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt index 0dd63852..386e9fa5 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt +++ b/src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt @@ -1,63 +1,15 @@ cmake_minimum_required(VERSION 2.6) project(Persistence_representations_heat_maps_utilities) -file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") - -add_executable ( create_persistence_heat_maps create_persistence_heat_maps.cpp ) -target_link_libraries(create_persistence_heat_maps ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME create_persistence_heat_maps COMMAND $<TARGET_FILE:create_persistence_heat_maps> - "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - - -add_executable ( create_pssk create_pssk.cpp ) -target_link_libraries(create_pssk ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME create_pssk COMMAND $<TARGET_FILE:create_pssk> - "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( create_p_h_m_weighted_by_distance_from_diagonal create_p_h_m_weighted_by_distance_from_diagonal.cpp ) -target_link_libraries(create_p_h_m_weighted_by_distance_from_diagonal ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME create_p_h_m_weighted_by_distance_from_diagonal COMMAND $<TARGET_FILE:create_p_h_m_weighted_by_distance_from_diagonal> - "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( create_p_h_m_weighted_by_squared_diag_distance create_p_h_m_weighted_by_squared_diag_distance.cpp ) -target_link_libraries(create_p_h_m_weighted_by_squared_diag_distance ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME create_p_h_m_weighted_by_squared_diag_distance COMMAND $<TARGET_FILE:create_p_h_m_weighted_by_squared_diag_distance> - "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( create_p_h_m_weighted_by_arctan_of_their_persistence create_p_h_m_weighted_by_arctan_of_their_persistence.cpp ) -target_link_libraries(create_p_h_m_weighted_by_arctan_of_their_persistence ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME create_p_h_m_weighted_by_arctan_of_their_persistence COMMAND $<TARGET_FILE:create_p_h_m_weighted_by_arctan_of_their_persistence> - "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( average_persistence_heat_maps average_persistence_heat_maps.cpp ) -target_link_libraries(average_persistence_heat_maps ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME average_persistence_heat_maps COMMAND $<TARGET_FILE:average_persistence_heat_maps> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( plot_persistence_heat_map plot_persistence_heat_map.cpp ) -target_link_libraries(plot_persistence_heat_map ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME plot_persistence_heat_map COMMAND $<TARGET_FILE:plot_persistence_heat_map> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( compute_distance_of_persistence_heat_maps compute_distance_of_persistence_heat_maps.cpp ) -target_link_libraries(compute_distance_of_persistence_heat_maps ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_distance_of_persistence_heat_maps COMMAND $<TARGET_FILE:compute_distance_of_persistence_heat_maps> - "1" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( compute_scalar_product_of_persistence_heat_maps compute_scalar_product_of_persistence_heat_maps.cpp ) -target_link_libraries(compute_scalar_product_of_persistence_heat_maps ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_scalar_product_of_persistence_heat_maps COMMAND $<TARGET_FILE:compute_scalar_product_of_persistence_heat_maps> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") +add_persistence_representation_creation_utility(create_pssk "10" "-1" "-1" "4" "-1") +add_persistence_representation_creation_utility(create_p_h_m_weighted_by_arctan_of_their_persistence "10" "-1" "-1" "4" "-1") +add_persistence_representation_creation_utility(create_p_h_m_weighted_by_distance_from_diagonal "10" "-1" "-1" "4" "-1") +add_persistence_representation_creation_utility(create_p_h_m_weighted_by_squared_diag_distance "10" "-1" "-1" "4" "-1") +# Need to set grid min and max for further average, distance and scalar_product +add_persistence_representation_creation_utility(create_persistence_heat_maps "10" "0" "35" "10" "-1") + +add_persistence_representation_plot_utility(plot_persistence_heat_map ".mps") + +add_persistence_representation_function_utility(average_persistence_heat_maps ".mps") +add_persistence_representation_function_utility(compute_distance_of_persistence_heat_maps ".mps" "1") +add_persistence_representation_function_utility(compute_scalar_product_of_persistence_heat_maps ".mps") 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 4e81375a..6739e0b6 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 @@ -29,21 +29,20 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>; int main(int argc, char** argv) { - std::cout << "This program computes average persistence landscape of persistence landscapes created based on " - "persistence diagrams provided as an input. Please call this program with the names of files with " - "persistence diagrams \n"; - std::vector<const char*> filenames; + std::cout << "This program computes average of persistence heat maps stored in files (the files needs to be " + << "created beforehand).\n" + << "The parameters of this programs are names of files with persistence heat maps.\n"; - if (argc == 1) { - std::cout << "No input files given, the program will now terminate \n"; + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; return 1; } + std::vector<const char*> filenames; for (int i = 1; i < argc; ++i) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence landscapes...\n"; std::vector<Persistence_heat_maps*> maps; for (size_t i = 0; i != filenames.size(); ++i) { Persistence_heat_maps* l = new Persistence_heat_maps; @@ -53,13 +52,12 @@ int main(int argc, char** argv) { Persistence_heat_maps av; av.compute_average(maps); - av.print_to_file("average.mps"); for (size_t i = 0; i != filenames.size(); ++i) { delete maps[i]; } - std::cout << "Done \n"; + std::cout << "Average can be found in 'average.mps' file\n"; return 0; } 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 befb0837..ed8278a2 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 @@ -31,11 +31,11 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>; int main(int argc, char** argv) { - std::cout << "This program computes distance of persistence heat maps stored in a file (the file needs to be created " - "beforehand). \n"; - std::cout << "The first parameter of a program is an integer p. The program compute L^p distance of the two heat " - "maps. For L^infty distance choose p = -1. \n"; - std::cout << "The remaining parameters of this program are names of files with persistence heat maps.\n"; + std::cout << "This program computes distance of persistence heat maps stored in files (the files needs to be " + << "created beforehand).\n" + << "The first parameter of a program is an integer p. The program compute L^p distance of the two heat " + << "maps. For L^infty distance choose p = -1. \n" + << "The remaining parameters of this program are names of files with persistence heat maps.\n"; if (argc < 3) { std::cout << "Wrong number of parameters, the program will now terminate \n"; @@ -78,7 +78,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("distance"); + out.open("distance.mps"); for (size_t i = 0; i != distance.size(); ++i) { for (size_t j = 0; j != distance.size(); ++j) { std::cout << distance[i][j] << " "; @@ -89,5 +89,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'distance.mps' file\n"; return 0; } 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 c684a336..63626853 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 @@ -30,9 +30,14 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>; int main(int argc, char** argv) { - std::cout << "This program computes scalar product of persistence landscapes stored in a file (the file needs to be " - "created beforehand). \n"; - std::cout << "The parameters of this programs are names of files with persistence landscapes.\n"; + std::cout << "This program computes scalar product of persistence heat maps stored in a file (the file needs to be " + << "created beforehand). \n" + << "The parameters of this programs are names of files with persistence heat maps.\n"; + + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; + return 1; + } std::vector<const char*> filenames; for (int i = 1; i < argc; ++i) { @@ -64,7 +69,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("scalar_product"); + out.open("scalar_product.mps"); for (size_t i = 0; i != scalar_product.size(); ++i) { for (size_t j = 0; j != scalar_product.size(); ++j) { std::cout << scalar_product[i][j] << " "; @@ -75,5 +80,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'scalar_product.mps' file\n"; return 0; } 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 2bf185a3..47c70484 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 @@ -32,22 +32,22 @@ using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<arc_tan_of_persistence_of_point>; int main(int argc, char** argv) { - std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " - "weighted by the arc tangential of their persistence.\n"; - std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; - std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " - "based on the data, set them both to -1 \n"; - std::cerr << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " - "of pixels \n"; - std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the " - "persistence heat maps."; - std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the " - "procedure please provide the dimension of persistence you want to use."; - std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." - << std::endl; - std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; + std::cout << "This program creates persistence heat map files (*.mps) of persistence diagrams files (*.pers) " + << "provided as an input.The Gaussian kernels are weighted by the arc tangential of their persistence.\n" + << "The first parameter of a program is an integer, a size of a grid.\n" + << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " + << "based on the data, set them both to -1 \n" + << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " + << "of pixels.\n" + << "The fifth parameter of this program is a dimension of persistence that will be used in creation of " + << "the persistence heat maps." + << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the " + << "procedure please provide the dimension of persistence you want to use." + << "If in your files there are only birth-death pairs of the same dimension, set the fifth parameter to " + << "-1.\n" + << "The remaining parameters are the names of files with persistence diagrams. \n"; - if (argc < 5) { + if (argc < 7) { std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; } @@ -68,9 +68,7 @@ int main(int argc, char** argv) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence heat maps...\n"; std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1); - for (size_t i = 0; i != filenames.size(); ++i) { std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; Persistence_heat_maps l(filenames[i], filter, false, size_of_grid, min_, max_, dimension); @@ -79,6 +77,5 @@ int main(int argc, char** argv) { ss << filenames[i] << ".mps"; l.print_to_file(ss.str().c_str()); } - std::cout << "Done \n"; return 0; } 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 ec9477f1..659a5105 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 @@ -32,22 +32,23 @@ using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<distance_from_diagonal_scaling>; int main(int argc, char** argv) { - std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " - "weighted by the distance of a center from the diagonal.\n"; - std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; - std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " - "based on the data, set them both to -1 \n"; - std::cerr << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " - "of pixels \n"; - std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the " - "persistence heat maps."; - std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the " - "procedure please provide the dimension of persistence you want to use."; - std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." - << std::endl; - std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; + std::cout << "This program creates persistence heat map files (*.mps) of persistence diagrams files (*.pers) " + << "provided as an input.The Gaussian kernels are weighted by the distance of a center from the " + << "diagonal.\n" + << "The first parameter of a program is an integer, a size of a grid.\n" + << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " + << "based on the data, set them both to -1 \n" + << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " + << "of pixels.\n" + << "The fifth parameter of this program is a dimension of persistence that will be used in creation of " + << "the persistence heat maps." + << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the " + << "procedure please provide the dimension of persistence you want to use." + << "If in your files there are only birth-death pairs of the same dimension, set the fifth parameter to " + << "-1.\n" + << "The remaining parameters are the names of files with persistence diagrams. \n"; - if (argc < 5) { + if (argc < 7) { std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; } @@ -68,9 +69,7 @@ int main(int argc, char** argv) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence heat maps...\n"; std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1); - for (size_t i = 0; i != filenames.size(); ++i) { std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; Persistence_heat_maps l(filenames[i], filter, false, size_of_grid, min_, max_, dimension); @@ -79,6 +78,5 @@ int main(int argc, char** argv) { ss << filenames[i] << ".mps"; l.print_to_file(ss.str().c_str()); } - std::cout << "Done \n"; return 0; } 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 ffec8b3d..9497b188 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 @@ -33,22 +33,23 @@ using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<squared_distance_from_diagonal_scaling>; int main(int argc, char** argv) { - std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " - "weighted by the square of distance of a center from the diagonal.\n"; - std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; - std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " - "based on the data, set them both to -1 \n"; - std::cerr << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " - "of pixels \n"; - std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the " - "persistence heat maps."; - std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the " - "procedure please provide the dimension of persistence you want to use."; - std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." - << std::endl; - std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; + std::cout << "This program creates persistence heat map files (*.mps) of persistence diagrams files (*.pers) " + << "provided as an input.The Gaussian kernels are weighted by the square of distance of a center from the " + << "diagonal.\n" + << "The first parameter of a program is an integer, a size of a grid.\n" + << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " + << "based on the data, set them both to -1 \n" + << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " + << "of pixels.\n" + << "The fifth parameter of this program is a dimension of persistence that will be used in creation of " + << "the persistence heat maps." + << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the " + << "procedure please provide the dimension of persistence you want to use." + << "If in your files there are only birth-death pairs of the same dimension, set the fifth parameter to " + << "-1.\n" + << "The remaining parameters are the names of files with persistence diagrams. \n"; - if (argc < 5) { + if (argc < 7) { std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; } @@ -69,9 +70,7 @@ int main(int argc, char** argv) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence heat maps...\n"; std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1); - for (size_t i = 0; i != filenames.size(); ++i) { std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; Persistence_heat_maps l(filenames[i], filter, false, size_of_grid, min_, max_, dimension); @@ -80,6 +79,5 @@ int main(int argc, char** argv) { ss << filenames[i] << ".mps"; l.print_to_file(ss.str().c_str()); } - std::cout << "Done \n"; return 0; } 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 db2f0008..25cd1067 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 @@ -31,21 +31,22 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>; int main(int argc, char** argv) { - std::cout << "This program creates persistence heat map of diagrams provided as an input.\n"; - std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; - std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " - "based on the data, set them both to -1 \n"; - std::cerr << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " - "of pixels \n"; + std::cout << "This program creates persistence heat map files (*.mps) of persistence diagrams files (*.pers) " + << "provided as an input.\n" + << "The first parameter of a program is an integer, a size of a grid.\n" + << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " + << "based on the data, set them both to -1 \n" + << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " + << "of pixels.\n" + << "The fifth parameter of this program is a dimension of persistence that will be used in creation of " + << "the persistence heat maps." + << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the " + << "procedure please provide the dimension of persistence you want to use." + << "If in your files there are only birth-death pairs of the same dimension, set the fifth parameter to " + << "-1.\n" + << "The remaining parameters are the names of files with persistence diagrams. \n"; - std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the " - "persistence heat maps."; - std::cout << "If your input file contains persistence pairs of various dimension, as a fifth parameter of the " - "procedure please provide the dimension of persistence you want to use."; - std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." - << std::endl; - std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; - if (argc < 5) { + if (argc < 7) { std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; } @@ -64,17 +65,14 @@ int main(int argc, char** argv) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence heat maps...\n"; std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1); - for (size_t i = 0; i != filenames.size(); ++i) { - std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; + std::cout << "Creating a heat map based on file : " << filenames[i] << std::endl; Persistence_heat_maps l(filenames[i], filter, false, size_of_grid, min_, max_, dimension); std::stringstream ss; ss << filenames[i] << ".mps"; l.print_to_file(ss.str().c_str()); } - std::cout << "Done \n"; return 0; } 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 6aefbb00..97ddb8f0 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp @@ -30,21 +30,22 @@ using PSSK = Gudhi::Persistence_representations::PSSK; int main(int argc, char** argv) { - std::cout << "This program creates PSSK of diagrams provided as an input.\n"; - std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; - std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " - "based on the data, set them both to -1 \n"; - std::cerr << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " - "of pixels \n"; - std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the " - "persistence heat maps."; - std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the " - "procedure please provide the dimension of persistence you want to use."; - std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." - << std::endl; - std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; + std::cout << "This program creates PSSK files (*.pssk) of persistence diagrams files (*.pers) " + << "provided as an input.\n" + << "The first parameter of a program is an integer, a size of a grid.\n" + << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " + << "based on the data, set them both to -1 \n" + << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number " + << "of pixels.\n" + << "The fifth parameter of this program is a dimension of persistence that will be used in creation of " + << "the PSSK." + << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the " + << "procedure please provide the dimension of persistence you want to use." + << "If in your files there are only birth-death pairs of the same dimension, set the first parameter to " + << "-1.\n" + << "The remaining parameters are the names of files with persistence diagrams. \n"; - if (argc < 5) { + if (argc < 7) { std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; } @@ -65,17 +66,14 @@ int main(int argc, char** argv) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence heat maps...\n"; std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1); - for (size_t i = 0; i != filenames.size(); ++i) { - std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; + std::cout << "Creating a PSSK based on a file : " << filenames[i] << std::endl; PSSK l(filenames[i], filter, size_of_grid, min_, max_, dimension); std::stringstream ss; ss << filenames[i] << ".pssk"; l.print_to_file(ss.str().c_str()); } - std::cout << "Done \n"; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp index a7c9f2d8..63711d83 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp @@ -29,8 +29,12 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>; int main(int argc, char** argv) { - std::cout << "This program plot persistence landscape stored in a file (the file needs to be created beforehand). " - "Please call the code with the name of a landscape file \n"; + std::cout << "This program creates a gnuplot script from a persistence heat maps stored in a file (the file needs " + << "to be created beforehand). Please call the code with the name of a single heat maps file \n"; + if (argc != 2) { + std::cout << "Wrong parameter list, the program will now terminate \n"; + return 1; + } Persistence_heat_maps l; l.load_from_file(argv[1]); l.plot(argv[1]); diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/simple_diagram.txt.mps b/src/Persistence_representations/utilities/persistence_heat_maps/simple_diagram.txt.mps deleted file mode 100644 index b7643887..00000000 --- a/src/Persistence_representations/utilities/persistence_heat_maps/simple_diagram.txt.mps +++ /dev/null @@ -1,11 +0,0 @@ -0.93 8.0707 -0.0492104 0.03889 0.0190956 0.00603584 0.00131569 0.000120934 2.10152e-05 0 0 0 -0.0650745 0.0539306 0.0296488 0.011745 0.00357642 0.000695928 0.000120934 0 0 0 -0.0572665 0.0559446 0.0409942 0.0230905 0.00937173 0.00242903 0.000422102 0 0 0 -0.0409942 0.0559656 0.0573874 0.0408475 0.0192639 0.00628964 0.00178718 0.000422102 0.000120934 2.10152e-05 -0.0296488 0.0540515 0.0657704 0.0519133 0.0283092 0.0132056 0.00628964 0.00242903 0.000695928 0.000120934 -0.0190956 0.0393121 0.0516395 0.0465955 0.0359385 0.0283092 0.0192639 0.00937173 0.00357642 0.00131569 -0.00847814 0.0188418 0.0281882 0.0358964 0.0465955 0.0519133 0.0408475 0.0230905 0.011745 0.00603584 -0.00242903 0.00628964 0.0132056 0.0281882 0.0516395 0.0657704 0.0573874 0.0409942 0.0296488 0.0190956 -0.000422102 0.00178718 0.00628964 0.0188418 0.0393121 0.0540515 0.0559656 0.0559446 0.0539306 0.03889 -0 0.000422102 0.00242903 0.00847814 0.0190956 0.0296488 0.0409942 0.0572665 0.0650745 0.0492104 diff --git a/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt index 105b7efb..897e12a3 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt +++ b/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt @@ -1,46 +1,32 @@ cmake_minimum_required(VERSION 2.6) project(Persistence_representations_intervals_utilities) -file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") -add_executable ( plot_persistence_intervals plot_persistence_intervals.cpp ) -target_link_libraries( plot_persistence_intervals ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME plot_persistence_intervals COMMAND $<TARGET_FILE:plot_persistence_intervals> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( compute_birth_death_range_in_persistence_diagram compute_birth_death_range_in_persistence_diagram.cpp ) -target_link_libraries( compute_birth_death_range_in_persistence_diagram ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_birth_death_range_in_persistence_diagram COMMAND $<TARGET_FILE:compute_birth_death_range_in_persistence_diagram> - "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") +add_executable ( plot_histogram_of_intervals_lengths plot_histogram_of_intervals_lengths.cpp ) -add_executable ( compute_number_of_dominant_intervals compute_number_of_dominant_intervals.cpp ) -target_link_libraries( compute_number_of_dominant_intervals ${Boost_SYSTEM_LIBRARY}) +add_test(NAME plot_histogram_of_intervals_lengths COMMAND $<TARGET_FILE:plot_histogram_of_intervals_lengths> + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" "-1") -add_test(NAME compute_number_of_dominant_intervals COMMAND $<TARGET_FILE:compute_number_of_dominant_intervals> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" "-1" "2") +add_persistence_representation_plot_utility(plot_persistence_intervals "") +add_persistence_representation_plot_utility(plot_persistence_Betti_numbers "") -add_executable ( plot_histogram_of_intervals_lengths plot_histogram_of_intervals_lengths.cpp ) -target_link_libraries( plot_histogram_of_intervals_lengths ${Boost_SYSTEM_LIBRARY}) +add_persistence_representation_creation_utility(compute_birth_death_range_in_persistence_diagram "-1") -add_test(NAME plot_histogram_of_intervals_lengths COMMAND $<TARGET_FILE:plot_histogram_of_intervals_lengths> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" "2") -add_executable ( plot_persistence_Betti_numbers plot_persistence_Betti_numbers.cpp ) -target_link_libraries( plot_persistence_Betti_numbers ${Boost_SYSTEM_LIBRARY}) +add_executable ( compute_number_of_dominant_intervals compute_number_of_dominant_intervals.cpp ) +add_test(NAME Persistence_representation_utilities_compute_number_of_dominant_intervals + COMMAND $<TARGET_FILE:compute_number_of_dominant_intervals> + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" "-1" "2") -add_test(NAME plot_persistence_Betti_numbers COMMAND $<TARGET_FILE:plot_persistence_Betti_numbers> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) add_executable ( compute_bottleneck_distance compute_bottleneck_distance.cpp ) - target_link_libraries( compute_bottleneck_distance ${Boost_SYSTEM_LIBRARY}) if (TBB_FOUND) target_link_libraries(compute_bottleneck_distance ${TBB_LIBRARIES}) endif(TBB_FOUND) - - add_test(NAME compute_bottleneck_distance COMMAND $<TARGET_FILE:compute_bottleneck_distance> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") + add_test(NAME Persistence_representation_utilities_compute_bottleneck_distance + COMMAND $<TARGET_FILE:compute_bottleneck_distance> + "-1" + "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" + "${CMAKE_CURRENT_BINARY_DIR}/../second.pers") endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) 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 66fa31ca..9102da79 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 @@ -20,7 +20,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/reader_utils.h> #include <gudhi/Persistence_intervals.h> #include <iostream> @@ -31,16 +30,21 @@ using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals; int main(int argc, char** argv) { - std::cout << "This program compute the range of birth and death times of persistence pairs in diagrams provided as " - "an input. \n"; - std::cout << "The first parameter of the program is the dimension of persistence to be used. If your file contains "; - std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence " - "pairs you want to use. If your input files consist only "; - std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; - std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n"; + std::cout << "This program computes the range of birth and death times of persistence pairs in diagrams provided as " + << "an input.\n" + << "The first parameter is the dimension of persistence to be used to create persistence intervals. " + << "If your file contains the information about dimension of persistence pairs, please provide here the " + << "dimension of persistence pairs you want to use. " + << "If your input files consist only of birth-death pairs, please set this first parameter to -1.\n" + << "The remaining parameters of the program are the names of files with persistence diagrams.\n"; + + if (argc < 3) { + std::cout << "Wrong parameter list, the program will now terminate \n"; + return 1; + } - int dim = atoi(argv[1]); unsigned dimension = std::numeric_limits<unsigned>::max(); + int dim = atoi(argv[1]); if (dim >= 0) { dimension = (unsigned)dim; } 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 0b1b526d..c8290845 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp @@ -21,7 +21,6 @@ */ #include <gudhi/Persistence_intervals_with_distances.h> -#include <gudhi/read_persistence_from_file.h> #include <iostream> #include <sstream> @@ -31,21 +30,21 @@ using Persistence_intervals_with_distances = Gudhi::Persistence_representations::Persistence_intervals_with_distances; int main(int argc, char** argv) { - std::cout << "This program compute the bottleneck distance of persistence diagrams stored in a files. \n"; - std::cout << "The first parameter of the program is the dimension of persistence to be used to construct persistence " - "landscapes. If your file contains "; - std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence " - "pairs you want to use. If your input files consist only "; - std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; - std::cout << "The remaining parameters of this programs are names of files with persistence diagrams.\n"; + std::cout << "This program computes the bottleneck distance of persistence pairs in diagrams provided as " + << "an input.\n" + << "The first parameter is the dimension of persistence to be used to create persistence intervals. " + << "If your file contains the information about dimension of persistence pairs, please provide here the " + << "dimension of persistence pairs you want to use. " + << "If your input files consist only of birth-death pairs, please set this first parameter to -1.\n" + << "The remaining parameters of the program are the names of files with persistence diagrams.\n"; if (argc < 3) { std::cout << "Wrong number of parameters, the program will now terminate \n"; return 1; } - int dim = atoi(argv[1]); unsigned dimension = std::numeric_limits<unsigned>::max(); + int dim = atoi(argv[1]); if (dim >= 0) { dimension = (unsigned)dim; } @@ -80,7 +79,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("distance"); + out.open("distance.itv"); for (size_t i = 0; i != distance.size(); ++i) { for (size_t j = 0; j != distance.size(); ++j) { std::cout << distance[i][j] << " "; @@ -91,5 +90,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'distance.itv' file\n"; return 0; } 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 1286ca57..b3d126f0 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 @@ -20,7 +20,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/reader_utils.h> #include <gudhi/Persistence_intervals.h> #include <iostream> 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 d68f4584..ccb5b645 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 @@ -20,7 +20,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/reader_utils.h> #include <gudhi/Persistence_intervals.h> #include <iostream> @@ -31,30 +30,34 @@ using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals; int main(int argc, char** argv) { - std::cout << "This program compute a histogram of barcode's length. A number of bins in the histogram is a parameter " - "of this program. \n"; - if (argc != 3) { + std::cout << "This program computes a histogram of barcode's length. A number of bins in the histogram is a " + << "parameter of this program. \n"; + if ((argc != 3) && (argc != 4)) { std::cout << "To run this program, please provide the name of a file with persistence diagram and number of " - "dominant intervals you would like to get \n"; - std::cout << "The third parameter of a program is the dimension of the persistence that is to be used. If your " - "file contains only birth-death pairs, you can skip this parameter\n"; + << "dominant intervals you would like to get. Set a negative number dominant intervals value " + << "If your file contains only birth-death pairs.\n" + << "The third parameter is the dimension of the persistence that is to be used. If your " + << "file contains only birth-death pairs, you can skip this parameter\n"; return 1; } - unsigned dimension = std::numeric_limits<unsigned>::max(); - int dim = -1; - if (argc > 2) { - dim = atoi(argv[2]); + + unsigned dominant_interval_number = std::numeric_limits<unsigned>::max(); + int nbr = atoi(argv[2]); + if (nbr >= 0) { + dominant_interval_number = static_cast<unsigned>(nbr); } - if (dim >= 0) { - dimension = (unsigned)dim; + + int persistence_dimension = -1; + if (argc == 4) { + persistence_dimension = atoi(argv[3]); } - Persistence_intervals p(argv[1], dimension); - std::vector<std::pair<double, double> > dominant_intervals = p.dominant_intervals(atoi(argv[2])); + Persistence_intervals p(argv[1], dominant_interval_number); + std::vector<std::pair<double, double> > dominant_intervals = p.dominant_intervals(persistence_dimension); std::vector<size_t> histogram = p.histogram_of_lengths(10); std::stringstream gnuplot_script; - gnuplot_script << argv[1] << "_Gnuplot_script"; + gnuplot_script << argv[1] << "_GnuplotScript"; std::ofstream out; out.open(gnuplot_script.str().c_str()); @@ -66,7 +69,9 @@ int main(int argc, char** argv) { out << histogram[i] << std::endl; } out << std::endl; - std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; out.close(); + + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; return 0; } 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 da2b9319..b433c2b3 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 @@ -20,7 +20,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/reader_utils.h> #include <gudhi/Persistence_intervals.h> #include <iostream> @@ -31,29 +30,24 @@ using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals; int main(int argc, char** argv) { - std::cout << "This program compute a plot of persistence Betti numbers. The input parameter is a file with " - "persistence intervals. \n"; - std::cout << "The second optional parameter of a program is the dimension of the persistence that is to be used. If " - "your file contains only birth-death pairs, you can skip this parameter\n"; - if (argc < 2) { - std::cout << "To run this program, please provide the name of a file with persistence diagram and number of " - "dominant intervals you would like to get \n"; + if ((argc != 3) && (argc != 2)) { + std::cout << "This program creates a gnuplot script of Betti numbers from a single persistence diagram file" + << "(*.pers).\n" + << "To run this program, please provide the name of a file with persistence diagram.\n" + << "The second optional parameter of a program is the dimension of the persistence that is to be used. " + << "If your file contains only birth-death pairs, you can skip this parameter.\n"; return 1; } + unsigned dimension = std::numeric_limits<unsigned>::max(); int dim = -1; - if (argc > 2) { + if (argc == 3) { dim = atoi(argv[2]); } if (dim >= 0) { dimension = (unsigned)dim; } - std::stringstream gnuplot_script; - gnuplot_script << argv[1] << "_Gnuplot_script"; - std::ofstream out; - out.open(gnuplot_script.str().c_str()); - Persistence_intervals p(argv[1], dimension); std::vector<std::pair<double, size_t> > pbns = p.compute_persistent_betti_numbers(); @@ -69,6 +63,11 @@ int main(int argc, char** argv) { xRangeEnd += (xRangeEnd - xRangeBegin) / 100.0; yRangeEnd += yRangeEnd / 100; + std::stringstream gnuplot_script; + gnuplot_script << argv[1] << "_GnuplotScript"; + std::ofstream out; + out.open(gnuplot_script.str().c_str()); + out << "set xrange [" << xRangeBegin << " : " << xRangeEnd << "]" << std::endl; out << "set yrange [" << yRangeBegin << " : " << yRangeEnd << "]" << std::endl; out << "plot '-' using 1:2 notitle with lp " << std::endl; @@ -81,7 +80,8 @@ int main(int argc, char** argv) { out << std::endl; out.close(); - std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; + std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'" + << gnuplot_script.str().c_str() << "\'\"" << std::endl; return 0; } 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 e7d29e84..33387802 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp @@ -20,9 +20,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/reader_utils.h> #include <gudhi/Persistence_intervals.h> -#include <gudhi/read_persistence_from_file.h> #include <iostream> #include <limits> @@ -32,15 +30,16 @@ using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals; int main(int argc, char** argv) { - if (argc < 2) { - std::cout << "To run this program, please provide the name of a file with persistence diagram \n"; - std::cout << "The second optional parameter of a program is the dimension of the persistence that is to be used. " - "If your file contains only birth-death pairs, you can skip this parameter\n"; + if ((argc != 3) && (argc != 2)) { + std::cout << "This program creates a gnuplot script from a single persistence diagram file (*.pers).\n" + << "To run this program, please provide the name of a file with persistence diagram.\n" + << "The second optional parameter of a program is the dimension of the persistence that is to be used. " + << "If your file contains only birth-death pairs, you can skip this parameter.\n"; return 1; } unsigned dimension = std::numeric_limits<unsigned>::max(); int dim = -1; - if (argc > 2) { + if (argc == 3) { dim = atoi(argv[2]); } if (dim >= 0) { diff --git a/src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt index baf8de3c..d7087ed8 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt +++ b/src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt @@ -1,38 +1,10 @@ cmake_minimum_required(VERSION 2.6) -project(Persistence_representations_lanscapes_utilities) +project(Persistence_representations_landscapes_utilities) -file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") +add_persistence_representation_creation_utility(create_landscapes "-1") -add_executable ( create_landscapes create_landscapes.cpp ) -target_link_libraries(create_landscapes ${Boost_SYSTEM_LIBRARY}) +add_persistence_representation_plot_utility(plot_landscapes ".land") -# Will create simple_diagram.txt.land -add_test(NAME create_landscapes COMMAND $<TARGET_FILE:create_landscapes> - "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( average_landscapes average_landscapes.cpp ) -target_link_libraries(average_landscapes ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME average_landscapes COMMAND $<TARGET_FILE:average_landscapes> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( plot_landscapes plot_landscapes.cpp ) -target_link_libraries(plot_landscapes ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME plot_landscapes COMMAND $<TARGET_FILE:plot_landscapes> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( compute_distance_of_landscapes compute_distance_of_landscapes.cpp ) -target_link_libraries(compute_distance_of_landscapes ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_distance_of_landscapes COMMAND $<TARGET_FILE:compute_distance_of_landscapes> - "1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.land" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.land") - -add_executable ( compute_scalar_product_of_landscapes compute_scalar_product_of_landscapes.cpp ) -target_link_libraries(compute_scalar_product_of_landscapes ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_scalar_product_of_landscapes COMMAND $<TARGET_FILE:compute_scalar_product_of_landscapes> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.land" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.land") +add_persistence_representation_function_utility(average_landscapes ".land") +add_persistence_representation_function_utility(compute_distance_of_landscapes ".land" "1") +add_persistence_representation_function_utility(compute_scalar_product_of_landscapes ".land") diff --git a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp index 526130e9..1a59be8c 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp @@ -28,14 +28,13 @@ using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape; int main(int argc, char** argv) { - std::cout << "This program computes average persistence landscape of persistence landscapes created based on " - "persistence diagrams provided as an input (you must create them first).\n"; - std::cout << "Please call this program with the names of files with persistence landscapes. The program will create " - "a persistence landscape which will be their average \n"; + std::cout << "This program computes average of persistence landscapes stored in files (the files needs to be " + << "created beforehand).\n" + << "The parameters of this programs are names of files with persistence landscapes.\n"; std::vector<const char*> filenames; - if (argc == 1) { - std::cout << "No input files given, the program will now terminate \n"; + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; return 1; } @@ -43,7 +42,6 @@ int main(int argc, char** argv) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence landscapes...\n"; std::vector<Persistence_landscape*> lands; for (size_t i = 0; i != filenames.size(); ++i) { Persistence_landscape* l = new Persistence_landscape; @@ -60,7 +58,6 @@ int main(int argc, char** argv) { delete lands[i]; } - std::cout << "Done \n"; - + std::cout << "Average can be found in 'average.land' file\n"; return 0; } 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 b3881d6a..5062f521 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 @@ -30,11 +30,11 @@ using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape; 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 " - "beforehand). \n"; - std::cout << "The first parameter of a program is an integer p. The program compute L^p distance of the given " - "landscapes. For L^infty distance choose p = -1. \n"; - std::cout << "The remaining parameters of this programs are names of files with persistence landscapes."; + std::cout << "This program computes distance of persistence landscapes stored in files (the files needs to be " + << "created beforehand).\n" + << "The first parameter of a program is an integer p. The program compute L^p distance of the two heat " + << "maps. For L^infty distance choose p = -1. \n" + << "The remaining parameters of this program are names of files with persistence landscapes.\n"; if (argc < 3) { std::cout << "Wrong number of parameters, the program will now terminate \n"; @@ -54,7 +54,6 @@ int main(int argc, char** argv) { std::vector<Persistence_landscape> landscaspes; landscaspes.reserve(filenames.size()); for (size_t file_no = 0; file_no != filenames.size(); ++file_no) { - std::cout << "Loading persistence landscape from a file : " << filenames[file_no] << std::endl; Persistence_landscape l; l.load_landscape_from_file(filenames[file_no]); landscaspes.push_back(l); @@ -78,7 +77,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("distance"); + out.open("distance.land"); for (size_t i = 0; i != distance.size(); ++i) { for (size_t j = 0; j != distance.size(); ++j) { std::cout << distance[i][j] << " "; @@ -89,5 +88,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'distance.land' file\n"; return 0; } 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 8dad7b4d..5b5e9fa3 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 @@ -29,9 +29,14 @@ using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape; 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 " - "created beforehand). \n"; - std::cout << "The parameters of this programs are names of files with persistence landscapes.\n"; + std::cout << "This program computes scalar product of persistence landscapes stored in a file (the file needs to be " + << "created beforehand). \n" + << "The parameters of this programs are names of files with persistence landscapes.\n"; + + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; + return 1; + } std::vector<const char*> filenames; for (int i = 1; i < argc; ++i) { @@ -40,7 +45,6 @@ int main(int argc, char** argv) { std::vector<Persistence_landscape> landscaspes; landscaspes.reserve(filenames.size()); for (size_t file_no = 0; file_no != filenames.size(); ++file_no) { - std::cout << "Reading persistence landscape from a file : " << filenames[file_no] << std::endl; Persistence_landscape l; l.load_landscape_from_file(filenames[file_no]); landscaspes.push_back(l); @@ -64,7 +68,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("scalar_product"); + out.open("scalar_product.land"); for (size_t i = 0; i != scalar_product.size(); ++i) { for (size_t j = 0; j != scalar_product.size(); ++j) { std::cout << scalar_product[i][j] << " "; @@ -75,5 +79,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'scalar_product.land' file\n"; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp index 325081d1..6030e994 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp @@ -30,13 +30,20 @@ using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape; int main(int argc, char** argv) { - std::cout << "This program creates persistence landscapes of diagrams provided as an input. \n"; - std::cout << "The first parameter of the program is the dimension of persistence to be used to construct persistence " - "landscapes. If your file contains "; - std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence " - "pairs you want to use. If your input files consist only "; - std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; - std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n"; + std::cout << "This program creates persistence landscapes files (*.land) of persistence diagrams files (*.pers) " + << "provided as an input.\n" + << "The first parameter of this program is a dimension of persistence that will be used in creation of " + << "the persistence heat maps." + << "If your input files contains persistence pairs of various dimension, as a first parameter of the " + << "procedure please provide the dimension of persistence you want to use." + << "If in your files there are only birth-death pairs of the same dimension, set the first parameter to " + << "-1.\n" + << "The remaining parameters are the names of files with persistence diagrams. \n"; + + if (argc < 3) { + std::cout << "Wrong parameter list, the program will now terminate \n"; + return 1; + } std::vector<const char*> filenames; int dim = atoi(argv[1]); unsigned dimension = std::numeric_limits<unsigned>::max(); @@ -47,13 +54,12 @@ int main(int argc, char** argv) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence landscapes...\n"; for (size_t i = 0; i != filenames.size(); ++i) { + std::cout << "Creating a landscape based on file : " << filenames[i] << std::endl; Persistence_landscape l(filenames[i], dimension); std::stringstream ss; ss << filenames[i] << ".land"; l.print_to_file(ss.str().c_str()); } - std::cout << "Done \n"; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp index ebdb20a1..c797a7a8 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp @@ -28,16 +28,16 @@ using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape; int main(int argc, char** argv) { - std::cout << "This program plot persistence landscape stored in a file (the file needs to be created beforehand). " - "Please call the code with the name of a landscape file \n"; + std::cout << "This program creates a gnuplot script from a persistence landscape stored in a file (the file needs " + << "to be created beforehand). Please call the code with the name of a single landscape file.\n"; + if (argc != 2) { + std::cout << "Wrong parameter list, the program will now terminate \n"; + return 1; + } + Persistence_landscape l; l.load_landscape_from_file(argv[1]); - - std::stringstream ss; - ss << argv[1] << "_gnuplot_script"; - l.plot(ss.str().c_str()); - - std::cout << "Done \n"; + l.plot(argv[1]); return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes/simple_diagram.txt.land b/src/Persistence_representations/utilities/persistence_landscapes/simple_diagram.txt.land deleted file mode 100644 index b99d2f62..00000000 --- a/src/Persistence_representations/utilities/persistence_landscapes/simple_diagram.txt.land +++ /dev/null @@ -1,13 +0,0 @@ -#lambda_0 -1 0 -1.5 0.5 -2 0 -3 0 -3.5 0.5 -4 0 -5 0 -5.5 0.5 -6 0 -7 0 -7.5 0.5 -8 0 diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt index 55a4fd50..c5ea4bbf 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt @@ -1,38 +1,11 @@ cmake_minimum_required(VERSION 2.6) project(Persistence_representations_lanscapes_on_grid_utilities) -file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") +# Need to set grid min and max for further average, distance and scalar_product +add_persistence_representation_creation_utility(create_landscapes_on_grid "100" "0" "35" "-1") -add_executable ( create_landscapes_on_grid create_landscapes_on_grid.cpp ) -target_link_libraries(create_landscapes_on_grid ${Boost_SYSTEM_LIBRARY}) +add_persistence_representation_plot_utility(plot_landscapes_on_grid ".g_land") -# Will create simple_diagram.txt.land -add_test(NAME create_landscapes_on_grid COMMAND $<TARGET_FILE:create_landscapes_on_grid> - "100" "-1" "-1" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( average_landscapes_on_grid average_landscapes_on_grid.cpp ) -target_link_libraries(average_landscapes_on_grid ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME average_landscapes_on_grid COMMAND $<TARGET_FILE:average_landscapes_on_grid> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land") - -add_executable ( plot_landscapes_on_grid plot_landscapes_on_grid.cpp ) -target_link_libraries(plot_landscapes_on_grid ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME plot_landscapes_on_grid COMMAND $<TARGET_FILE:plot_landscapes_on_grid> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land") - -add_executable ( compute_distance_of_landscapes_on_grid compute_distance_of_landscapes_on_grid.cpp ) -target_link_libraries(compute_distance_of_landscapes_on_grid ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_distance_of_landscapes_on_grid COMMAND $<TARGET_FILE:compute_distance_of_landscapes_on_grid> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land") - -add_executable ( compute_scalar_product_of_landscapes_on_grid compute_scalar_product_of_landscapes_on_grid.cpp ) -target_link_libraries(compute_scalar_product_of_landscapes_on_grid ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_scalar_product_of_landscapes_on_grid COMMAND $<TARGET_FILE:compute_scalar_product_of_landscapes_on_grid> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land") +add_persistence_representation_function_utility(average_landscapes_on_grid ".g_land") +add_persistence_representation_function_utility(compute_distance_of_landscapes_on_grid ".g_land" "1") +add_persistence_representation_function_utility(compute_scalar_product_of_landscapes_on_grid ".g_land") diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp index d50118a0..0b098d1a 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp @@ -28,21 +28,20 @@ using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid; int main(int argc, char** argv) { - std::cout << "This program computes average persistence landscape on grid of persistence landscapes on grid created " - "based on persistence diagrams provided as an input. Please call this program with the names of files " - "with persistence diagrams \n"; - std::vector<const char*> filenames; + std::cout << "This program computes average of persistence landscapes on grid stored in files (the files needs to " + << "be created beforehand).\n" + << "The parameters of this programs are names of files with persistence landscapes on grid.\n"; - if (argc == 1) { - std::cout << "No input files given, the program will now terminate \n"; + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; return 1; } + std::vector<const char*> filenames; for (int i = 1; i < argc; ++i) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence landscapes...\n"; std::vector<Persistence_landscape_on_grid*> lands; for (size_t i = 0; i != filenames.size(); ++i) { Persistence_landscape_on_grid* l = new Persistence_landscape_on_grid; @@ -59,7 +58,6 @@ int main(int argc, char** argv) { delete lands[i]; } - std::cout << "Done \n"; - + std::cout << "Average can be found in 'average.g_land' file\n"; return 0; } 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 859c6991..fd0fcd15 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 @@ -30,11 +30,11 @@ using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid; 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 " - "created beforehand). \n"; - std::cout << "The first parameter of a program is an integer p. The program compute L^p distance of the landscapes " - "on grid. For L^infty distance choose p = -1. \n"; - std::cout << "The remaining parameters of this programs are names of files with persistence landscapes on grid.\n"; + std::cout << "This program computes distance of persistence landscapes on grid stored in files (the files needs to " + << "be created beforehand).\n" + << "The first parameter of a program is an integer p. The program compute L^p distance of the two heat " + << "maps. For L^infty distance choose p = -1. \n" + << "The remaining parameters of this program are names of files with persistence landscapes on grid.\n"; if (argc < 3) { std::cout << "Wrong number of parameters, the program will now terminate \n"; @@ -77,7 +77,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("distance"); + out.open("distance.g_land"); for (size_t i = 0; i != distance.size(); ++i) { for (size_t j = 0; j != distance.size(); ++j) { std::cout << distance[i][j] << " "; @@ -88,5 +88,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'distance.g_land' file\n"; return 0; } 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 e95bf8ad..e2222487 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 @@ -29,9 +29,14 @@ using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid; 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 " - "to be created beforehand). \n"; - std::cout << "The parameters of this programs are names of files with persistence landscapes on grid.\n"; + std::cout << "This program computes scalar product of persistence landscapes on grid stored in a file (the file needs to " + << "be created beforehand). \n" + << "The parameters of this programs are names of files with persistence landscapes on grid.\n"; + + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; + return 1; + } std::vector<const char*> filenames; for (int i = 1; i < argc; ++i) { @@ -63,7 +68,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("scalar_product"); + out.open("scalar_product.g_land"); for (size_t i = 0; i != scalar_product.size(); ++i) { for (size_t j = 0; j != scalar_product.size(); ++j) { std::cout << scalar_product[i][j] << " "; @@ -74,5 +79,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'scalar_product.g_land' file\n"; return 0; } 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 8d747c14..2827f982 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 @@ -30,22 +30,25 @@ using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid; int main(int argc, char** argv) { - std::cout << "This program creates persistence landscape on grid of diagrams provided as an input.\n"; - std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; - std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " - "based on the data, set them both to -1 \n"; - std::cout << "The fourth parameter of the program is the dimension of persistence to be used to construct " - "persistence landscape on a grid. If your file contains "; - std::cout << "the information about dimension of birth-death pairs, please provide here the dimension of intervals " - "you want to use. If your input files consist only "; - std::cout << "of birth-death pairs, please set the fourth parameter to -1 \n"; - std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; + std::cout << "This program creates persistence landscapes on grid files (*.g_land) of persistence diagrams files " + << "(*.pers) provided as an input.\n" + << "The first parameter of a program is an integer, a size of a grid.\n" + << "The second and third parameters are min and max of the grid. If you want those numbers to be computed " + << "based on the data, set them both to -1 \n" + << "The fourth parameter of this program is a dimension of persistence that will be used in creation of " + << "the persistence heat maps." + << "If your input files contains persistence pairs of various dimension, as a fourth parameter of the " + << "procedure please provide the dimension of persistence you want to use." + << "If in your files there are only birth-death pairs of the same dimension, set the fourth parameter to " + << "-1.\n" + << "The remaining parameters are the names of files with persistence diagrams. \n"; - if (argc < 5) { + if (argc < 6) { std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; } + size_t size_of_grid = (size_t)atoi(argv[1]); double min_ = atof(argv[2]); double max_ = atof(argv[3]); @@ -60,7 +63,6 @@ int main(int argc, char** argv) { filenames.push_back(argv[i]); } - std::cout << "Creating persistence landscapes...\n"; for (size_t i = 0; i != filenames.size(); ++i) { std::cout << "Creating persistence landscape on a grid based on a file : " << filenames[i] << std::endl; Persistence_landscape_on_grid l; @@ -74,6 +76,5 @@ int main(int argc, char** argv) { ss << filenames[i] << ".g_land"; l.print_to_file(ss.str().c_str()); } - std::cout << "Done \n"; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp index 42822a01..dddb3615 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp @@ -28,20 +28,17 @@ using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid; int main(int argc, char** argv) { - std::cout << "This program plot persistence landscape on grid stored in a file (the file needs to be created " - "beforehand). Please call the code with the name of a landscape on grid file \n"; - if (argc == 1) { - std::cout << "Wrong parameters of a program call, the program will now terminate \n"; + std::cout << "This program creates a gnuplot script from a persistence landscape on grid stored in a file (the file " + << "needs to be created beforehand). Please call the code with the name of a single landscape on grid file" + << ".\n"; + if (argc != 2) { + std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; } + Persistence_landscape_on_grid l; l.load_landscape_from_file(argv[1]); - - std::stringstream ss; - ss << argv[1] << "_gnuplot_script"; - l.plot(ss.str().c_str()); - - std::cout << "Done \n"; + l.plot(argv[1]); return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/simple_diagram.txt.g_land b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/simple_diagram.txt.g_land deleted file mode 100644 index dc53b932..00000000 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/simple_diagram.txt.g_land +++ /dev/null @@ -1,104 +0,0 @@ -1 -8 -101 - -0.07 -0.14 -0.21 -0.28 -0.35 -0.42 -0.49 -0.42 -0.35 -0.28 -0.21 -0.14 -0.07 - - - - - - - - - - - - - - - -0.07 -0.14 -0.21 -0.28 -0.35 -0.42 -0.49 -0.42 -0.35 -0.28 -0.21 -0.14 -0.07 - - - - - - - - - - - - - - - - -0.07 -0.14 -0.21 -0.28 -0.35 -0.42 -0.49 -0.42 -0.35 -0.28 -0.21 -0.14 -0.07 - - - - - - - - - - - - - - - -0.07 -0.14 -0.21 -0.28 -0.35 -0.42 -0.49 -0.42 -0.35 -0.28 -0.21 -0.14 -0.07 - - diff --git a/src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt index e3d1013b..a401c955 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt +++ b/src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt @@ -1,38 +1,10 @@ cmake_minimum_required(VERSION 2.6) project(Persistence_vectors_utilities) -file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") +add_persistence_representation_creation_utility(create_persistence_vectors "-1") -add_executable ( create_persistence_vectors create_persistence_vectors.cpp ) -target_link_libraries(create_persistence_vectors ${Boost_SYSTEM_LIBRARY}) +add_persistence_representation_plot_utility(plot_persistence_vectors ".vect") -# Will create simple_diagram.txt.vect -add_test(NAME create_persistence_vectors COMMAND $<TARGET_FILE:create_persistence_vectors> - "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt") - -add_executable ( average_persistence_vectors average_persistence_vectors.cpp ) -target_link_libraries(average_persistence_vectors ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME average_persistence_vectors COMMAND $<TARGET_FILE:average_persistence_vectors> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect") - -add_executable ( compute_distance_of_persistence_vectors compute_distance_of_persistence_vectors.cpp ) -target_link_libraries(compute_distance_of_persistence_vectors ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_distance_of_persistence_vectors COMMAND $<TARGET_FILE:compute_distance_of_persistence_vectors> - "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect") - -add_executable ( compute_scalar_product_of_persistence_vectors compute_scalar_product_of_persistence_vectors.cpp ) -target_link_libraries(compute_scalar_product_of_persistence_vectors ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME compute_scalar_product_of_persistence_vectors COMMAND $<TARGET_FILE:compute_scalar_product_of_persistence_vectors> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect" - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect") - -add_executable ( plot_persistence_vectors plot_persistence_vectors.cpp ) -target_link_libraries(plot_persistence_vectors ${Boost_SYSTEM_LIBRARY}) - -add_test(NAME plot_persistence_vectors COMMAND $<TARGET_FILE:plot_persistence_vectors> - "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect") +add_persistence_representation_function_utility(average_persistence_vectors ".vect") +add_persistence_representation_function_utility(compute_distance_of_persistence_vectors ".vect" "1") +add_persistence_representation_function_utility(compute_scalar_product_of_persistence_vectors ".vect") 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 366ee2bc..8de7725c 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp @@ -30,21 +30,20 @@ using Vector_distances_in_diagram = Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>; int main(int argc, char** argv) { - std::cout << "This program computes average persistence vector of persistence vectors created based on persistence " - "diagrams provided as an input. \n"; - std::cout << "Please call this program with the names of files with persistence diagrams \n"; - std::vector<const char*> filenames; + std::cout << "This program computes average of persistence vectors stored in files (the files needs to " + << "be created beforehand).\n" + << "The parameters of this programs are names of files with persistence vectors.\n"; - if (argc == 1) { - std::cout << "No input files given, the program will now terminate \n"; + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; return 1; } + std::vector<const char*> filenames; for (int i = 1; i < argc; ++i) { filenames.push_back(argv[i]); } - std::cout << "Reading persistence vectors...\n"; std::vector<Vector_distances_in_diagram*> lands; for (size_t i = 0; i != filenames.size(); ++i) { Vector_distances_in_diagram* l = new Vector_distances_in_diagram; 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 3aed297e..f8b71e5b 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 @@ -79,7 +79,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("distance"); + out.open("distance.vect"); for (size_t i = 0; i != distance.size(); ++i) { for (size_t j = 0; j != distance.size(); ++j) { std::cout << distance[i][j] << " "; @@ -90,5 +90,6 @@ int main(int argc, char** argv) { } out.close(); + std::cout << "Distance can be found in 'distance.vect' file\n"; return 0; } 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 d9ad4360..bda0b61b 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 @@ -32,9 +32,14 @@ using Vector_distances_in_diagram = Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>; 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 " - "created beforehand). \n"; - std::cout << "The parameters of this programs are names of files with persistence vectors.\n"; + std::cout << "This program computes scalar product of persistence vectors stored in a file (the file needs to " + << "be created beforehand). \n" + << "The parameters of this programs are names of files with persistence vectors.\n"; + + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; + return 1; + } std::vector<const char*> filenames; for (int i = 1; i < argc; ++i) { @@ -66,7 +71,7 @@ int main(int argc, char** argv) { // and now output the result to the screen and a file: std::ofstream out; - out.open("scalar_product"); + out.open("scalar_product.vect"); for (size_t i = 0; i != scalar_product.size(); ++i) { for (size_t j = 0; j != scalar_product.size(); ++j) { std::cout << scalar_product[i][j] << " "; @@ -76,5 +81,7 @@ int main(int argc, char** argv) { out << std::endl; } out.close(); + + std::cout << "Distance can be found in 'scalar_product.vect' file\n"; return 0; } 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 b618ca67..753675cb 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp @@ -32,13 +32,21 @@ using Vector_distances_in_diagram = Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>; int main(int argc, char** argv) { - std::cout << "This program creates persistence vectors of diagrams provided as an input. The first parameter of this " - "program is a dimension of persistence "; - std::cout << " that will be used in creation of the persistence vectors. If our input files contain persistence " - "pairs of various dimension, as a second parameter of the "; - std::cout << " procedure please provide the dimension of persistence you want to use. If in your file there are only " - "birth-death pairs of the same dimension, set the first parameter to -1." - << std::endl; + std::cout << "This program creates persistence vectors files (*.vect) of persistence diagrams files (*.pers) " + << "provided as an input.\n" + << "The first parameter of this program is a dimension of persistence that will be used in creation of " + << "the persistence heat maps." + << "If your input files contains persistence pairs of various dimension, as a first parameter of the " + << "procedure please provide the dimension of persistence you want to use." + << "If in your files there are only birth-death pairs of the same dimension, set the first parameter to " + << "-1.\n" + << "The remaining parameters are the names of files with persistence diagrams. \n"; + + if (argc < 3) { + std::cout << "Wrong parameter list, the program will now terminate \n"; + return 1; + } + std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; int dim = atoi(argv[1]); unsigned dimension = std::numeric_limits<unsigned>::max(); @@ -58,6 +66,5 @@ int main(int argc, char** argv) { ss << filenames[i] << ".vect"; l.print_to_file(ss.str().c_str()); } - std::cout << "Done \n"; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_vectors/simple_diagram.txt.vect b/src/Persistence_representations/utilities/persistence_vectors/simple_diagram.txt.vect deleted file mode 100644 index 1d4eeaaf..00000000 --- a/src/Persistence_representations/utilities/persistence_vectors/simple_diagram.txt.vect +++ /dev/null @@ -1 +0,0 @@ -0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 0.707107
\ No newline at end of file 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 <gudhi/Simplex_tree.h> #include <gudhi/distance_functions.h> #include <gudhi/reader_utils.h> +#include <gudhi/Unitary_tests_utils.h> // Type definitions using Point = std::vector<double>; @@ -44,10 +45,6 @@ using Filtration_value = Simplex_tree::Filtration_value; using Rips_complex = Gudhi::rips_complex::Rips_complex<Simplex_tree::Filtration_value>; using Distance_matrix = std::vector<std::vector<Filtration_value>>; -bool are_almost_the_same(float a, float b) { - return std::fabs(a - b) < std::numeric_limits<float>::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 $<TARGET_FILE:${unitary_test}> - "--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/cmake/modules/GUDHI_third_party_libraries.cmake b/src/cmake/modules/GUDHI_third_party_libraries.cmake index 84545f18..419c2581 100644 --- a/src/cmake/modules/GUDHI_third_party_libraries.cmake +++ b/src/cmake/modules/GUDHI_third_party_libraries.cmake @@ -85,7 +85,6 @@ FIND_PROGRAM( GCOVR_PATH gcovr ) if (GCOVR_PATH) message("gcovr found in ${GCOVR_PATH}") endif() -# Required programs for unitary tests purpose FIND_PROGRAM( GPROF_PATH gprof ) if (GPROF_PATH) message("gprof found in ${GPROF_PATH}") @@ -94,6 +93,10 @@ FIND_PROGRAM( DIFF_PATH diff ) if (DIFF_PATH) message("diff found in ${DIFF_PATH}") endif() +FIND_PROGRAM( GNUPLOT_PATH gnuplot ) +if (GNUPLOT_PATH) + message("gnuplot found in ${GNUPLOT_PATH}") +endif() # BOOST ISSUE result_of vs C++11 add_definitions(-DBOOST_RESULT_OF_USE_DECLTYPE) diff --git a/src/common/include/gudhi/Debug_utils.h b/src/common/include/gudhi/Debug_utils.h index e8bd7660..90d3cf47 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 <http://www.gnu.org/licenses/>. + */ +#ifndef UNITARY_TESTS_UTILS_H_ +#define UNITARY_TESTS_UTILS_H_ + +#include <boost/test/unit_test.hpp> + +#include <iostream> + +template<typename FloatingType > +void GUDHI_TEST_FLOAT_EQUALITY_CHECK(FloatingType a, FloatingType b, + FloatingType epsilon = std::numeric_limits<FloatingType>::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_ |