summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology
diff options
context:
space:
mode:
Diffstat (limited to 'src/Persistent_cohomology')
-rw-r--r--src/Persistent_cohomology/benchmark/CMakeLists.txt14
-rw-r--r--src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp38
-rw-r--r--src/Persistent_cohomology/concept/FilteredComplex.h2
-rw-r--r--src/Persistent_cohomology/doc/Intro_persistent_cohomology.h23
-rw-r--r--src/Persistent_cohomology/example/CMakeLists.txt80
-rw-r--r--src/Persistent_cohomology/example/custom_persistence_sort.cpp31
-rw-r--r--src/Persistent_cohomology/example/persistence_from_file.cpp43
-rw-r--r--src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp48
-rw-r--r--src/Persistent_cohomology/example/plain_homology.cpp11
-rw-r--r--src/Persistent_cohomology/example/rips_multifield_persistence.cpp39
-rw-r--r--src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp31
-rw-r--r--src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp41
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h38
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h18
-rw-r--r--src/Persistent_cohomology/test/betti_numbers_unit_test.cpp30
-rw-r--r--src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp196
-rw-r--r--src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp88
17 files changed, 371 insertions, 400 deletions
diff --git a/src/Persistent_cohomology/benchmark/CMakeLists.txt b/src/Persistent_cohomology/benchmark/CMakeLists.txt
index 2bb3b0c7..ad8dc84b 100644
--- a/src/Persistent_cohomology/benchmark/CMakeLists.txt
+++ b/src/Persistent_cohomology/benchmark/CMakeLists.txt
@@ -2,11 +2,13 @@ project(Persistent_cohomology_benchmark)
if(GMP_FOUND)
if(GMPXX_FOUND)
- add_executable ( performance_rips_persistence EXCLUDE_FROM_ALL performance_rips_persistence.cpp )
- target_link_libraries(performance_rips_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
- if (TBB_FOUND)
- target_link_libraries(performance_rips_persistence ${TBB_LIBRARIES})
- endif(TBB_FOUND)
- file(COPY "${CMAKE_SOURCE_DIR}/data/points/Kl.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
+ if (TARGET Boost::program_options)
+ add_executable ( performance_rips_persistence EXCLUDE_FROM_ALL performance_rips_persistence.cpp )
+ target_link_libraries(performance_rips_persistence Boost::program_options ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
+ if (TBB_FOUND)
+ target_link_libraries(performance_rips_persistence ${TBB_LIBRARIES})
+ endif(TBB_FOUND)
+ file(COPY "${CMAKE_SOURCE_DIR}/data/points/Kl.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
+ endif()
endif(GMPXX_FOUND)
endif(GMP_FOUND)
diff --git a/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp b/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp
index 45757002..3bec8830 100644
--- a/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp
+++ b/src/Persistent_cohomology/benchmark/performance_rips_persistence.cpp
@@ -49,7 +49,7 @@ void timing_persistence(FilteredComplex & cpx
* with a Hasse diagram. The Hasse diagram represents explicitly all
* codimension 1 incidence relations in the complex, and hence leads to
* a faster computation of persistence because boundaries are precomputed.
- * Hovewer, the simplex tree may be constructed directly from a point cloud and
+ * However, the simplex tree may be constructed directly from a point cloud and
* is more compact.
* We compute persistent homology with coefficient fields Z/2Z and Z/1223Z.
* We present also timings for the computation of multi-field persistent
@@ -74,7 +74,7 @@ int main(int argc, char * argv[]) {
Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance());
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << "Compute Rips graph in " << elapsed_sec << " ms.\n";
+ std::clog << "Compute Rips graph in " << elapsed_sec << " ms.\n";
// Construct the Rips complex in a Simplex Tree
Simplex_tree st;
@@ -86,16 +86,16 @@ int main(int argc, char * argv[]) {
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << "Compute Rips complex in " << elapsed_sec << " ms.\n";
- std::cout << " - dimension = " << st.dimension() << std::endl;
- std::cout << " - number of simplices = " << st.num_simplices() << std::endl;
+ std::clog << "Compute Rips complex in " << elapsed_sec << " ms.\n";
+ std::clog << " - dimension = " << st.dimension() << std::endl;
+ std::clog << " - number of simplices = " << st.num_simplices() << std::endl;
// Sort the simplices in the order of the filtration
start = std::chrono::system_clock::now();
st.initialize_filtration();
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << "Order the simplices of the filtration in " << elapsed_sec << " ms.\n";
+ std::clog << "Order the simplices of the filtration in " << elapsed_sec << " ms.\n";
// Copy the keys inside the simplices
start = std::chrono::system_clock::now();
@@ -106,22 +106,22 @@ int main(int argc, char * argv[]) {
}
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << "Copied the keys inside the simplices in " << elapsed_sec << " ms.\n";
+ std::clog << "Copied the keys inside the simplices in " << elapsed_sec << " ms.\n";
// Convert the simplex tree into a hasse diagram
start = std::chrono::system_clock::now();
Gudhi::Hasse_complex<> hcpx(st);
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << "Convert the simplex tree into a Hasse diagram in " << elapsed_sec << " ms.\n";
+ std::clog << "Convert the simplex tree into a Hasse diagram in " << elapsed_sec << " ms.\n";
- std::cout << "Timings when using a simplex tree: \n";
+ std::clog << "Timings when using a simplex tree: \n";
timing_persistence(st, p);
timing_persistence(st, q);
timing_persistence(st, p, q);
- std::cout << "Timings when using a Hasse complex: \n";
+ std::clog << "Timings when using a Hasse complex: \n";
timing_persistence(hcpx, p);
timing_persistence(hcpx, q);
timing_persistence(hcpx, p, q);
@@ -130,7 +130,7 @@ int main(int argc, char * argv[]) {
}
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << "Running the complex destructors in " << elapsed_sec << " ms.\n";
+ std::clog << "Running the complex destructors in " << elapsed_sec << " ms.\n";
return 0;
}
@@ -145,13 +145,13 @@ timing_persistence(FilteredComplex & cpx
Gudhi::persistent_cohomology::Persistent_cohomology< FilteredComplex, Field_Zp > pcoh(cpx);
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << " Initialize pcoh in " << elapsed_sec << " ms.\n";
+ std::clog << " Initialize pcoh in " << elapsed_sec << " ms.\n";
// initializes the coefficient field for homology
start = std::chrono::system_clock::now();
pcoh.init_coefficients(p);
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n";
+ std::clog << " Initialize the coefficient field in " << elapsed_sec << " ms.\n";
start = std::chrono::system_clock::now();
@@ -159,12 +159,12 @@ timing_persistence(FilteredComplex & cpx
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << " Compute persistent homology in Z/" << p << "Z in " << elapsed_sec << " ms.\n";
+ std::clog << " Compute persistent homology in Z/" << p << "Z in " << elapsed_sec << " ms.\n";
start = std::chrono::system_clock::now();
}
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n";
+ std::clog << " Run the persistence destructors in " << elapsed_sec << " ms.\n";
}
template< typename FilteredComplex>
@@ -179,13 +179,13 @@ timing_persistence(FilteredComplex & cpx
Gudhi::persistent_cohomology::Persistent_cohomology< FilteredComplex, Multi_field > pcoh(cpx);
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << " Initialize pcoh in " << elapsed_sec << " ms.\n";
+ std::clog << " Initialize pcoh in " << elapsed_sec << " ms.\n";
// initializes the coefficient field for homology
start = std::chrono::system_clock::now();
pcoh.init_coefficients(p, q);
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n";
+ std::clog << " Initialize the coefficient field in " << elapsed_sec << " ms.\n";
// compute persistent homology, disgarding persistent features of life shorter than min_persistence
start = std::chrono::system_clock::now();
@@ -194,11 +194,11 @@ timing_persistence(FilteredComplex & cpx
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ "
+ std::clog << " Compute multi-field persistent homology in all coefficient fields Z/pZ "
<< "with p in [" << p << ";" << q << "] in " << elapsed_sec << " ms.\n";
start = std::chrono::system_clock::now();
}
end = std::chrono::system_clock::now();
elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n";
+ std::clog << " Run the persistence destructors in " << elapsed_sec << " ms.\n";
}
diff --git a/src/Persistent_cohomology/concept/FilteredComplex.h b/src/Persistent_cohomology/concept/FilteredComplex.h
index 26ac7ac8..59ce25e3 100644
--- a/src/Persistent_cohomology/concept/FilteredComplex.h
+++ b/src/Persistent_cohomology/concept/FilteredComplex.h
@@ -103,7 +103,7 @@ Filtration_simplex_range filtration_simplex_range();
/** @} */
-/* \brief Iterator over the simplices of the complex,
+/** \brief Iterator over the simplices of the complex,
* in an arbitrary order.
*
* 'value_type' must be 'Simplex_handle'.*/
diff --git a/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h b/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h
index 46b784d8..94579564 100644
--- a/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h
+++ b/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h
@@ -21,7 +21,7 @@ namespace persistent_cohomology {
\author Clément Maria
Computation of persistent cohomology using the algorithm of
- \cite DBLP:journals/dcg/SilvaMV11 and \cite DBLP:journals/corr/abs-1208-5018
+ \cite DBLP:journals/dcg/SilvaMV11 and \cite DBLP:conf/compgeom/DeyFW14
and the Compressed Annotation Matrix
implementation of \cite DBLP:conf/esa/BoissonnatDM13
@@ -131,8 +131,7 @@ namespace persistent_cohomology {
We provide several example files: run these examples with -h for details on their use, and read the README file.
-\li <a href="_rips_complex_2rips_persistence_8cpp-example.html">
-Rips_complex/rips_persistence.cpp</a> computes the Rips complex of a point cloud and outputs its persistence
+\li \gudhi_example_link{Rips_complex,rips_persistence.cpp} computes the Rips complex of a point cloud and outputs its persistence
diagram.
\code $> ./rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 3 \endcode
\code The complex contains 177838 simplices
@@ -144,12 +143,10 @@ diagram.
More details on the <a href="../../ripscomplex/">Rips complex utilities</a> dedicated page.
-\li <a href="_persistent_cohomology_2rips_multifield_persistence_8cpp-example.html">
-Persistent_cohomology/rips_multifield_persistence.cpp</a> computes the Rips complex of a point cloud and outputs its
+\li \gudhi_example_link{Persistent_cohomology,rips_multifield_persistence.cpp} computes the Rips complex of a point cloud and outputs its
persistence diagram with a family of field coefficients.
-\li <a href="_rips_complex_2rips_distance_matrix_persistence_8cpp-example.html">
-Rips_complex/rips_distance_matrix_persistence.cpp</a> computes the Rips complex of a distance matrix and
+\li \gudhi_example_link{Rips_complex,rips_distance_matrix_persistence.cpp} computes the Rips complex of a distance matrix and
outputs its persistence diagram.
The file should contain square or lower triangular distance matrix with semicolons as separators.
@@ -158,8 +155,7 @@ Please refer to data/distance_matrix/lower_triangular_distance_matrix.csv for an
More details on the <a href="../../ripscomplex/">Rips complex utilities</a> dedicated page.
-\li <a href="_rips_complex_2rips_correlation_matrix_persistence_8cpp-example.html">
-Rips_complex/rips_correlation_matrix_persistence.cpp</a>
+\li \gudhi_example_link{Rips_complex,rips_correlation_matrix_persistence.cpp}
computes the Rips complex of a correlation matrix and outputs its persistence diagram.
Note that no check is performed if the matrix given as the input is a correlation matrix.
@@ -169,8 +165,7 @@ Please refer to data/correlation_matrix/lower_triangular_correlation_matrix.csv
More details on the <a href="../../ripscomplex/">Rips complex utilities</a> dedicated page.
-\li <a href="_alpha_complex_2alpha_complex_3d_persistence_8cpp-example.html">
-Alpha_complex/alpha_complex_3d_persistence.cpp</a> computes the persistent homology with
+\li \gudhi_example_link{Alpha_complex,alpha_complex_3d_persistence.cpp} computes the persistent homology with
\f$\mathbb{Z}/2\mathbb{Z}\f$ coefficients of the alpha complex on points sampling from an OFF file.
\code $> ./alpha_complex_3d_persistence ../../data/points/tore3D_300.off -p 2 -m 0.45 \endcode
\code Simplex_tree dim: 3
@@ -235,8 +230,7 @@ Note that the lengths of the sides of the periodic cuboid have to be the same.<b
3 2 36.8838 inf
3 3 58.6783 inf \endcode
-\li <a href="_alpha_complex_2alpha_complex_persistence_8cpp-example.html">
-Alpha_complex/alpha_complex_persistence.cpp</a> computes the persistent homology with
+\li \gudhi_example_link{Alpha_complex,alpha_complex_persistence.cpp} computes the persistent homology with
\f$\mathbb{Z}/p\mathbb{Z}\f$ coefficients of the alpha complex on points sampling from an OFF file.
\code $> ./alpha_complex_persistence -r 32 -p 2 -m 0.45 ../../data/points/tore3D_300.off \endcode
\code Alpha complex is of dimension 3 - 9273 simplices - 300 vertices.
@@ -248,8 +242,7 @@ Simplex_tree dim: 3
More details on the <a href="../../alphacomplex/">Alpha complex utilities</a> dedicated page.
-\li <a href="_persistent_cohomology_2plain_homology_8cpp-example.html">
-Persistent_cohomology/plain_homology.cpp</a> computes the plain homology of a simple simplicial complex without
+\li \gudhi_example_link{Persistent_cohomology,plain_homology.cpp} computes the plain homology of a simple simplicial complex without
filtration values.
*/
diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt
index 94ec13c5..d66954d7 100644
--- a/src/Persistent_cohomology/example/CMakeLists.txt
+++ b/src/Persistent_cohomology/example/CMakeLists.txt
@@ -1,68 +1,70 @@
project(Persistent_cohomology_examples)
add_executable(plain_homology plain_homology.cpp)
+if (TBB_FOUND)
+ target_link_libraries(plain_homology ${TBB_LIBRARIES})
+endif()
+add_test(NAME Persistent_cohomology_example_plain_homology COMMAND $<TARGET_FILE:plain_homology>)
add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp)
-
-add_executable(rips_persistence_step_by_step rips_persistence_step_by_step.cpp)
-target_link_libraries(rips_persistence_step_by_step ${Boost_PROGRAM_OPTIONS_LIBRARY})
-
-add_executable(rips_persistence_via_boundary_matrix rips_persistence_via_boundary_matrix.cpp)
-target_link_libraries(rips_persistence_via_boundary_matrix ${Boost_PROGRAM_OPTIONS_LIBRARY})
-
-add_executable(persistence_from_file persistence_from_file.cpp)
-target_link_libraries(persistence_from_file ${Boost_PROGRAM_OPTIONS_LIBRARY})
-
if (TBB_FOUND)
- target_link_libraries(plain_homology ${TBB_LIBRARIES})
target_link_libraries(persistence_from_simple_simplex_tree ${TBB_LIBRARIES})
- target_link_libraries(rips_persistence_step_by_step ${TBB_LIBRARIES})
- target_link_libraries(rips_persistence_via_boundary_matrix ${TBB_LIBRARIES})
- target_link_libraries(persistence_from_file ${TBB_LIBRARIES})
endif()
-
-add_test(NAME Persistent_cohomology_example_plain_homology COMMAND $<TARGET_FILE:plain_homology>)
add_test(NAME Persistent_cohomology_example_from_simple_simplex_tree COMMAND $<TARGET_FILE:persistence_from_simple_simplex_tree>
- "1" "0")
-add_test(NAME Persistent_cohomology_example_from_rips_step_by_step_on_tore_3D COMMAND $<TARGET_FILE:rips_persistence_step_by_step>
- "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "3")
-add_test(NAME Persistent_cohomology_example_via_boundary_matrix COMMAND $<TARGET_FILE:rips_persistence_via_boundary_matrix>
- "${CMAKE_SOURCE_DIR}/data/points/Kl.off" "-r" "0.16" "-d" "3" "-p" "3" "-m" "100")
-add_test(NAME Persistent_cohomology_example_from_file_3_2_0 COMMAND $<TARGET_FILE:persistence_from_file>
- "${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc" "-p" "2" "-m" "0")
-add_test(NAME Persistent_cohomology_example_from_file_3_3_100 COMMAND $<TARGET_FILE:persistence_from_file>
- "${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc" "-p" "3" "-m" "100")
+ "2" "0")
-install(TARGETS plain_homology DESTINATION bin)
-install(TARGETS persistence_from_simple_simplex_tree DESTINATION bin)
-install(TARGETS rips_persistence_step_by_step DESTINATION bin)
-install(TARGETS rips_persistence_via_boundary_matrix DESTINATION bin)
-install(TARGETS persistence_from_file DESTINATION bin)
+if(TARGET Boost::program_options)
+ add_executable(rips_persistence_step_by_step rips_persistence_step_by_step.cpp)
+ target_link_libraries(rips_persistence_step_by_step Boost::program_options)
+ if (TBB_FOUND)
+ target_link_libraries(rips_persistence_step_by_step ${TBB_LIBRARIES})
+ endif()
+ add_test(NAME Persistent_cohomology_example_from_rips_step_by_step_on_tore_3D COMMAND $<TARGET_FILE:rips_persistence_step_by_step>
+ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "3")
+endif()
+
+if(TARGET Boost::program_options)
+ add_executable(rips_persistence_via_boundary_matrix rips_persistence_via_boundary_matrix.cpp)
+ target_link_libraries(rips_persistence_via_boundary_matrix Boost::program_options)
+ if (TBB_FOUND)
+ target_link_libraries(rips_persistence_via_boundary_matrix ${TBB_LIBRARIES})
+ endif()
+ add_test(NAME Persistent_cohomology_example_via_boundary_matrix COMMAND $<TARGET_FILE:rips_persistence_via_boundary_matrix>
+ "${CMAKE_SOURCE_DIR}/data/points/Kl.off" "-r" "0.16" "-d" "3" "-p" "3" "-m" "100")
+endif()
+
+if(TARGET Boost::program_options)
+ add_executable(persistence_from_file persistence_from_file.cpp)
+ target_link_libraries(persistence_from_file Boost::program_options)
+ if (TBB_FOUND)
+ target_link_libraries(persistence_from_file ${TBB_LIBRARIES})
+ endif()
+ add_test(NAME Persistent_cohomology_example_from_file_3_2_0 COMMAND $<TARGET_FILE:persistence_from_file>
+ "${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/Klein_bottle_complex.fsc" "-p" "2" "-m" "0")
+ add_test(NAME Persistent_cohomology_example_from_file_3_3_100 COMMAND $<TARGET_FILE:persistence_from_file>
+ "${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/Klein_bottle_complex.fsc" "-p" "3" "-m" "100")
+endif()
if(GMP_FOUND)
- if(GMPXX_FOUND)
+ if(GMPXX_FOUND)
+ if(TARGET Boost::program_options)
add_executable(rips_multifield_persistence rips_multifield_persistence.cpp )
target_link_libraries(rips_multifield_persistence
- ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
+ Boost::program_options ${GMPXX_LIBRARIES} ${GMP_LIBRARIES})
if (TBB_FOUND)
target_link_libraries(rips_multifield_persistence ${TBB_LIBRARIES})
endif(TBB_FOUND)
add_test(NAME Persistent_cohomology_example_multifield_2_71 COMMAND $<TARGET_FILE:rips_multifield_persistence>
"${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "2" "-q" "71")
- install(TARGETS rips_multifield_persistence DESTINATION bin)
- endif(GMPXX_FOUND)
+ endif()
+ endif(GMPXX_FOUND)
endif(GMP_FOUND)
if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0)
-
add_executable(custom_persistence_sort custom_persistence_sort.cpp)
target_link_libraries(custom_persistence_sort ${CGAL_LIBRARY})
-
if (TBB_FOUND)
target_link_libraries(custom_persistence_sort ${TBB_LIBRARIES})
endif(TBB_FOUND)
add_test(NAME Persistent_cohomology_example_custom_persistence_sort COMMAND $<TARGET_FILE:custom_persistence_sort>)
-
- install(TARGETS custom_persistence_sort DESTINATION bin)
-
endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0)
diff --git a/src/Persistent_cohomology/example/custom_persistence_sort.cpp b/src/Persistent_cohomology/example/custom_persistence_sort.cpp
index be74cf50..bba0b2f7 100644
--- a/src/Persistent_cohomology/example/custom_persistence_sort.cpp
+++ b/src/Persistent_cohomology/example/custom_persistence_sort.cpp
@@ -33,7 +33,7 @@ using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomolog
Gudhi::persistent_cohomology::Field_Zp >;
std::vector<Point> random_points() {
- // Instanciate a random point generator
+ // Instantiate a random point generator
CGAL::Random rng(0);
// Generate "points_number" random points in a vector
@@ -70,26 +70,23 @@ struct cmp_intervals_by_dim_then_length {
int main(int argc, char **argv) {
std::vector<Point> points = random_points();
- std::cout << "Points size=" << points.size() << std::endl;
+ std::clog << "Points size=" << points.size() << std::endl;
// Alpha complex persistence computation from generated points
Alpha_complex alpha_complex_from_points(points);
- std::cout << "alpha_complex_from_points" << std::endl;
+ std::clog << "alpha_complex_from_points" << std::endl;
Simplex_tree simplex;
- std::cout << "simplex" << std::endl;
+ std::clog << "simplex" << std::endl;
if (alpha_complex_from_points.create_complex(simplex, 0.6)) {
- std::cout << "simplex" << std::endl;
+ std::clog << "simplex" << std::endl;
// ----------------------------------------------------------------------------
// Display information about the alpha complex
// ----------------------------------------------------------------------------
- std::cout << "Simplicial complex is of dimension " << simplex.dimension() <<
+ std::clog << "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;
+ std::clog << "Simplex_tree dim: " << simplex.dimension() << std::endl;
Persistent_cohomology pcoh(simplex);
@@ -102,23 +99,23 @@ int main(int argc, char **argv) {
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)) << " "
+ std::clog << 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 : ";
+ std::clog << "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;
+ std::clog << "b" << dim << " = " << pcoh.persistent_betti_number(dim, 0.40, 0.41) << " ; ";
+ std::clog << std::endl;
// Betti numbers
std::vector<int> betti_numbers = pcoh.betti_numbers();
- std::cout << "The Betti numbers are : ";
+ std::clog << "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;
+ std::clog << "b" << i << " = " << betti_numbers[i] << " ; ";
+ std::clog << std::endl;
}
return 0;
}
diff --git a/src/Persistent_cohomology/example/persistence_from_file.cpp b/src/Persistent_cohomology/example/persistence_from_file.cpp
index d169cc63..7f89c001 100644
--- a/src/Persistent_cohomology/example/persistence_from_file.cpp
+++ b/src/Persistent_cohomology/example/persistence_from_file.cpp
@@ -37,9 +37,9 @@ int main(int argc, char * argv[]) {
program_options(argc, argv, simplex_tree_file, output_file, p, min_persistence);
- std::cout << "Simplex_tree from file=" << simplex_tree_file.c_str() << " - output_file=" << output_file.c_str()
+ std::clog << "Simplex_tree from file=" << simplex_tree_file.c_str() << " - output_file=" << output_file.c_str()
<< std::endl;
- std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl;
+ std::clog << " - p=" << p << " - min_persistence=" << min_persistence << std::endl;
// Read the list of simplices from a file.
Simplex_tree<> simplex_tree;
@@ -47,21 +47,18 @@ int main(int argc, char * argv[]) {
std::ifstream simplex_tree_stream(simplex_tree_file);
simplex_tree_stream >> simplex_tree;
- std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices" << std::endl;
- std::cout << " - dimension " << simplex_tree.dimension() << std::endl;
+ std::clog << "The complex contains " << simplex_tree.num_simplices() << " simplices" << std::endl;
+ std::clog << " - dimension " << simplex_tree.dimension() << std::endl;
/*
- std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl;
+ std::clog << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl;
for( auto f_simplex : simplex_tree.filtration_simplex_range() )
- { std::cout << " " << "[" << simplex_tree.filtration(f_simplex) << "] ";
+ { std::clog << " " << "[" << simplex_tree.filtration(f_simplex) << "] ";
for( auto vertex : simplex_tree.simplex_vertex_range(f_simplex) )
- { std::cout << vertex << " "; }
- std::cout << std::endl;
+ { std::clog << vertex << " "; }
+ std::clog << std::endl;
}*/
- // Sort the simplices in the order of the filtration
- simplex_tree.initialize_filtration();
-
// Compute the persistence diagram of the complex
Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree);
// initializes the coefficient field for homology
@@ -96,7 +93,7 @@ void program_options(int argc, char * argv[]
visible.add_options()
("help,h", "produce help message")
("output-file,o", po::value<std::string>(&output_file)->default_value(std::string()),
- "Name of file in which the persistence diagram is written. Default print in std::cout")
+ "Name of file in which the persistence diagram is written. Default print in standard output")
("field-charac,p", po::value<int>(&p)->default_value(11),
"Characteristic p of the coefficient field Z/pZ for computing homology.")
("min-persistence,m", po::value<Filtration_value>(&min_persistence),
@@ -114,17 +111,17 @@ void program_options(int argc, char * argv[]
po::notify(vm);
if (vm.count("help") || !vm.count("input-file")) {
- std::cout << std::endl;
- std::cout << "Compute the persistent homology with coefficient field Z/pZ \n";
- std::cout << "of a Rips complex defined on a set of input points.\n \n";
- std::cout << "The output diagram contains one bar per line, written with the convention: \n";
- std::cout << " p dim b d \n";
- std::cout << "where dim is the dimension of the homological feature,\n";
- std::cout << "b and d are respectively the birth and death of the feature and \n";
- std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl;
-
- std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
- std::cout << visible << std::endl;
+ std::clog << std::endl;
+ std::clog << "Compute the persistent homology with coefficient field Z/pZ \n";
+ std::clog << "of a Rips complex defined on a set of input points.\n \n";
+ std::clog << "The output diagram contains one bar per line, written with the convention: \n";
+ std::clog << " p dim b d \n";
+ std::clog << "where dim is the dimension of the homological feature,\n";
+ std::clog << "b and d are respectively the birth and death of the feature and \n";
+ std::clog << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl;
+
+ std::clog << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
+ std::clog << visible << std::endl;
exit(-1);
}
}
diff --git a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp
index 3c91662f..3da6771e 100644
--- a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp
+++ b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp
@@ -51,62 +51,62 @@ int main(int argc, char * const argv[]) {
}
// TEST OF INSERTION
- std::cout << "********************************************************************" << std::endl;
- std::cout << "TEST OF INSERTION" << std::endl;
+ std::clog << "********************************************************************" << std::endl;
+ std::clog << "TEST OF INSERTION" << std::endl;
Simplex_tree st;
// ++ FIRST
- std::cout << " - INSERT (0,1,2)" << std::endl;
+ std::clog << " - INSERT (0,1,2)" << std::endl;
typeVectorVertex SimplexVector = {0, 1, 2};
st.insert_simplex_and_subfaces(SimplexVector, 0.3);
// ++ SECOND
- std::cout << " - INSERT 3" << std::endl;
+ std::clog << " - INSERT 3" << std::endl;
SimplexVector = {3};
st.insert_simplex_and_subfaces(SimplexVector, 0.1);
// ++ THIRD
- std::cout << " - INSERT (0,3)" << std::endl;
+ std::clog << " - INSERT (0,3)" << std::endl;
SimplexVector = {0, 3};
st.insert_simplex_and_subfaces(SimplexVector, 0.2);
// ++ FOURTH
- std::cout << " - INSERT (0,1) (already inserted)" << std::endl;
+ std::clog << " - INSERT (0,1) (already inserted)" << std::endl;
SimplexVector = {0, 1};
st.insert_simplex_and_subfaces(SimplexVector, 0.2);
// ++ FIFTH
- std::cout << " - INSERT (3,4,5)" << std::endl;
+ std::clog << " - INSERT (3,4,5)" << std::endl;
SimplexVector = {3, 4, 5};
st.insert_simplex_and_subfaces(SimplexVector, 0.3);
// ++ SIXTH
- std::cout << " - INSERT (0,1,6,7)" << std::endl;
+ std::clog << " - INSERT (0,1,6,7)" << std::endl;
SimplexVector = {0, 1, 6, 7};
st.insert_simplex_and_subfaces(SimplexVector, 0.4);
// ++ SEVENTH
- std::cout << " - INSERT (4,5,8,9)" << std::endl;
+ std::clog << " - INSERT (4,5,8,9)" << std::endl;
SimplexVector = {4, 5, 8, 9};
st.insert_simplex_and_subfaces(SimplexVector, 0.4);
// ++ EIGHTH
- std::cout << " - INSERT (9,10,11)" << std::endl;
+ std::clog << " - INSERT (9,10,11)" << std::endl;
SimplexVector = {9, 10, 11};
st.insert_simplex_and_subfaces(SimplexVector, 0.3);
- // ++ NINETH
- std::cout << " - INSERT (2,10,12)" << std::endl;
+ // ++ NINTH
+ std::clog << " - INSERT (2,10,12)" << std::endl;
SimplexVector = {2, 10, 12};
st.insert_simplex_and_subfaces(SimplexVector, 0.3);
// ++ TENTH
- std::cout << " - INSERT (11,6)" << std::endl;
+ std::clog << " - INSERT (11,6)" << std::endl;
SimplexVector = {6, 11};
st.insert_simplex_and_subfaces(SimplexVector, 0.2);
// ++ ELEVENTH
- std::cout << " - INSERT (13,14,15)" << std::endl;
+ std::clog << " - INSERT (13,14,15)" << std::endl;
SimplexVector = {13, 14, 15};
st.insert_simplex_and_subfaces(SimplexVector, 0.25);
@@ -131,24 +131,24 @@ int main(int argc, char * const argv[]) {
/* An edge [10,12,2] */
- std::cout << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices "
+ std::clog << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices "
<< std::endl;
- std::cout << " - dimension " << st.dimension() << std::endl;
- std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:"
+ std::clog << " - dimension " << st.dimension() << std::endl;
+ std::clog << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:"
<< std::endl;
- std::cout << "**************************************************************" << std::endl;
- std::cout << "strict graph G { " << std::endl;
+ std::clog << "**************************************************************" << std::endl;
+ std::clog << "strict graph G { " << std::endl;
for (auto f_simplex : st.filtration_simplex_range()) {
- std::cout << " " << "[" << st.filtration(f_simplex) << "] ";
+ std::clog << " " << "[" << st.filtration(f_simplex) << "] ";
for (auto vertex : st.simplex_vertex_range(f_simplex)) {
- std::cout << static_cast<int>(vertex) << " -- ";
+ std::clog << static_cast<int>(vertex) << " -- ";
}
- std::cout << ";" << std::endl;
+ std::clog << ";" << std::endl;
}
- std::cout << "}" << std::endl;
- std::cout << "**************************************************************" << std::endl;
+ std::clog << "}" << std::endl;
+ std::clog << "**************************************************************" << std::endl;
// Compute the persistence diagram of the complex
Persistent_cohomology pcoh(st);
diff --git a/src/Persistent_cohomology/example/plain_homology.cpp b/src/Persistent_cohomology/example/plain_homology.cpp
index 84333e46..236b67de 100644
--- a/src/Persistent_cohomology/example/plain_homology.cpp
+++ b/src/Persistent_cohomology/example/plain_homology.cpp
@@ -59,9 +59,6 @@ int main() {
st.insert_simplex_and_subfaces(edge35);
st.insert_simplex(vertex4);
- // Sort the simplices in the order of the filtration
- st.initialize_filtration();
-
// Class for homology computation
// By default, since the complex has dimension 1, only 0-dimensional homology would be computed.
// Here we also want persistent homology to be computed for the maximal dimension in the complex (persistence_dim_max = true)
@@ -83,9 +80,9 @@ int main() {
pcoh.output_diagram();
// Print the Betti numbers are b0=2 and b1=2.
- std::cout << std::endl;
- std::cout << "The Betti numbers are : ";
+ std::clog << std::endl;
+ std::clog << "The Betti numbers are : ";
for (int i = 0; i < 3; i++)
- std::cout << "b" << i << " = " << pcoh.betti_number(i) << " ; ";
- std::cout << std::endl;
+ std::clog << "b" << i << " = " << pcoh.betti_number(i) << " ; ";
+ std::clog << std::endl;
}
diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp
index 9eb5ccfc..84453898 100644
--- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp
+++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp
@@ -56,11 +56,8 @@ int main(int argc, char * argv[]) {
Simplex_tree simplex_tree;
rips_complex_from_file.create_complex(simplex_tree, dim_max);
- std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n";
- std::cout << " and has dimension " << simplex_tree.dimension() << " \n";
-
- // Sort the simplices in the order of the filtration
- simplex_tree.initialize_filtration();
+ std::clog << "The complex contains " << simplex_tree.num_simplices() << " simplices \n";
+ std::clog << " and has dimension " << simplex_tree.dimension() << " \n";
// Compute the persistence diagram of the complex
Persistent_cohomology pcoh(simplex_tree);
@@ -99,7 +96,7 @@ void program_options(int argc, char * argv[]
visible.add_options()
("help,h", "produce help message")
("output-file,o", po::value<std::string>(&filediag)->default_value(std::string()),
- "Name of file in which the persistence diagram is written. Default print in std::cout")
+ "Name of file in which the persistence diagram is written. Default print in standard output")
("max-edge-length,r", po::value<Filtration_value>(&threshold)->default_value(0),
"Maximal length of an edge for the Rips complex construction.")
("cpx-dimension,d", po::value<int>(&dim_max)->default_value(1),
@@ -107,7 +104,7 @@ void program_options(int argc, char * argv[]
("min-field-charac,p", po::value<int>(&min_p)->default_value(2),
"Minimal characteristic p of the coefficient field Z/pZ.")
("max-field-charac,q", po::value<int>(&max_p)->default_value(1223),
- "Minimial characteristic q of the coefficient field Z/pZ.")
+ "Maximal characteristic q of the coefficient field Z/pZ.")
("min-persistence,m", po::value<Filtration_value>(&min_persistence),
"Minimal lifetime of homology feature to be recorded. Default is 0");
@@ -123,20 +120,20 @@ void program_options(int argc, char * argv[]
po::notify(vm);
if (vm.count("help") || !vm.count("input-file")) {
- std::cout << std::endl;
- std::cout << "Compute the persistent homology with various coefficient fields \n";
- std::cout << "of a Rips complex defined on a set of input points. The coefficient \n";
- std::cout << "fields are all the Z/rZ for a prime number r contained in the \n";
- std::cout << "specified range [p,q]\n \n";
- std::cout << "The output diagram contains one bar per line, written with the convention: \n";
- std::cout << " p1*...*pr dim b d \n";
- std::cout << "where dim is the dimension of the homological feature,\n";
- std::cout << "b and d are respectively the birth and death of the feature and \n";
- std::cout << "p1*...*pr is the product of prime numbers pi such that the homology \n";
- std::cout << "feature exists in homology with Z/piZ coefficients." << std::endl << std::endl;
-
- std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
- std::cout << visible << std::endl;
+ std::clog << std::endl;
+ std::clog << "Compute the persistent homology with various coefficient fields \n";
+ std::clog << "of a Rips complex defined on a set of input points. The coefficient \n";
+ std::clog << "fields are all the Z/rZ for a prime number r contained in the \n";
+ std::clog << "specified range [p,q]\n \n";
+ std::clog << "The output diagram contains one bar per line, written with the convention: \n";
+ std::clog << " p1*...*pr dim b d \n";
+ std::clog << "where dim is the dimension of the homological feature,\n";
+ std::clog << "b and d are respectively the birth and death of the feature and \n";
+ std::clog << "p1*...*pr is the product of prime numbers pi such that the homology \n";
+ std::clog << "feature exists in homology with Z/piZ coefficients." << std::endl << std::endl;
+
+ std::clog << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
+ std::clog << visible << std::endl;
exit(-1);
}
}
diff --git a/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp b/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp
index 02db05ec..6f37cf5c 100644
--- a/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp
+++ b/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp
@@ -73,11 +73,8 @@ int main(int argc, char * argv[]) {
// expand the graph until dimension dim_max
st.expansion(dim_max);
- std::cout << "The complex contains " << st.num_simplices() << " simplices \n";
- std::cout << " and has dimension " << st.dimension() << " \n";
-
- // Sort the simplices in the order of the filtration
- st.initialize_filtration();
+ std::clog << "The complex contains " << st.num_simplices() << " simplices \n";
+ std::clog << " and has dimension " << st.dimension() << " \n";
// Compute the persistence diagram of the complex
Persistent_cohomology pcoh(st);
@@ -115,7 +112,7 @@ void program_options(int argc, char * argv[]
visible.add_options()
("help,h", "produce help message")
("output-file,o", po::value<std::string>(&filediag)->default_value(std::string()),
- "Name of file in which the persistence diagram is written. Default print in std::cout")
+ "Name of file in which the persistence diagram is written. Default print in standard output")
("max-edge-length,r",
po::value<Filtration_value>(&threshold)->default_value(std::numeric_limits<Filtration_value>::infinity()),
"Maximal length of an edge for the Rips complex construction.")
@@ -138,17 +135,17 @@ void program_options(int argc, char * argv[]
po::notify(vm);
if (vm.count("help") || !vm.count("input-file")) {
- std::cout << std::endl;
- std::cout << "Compute the persistent homology with coefficient field Z/pZ \n";
- std::cout << "of a Rips complex defined on a set of input points.\n \n";
- std::cout << "The output diagram contains one bar per line, written with the convention: \n";
- std::cout << " p dim b d \n";
- std::cout << "where dim is the dimension of the homological feature,\n";
- std::cout << "b and d are respectively the birth and death of the feature and \n";
- std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl;
-
- std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
- std::cout << visible << std::endl;
+ std::clog << std::endl;
+ std::clog << "Compute the persistent homology with coefficient field Z/pZ \n";
+ std::clog << "of a Rips complex defined on a set of input points.\n \n";
+ std::clog << "The output diagram contains one bar per line, written with the convention: \n";
+ std::clog << " p dim b d \n";
+ std::clog << "where dim is the dimension of the homological feature,\n";
+ std::clog << "b and d are respectively the birth and death of the feature and \n";
+ std::clog << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl;
+
+ std::clog << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
+ std::clog << visible << std::endl;
exit(-1);
}
}
diff --git a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp
index 37fa5e93..6b60f603 100644
--- a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp
+++ b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp
@@ -17,10 +17,6 @@
#include <boost/program_options.hpp>
-#ifdef GUDHI_USE_TBB
-#include <tbb/task_scheduler_init.h>
-#endif
-
#include <string>
#include <vector>
@@ -64,13 +60,8 @@ int main(int argc, char * argv[]) {
Simplex_tree& st = *new Simplex_tree;
rips_complex_from_file.create_complex(st, dim_max);
- std::cout << "The complex contains " << st.num_simplices() << " simplices \n";
- std::cout << " and has dimension " << st.dimension() << " \n";
-
-#ifdef GUDHI_USE_TBB
- // Unnecessary, but clarifies which operations are parallel.
- tbb::task_scheduler_init ts;
-#endif
+ std::clog << "The complex contains " << st.num_simplices() << " simplices \n";
+ std::clog << " and has dimension " << st.dimension() << " \n";
// Sort the simplices in the order of the filtration
st.initialize_filtration();
@@ -81,10 +72,6 @@ int main(int argc, char * argv[]) {
// Convert to a more convenient representation.
Gudhi::Hasse_complex<> hcpx(st);
-#ifdef GUDHI_USE_TBB
- ts.terminate();
-#endif
-
// Free some space.
delete &st;
@@ -122,7 +109,7 @@ void program_options(int argc, char * argv[]
visible.add_options()
("help,h", "produce help message")
("output-file,o", po::value<std::string>(&filediag)->default_value(std::string()),
- "Name of file in which the persistence diagram is written. Default print in std::cout")
+ "Name of file in which the persistence diagram is written. Default print in standard output")
("max-edge-length,r", po::value<Filtration_value>(&threshold)->default_value(0),
"Maximal length of an edge for the Rips complex construction.")
("cpx-dimension,d", po::value<int>(&dim_max)->default_value(1),
@@ -144,17 +131,17 @@ void program_options(int argc, char * argv[]
po::notify(vm);
if (vm.count("help") || !vm.count("input-file")) {
- std::cout << std::endl;
- std::cout << "Compute the persistent homology with coefficient field Z/pZ \n";
- std::cout << "of a Rips complex defined on a set of input points.\n \n";
- std::cout << "The output diagram contains one bar per line, written with the convention: \n";
- std::cout << " p dim b d \n";
- std::cout << "where dim is the dimension of the homological feature,\n";
- std::cout << "b and d are respectively the birth and death of the feature and \n";
- std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl;
-
- std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
- std::cout << visible << std::endl;
+ std::clog << std::endl;
+ std::clog << "Compute the persistent homology with coefficient field Z/pZ \n";
+ std::clog << "of a Rips complex defined on a set of input points.\n \n";
+ std::clog << "The output diagram contains one bar per line, written with the convention: \n";
+ std::clog << " p dim b d \n";
+ std::clog << "where dim is the dimension of the homological feature,\n";
+ std::clog << "b and d are respectively the birth and death of the feature and \n";
+ std::clog << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl;
+
+ std::clog << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
+ std::clog << visible << std::endl;
exit(-1);
}
}
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index 0f1876d0..c00bd33d 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -100,7 +100,7 @@ class Persistent_cohomology {
ds_rank_(num_simplices_), // union-find
ds_parent_(num_simplices_), // union-find
ds_repr_(num_simplices_, NULL), // union-find -> annotation vectors
- dsets_(&ds_rank_[0], &ds_parent_[0]), // union-find
+ dsets_(ds_rank_.data(), ds_parent_.data()), // union-find
cam_(), // collection of annotation vectors
zero_cocycles_(), // union-find -> Simplex_key of creator for 0-homology
transverse_idx_(), // key -> row
@@ -211,7 +211,7 @@ class Persistent_cohomology {
/** \brief Update the cohomology groups under the insertion of an edge.
*
* The 0-homology is maintained with a simple Union-Find data structure, which
- * explains the existance of a specific function of edge insertions. */
+ * explains the existence of a specific function of edge insertions. */
void update_cohomology_groups_edge(Simplex_handle sigma) {
Simplex_handle u, v;
boost::tie(u, v) = cpx_->endpoints(sigma);
@@ -288,10 +288,7 @@ class Persistent_cohomology {
// with multiplicity. We used to sum the coefficients directly in
// annotations_in_boundary by using a map, we now do it later.
typedef std::pair<Column *, int> annotation_t;
-#ifdef GUDHI_CAN_USE_CXX11_THREAD_LOCAL
- thread_local
-#endif // GUDHI_CAN_USE_CXX11_THREAD_LOCAL
- std::vector<annotation_t> annotations_in_boundary;
+ thread_local std::vector<annotation_t> annotations_in_boundary;
annotations_in_boundary.clear();
int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the
// alternate sum in the boundary.
@@ -564,35 +561,22 @@ class Persistent_cohomology {
void output_diagram(std::ostream& ostream = std::cout) {
cmp_intervals_by_length cmp(cpx_);
std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp);
- bool has_infinity = std::numeric_limits<Filtration_value>::has_infinity;
for (auto pair : persistent_pairs_) {
- // Special case on windows, inf is "1.#INF" (cf. unitary tests and R package TDA)
- if (has_infinity && cpx_->filtration(get<1>(pair)) == std::numeric_limits<Filtration_value>::infinity()) {
- ostream << get<2>(pair) << " " << cpx_->dimension(get<0>(pair)) << " "
- << cpx_->filtration(get<0>(pair)) << " inf " << std::endl;
- } else {
- ostream << get<2>(pair) << " " << cpx_->dimension(get<0>(pair)) << " "
- << cpx_->filtration(get<0>(pair)) << " "
- << cpx_->filtration(get<1>(pair)) << " " << std::endl;
- }
+ ostream << get<2>(pair) << " " << cpx_->dimension(get<0>(pair)) << " "
+ << cpx_->filtration(get<0>(pair)) << " "
+ << cpx_->filtration(get<1>(pair)) << " " << std::endl;
}
}
void write_output_diagram(std::string diagram_name) {
std::ofstream diagram_out(diagram_name.c_str());
+ diagram_out.exceptions(diagram_out.failbit);
cmp_intervals_by_length cmp(cpx_);
std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp);
- bool has_infinity = std::numeric_limits<Filtration_value>::has_infinity;
for (auto pair : persistent_pairs_) {
- // Special case on windows, inf is "1.#INF"
- if (has_infinity && cpx_->filtration(get<1>(pair)) == std::numeric_limits<Filtration_value>::infinity()) {
- diagram_out << cpx_->dimension(get<0>(pair)) << " "
- << cpx_->filtration(get<0>(pair)) << " inf" << std::endl;
- } else {
- diagram_out << cpx_->dimension(get<0>(pair)) << " "
- << cpx_->filtration(get<0>(pair)) << " "
- << cpx_->filtration(get<1>(pair)) << std::endl;
- }
+ diagram_out << cpx_->dimension(get<0>(pair)) << " "
+ << cpx_->filtration(get<0>(pair)) << " "
+ << cpx_->filtration(get<1>(pair)) << std::endl;
}
}
@@ -739,7 +723,7 @@ class Persistent_cohomology {
boost::disjoint_sets<int *, Simplex_key *> dsets_;
/* The compressed annotation matrix fields.*/
Cam cam_;
- /* Dictionary establishing the correspondance between the Simplex_key of
+ /* Dictionary establishing the correspondence between the Simplex_key of
* the root vertex in the union-find ds and the Simplex_key of the vertex which
* created the connected component as a 0-dimension homology feature.*/
std::map<Simplex_key, Simplex_key> zero_cocycles_;
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
index 0673625c..f442b632 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
@@ -13,6 +13,7 @@
#include <utility>
#include <vector>
+#include <stdexcept>
namespace Gudhi {
@@ -33,15 +34,28 @@ class Field_Zp {
}
void init(int charac) {
- assert(charac > 0); // division by zero + non negative values
Prime = charac;
+
+ // Check that the provided prime is less than the maximum allowed as int, calculation below, and 'plus_times_equal' function : 46337 ; i.e (max_prime-1)*max_prime <= INT_MAX
+ if(Prime > 46337)
+ throw std::invalid_argument("Maximum homology_coeff_field allowed value is 46337");
+
+ // Check for primality
+ if (Prime <= 1)
+ throw std::invalid_argument("homology_coeff_field must be a prime number");
+
inverse_.clear();
inverse_.reserve(charac);
inverse_.push_back(0);
for (int i = 1; i < Prime; ++i) {
int inv = 1;
- while (((inv * i) % Prime) != 1)
+ int mult = inv * i;
+ while ( (mult % Prime) != 1) {
++inv;
+ if(mult == Prime)
+ throw std::invalid_argument("homology_coeff_field must be a prime number");
+ mult = inv * i;
+ }
inverse_.push_back(inv);
}
}
diff --git a/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp b/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp
index b9f11607..7a2feeff 100644
--- a/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp
+++ b/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp
@@ -82,7 +82,7 @@ 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;
+ std::clog << "BETTI NUMBERS" << std::endl;
BOOST_CHECK(pcoh.betti_number(0) == 2);
BOOST_CHECK(pcoh.betti_number(1) == 1);
@@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE( plain_homology_betti_numbers )
BOOST_CHECK(bns[1] == 1);
BOOST_CHECK(bns[2] == 0);
- std::cout << "GET PERSISTENT PAIRS" << std::endl;
+ std::clog << "GET PERSISTENT PAIRS" << std::endl;
// Custom sort and output persistence
cmp_intervals_by_dim_then_length<Mini_simplex_tree> cmp(&st);
@@ -118,12 +118,12 @@ BOOST_AUTO_TEST_CASE( plain_homology_betti_numbers )
BOOST_CHECK(st.filtration(get<0>(persistent_pairs[2])) == 0);
BOOST_CHECK(get<1>(persistent_pairs[2]) == st.null_simplex());
- std::cout << "INTERVALS IN DIMENSION" << std::endl;
+ std::clog << "INTERVALS IN DIMENSION" << std::endl;
auto intervals_in_dimension_0 = pcoh.intervals_in_dimension(0);
- std::cout << "intervals_in_dimension_0.size() = " << intervals_in_dimension_0.size() << std::endl;
+ std::clog << "intervals_in_dimension_0.size() = " << intervals_in_dimension_0.size() << std::endl;
for (std::size_t i = 0; i < intervals_in_dimension_0.size(); i++)
- std::cout << "intervals_in_dimension_0[" << i << "] = [" << intervals_in_dimension_0[i].first << "," <<
+ std::clog << "intervals_in_dimension_0[" << i << "] = [" << intervals_in_dimension_0[i].first << "," <<
intervals_in_dimension_0[i].second << "]" << std::endl;
BOOST_CHECK(intervals_in_dimension_0.size() == 2);
BOOST_CHECK(intervals_in_dimension_0[0].first == 0);
@@ -133,16 +133,16 @@ BOOST_AUTO_TEST_CASE( plain_homology_betti_numbers )
auto intervals_in_dimension_1 = pcoh.intervals_in_dimension(1);
- std::cout << "intervals_in_dimension_1.size() = " << intervals_in_dimension_1.size() << std::endl;
+ std::clog << "intervals_in_dimension_1.size() = " << intervals_in_dimension_1.size() << std::endl;
for (std::size_t i = 0; i < intervals_in_dimension_1.size(); i++)
- std::cout << "intervals_in_dimension_1[" << i << "] = [" << intervals_in_dimension_1[i].first << "," <<
+ std::clog << "intervals_in_dimension_1[" << i << "] = [" << intervals_in_dimension_1[i].first << "," <<
intervals_in_dimension_1[i].second << "]" << std::endl;
BOOST_CHECK(intervals_in_dimension_1.size() == 1);
BOOST_CHECK(intervals_in_dimension_1[0].first == 0);
BOOST_CHECK(intervals_in_dimension_1[0].second == std::numeric_limits<Mini_simplex_tree::Filtration_value>::infinity());
auto intervals_in_dimension_2 = pcoh.intervals_in_dimension(2);
- std::cout << "intervals_in_dimension_2.size() = " << intervals_in_dimension_2.size() << std::endl;
+ std::clog << "intervals_in_dimension_2.size() = " << intervals_in_dimension_2.size() << std::endl;
BOOST_CHECK(intervals_in_dimension_2.size() == 0);
}
@@ -259,12 +259,12 @@ BOOST_AUTO_TEST_CASE( betti_numbers )
BOOST_CHECK(st.filtration(get<0>(persistent_pairs[2])) == 1);
BOOST_CHECK(get<1>(persistent_pairs[2]) == st.null_simplex());
- std::cout << "INTERVALS IN DIMENSION" << std::endl;
+ std::clog << "INTERVALS IN DIMENSION" << std::endl;
auto intervals_in_dimension_0 = pcoh.intervals_in_dimension(0);
- std::cout << "intervals_in_dimension_0.size() = " << intervals_in_dimension_0.size() << std::endl;
+ std::clog << "intervals_in_dimension_0.size() = " << intervals_in_dimension_0.size() << std::endl;
for (std::size_t i = 0; i < intervals_in_dimension_0.size(); i++)
- std::cout << "intervals_in_dimension_0[" << i << "] = [" << intervals_in_dimension_0[i].first << "," <<
+ std::clog << "intervals_in_dimension_0[" << i << "] = [" << intervals_in_dimension_0[i].first << "," <<
intervals_in_dimension_0[i].second << "]" << std::endl;
BOOST_CHECK(intervals_in_dimension_0.size() == 2);
BOOST_CHECK(intervals_in_dimension_0[0].first == 2);
@@ -273,19 +273,19 @@ BOOST_AUTO_TEST_CASE( betti_numbers )
BOOST_CHECK(intervals_in_dimension_0[1].second == std::numeric_limits<Mini_simplex_tree::Filtration_value>::infinity());
auto intervals_in_dimension_1 = pcoh.intervals_in_dimension(1);
- std::cout << "intervals_in_dimension_1.size() = " << intervals_in_dimension_1.size() << std::endl;
+ std::clog << "intervals_in_dimension_1.size() = " << intervals_in_dimension_1.size() << std::endl;
for (std::size_t i = 0; i < intervals_in_dimension_1.size(); i++)
- std::cout << "intervals_in_dimension_1[" << i << "] = [" << intervals_in_dimension_1[i].first << "," <<
+ std::clog << "intervals_in_dimension_1[" << i << "] = [" << intervals_in_dimension_1[i].first << "," <<
intervals_in_dimension_1[i].second << "]" << std::endl;
BOOST_CHECK(intervals_in_dimension_1.size() == 1);
BOOST_CHECK(intervals_in_dimension_1[0].first == 4);
BOOST_CHECK(intervals_in_dimension_1[0].second == std::numeric_limits<Mini_simplex_tree::Filtration_value>::infinity());
auto intervals_in_dimension_2 = pcoh.intervals_in_dimension(2);
- std::cout << "intervals_in_dimension_2.size() = " << intervals_in_dimension_2.size() << std::endl;
+ std::clog << "intervals_in_dimension_2.size() = " << intervals_in_dimension_2.size() << std::endl;
BOOST_CHECK(intervals_in_dimension_2.size() == 0);
- std::cout << "EMPTY COMPLEX" << std::endl;
+ std::clog << "EMPTY COMPLEX" << std::endl;
Simplex_tree empty;
empty.initialize_filtration();
St_persistence pcoh_empty(empty, false);
diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
index a1c106d5..ea41a8aa 100644
--- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
+++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp
@@ -21,7 +21,7 @@ using namespace boost::unit_test;
typedef Simplex_tree<> typeST;
-std::string test_rips_persistence(int coefficient, int min_persistence) {
+std::string test_persistence(int coefficient, int min_persistence) {
// file is copied in CMakeLists.txt
std::ifstream simplex_tree_stream;
simplex_tree_stream.open("simplex_tree_file_for_unit_test.txt");
@@ -30,7 +30,7 @@ std::string test_rips_persistence(int coefficient, int min_persistence) {
simplex_tree_stream.close();
// Display the Simplex_tree
- std::cout << "The complex contains " << st.num_simplices() << " simplices" << " - dimension= " << st.dimension()
+ std::clog << "The complex contains " << st.num_simplices() << " simplices" << " - dimension= " << st.dimension()
<< std::endl;
// Check
@@ -44,16 +44,16 @@ std::string test_rips_persistence(int coefficient, int min_persistence) {
Persistent_cohomology<Simplex_tree<>, Field_Zp> pcoh(st);
pcoh.init_coefficients( coefficient ); // initializes the coefficient field for homology
- // Check infinite rips
+ // Compute the persistent homology of the complex
pcoh.compute_persistent_cohomology( min_persistence ); // Minimal lifetime of homology feature to be recorded.
- std::ostringstream ossInfinite;
+ std::ostringstream ossPers;
- pcoh.output_diagram(ossInfinite);
- std::string strInfinite = ossInfinite.str();
- return strInfinite;
+ pcoh.output_diagram(ossPers);
+ std::string strPers = ossPers.str();
+ return strPers;
}
-void test_rips_persistence_in_dimension(int dimension) {
+void test_persistence_with_coeff_field(int coeff_field) {
std::string value0(" 0 0.02 1.12");
std::string value1(" 0 0.03 1.13");
std::string value2(" 0 0.04 1.14");
@@ -65,112 +65,104 @@ void test_rips_persistence_in_dimension(int dimension) {
std::string value8(" 0 0 inf" );
std::string value9(" 0 0.01 inf" );
- value0.insert(0,std::to_string(dimension));
- value1.insert(0,std::to_string(dimension));
- value2.insert(0,std::to_string(dimension));
- value3.insert(0,std::to_string(dimension));
- value4.insert(0,std::to_string(dimension));
- value5.insert(0,std::to_string(dimension));
- value6.insert(0,std::to_string(dimension));
- value7.insert(0,std::to_string(dimension));
- value8.insert(0,std::to_string(dimension));
- value9.insert(0,std::to_string(dimension));
-
- std::cout << "********************************************************************" << std::endl;
- std::cout << "TEST OF RIPS_PERSISTENT_COHOMOLOGY_SINGLE_FIELD DIM=" << dimension << " MIN_PERS=0" << std::endl;
-
- std::string str_rips_persistence = test_rips_persistence(dimension, 0);
- std::cout << str_rips_persistence << std::endl;
+ value0.insert(0,std::to_string(coeff_field));
+ value1.insert(0,std::to_string(coeff_field));
+ value2.insert(0,std::to_string(coeff_field));
+ value3.insert(0,std::to_string(coeff_field));
+ value4.insert(0,std::to_string(coeff_field));
+ value5.insert(0,std::to_string(coeff_field));
+ value6.insert(0,std::to_string(coeff_field));
+ value7.insert(0,std::to_string(coeff_field));
+ value8.insert(0,std::to_string(coeff_field));
+ value9.insert(0,std::to_string(coeff_field));
+
+ std::clog << "********************************************************************" << std::endl;
+ std::clog << "TEST OF PERSISTENT_COHOMOLOGY_SINGLE_FIELD COEFF_FIELD=" << coeff_field << " MIN_PERS=0" << std::endl;
+
+ std::string str_persistence = test_persistence(coeff_field, 0);
+ std::clog << str_persistence << std::endl;
- BOOST_CHECK(str_rips_persistence.find(value0) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value1) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value2) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value3) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value4) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value5) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value6) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value7) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value8) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value9) != std::string::npos); // Check found
- std::cout << "str_rips_persistence=" << str_rips_persistence << std::endl;
-
- std::cout << "********************************************************************" << std::endl;
- std::cout << "TEST OF RIPS_PERSISTENT_COHOMOLOGY_SINGLE_FIELD DIM=" << dimension << " MIN_PERS=1" << std::endl;
-
- str_rips_persistence = test_rips_persistence(dimension, 1);
-
- BOOST_CHECK(str_rips_persistence.find(value0) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value1) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value2) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value3) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value4) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value5) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value6) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value7) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value8) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value9) != std::string::npos); // Check found
- std::cout << "str_rips_persistence=" << str_rips_persistence << std::endl;
-
- std::cout << "********************************************************************" << std::endl;
- std::cout << "TEST OF RIPS_PERSISTENT_COHOMOLOGY_SINGLE_FIELD DIM=" << dimension << " MIN_PERS=2" << std::endl;
-
- str_rips_persistence = test_rips_persistence(dimension, 2);
-
- BOOST_CHECK(str_rips_persistence.find(value0) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value1) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value2) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value3) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value4) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value5) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value6) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value7) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value8) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value9) != std::string::npos); // Check found
- std::cout << "str_rips_persistence=" << str_rips_persistence << std::endl;
-
- std::cout << "********************************************************************" << std::endl;
- std::cout << "TEST OF RIPS_PERSISTENT_COHOMOLOGY_SINGLE_FIELD DIM=" << dimension << " MIN_PERS=Inf" << std::endl;
-
- str_rips_persistence = test_rips_persistence(dimension, (std::numeric_limits<int>::max)());
-
- BOOST_CHECK(str_rips_persistence.find(value0) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value1) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value2) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value3) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value4) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value5) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value6) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value7) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value8) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value9) != std::string::npos); // Check found
- std::cout << "str_rips_persistence=" << str_rips_persistence << std::endl;
+ BOOST_CHECK(str_persistence.find(value0) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value1) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value2) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value3) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value4) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value5) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value6) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value7) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value8) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value9) != std::string::npos); // Check found
+ std::clog << "str_persistence=" << str_persistence << std::endl;
+
+ std::clog << "********************************************************************" << std::endl;
+ std::clog << "TEST OF PERSISTENT_COHOMOLOGY_SINGLE_FIELD COEFF_FIELD=" << coeff_field << " MIN_PERS=1" << std::endl;
+
+ str_persistence = test_persistence(coeff_field, 1);
+
+ BOOST_CHECK(str_persistence.find(value0) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value1) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value2) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value3) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value4) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value5) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value6) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value7) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value8) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value9) != std::string::npos); // Check found
+ std::clog << "str_persistence=" << str_persistence << std::endl;
+
+ std::clog << "********************************************************************" << std::endl;
+ std::clog << "TEST OF PERSISTENT_COHOMOLOGY_SINGLE_FIELD COEFF_FIELD=" << coeff_field << " MIN_PERS=2" << std::endl;
+
+ str_persistence = test_persistence(coeff_field, 2);
+
+ BOOST_CHECK(str_persistence.find(value0) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value1) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value2) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value3) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value4) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value5) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value6) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value7) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value8) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value9) != std::string::npos); // Check found
+ std::clog << "str_persistence=" << str_persistence << std::endl;
+
+ std::clog << "********************************************************************" << std::endl;
+ std::clog << "TEST OF PERSISTENT_COHOMOLOGY_SINGLE_FIELD COEFF_FIELD=" << coeff_field << " MIN_PERS=Inf" << std::endl;
+
+ str_persistence = test_persistence(coeff_field, (std::numeric_limits<int>::max)());
+
+ BOOST_CHECK(str_persistence.find(value0) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value1) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value2) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value3) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value4) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value5) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value6) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value7) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value8) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value9) != std::string::npos); // Check found
+ std::clog << "str_persistence=" << str_persistence << std::endl;
}
-BOOST_AUTO_TEST_CASE( rips_persistent_cohomology_single_field_dim_1 )
+BOOST_AUTO_TEST_CASE( persistent_cohomology_single_field_coeff_not_prime )
{
- test_rips_persistence_in_dimension(1);
+ for (auto non_prime : {0, 1, 4, 6})
+ BOOST_CHECK_THROW(test_persistence_with_coeff_field(non_prime), std::invalid_argument);
}
-BOOST_AUTO_TEST_CASE( rips_persistent_cohomology_single_field_dim_2 )
+BOOST_AUTO_TEST_CASE( persistent_cohomology_single_field_coeff_prime )
{
- test_rips_persistence_in_dimension(2);
+ for (auto prime : {2, 3, 5, 11, 13})
+ test_persistence_with_coeff_field(prime);
}
-BOOST_AUTO_TEST_CASE( rips_persistent_cohomology_single_field_dim_3 )
+BOOST_AUTO_TEST_CASE( persistent_cohomology_single_field_coeff_limit )
{
- test_rips_persistence_in_dimension(3);
+ BOOST_CHECK_THROW(test_persistence_with_coeff_field(46349), std::invalid_argument);
}
-BOOST_AUTO_TEST_CASE( rips_persistent_cohomology_single_field_dim_5 )
-{
- test_rips_persistence_in_dimension(5);
-}
-
-// TODO(VR): not working from 6
-// std::string str_rips_persistence = test_rips_persistence(6, 0);
-// TODO(VR): division by zero
-// std::string str_rips_persistence = test_rips_persistence(0, 0);
-
/** SimplexTree minimal options to test the limits.
*
* Maximum number of simplices to compute persistence is <CODE>std::numeric_limits<std::uint8_t>::max()<\CODE> = 256.*/
diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp
index 9e767943..c6c0bfaf 100644
--- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp
+++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp
@@ -21,7 +21,7 @@ using namespace boost::unit_test;
typedef Simplex_tree<> typeST;
-std::string test_rips_persistence(int min_coefficient, int max_coefficient, double min_persistence) {
+std::string test_persistence(int min_coefficient, int max_coefficient, double min_persistence) {
// file is copied in CMakeLists.txt
std::ifstream simplex_tree_stream;
simplex_tree_stream.open("simplex_tree_file_for_multi_field_unit_test.txt");
@@ -30,7 +30,7 @@ std::string test_rips_persistence(int min_coefficient, int max_coefficient, doub
simplex_tree_stream.close();
// Display the Simplex_tree
- std::cout << "The complex contains " << st.num_simplices() << " simplices" << " - dimension= " << st.dimension()
+ std::clog << "The complex contains " << st.num_simplices() << " simplices" << " - dimension= " << st.dimension()
<< std::endl;
// Check
@@ -44,17 +44,17 @@ std::string test_rips_persistence(int min_coefficient, int max_coefficient, doub
Persistent_cohomology<Simplex_tree<>, Multi_field> pcoh(st);
pcoh.init_coefficients(min_coefficient, max_coefficient); // initializes the coefficient field for homology
- // Check infinite rips
+ // Compute the persistent homology of the complex
pcoh.compute_persistent_cohomology(min_persistence); // Minimal lifetime of homology feature to be recorded.
- std::ostringstream ossRips;
- pcoh.output_diagram(ossRips);
+ std::ostringstream ossPers;
+ pcoh.output_diagram(ossPers);
- std::string strRips = ossRips.str();
- return strRips;
+ std::string strPers = ossPers.str();
+ return strPers;
}
-void test_rips_persistence_in_dimension(int min_dimension, int max_dimension) {
+void test_persistence_with_coeff_field(int min_coefficient, int max_coefficient) {
// there are 2 discontinued ensembles
std::string value0(" 0 0.25 inf");
std::string value1(" 1 0.4 inf");
@@ -68,48 +68,60 @@ void test_rips_persistence_in_dimension(int min_dimension, int max_dimension) {
std::string value6(" 2 0.3 inf");
std::string value7(" 2 0.4 inf");
- std::cout << "********************************************************************" << std::endl;
- std::cout << "TEST OF RIPS_PERSISTENT_COHOMOLOGY_MULTI_FIELD MIN_DIM=" << min_dimension << " MAX_DIM=" << max_dimension << " MIN_PERS=0" << std::endl;
+ std::clog << "********************************************************************" << std::endl;
+ std::clog << "TEST OF PERSISTENT_COHOMOLOGY_MULTI_FIELD MIN_COEFF=" << min_coefficient << " MAX_COEFF=" << max_coefficient << " MIN_PERS=0" << std::endl;
- std::string str_rips_persistence = test_rips_persistence(min_dimension, max_dimension, 0.0);
- std::cout << "str_rips_persistence=" << str_rips_persistence << std::endl;
+ std::string str_persistence = test_persistence(min_coefficient, max_coefficient, 0.0);
+ std::clog << "str_persistence=" << str_persistence << std::endl;
- BOOST_CHECK(str_rips_persistence.find(value0) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value1) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value2) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value0) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value1) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value2) != std::string::npos); // Check found
- if ((min_dimension < 2) && (max_dimension < 2)) {
- BOOST_CHECK(str_rips_persistence.find(value3) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value4) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value5) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value6) != std::string::npos); // Check found
- BOOST_CHECK(str_rips_persistence.find(value7) != std::string::npos); // Check found
+ if ((min_coefficient < 2) && (max_coefficient < 2)) {
+ BOOST_CHECK(str_persistence.find(value3) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value4) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value5) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value6) != std::string::npos); // Check found
+ BOOST_CHECK(str_persistence.find(value7) != std::string::npos); // Check found
} else {
- BOOST_CHECK(str_rips_persistence.find(value3) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value4) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value5) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value6) == std::string::npos); // Check not found
- BOOST_CHECK(str_rips_persistence.find(value7) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value3) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value4) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value5) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value6) == std::string::npos); // Check not found
+ BOOST_CHECK(str_persistence.find(value7) == std::string::npos); // Check not found
}
}
-BOOST_AUTO_TEST_CASE(rips_persistent_cohomology_multi_field_dim_1_2) {
- test_rips_persistence_in_dimension(0, 1);
+BOOST_AUTO_TEST_CASE(persistent_cohomology_multi_field_coeff_0_0) {
+ test_persistence_with_coeff_field(0, 0);
}
-BOOST_AUTO_TEST_CASE(rips_persistent_cohomology_multi_field_dim_2_3) {
- test_rips_persistence_in_dimension(1, 3);
+BOOST_AUTO_TEST_CASE(persistent_cohomology_multi_field_coeff_0_1) {
+ test_persistence_with_coeff_field(0, 1);
}
-BOOST_AUTO_TEST_CASE(rips_persistent_cohomology_multi_field_dim_1_5) {
- test_rips_persistence_in_dimension(1, 5);
+BOOST_AUTO_TEST_CASE(persistent_cohomology_multi_field_coeff_0_6) {
+ test_persistence_with_coeff_field(0, 6);
}
-// TODO(VR): not working from 6
-// std::string str_rips_persistence = test_rips_persistence(6, 0);
-// TODO(VR): division by zero
-// std::string str_rips_persistence = test_rips_persistence(0, 0);
-// TODO(VR): is result OK of :
-// test_rips_persistence_in_dimension(3, 4);
+BOOST_AUTO_TEST_CASE(persistent_cohomology_multi_field_coeff_1_2) {
+ test_persistence_with_coeff_field(1, 2);
+}
+
+BOOST_AUTO_TEST_CASE(persistent_cohomology_multi_field_coeff_1_3) {
+ test_persistence_with_coeff_field(1, 3);
+}
+
+BOOST_AUTO_TEST_CASE(persistent_cohomology_multi_field_coeff_1_5) {
+ test_persistence_with_coeff_field(1, 5);
+}
+
+BOOST_AUTO_TEST_CASE(persistent_cohomology_multi_field_coeff_2_3) {
+ test_persistence_with_coeff_field(2, 3);
+}
+BOOST_AUTO_TEST_CASE(persistent_cohomology_multi_field_coeff_3_4) {
+ test_persistence_with_coeff_field(3, 4);
+}