From 3d5bf7ed64b155894787cb356aead439977643e4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 22 Sep 2016 14:38:46 +0000 Subject: New template function create_complex for Alpha_complex to create the simplicial complex git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_create_complex@1540 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 24e53dc58d158166b976dd09760ad0e2acaf8e36 --- .../example/alpha_complex_persistence.cpp | 63 ++++++++------- .../example/custom_persistence_sort.cpp | 89 +++++++++++++--------- 2 files changed, 89 insertions(+), 63 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp index cb181936..44eda6aa 100644 --- a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp @@ -4,6 +4,8 @@ #include #include +// to construct a simplex_tree from alpha complex +#include #include #include @@ -30,35 +32,38 @@ int main(int argc, char **argv) { // Init of an alpha complex from an OFF file // ---------------------------------------------------------------------------- using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; - Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points, alpha_square_max_value); - - // ---------------------------------------------------------------------------- - // Display information about the alpha complex - // ---------------------------------------------------------------------------- - std::cout << "Alpha complex is of dimension " << alpha_complex_from_file.dimension() << - " - " << alpha_complex_from_file.num_simplices() << " simplices - " << - alpha_complex_from_file.num_vertices() << " vertices." << std::endl; - - // Sort the simplices in the order of the filtration - alpha_complex_from_file.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << alpha_complex_from_file.dimension() << std::endl; - // Compute the persistence diagram of the complex - Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::alpha_complex::Alpha_complex, - Gudhi::persistent_cohomology::Field_Zp > pcoh(alpha_complex_from_file); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (output_file_diag.empty()) { - pcoh.output_diagram(); - } else { - std::cout << "Result in file: " << output_file_diag << std::endl; - std::ofstream out(output_file_diag); - pcoh.output_diagram(out); - out.close(); + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); + + Gudhi::Simplex_tree<> simplex; + if (alpha_complex_from_file.create_complex(simplex, alpha_square_max_value)) { + // ---------------------------------------------------------------------------- + // Display information about the alpha complex + // ---------------------------------------------------------------------------- + std::cout << "Simplicial complex is of dimension " << simplex.dimension() << + " - " << simplex.num_simplices() << " simplices - " << + simplex.num_vertices() << " vertices." << std::endl; + + // Sort the simplices in the order of the filtration + simplex.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; + // Compute the persistence diagram of the complex + Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::Simplex_tree<>, + Gudhi::persistent_cohomology::Field_Zp > pcoh(simplex); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (output_file_diag.empty()) { + pcoh.output_diagram(); + } else { + std::cout << "Result in file: " << output_file_diag << std::endl; + std::ofstream out(output_file_diag); + pcoh.output_diagram(out); + out.close(); + } } return 0; diff --git a/src/Persistent_cohomology/example/custom_persistence_sort.cpp b/src/Persistent_cohomology/example/custom_persistence_sort.cpp index 9af38611..8e254700 100644 --- a/src/Persistent_cohomology/example/custom_persistence_sort.cpp +++ b/src/Persistent_cohomology/example/custom_persistence_sort.cpp @@ -27,6 +27,8 @@ #include #include +// to construct a simplex_tree from alpha complex +#include #include #include @@ -38,6 +40,9 @@ using Kernel = CGAL::Epick_d< CGAL::Dimension_tag<3> >; using Point = Kernel::Point_d; using Alpha_complex = Gudhi::alpha_complex::Alpha_complex; +using Simplex_tree = Gudhi::Simplex_tree<>; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< Simplex_tree, + Gudhi::persistent_cohomology::Field_Zp >; std::vector random_points() { // Instanciate a random point generator @@ -60,7 +65,7 @@ std::vector random_points() { * Compare two intervals by dimension, then by length. */ struct cmp_intervals_by_dim_then_length { - explicit cmp_intervals_by_dim_then_length(Alpha_complex * sc) + explicit cmp_intervals_by_dim_then_length(Simplex_tree * sc) : sc_(sc) { } template @@ -71,46 +76,62 @@ struct cmp_intervals_by_dim_then_length { else return (sc_->dimension(get < 0 > (p1)) > sc_->dimension(get < 0 > (p2))); } - Alpha_complex* sc_; + Simplex_tree* sc_; }; int main(int argc, char **argv) { std::vector points = random_points(); + std::cout << "Points size=" << points.size() << std::endl; // Alpha complex persistence computation from generated points - Alpha_complex alpha_complex_from_points(points, 0.6); - - using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< Alpha_complex, - Gudhi::persistent_cohomology::Field_Zp >; - Persistent_cohomology pcoh(alpha_complex_from_points); - - // initializes the coefficient field for homology - Z/3Z - pcoh.init_coefficients(3); - pcoh.compute_persistent_cohomology(0.2); - - // Custom sort and output persistence - cmp_intervals_by_dim_then_length cmp(&alpha_complex_from_points); - auto persistent_pairs = pcoh.get_persistent_pairs(); - std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp); - for (auto pair : persistent_pairs) { - std::cout << alpha_complex_from_points.dimension(get<0>(pair)) << " " - << alpha_complex_from_points.filtration(get<0>(pair)) << " " - << alpha_complex_from_points.filtration(get<1>(pair)) << std::endl; + Alpha_complex alpha_complex_from_points(points); + std::cout << "alpha_complex_from_points" << std::endl; + + Simplex_tree simplex; + std::cout << "simplex" << std::endl; + if (alpha_complex_from_points.create_complex(simplex, 0.6)) { + std::cout << "simplex" << std::endl; + // ---------------------------------------------------------------------------- + // Display information about the alpha complex + // ---------------------------------------------------------------------------- + std::cout << "Simplicial complex is of dimension " << simplex.dimension() << + " - " << simplex.num_simplices() << " simplices - " << + simplex.num_vertices() << " vertices." << std::endl; + + // Sort the simplices in the order of the filtration + simplex.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; + + Persistent_cohomology pcoh(simplex); + + // initializes the coefficient field for homology - Z/3Z + pcoh.init_coefficients(3); + pcoh.compute_persistent_cohomology(0.2); + + // Custom sort and output persistence + cmp_intervals_by_dim_then_length cmp(&simplex); + auto persistent_pairs = pcoh.get_persistent_pairs(); + std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp); + for (auto pair : persistent_pairs) { + std::cout << simplex.dimension(get<0>(pair)) << " " + << simplex.filtration(get<0>(pair)) << " " + << simplex.filtration(get<1>(pair)) << std::endl; + } + + // Persistent Betti numbers + std::cout << "The persistent Betti numbers in interval [0.40, 0.41] are : "; + for (int dim = 0; dim < simplex.dimension(); dim++) + std::cout << "b" << dim << " = " << pcoh.persistent_betti_number(dim, 0.40, 0.41) << " ; "; + std::cout << std::endl; + + // Betti numbers + std::vector betti_numbers = pcoh.betti_numbers(); + std::cout << "The Betti numbers are : "; + for (std::size_t i = 0; i < betti_numbers.size(); i++) + std::cout << "b" << i << " = " << betti_numbers[i] << " ; "; + std::cout << std::endl; } - - // Persistent Betti numbers - std::cout << "The persistent Betti numbers in interval [0.40, 0.41] are : "; - for (int dim = 0; dim < alpha_complex_from_points.dimension(); dim++) - std::cout << "b" << dim << " = " << pcoh.persistent_betti_number(dim, 0.40, 0.41) << " ; "; - std::cout << std::endl; - - // Betti numbers - std::vector betti_numbers = pcoh.betti_numbers(); - std::cout << "The Betti numbers are : "; - for (std::size_t i = 0; i < betti_numbers.size(); i++) - std::cout << "b" << i << " = " << betti_numbers[i] << " ; "; - std::cout << std::endl; - return 0; } -- cgit v1.2.3 From 0101a149fc124d62f8a4966654fa30e01f57d424 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 23 Sep 2016 09:37:35 +0000 Subject: Fix cpplints git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_create_complex@1548 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b8d7d5b4bde8aeec92d6bfc79b8c146c551317c0 --- src/Alpha_complex/concept/Simplicial_complex_for_alpha.h | 7 +++---- src/Alpha_complex/example/Alpha_complex_from_off.cpp | 7 ++++--- src/Alpha_complex/example/Alpha_complex_from_points.cpp | 2 +- src/Alpha_complex/include/gudhi/Alpha_complex.h | 6 +++--- .../example/alpha_complex_persistence.cpp | 8 ++++---- .../example/custom_persistence_sort.cpp | 14 +++++++------- 6 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Alpha_complex/concept/Simplicial_complex_for_alpha.h b/src/Alpha_complex/concept/Simplicial_complex_for_alpha.h index 2fd5dc03..384ac2eb 100644 --- a/src/Alpha_complex/concept/Simplicial_complex_for_alpha.h +++ b/src/Alpha_complex/concept/Simplicial_complex_for_alpha.h @@ -40,7 +40,7 @@ struct SimplicialComplexForAlpha { /** Returns the number of vertices in the simplicial complex. */ std::size_t num_vertices(); - + /** Gets the simplicial complex dimension. */ int dimension(); @@ -61,10 +61,10 @@ struct SimplicialComplexForAlpha { /** Browses the simplicial complex to make the filtration non-decreasing. */ void make_filtration_non_decreasing(); - + /** Prune the simplicial complex above 'filtration' value given as parameter. */ void prune_above_filtration(Filtration_value filtration); - + /** Sorts the filtration values in the simplicial complex. */ void initialize_filtration(); @@ -88,7 +88,6 @@ struct SimplicialComplexForAlpha { /** \brief Return type of an insertion of a simplex */ typedef unspecified Insertion_result_type; - }; } // namespace alpha_complex diff --git a/src/Alpha_complex/example/Alpha_complex_from_off.cpp b/src/Alpha_complex/example/Alpha_complex_from_off.cpp index 31f8e10c..32bef1cd 100644 --- a/src/Alpha_complex/example/Alpha_complex_from_off.cpp +++ b/src/Alpha_complex/example/Alpha_complex_from_off.cpp @@ -39,15 +39,16 @@ int main(int argc, char **argv) { Gudhi::Simplex_tree<> simplex; if (alpha_complex_from_file.create_complex(simplex, alpha_square_max_value)) { std::ostream output_stream(streambufffer); - + // ---------------------------------------------------------------------------- // Display information about the alpha complex // ---------------------------------------------------------------------------- output_stream << "Alpha complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices() << " simplices - " << simplex.num_vertices() << " vertices." << std::endl; - - output_stream << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + + output_stream << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << + std::endl; for (auto f_simplex : simplex.filtration_simplex_range()) { output_stream << " ( "; for (auto vertex : simplex.simplex_vertex_range(f_simplex)) { diff --git a/src/Alpha_complex/example/Alpha_complex_from_points.cpp b/src/Alpha_complex/example/Alpha_complex_from_points.cpp index fa3c1efc..491b7e6d 100644 --- a/src/Alpha_complex/example/Alpha_complex_from_points.cpp +++ b/src/Alpha_complex/example/Alpha_complex_from_points.cpp @@ -53,7 +53,7 @@ int main(int argc, char **argv) { std::cout << "Alpha complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices() << " simplices - " << simplex.num_vertices() << " vertices." << std::endl; - + std::cout << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; for (auto f_simplex : simplex.filtration_simplex_range()) { std::cout << " ( "; diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index ab96531f..8bb6af1f 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -232,7 +232,7 @@ class Alpha_complex { typedef typename SimplicialComplexForAlpha::Vertex_handle Vertex_handle; typedef typename SimplicialComplexForAlpha::Simplex_handle Simplex_handle; typedef std::vector Vector_vertex; - + if (triangulation_ == nullptr) { std::cerr << "Alpha_complex cannot create_complex from a NULL triangulation\n"; return false; // ----- >> @@ -249,7 +249,7 @@ class Alpha_complex { std::cerr << "Alpha_complex create_complex - complex is not empty\n"; return false; // ----- >> } - + complex.set_dimension(triangulation_->maximal_dimension()); // -------------------------------------------------------------------------------------------- @@ -353,7 +353,7 @@ class Alpha_complex { #ifdef DEBUG_TRACES typedef typename SimplicialComplexForAlpha::Vertex_handle Vertex_handle; #endif // DEBUG_TRACES - + // ### Foreach Tau face of Sigma for (auto f_boundary : complex.boundary_simplex_range(f_simplex)) { #ifdef DEBUG_TRACES diff --git a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp index 44eda6aa..2412569a 100644 --- a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp @@ -42,19 +42,19 @@ int main(int argc, char **argv) { std::cout << "Simplicial complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices() << " simplices - " << simplex.num_vertices() << " vertices." << std::endl; - + // Sort the simplices in the order of the filtration simplex.initialize_filtration(); - + std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; // Compute the persistence diagram of the complex Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::Simplex_tree<>, Gudhi::persistent_cohomology::Field_Zp > pcoh(simplex); // initializes the coefficient field for homology pcoh.init_coefficients(coeff_field_characteristic); - + pcoh.compute_persistent_cohomology(min_persistence); - + // Output the diagram in filediag if (output_file_diag.empty()) { pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/custom_persistence_sort.cpp b/src/Persistent_cohomology/example/custom_persistence_sort.cpp index 8e254700..64f2a4dc 100644 --- a/src/Persistent_cohomology/example/custom_persistence_sort.cpp +++ b/src/Persistent_cohomology/example/custom_persistence_sort.cpp @@ -97,18 +97,18 @@ int main(int argc, char **argv) { std::cout << "Simplicial complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices() << " simplices - " << simplex.num_vertices() << " vertices." << std::endl; - + // Sort the simplices in the order of the filtration simplex.initialize_filtration(); - + std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; - + Persistent_cohomology pcoh(simplex); - + // initializes the coefficient field for homology - Z/3Z pcoh.init_coefficients(3); pcoh.compute_persistent_cohomology(0.2); - + // Custom sort and output persistence cmp_intervals_by_dim_then_length cmp(&simplex); auto persistent_pairs = pcoh.get_persistent_pairs(); @@ -118,13 +118,13 @@ int main(int argc, char **argv) { << simplex.filtration(get<0>(pair)) << " " << simplex.filtration(get<1>(pair)) << std::endl; } - + // Persistent Betti numbers std::cout << "The persistent Betti numbers in interval [0.40, 0.41] are : "; for (int dim = 0; dim < simplex.dimension(); dim++) std::cout << "b" << dim << " = " << pcoh.persistent_betti_number(dim, 0.40, 0.41) << " ; "; std::cout << std::endl; - + // Betti numbers std::vector betti_numbers = pcoh.betti_numbers(); std::cout << "The Betti numbers are : "; -- cgit v1.2.3 From 383f95d7e767ef6254dff9c3b8f75ff98c1ae7ed Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 5 Oct 2016 09:34:04 +0000 Subject: Fix Windows failed UT git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@1641 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a85234208799a35da37cabcea4704018873cf13f --- src/Persistent_cohomology/example/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index d97d1b63..2beca531 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -31,9 +31,9 @@ endif() add_test(plain_homology ${CMAKE_CURRENT_BINARY_DIR}/plain_homology) add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.2 -d 3 -p 3 -m 100) -add_test(rips_persistence_via_boundary_matrix_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence_via_boundary_matrix ${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.txt -r 0.3 -d 3 -p 3 -m 100) -add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 2 -m 0) -add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) +add_test(rips_persistence_via_boundary_matrix_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence_via_boundary_matrix ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.2 -d 3 -p 3 -m 100) +add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/filtered_simplicial_complex/bunny_5000_complex.fsc -p 2 -m 0) +add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc -p 3 -m 100) if(GMP_FOUND) if(GMPXX_FOUND) -- cgit v1.2.3 From e5a99b635c16cf63d50b29c716f38250f35e363b Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 5 Oct 2016 10:01:40 +0000 Subject: Fix UT git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@1644 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 66eca6d5355fbdfc100fb74db70328501c6d7feb --- src/Persistent_cohomology/example/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index 2beca531..0899958c 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -32,7 +32,7 @@ add_test(plain_homology ${CMAKE_CURRENT_BINARY_DIR}/plain_homology) add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.2 -d 3 -p 3 -m 100) add_test(rips_persistence_via_boundary_matrix_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence_via_boundary_matrix ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.2 -d 3 -p 3 -m 100) -add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/filtered_simplicial_complex/bunny_5000_complex.fsc -p 2 -m 0) +add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc -p 2 -m 0) add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc -p 3 -m 100) if(GMP_FOUND) -- cgit v1.2.3 From 6f631ce5b14d8808a37e1085c3c24704a553d23a Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 20:23:08 +0000 Subject: Tests are too long git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@1672 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a2c79e443983f4f643b0ab3e21ab5e4fa978e27d --- src/Persistent_cohomology/example/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index 0899958c..758bd6b1 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -30,8 +30,8 @@ endif() add_test(plain_homology ${CMAKE_CURRENT_BINARY_DIR}/plain_homology) add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) -add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.2 -d 3 -p 3 -m 100) -add_test(rips_persistence_via_boundary_matrix_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence_via_boundary_matrix ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.2 -d 3 -p 3 -m 100) +add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.16 -d 3 -p 3 -m 100) +add_test(rips_persistence_via_boundary_matrix_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence_via_boundary_matrix ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.16 -d 3 -p 3 -m 100) add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc -p 2 -m 0) add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc -p 3 -m 100) -- cgit v1.2.3 From 0df3c9bcca4345b8be27ca2fd90eb5137072740c Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 15 Dec 2016 20:50:56 +0000 Subject: New pairs in dimension function in Persistence cohomology git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@1887 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 76bc9a951d752a6ca0f62244012965b5b6597a17 --- .../include/gudhi/Persistent_cohomology.h | 15 ++++++ .../test/betti_numbers_unit_test.cpp | 57 ++++++++++++++++++++++ 2 files changed, 72 insertions(+) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index b31df6a4..d3a8acc0 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -690,6 +690,21 @@ class Persistent_cohomology { return persistent_pairs_; } + /** @brief Returns persistence pairs for a given dimension. + * @param[in] dimension Dimension to get the birth and death pairs from. + * @return A vector of persistence intervals (birth and death) on a fixed dimension. + */ + std::vector< std::pair< Filtration_value , Filtration_value > > + pairs_in_dimension( unsigned dimension ) { + std::vector< std::pair< Filtration_value , Filtration_value > > result; + for (auto pair : persistent_pairs_) { + if (cpx_->dimension( get<0>(pair)) == dimension ) { + result.push_back(std::pair(cpx_->filtration(get<0>(pair)), + cpx_->filtration(get<1>(pair)))); + } + } + return result; + } private: /* * Structure representing a cocycle. diff --git a/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp b/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp index 40221005..67dfcce4 100644 --- a/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp +++ b/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp @@ -84,6 +84,8 @@ BOOST_AUTO_TEST_CASE( plain_homology_betti_numbers ) // 2 1 0 inf // means that in Z/2Z-homology, the Betti numbers are b0=2 and b1=1. + std::cout << "BETTI NUMBERS" << std::endl; + BOOST_CHECK(pcoh.betti_number(0) == 2); BOOST_CHECK(pcoh.betti_number(1) == 1); BOOST_CHECK(pcoh.betti_number(2) == 0); @@ -93,6 +95,8 @@ BOOST_AUTO_TEST_CASE( plain_homology_betti_numbers ) BOOST_CHECK(bns[0] == 2); BOOST_CHECK(bns[1] == 1); BOOST_CHECK(bns[2] == 0); + + std::cout << "GET PERSISTENT PAIRS" << std::endl; // Custom sort and output persistence cmp_intervals_by_dim_then_length cmp(&st); @@ -115,6 +119,33 @@ BOOST_AUTO_TEST_CASE( plain_homology_betti_numbers ) BOOST_CHECK(st.dimension(get<0>(persistent_pairs[2])) == 0); BOOST_CHECK(st.filtration(get<0>(persistent_pairs[2])) == 0); BOOST_CHECK(get<1>(persistent_pairs[2]) == st.null_simplex()); + + std::cout << "PAIRS IN DIMENSION" << std::endl; + + auto pairs_in_dimension_0 = pcoh.pairs_in_dimension(0); + std::cout << "pairs_in_dimension_0.size() = " << pairs_in_dimension_0.size() << std::endl; + for (int i = 0; i < pairs_in_dimension_0.size(); i++) + std::cout << "pairs_in_dimension_0[" << i << "] = [" << pairs_in_dimension_0[i].first << "," << + pairs_in_dimension_0[i].second << "]" << std::endl; + BOOST_CHECK(pairs_in_dimension_0.size() == 2); + BOOST_CHECK(pairs_in_dimension_0[0].first == 0); + BOOST_CHECK(pairs_in_dimension_0[0].second == std::numeric_limits::infinity()); + BOOST_CHECK(pairs_in_dimension_0[1].first == 0); + BOOST_CHECK(pairs_in_dimension_0[1].second == std::numeric_limits::infinity()); + + + auto pairs_in_dimension_1 = pcoh.pairs_in_dimension(1); + std::cout << "pairs_in_dimension_1.size() = " << pairs_in_dimension_1.size() << std::endl; + for (int i = 0; i < pairs_in_dimension_1.size(); i++) + std::cout << "pairs_in_dimension_1[" << i << "] = [" << pairs_in_dimension_1[i].first << "," << + pairs_in_dimension_1[i].second << "]" << std::endl; + BOOST_CHECK(pairs_in_dimension_1.size() == 1); + BOOST_CHECK(pairs_in_dimension_1[0].first == 0); + BOOST_CHECK(pairs_in_dimension_1[0].second == std::numeric_limits::infinity()); + + auto pairs_in_dimension_2 = pcoh.pairs_in_dimension(2); + std::cout << "pairs_in_dimension_2.size() = " << pairs_in_dimension_2.size() << std::endl; + BOOST_CHECK(pairs_in_dimension_2.size() == 0); } using Simplex_tree = Gudhi::Simplex_tree<>; @@ -231,4 +262,30 @@ BOOST_AUTO_TEST_CASE( betti_numbers ) BOOST_CHECK(st.dimension(get<0>(persistent_pairs[2])) == 0); BOOST_CHECK(st.filtration(get<0>(persistent_pairs[2])) == 1); BOOST_CHECK(get<1>(persistent_pairs[2]) == st.null_simplex()); + + std::cout << "PAIRS IN DIMENSION" << std::endl; + + auto pairs_in_dimension_0 = pcoh.pairs_in_dimension(0); + std::cout << "pairs_in_dimension_0.size() = " << pairs_in_dimension_0.size() << std::endl; + for (int i = 0; i < pairs_in_dimension_0.size(); i++) + std::cout << "pairs_in_dimension_0[" << i << "] = [" << pairs_in_dimension_0[i].first << "," << + pairs_in_dimension_0[i].second << "]" << std::endl; + BOOST_CHECK(pairs_in_dimension_0.size() == 2); + BOOST_CHECK(pairs_in_dimension_0[0].first == 2); + BOOST_CHECK(pairs_in_dimension_0[0].second == std::numeric_limits::infinity()); + BOOST_CHECK(pairs_in_dimension_0[1].first == 1); + BOOST_CHECK(pairs_in_dimension_0[1].second == std::numeric_limits::infinity()); + + auto pairs_in_dimension_1 = pcoh.pairs_in_dimension(1); + std::cout << "pairs_in_dimension_1.size() = " << pairs_in_dimension_1.size() << std::endl; + for (int i = 0; i < pairs_in_dimension_1.size(); i++) + std::cout << "pairs_in_dimension_1[" << i << "] = [" << pairs_in_dimension_1[i].first << "," << + pairs_in_dimension_1[i].second << "]" << std::endl; + BOOST_CHECK(pairs_in_dimension_1.size() == 1); + BOOST_CHECK(pairs_in_dimension_1[0].first == 4); + BOOST_CHECK(pairs_in_dimension_1[0].second == std::numeric_limits::infinity()); + + auto pairs_in_dimension_2 = pcoh.pairs_in_dimension(2); + std::cout << "pairs_in_dimension_2.size() = " << pairs_in_dimension_2.size() << std::endl; + BOOST_CHECK(pairs_in_dimension_2.size() == 0); } -- cgit v1.2.3