summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Alpha_complex/include/gudhi/Alpha_complex.h18
-rw-r--r--src/Alpha_complex/test/Alpha_complex_unit_test.cpp60
-rw-r--r--src/Bottleneck_distance/test/bottleneck_unit_test.cpp37
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_intervals.h5
-rw-r--r--src/Persistence_representations/test/persistence_intervals_test.cpp211
-rw-r--r--src/common/include/gudhi/Unitary_tests_utils.h11
-rw-r--r--src/python/doc/img/sklearn-tda.pngbin0 -> 388075 bytes
-rw-r--r--src/python/doc/representations_sum.inc2
8 files changed, 124 insertions, 220 deletions
diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h
index 6b4d8463..f2a05e95 100644
--- a/src/Alpha_complex/include/gudhi/Alpha_complex.h
+++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h
@@ -121,8 +121,8 @@ class Alpha_complex {
// size_type type from CGAL.
typedef typename Delaunay_triangulation::size_type size_type;
- // Map type to switch from simplex tree vertex handle to CGAL vertex iterator.
- typedef typename std::map< std::size_t, CGAL_vertex_iterator > Vector_vertex_iterator;
+ // Structure to switch from simplex tree vertex handle to CGAL vertex iterator.
+ typedef typename std::vector< CGAL_vertex_iterator > Vector_vertex_iterator;
private:
/** \brief Vertex iterator vector to switch from simplex tree vertex handle to CGAL vertex iterator.
@@ -191,14 +191,6 @@ class Alpha_complex {
return vertex_handle_to_iterator_.at(vertex)->point();
}
- /** \brief number_of_vertices returns the number of vertices (same as the number of points).
- *
- * @return The number of vertices.
- */
- std::size_t number_of_vertices() const {
- return vertex_handle_to_iterator_.size();
- }
-
private:
template<typename InputPointRange >
void init_from_range(const InputPointRange& points) {
@@ -238,14 +230,16 @@ class Alpha_complex {
hint = pos->full_cell();
}
// --------------------------------------------------------------------------------------------
- // double map to retrieve simplex tree vertex handles from CGAL vertex iterator and vice versa
+ // structure to retrieve CGAL points from vertex handle - one vertex handle per point.
+ // Needs to be constructed before as vertex handles arrives in no particular order.
+ vertex_handle_to_iterator_.resize(point_cloud.size());
// Loop on triangulation vertices list
for (CGAL_vertex_iterator vit = triangulation_->vertices_begin(); vit != triangulation_->vertices_end(); ++vit) {
if (!triangulation_->is_infinite(*vit)) {
#ifdef DEBUG_TRACES
std::cout << "Vertex insertion - " << vit->data() << " -> " << vit->point() << std::endl;
#endif // DEBUG_TRACES
- vertex_handle_to_iterator_.emplace(vit->data(), vit);
+ vertex_handle_to_iterator_[vit->data()] = vit;
}
}
// --------------------------------------------------------------------------------------------
diff --git a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp
index 40b3fe09..27b671dd 100644
--- a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp
+++ b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp
@@ -53,20 +53,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_OFF_file, TestedKernel, list_of
Gudhi::alpha_complex::Alpha_complex<TestedKernel> alpha_complex_from_file(off_file_name);
- std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_file.number_of_vertices()
- << std::endl;
- BOOST_CHECK(alpha_complex_from_file.number_of_vertices() == 7);
-
Gudhi::Simplex_tree<> simplex_tree_60;
BOOST_CHECK(alpha_complex_from_file.create_complex(simplex_tree_60, max_alpha_square_value));
std::cout << "simplex_tree_60.dimension()=" << simplex_tree_60.dimension() << std::endl;
BOOST_CHECK(simplex_tree_60.dimension() == 2);
- std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_file.number_of_vertices()
- << std::endl;
- BOOST_CHECK(alpha_complex_from_file.number_of_vertices() == 7);
-
std::cout << "simplex_tree_60.num_vertices()=" << simplex_tree_60.num_vertices() << std::endl;
BOOST_CHECK(simplex_tree_60.num_vertices() == 7);
@@ -128,10 +120,6 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) {
Gudhi::Simplex_tree<> simplex_tree;
BOOST_CHECK(alpha_complex_from_points.create_complex(simplex_tree));
- std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_points.number_of_vertices()
- << std::endl;
- BOOST_CHECK(alpha_complex_from_points.number_of_vertices() == points.size());
-
// Another way to check num_simplices
std::cout << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl;
int num_simplices = 0;
@@ -151,7 +139,7 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) {
std::cout << "simplex_tree.dimension()=" << simplex_tree.dimension() << std::endl;
BOOST_CHECK(simplex_tree.dimension() == 3);
std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() << std::endl;
- BOOST_CHECK(simplex_tree.num_vertices() == 4);
+ BOOST_CHECK(simplex_tree.num_vertices() == points.size());
for (auto f_simplex : simplex_tree.filtration_simplex_range()) {
switch (simplex_tree.dimension(f_simplex)) {
@@ -261,10 +249,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_empty_points, TestedKernel, lis
Gudhi::Simplex_tree<> simplex_tree;
BOOST_CHECK(!alpha_complex_from_points.create_complex(simplex_tree));
- std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_points.number_of_vertices()
- << std::endl;
- BOOST_CHECK(alpha_complex_from_points.number_of_vertices() == points.size());
-
std::cout << "simplex_tree.num_simplices()=" << simplex_tree.num_simplices() << std::endl;
BOOST_CHECK(simplex_tree.num_simplices() == 0);
@@ -272,5 +256,45 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_empty_points, TestedKernel, lis
BOOST_CHECK(simplex_tree.dimension() == -1);
std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() << std::endl;
- BOOST_CHECK(simplex_tree.num_vertices() == 0);
+ BOOST_CHECK(simplex_tree.num_vertices() == points.size());
+}
+
+using Inexact_kernel_2 = CGAL::Epick_d< CGAL::Dimension_tag<2> >;
+using Exact_kernel_2 = CGAL::Epeck_d< CGAL::Dimension_tag<2> >;
+using list_of_kernel_2_variants = boost::mpl::list<Inexact_kernel_2, Exact_kernel_2>;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_with_duplicated_points, TestedKernel, list_of_kernel_2_variants) {
+ std::cout << "========== Alpha_complex_with_duplicated_points ==========" << std::endl;
+
+ using Point = typename TestedKernel::Point_d;
+ using Vector_of_points = std::vector<Point>;
+
+ // ----------------------------------------------------------------------------
+ // Init of a list of points
+ // ----------------------------------------------------------------------------
+ Vector_of_points points;
+ points.push_back(Point(1.0, 1.0));
+ points.push_back(Point(7.0, 0.0));
+ points.push_back(Point(4.0, 6.0));
+ points.push_back(Point(9.0, 6.0));
+ points.push_back(Point(0.0, 14.0));
+ points.push_back(Point(2.0, 19.0));
+ points.push_back(Point(9.0, 17.0));
+ // duplicated points
+ points.push_back(Point(1.0, 1.0));
+ points.push_back(Point(7.0, 0.0));
+
+ // ----------------------------------------------------------------------------
+ // Init of an alpha complex from the list of points
+ // ----------------------------------------------------------------------------
+ std::cout << "Init" << std::endl;
+ Gudhi::alpha_complex::Alpha_complex<TestedKernel> alpha_complex_from_points(points);
+
+ Gudhi::Simplex_tree<> simplex_tree;
+ std::cout << "create_complex" << std::endl;
+ BOOST_CHECK(alpha_complex_from_points.create_complex(simplex_tree));
+
+ std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices()
+ << std::endl;
+ BOOST_CHECK(simplex_tree.num_vertices() < points.size());
}
diff --git a/src/Bottleneck_distance/test/bottleneck_unit_test.cpp b/src/Bottleneck_distance/test/bottleneck_unit_test.cpp
index 3fc6fc7b..2c520045 100644
--- a/src/Bottleneck_distance/test/bottleneck_unit_test.cpp
+++ b/src/Bottleneck_distance/test/bottleneck_unit_test.cpp
@@ -15,6 +15,7 @@
#include <random>
#include <gudhi/Bottleneck.h>
+#include <gudhi/Unitary_tests_utils.h>
using namespace Gudhi::persistence_diagram;
@@ -59,24 +60,24 @@ BOOST_AUTO_TEST_CASE(persistence_graph) {
BOOST_CHECK(g.size() == (n1 + n2));
//
BOOST_CHECK((int) d.size() == (n1 + n2)*(n1 + n2) + n1 + n2 + 1);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, 0)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, n1 - 1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, n1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, n2 - 1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, n2)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(0, (n1 + n2) - 1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, 0)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, n1 - 1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, n1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, n2 - 1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, n2)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance(n1, (n1 + n2) - 1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, 0)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, n1 - 1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, n1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, n2 - 1)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, n2)) > 0);
- BOOST_CHECK(std::count(d.begin(), d.end(), g.distance((n1 + n2) - 1, (n1 + n2) - 1)) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, 0))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, n1 - 1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, n1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, n2 - 1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, n2))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(0, (n1 + n2) - 1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, 0))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, n1 - 1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, n1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, n2 - 1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, n2))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance(n1, (n1 + n2) - 1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, 0))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, n1 - 1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, n1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, n2 - 1))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, n2))) > 0);
+ BOOST_CHECK(std::count(d.begin(), d.end(), GUDHI_PROTECT_FLOAT(g.distance((n1 + n2) - 1, (n1 + n2) - 1))) > 0);
}
BOOST_AUTO_TEST_CASE(neighbors_finder) {
diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h
index e2db4572..ea4220ea 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h
@@ -6,6 +6,8 @@
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
+ * - 2019/12 Vincent Rouvreau: Fix #118 - Make histogram_of_lengths and cumulative_histogram_of_lengths
+ * return the exact number_of_bins (was failing on x86)
*/
#ifndef PERSISTENCE_INTERVALS_H_
@@ -335,6 +337,9 @@ std::vector<size_t> Persistence_intervals::histogram_of_lengths(size_t number_of
getchar();
}
}
+ // we want number of bins equals to number_of_bins (some unexpected results on x86)
+ result[number_of_bins-1]+=result[number_of_bins];
+ result.resize(number_of_bins);
if (dbg) {
for (size_t i = 0; i != result.size(); ++i) std::cerr << result[i] << std::endl;
diff --git a/src/Persistence_representations/test/persistence_intervals_test.cpp b/src/Persistence_representations/test/persistence_intervals_test.cpp
index 3b7a2049..02ea8edb 100644
--- a/src/Persistence_representations/test/persistence_intervals_test.cpp
+++ b/src/Persistence_representations/test/persistence_intervals_test.cpp
@@ -6,6 +6,8 @@
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
+ * - 2019/12 Vincent Rouvreau: Fix #118 - Make histogram_of_lengths and cumulative_histogram_of_lengths
+ * return the exact number_of_bins (was failing on x86)
*/
#define BOOST_TEST_DYN_LINK
@@ -32,17 +34,8 @@ BOOST_AUTO_TEST_CASE(check_min_max_function) {
BOOST_AUTO_TEST_CASE(check_length_of_dominant_intervals) {
Persistence_intervals p("data/file_with_diagram");
std::vector<double> dominant_ten_intervals_length = p.length_of_dominant_intervals(10);
- std::vector<double> dominant_intervals_length;
- dominant_intervals_length.push_back(0.862625);
- dominant_intervals_length.push_back(0.800893);
- dominant_intervals_length.push_back(0.762061);
- dominant_intervals_length.push_back(0.756501);
- dominant_intervals_length.push_back(0.729367);
- dominant_intervals_length.push_back(0.718177);
- dominant_intervals_length.push_back(0.708395);
- dominant_intervals_length.push_back(0.702844);
- dominant_intervals_length.push_back(0.700468);
- dominant_intervals_length.push_back(0.622177);
+ std::vector<double> dominant_intervals_length{0.862625, 0.800893, 0.762061, 0.756501, 0.729367,
+ 0.718177, 0.708395, 0.702844, 0.700468, 0.622177};
for (size_t i = 0; i != dominant_ten_intervals_length.size(); ++i) {
GUDHI_TEST_FLOAT_EQUALITY_CHECK(dominant_ten_intervals_length[i], dominant_intervals_length[i],
Gudhi::Persistence_representations::epsi);
@@ -52,17 +45,11 @@ BOOST_AUTO_TEST_CASE(check_dominant_intervals) {
Persistence_intervals p("data/file_with_diagram");
std::vector<std::pair<double, double> > ten_dominant_intervals = p.dominant_intervals(10);
- std::vector<std::pair<double, double> > templ;
- templ.push_back(std::pair<double, double>(0.114718, 0.977343));
- templ.push_back(std::pair<double, double>(0.133638, 0.93453));
- templ.push_back(std::pair<double, double>(0.104599, 0.866659));
- templ.push_back(std::pair<double, double>(0.149798, 0.906299));
- templ.push_back(std::pair<double, double>(0.247352, 0.976719));
- templ.push_back(std::pair<double, double>(0.192675, 0.910852));
- templ.push_back(std::pair<double, double>(0.191836, 0.900231));
- templ.push_back(std::pair<double, double>(0.284998, 0.987842));
- templ.push_back(std::pair<double, double>(0.294069, 0.994537));
- templ.push_back(std::pair<double, double>(0.267421, 0.889597));
+ std::vector<std::pair<double, double> > templ{ {0.114718, 0.977343}, {0.133638, 0.93453},
+ {0.104599, 0.866659}, {0.149798, 0.906299},
+ {0.247352, 0.976719}, {0.192675, 0.910852},
+ {0.191836, 0.900231}, {0.284998, 0.987842},
+ {0.294069, 0.994537}, {0.267421, 0.889597} };
for (size_t i = 0; i != ten_dominant_intervals.size(); ++i) {
GUDHI_TEST_FLOAT_EQUALITY_CHECK(ten_dominant_intervals[i].first, templ[i].first,
@@ -75,18 +62,7 @@ BOOST_AUTO_TEST_CASE(check_dominant_intervals) {
BOOST_AUTO_TEST_CASE(check_histogram_of_lengths) {
Persistence_intervals p("data/file_with_diagram");
std::vector<size_t> histogram = p.histogram_of_lengths(10);
- std::vector<size_t> template_histogram;
- template_histogram.push_back(10);
- template_histogram.push_back(5);
- template_histogram.push_back(3);
- template_histogram.push_back(4);
- template_histogram.push_back(4);
- template_histogram.push_back(3);
- template_histogram.push_back(6);
- template_histogram.push_back(1);
- template_histogram.push_back(7);
- template_histogram.push_back(1);
- template_histogram.push_back(1);
+ std::vector<size_t> template_histogram{10, 5, 3, 4, 4, 3, 6, 1, 7, 2};
for (size_t i = 0; i != histogram.size(); ++i) {
BOOST_CHECK(histogram[i] == template_histogram[i]);
}
@@ -95,18 +71,7 @@ BOOST_AUTO_TEST_CASE(check_histogram_of_lengths) {
BOOST_AUTO_TEST_CASE(check_cumulative_histograms_of_lengths) {
Persistence_intervals p("data/file_with_diagram");
std::vector<size_t> cumulative_histogram = p.cumulative_histogram_of_lengths(10);
- std::vector<size_t> template_cumulative_histogram;
- template_cumulative_histogram.push_back(10);
- template_cumulative_histogram.push_back(15);
- template_cumulative_histogram.push_back(18);
- template_cumulative_histogram.push_back(22);
- template_cumulative_histogram.push_back(26);
- template_cumulative_histogram.push_back(29);
- template_cumulative_histogram.push_back(35);
- template_cumulative_histogram.push_back(36);
- template_cumulative_histogram.push_back(43);
- template_cumulative_histogram.push_back(44);
- template_cumulative_histogram.push_back(45);
+ std::vector<size_t> template_cumulative_histogram{10, 15, 18, 22, 26, 29, 35, 36, 43, 45};
for (size_t i = 0; i != cumulative_histogram.size(); ++i) {
BOOST_CHECK(cumulative_histogram[i] == template_cumulative_histogram[i]);
@@ -116,17 +81,8 @@ BOOST_AUTO_TEST_CASE(check_characteristic_function_of_diagram) {
Persistence_intervals p("data/file_with_diagram");
std::pair<double, double> min_max_ = p.get_x_range();
std::vector<double> char_funct_diag = p.characteristic_function_of_diagram(min_max_.first, min_max_.second);
- std::vector<double> template_char_funct_diag;
- template_char_funct_diag.push_back(0.370665);
- template_char_funct_diag.push_back(0.84058);
- template_char_funct_diag.push_back(1.24649);
- template_char_funct_diag.push_back(1.3664);
- template_char_funct_diag.push_back(1.34032);
- template_char_funct_diag.push_back(1.31904);
- template_char_funct_diag.push_back(1.14076);
- template_char_funct_diag.push_back(0.991259);
- template_char_funct_diag.push_back(0.800714);
- template_char_funct_diag.push_back(0.0676303);
+ std::vector<double> template_char_funct_diag{0.370665, 0.84058, 1.24649, 1.3664, 1.34032,
+ 1.31904, 1.14076, 0.991259, 0.800714, 0.0676303};
for (size_t i = 0; i != char_funct_diag.size(); ++i) {
GUDHI_TEST_FLOAT_EQUALITY_CHECK(char_funct_diag[i], template_char_funct_diag[i],
@@ -139,18 +95,8 @@ BOOST_AUTO_TEST_CASE(check_cumulative_characteristic_function_of_diagram) {
std::pair<double, double> min_max_ = p.get_x_range();
std::vector<double> cumul_char_funct_diag =
p.cumulative_characteristic_function_of_diagram(min_max_.first, min_max_.second);
- std::vector<double> template_char_funct_diag_cumul;
-
- template_char_funct_diag_cumul.push_back(0.370665);
- template_char_funct_diag_cumul.push_back(1.21125);
- template_char_funct_diag_cumul.push_back(2.45774);
- template_char_funct_diag_cumul.push_back(3.82414);
- template_char_funct_diag_cumul.push_back(5.16446);
- template_char_funct_diag_cumul.push_back(6.4835);
- template_char_funct_diag_cumul.push_back(7.62426);
- template_char_funct_diag_cumul.push_back(8.61552);
- template_char_funct_diag_cumul.push_back(9.41623);
- template_char_funct_diag_cumul.push_back(9.48386);
+ std::vector<double> template_char_funct_diag_cumul{0.370665, 1.21125, 2.45774, 3.82414, 5.16446,
+ 6.4835, 7.62426, 8.61552, 9.41623, 9.48386};
for (size_t i = 0; i != cumul_char_funct_diag.size(); ++i) {
GUDHI_TEST_FLOAT_EQUALITY_CHECK(cumul_char_funct_diag[i], template_char_funct_diag_cumul[i],
@@ -160,97 +106,29 @@ BOOST_AUTO_TEST_CASE(check_cumulative_characteristic_function_of_diagram) {
BOOST_AUTO_TEST_CASE(check_compute_persistent_betti_numbers) {
Persistence_intervals p("data/file_with_diagram");
- 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{ {0.0290362, 1}, {0.0307676, 2}, {0.0366312, 3}, {0.0544614, 4},
+ {0.0920033, 5}, {0.104599, 6}, {0.114718, 7}, {0.117379, 8},
+ {0.123493, 9}, {0.133638, 10}, {0.137798, 9}, {0.149798, 10},
+ {0.155421, 11}, {0.158443, 12}, {0.176956, 13}, {0.183234, 12},
+ {0.191069, 13}, {0.191333, 14}, {0.191836, 15}, {0.192675, 16},
+ {0.208564, 17}, {0.218425, 18}, {0.219902, 17}, {0.23233, 16},
+ {0.234558, 17}, {0.237166, 16}, {0.247352, 17}, {0.267421, 18},
+ {0.268093, 19}, {0.278734, 18}, {0.284722, 19}, {0.284998, 20},
+ {0.294069, 21}, {0.306293, 22}, {0.322361, 21}, {0.323152, 22},
+ {0.371021, 23}, {0.372395, 24}, {0.387744, 25}, {0.435537, 26},
+ {0.462911, 25}, {0.483569, 26}, {0.489209, 25}, {0.517115, 24},
+ {0.522197, 23}, {0.532665, 22}, {0.545262, 23}, {0.587227, 22},
+ {0.593036, 23}, {0.602647, 24}, {0.605044, 25}, {0.621962, 24},
+ {0.629449, 23}, {0.636719, 22}, {0.64957, 21}, {0.650781, 22},
+ {0.654951, 23}, {0.683489, 24}, {0.687172, 23}, {0.69703, 22},
+ {0.701174, 21}, {0.717623, 22}, {0.722023, 21}, {0.722298, 20},
+ {0.725347, 19}, {0.73071, 18}, {0.758355, 17}, {0.770913, 18},
+ {0.790833, 17}, {0.821211, 16}, {0.849305, 17}, {0.853669, 16},
+ {0.866659, 15}, {0.872896, 16}, {0.889597, 15}, {0.900231, 14},
+ {0.903847, 13}, {0.906299, 12}, {0.910852, 11}, {0.93453, 10},
+ {0.944757, 9}, {0.947812, 8}, {0.959154, 7}, {0.975654, 6},
+ {0.976719, 5}, {0.977343, 4}, {0.980129, 3}, {0.987842, 2},
+ {0.990127, 1}, {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) {
@@ -262,17 +140,8 @@ BOOST_AUTO_TEST_CASE(check_compute_persistent_betti_numbers) {
BOOST_AUTO_TEST_CASE(check_k_n_n) {
Persistence_intervals p("data/file_with_diagram");
std::vector<double> knn = p.k_n_n(5);
- std::vector<double> knn_template;
- knn_template.push_back(1.04208);
- knn_template.push_back(1.00344);
- knn_template.push_back(0.979395);
- knn_template.push_back(0.890643);
- knn_template.push_back(0.874769);
- knn_template.push_back(0.845787);
- knn_template.push_back(0.819713);
- knn_template.push_back(0.803984);
- knn_template.push_back(0.799864);
- knn_template.push_back(0.786945);
+ std::vector<double> knn_template{1.04208, 1.00344, 0.979395, 0.890643, 0.874769,
+ 0.845787, 0.819713, 0.803984, 0.799864, 0.786945};
for (size_t i = 0; i != knn.size(); ++i) {
GUDHI_TEST_FLOAT_EQUALITY_CHECK(knn[i], knn_template[i], Gudhi::Persistence_representations::epsi);
diff --git a/src/common/include/gudhi/Unitary_tests_utils.h b/src/common/include/gudhi/Unitary_tests_utils.h
index 7d039304..9b86460a 100644
--- a/src/common/include/gudhi/Unitary_tests_utils.h
+++ b/src/common/include/gudhi/Unitary_tests_utils.h
@@ -26,4 +26,15 @@ void GUDHI_TEST_FLOAT_EQUALITY_CHECK(FloatingType a, FloatingType b,
BOOST_CHECK(std::fabs(a - b) <= epsilon);
}
+// That's the usual x86 issue where a+b==a+b can return false (without any NaN) because one of them was stored in
+// memory (and thus rounded to 64 bits) while the other is still in a register (80 bits).
+template<typename FloatingType >
+FloatingType GUDHI_PROTECT_FLOAT(FloatingType value) {
+ volatile FloatingType protected_value = value;
+#ifdef DEBUG_TRACES
+ std::cout << "GUDHI_PROTECT_FLOAT - " << protected_value << std::endl;
+#endif
+ return protected_value;
+}
+
#endif // UNITARY_TESTS_UTILS_H_
diff --git a/src/python/doc/img/sklearn-tda.png b/src/python/doc/img/sklearn-tda.png
new file mode 100644
index 00000000..f0ff07f4
--- /dev/null
+++ b/src/python/doc/img/sklearn-tda.png
Binary files differ
diff --git a/src/python/doc/representations_sum.inc b/src/python/doc/representations_sum.inc
index 7b167a17..700828f1 100644
--- a/src/python/doc/representations_sum.inc
+++ b/src/python/doc/representations_sum.inc
@@ -3,7 +3,7 @@
+------------------------------------------------------------------+----------------------------------------------------------------+-----------------------------------------------+
| .. figure:: | Vectorizations, distances and kernels that work on persistence | :Author: Mathieu Carrière |
- | ../../doc/Persistence_representations/average_landscape.png | diagrams, compatible with scikit-learn. | |
+ | img/sklearn-tda.png | diagrams, compatible with scikit-learn. | |
| | | :Introduced in: GUDHI 3.1.0 |
| | | |
| | | :Copyright: MIT |