summaryrefslogtreecommitdiff
path: root/src/Persistence_representations/test/persistence_lanscapes_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Persistence_representations/test/persistence_lanscapes_test.cpp')
-rw-r--r--src/Persistence_representations/test/persistence_lanscapes_test.cpp170
1 files changed, 70 insertions, 100 deletions
diff --git a/src/Persistence_representations/test/persistence_lanscapes_test.cpp b/src/Persistence_representations/test/persistence_lanscapes_test.cpp
index 81adb6fa..e98ef894 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,14 +33,14 @@
using namespace Gudhi;
using namespace Gudhi::Persistence_representations;
-double epsilon = 0.0000005;
+double epsilon = 0.0005;
-BOOST_AUTO_TEST_CASE(check_construction_of_landscape) {
+BOOST_AUTO_TEST_CASE(check_construction_of_landscape) {
std::vector<std::pair<double, double> > diag =
- read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
+ read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
Persistence_landscape p(diag);
- Persistence_landscape q;
- q.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram");
+ Persistence_landscape q;
+ q.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram");
BOOST_CHECK(p == q);
}
@@ -47,19 +48,15 @@ BOOST_AUTO_TEST_CASE(check_construction_of_landscape_form_gudhi_style_file) {
Persistence_landscape p("data/persistence_file_with_four_entries_per_line", 1);
// p.print_to_file("persistence_file_with_four_entries_per_line_landscape");
Persistence_landscape q;
- q.load_landscape_from_file("data/persistence_file_with_four_entries_per_line_landscape");
+ q.load_landscape_from_file("data/persistence_file_with_four_entries_per_line_landscape");
BOOST_CHECK(p == q);
}
-
-
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 +64,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 +103,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 +121,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 +168,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 +190,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 +215,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,33 +227,9 @@ 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);
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
// Below I am storing the code used to generate tests for that functionality.
/*
if ( argc != 2 )