From 7b9b9dcdf26e283232195c9fb3b17f1cc23f0057 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 31 Jan 2018 14:48:07 +0000 Subject: test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/sparserips-glisse@3196 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4fbf12d3a2adc56ee85a13fc35571de3963fee70 --- src/Rips_complex/example/example_sparse_rips.cpp | 6 +-- src/Rips_complex/test/test_rips_complex.cpp | 67 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) (limited to 'src/Rips_complex') diff --git a/src/Rips_complex/example/example_sparse_rips.cpp b/src/Rips_complex/example/example_sparse_rips.cpp index 49725f0a..94e345ea 100644 --- a/src/Rips_complex/example/example_sparse_rips.cpp +++ b/src/Rips_complex/example/example_sparse_rips.cpp @@ -9,7 +9,7 @@ int main() { using Point = std::vector; using Simplex_tree = Gudhi::Simplex_tree; using Filtration_value = Simplex_tree::Filtration_value; - using Complex = Gudhi::rips_complex::Sparse_rips_complex; + using Sparse_rips = Gudhi::rips_complex::Sparse_rips_complex; Point points[] = { {1.0, 1.0}, @@ -24,10 +24,10 @@ int main() { // Init from Euclidean points // ---------------------------------------------------------------------------- double epsilon = 2; // very rough, no guarantees - Complex cpx(points, Gudhi::Euclidean_distance(), epsilon); + Sparse_rips sparse_rips(points, Gudhi::Euclidean_distance(), epsilon); Simplex_tree stree; - cpx.create_complex(stree, 10); + sparse_rips.create_complex(stree, 10); // ---------------------------------------------------------------------------- // Display information about the complex diff --git a/src/Rips_complex/test/test_rips_complex.cpp b/src/Rips_complex/test/test_rips_complex.cpp index 89afbc25..4e7b79d2 100644 --- a/src/Rips_complex/test/test_rips_complex.cpp +++ b/src/Rips_complex/test/test_rips_complex.cpp @@ -31,6 +31,7 @@ #include // std::max #include +#include // to construct Rips_complex from a OFF file of points #include #include @@ -43,6 +44,7 @@ using Point = std::vector; using Simplex_tree = Gudhi::Simplex_tree<>; using Filtration_value = Simplex_tree::Filtration_value; using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Sparse_rips_complex = Gudhi::rips_complex::Sparse_rips_complex; using Distance_matrix = std::vector>; BOOST_AUTO_TEST_CASE(RIPS_DOC_OFF_file) { @@ -230,6 +232,71 @@ BOOST_AUTO_TEST_CASE(Rips_complex_from_points) { } } +BOOST_AUTO_TEST_CASE(Sparse_rips_complex_from_points) { + // This is a clone of the test above + // ---------------------------------------------------------------------------- + // Init of a list of points + // ---------------------------------------------------------------------------- + Vector_of_points points; + std::vector coords = { 0.0, 0.0, 0.0, 1.0 }; + points.push_back(Point(coords.begin(), coords.end())); + coords = { 0.0, 0.0, 1.0, 0.0 }; + points.push_back(Point(coords.begin(), coords.end())); + coords = { 0.0, 1.0, 0.0, 0.0 }; + points.push_back(Point(coords.begin(), coords.end())); + coords = { 1.0, 0.0, 0.0, 0.0 }; + points.push_back(Point(coords.begin(), coords.end())); + + // ---------------------------------------------------------------------------- + // Init of a Rips complex from the list of points + // ---------------------------------------------------------------------------- + // .001 is small enough that we get a deterministic result matching the exact Rips + Sparse_rips_complex sparse_rips(points, Custom_square_euclidean_distance(), .001); + + std::cout << "========== Sparse_rips_complex_from_points ==========" << std::endl; + Simplex_tree st; + const int DIMENSION = 3; + sparse_rips.create_complex(st, DIMENSION); + + // Another way to check num_simplices + std::cout << "Iterator on Rips complex simplices in the filtration order, with [filtration value]:" << std::endl; + int num_simplices = 0; + for (auto f_simplex : st.filtration_simplex_range()) { + num_simplices++; + std::cout << " ( "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << vertex << " "; + } + std::cout << ") -> " << "[" << st.filtration(f_simplex) << "] "; + std::cout << std::endl; + } + BOOST_CHECK(num_simplices == 15); + std::cout << "st.num_simplices()=" << st.num_simplices() << std::endl; + BOOST_CHECK(st.num_simplices() == 15); + + std::cout << "st.dimension()=" << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == DIMENSION); + std::cout << "st.num_vertices()=" << st.num_vertices() << std::endl; + BOOST_CHECK(st.num_vertices() == 4); + + for (auto f_simplex : st.filtration_simplex_range()) { + std::cout << "dimension(" << st.dimension(f_simplex) << ") - f = " << st.filtration(f_simplex) << std::endl; + switch (st.dimension(f_simplex)) { + case 0: + GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), 0.0); + break; + case 1: + case 2: + case 3: + GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), 2.0); + break; + default: + BOOST_CHECK(false); // Shall not happen + break; + } + } +} + BOOST_AUTO_TEST_CASE(Rips_doc_csv_file) { // ---------------------------------------------------------------------------- // -- cgit v1.2.3