From c68ef729971d88818ceae9f1aa8e33f62a4dea7a Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 31 Jan 2018 13:41:06 +0000 Subject: Add example. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/sparserips-glisse@3195 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b8ded704563c6794c098f9b80b1a5e0200e84694 --- src/Rips_complex/example/CMakeLists.txt | 4 +++ src/Rips_complex/example/example_sparse_rips.cpp | 38 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/Rips_complex/example/example_sparse_rips.cpp (limited to 'src/Rips_complex/example') diff --git a/src/Rips_complex/example/CMakeLists.txt b/src/Rips_complex/example/CMakeLists.txt index 2940f164..8a22a6d8 100644 --- a/src/Rips_complex/example/CMakeLists.txt +++ b/src/Rips_complex/example/CMakeLists.txt @@ -11,11 +11,15 @@ add_executable ( Rips_complex_example_one_skeleton_from_distance_matrix example_ add_executable ( Rips_complex_example_from_csv_distance_matrix example_rips_complex_from_csv_distance_matrix_file.cpp ) +# Point cloud +add_executable ( Rips_complex_example_sparse example_sparse_rips_complex.cpp ) + if (TBB_FOUND) target_link_libraries(Rips_complex_example_from_off ${TBB_LIBRARIES}) target_link_libraries(Rips_complex_example_one_skeleton_from_points ${TBB_LIBRARIES}) target_link_libraries(Rips_complex_example_one_skeleton_from_distance_matrix ${TBB_LIBRARIES}) target_link_libraries(Rips_complex_example_from_csv_distance_matrix ${TBB_LIBRARIES}) + target_link_libraries(Rips_complex_example_sparse ${TBB_LIBRARIES}) endif() add_test(NAME Rips_complex_example_one_skeleton_from_points diff --git a/src/Rips_complex/example/example_sparse_rips.cpp b/src/Rips_complex/example/example_sparse_rips.cpp new file mode 100644 index 00000000..49725f0a --- /dev/null +++ b/src/Rips_complex/example/example_sparse_rips.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +#include +#include + +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; + + Point points[] = { + {1.0, 1.0}, + {7.0, 0.0}, + {4.0, 6.0}, + {9.0, 6.0}, + {0.0, 14.0}, + {2.0, 19.0}, + {9.0, 17.0}}; + + // ---------------------------------------------------------------------------- + // Init from Euclidean points + // ---------------------------------------------------------------------------- + double epsilon = 2; // very rough, no guarantees + Complex cpx(points, Gudhi::Euclidean_distance(), epsilon); + + Simplex_tree stree; + cpx.create_complex(stree, 10); + + // ---------------------------------------------------------------------------- + // Display information about the complex + // ---------------------------------------------------------------------------- + std::cout << "Sparse Rips complex is of dimension " << stree.dimension() << + " - " << stree.num_simplices() << " simplices - " << + stree.num_vertices() << " vertices." << std::endl; +} -- cgit v1.2.3 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/example') 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 From d3ff96460cbcd7de4d1f2d03c61e4227dd4c4767 Mon Sep 17 00:00:00 2001 From: glisse Date: Thu, 1 Feb 2018 17:52:06 +0000 Subject: typo in CMakeLists.txt + minor reformulation in doc. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/sparserips-glisse@3200 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: de115e83e56358fd3d283b802f16a2cc4f6db4f2 --- src/Rips_complex/doc/Intro_rips_complex.h | 6 ++++-- src/Rips_complex/example/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Rips_complex/example') diff --git a/src/Rips_complex/doc/Intro_rips_complex.h b/src/Rips_complex/doc/Intro_rips_complex.h index 96d90d98..81f24c71 100644 --- a/src/Rips_complex/doc/Intro_rips_complex.h +++ b/src/Rips_complex/doc/Intro_rips_complex.h @@ -44,8 +44,10 @@ namespace rips_complex { * simplex is the diameter of the corresponding subset of points. * * This filtered complex is most often used as an approximation of the - * Čech complex (they share the same 1-skeleton and are multiplicatively - * 2-interleaved or better), which is slightly bigger but easier to compute. + * Čech complex. After rescaling (Rips using the length of the edges and Čech + * the half-length), they share the same 1-skeleton and are multiplicatively + * 2-interleaved or better. While it is slightly bigger, it is also much + * easier to compute. * * The number of simplices in the full Rips complex is exponential in the * number of vertices, it is thus usually restricted, by excluding all the diff --git a/src/Rips_complex/example/CMakeLists.txt b/src/Rips_complex/example/CMakeLists.txt index 8a22a6d8..d05d3e57 100644 --- a/src/Rips_complex/example/CMakeLists.txt +++ b/src/Rips_complex/example/CMakeLists.txt @@ -12,7 +12,7 @@ add_executable ( Rips_complex_example_one_skeleton_from_distance_matrix example_ add_executable ( Rips_complex_example_from_csv_distance_matrix example_rips_complex_from_csv_distance_matrix_file.cpp ) # Point cloud -add_executable ( Rips_complex_example_sparse example_sparse_rips_complex.cpp ) +add_executable ( Rips_complex_example_sparse example_sparse_rips.cpp ) if (TBB_FOUND) target_link_libraries(Rips_complex_example_from_off ${TBB_LIBRARIES}) -- cgit v1.2.3