From f0b88dfb3523ad6e39b60c6cc56b18ec1fa3cd9f Mon Sep 17 00:00:00 2001 From: glisse Date: Sun, 18 Oct 2015 08:20:14 +0000 Subject: Update performance_rips_persistence, which hasn't been working for a long time. We might want to run it in the testsuite with a smaller parameter so it doesn't take too long. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@863 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1fd91395f855297cf4815d64e94b06a8c400c99b --- .../example/performance_rips_persistence.cpp | 81 +++++++++++++++++----- 1 file changed, 62 insertions(+), 19 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/performance_rips_persistence.cpp b/src/Persistent_cohomology/example/performance_rips_persistence.cpp index 0e912d57..fc48d6b1 100644 --- a/src/Persistent_cohomology/example/performance_rips_persistence.cpp +++ b/src/Persistent_cohomology/example/performance_rips_persistence.cpp @@ -63,10 +63,11 @@ void timing_persistence(FilteredComplex & cpx */ int main(int argc, char * argv[]) { std::chrono::time_point start, end; - int enlapsed_sec; + int elapsed_sec; + { - std::string filepoints = "../examples/Kl.txt"; - Filtration_value threshold = 0.3; + std::string filepoints = "../../../data/points/Kl.txt"; + Filtration_value threshold = 0.27; int dim_max = 3; int p = 2; int q = 1223; @@ -81,8 +82,8 @@ int main(int argc, char * argv[]) { Graph_t prox_graph = compute_proximity_graph(points, threshold , euclidean_distance); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Compute Rips graph in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Compute Rips graph in " << elapsed_sec << " ms.\n"; // Construct the Rips complex in a Simplex Tree Simplex_tree<> st; @@ -94,8 +95,8 @@ int main(int argc, char * argv[]) { st.expansion(dim_max); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Compute Rips complex in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(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; @@ -103,15 +104,26 @@ int main(int argc, char * argv[]) { start = std::chrono::system_clock::now(); st.initialize_filtration(); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Order the simplices of the filtration in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Order the simplices of the filtration in " << elapsed_sec << " ms.\n"; + + // Copy the keys inside the simplices + start = std::chrono::system_clock::now(); + { + int count = 0; + for (auto sh : st.filtration_simplex_range()) + st.assign_key(sh, count++); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "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(); Hasse_complex<> hcpx(st); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Convert the simplex tree into a Hasse diagram in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Convert the simplex tree into a Hasse diagram in " << elapsed_sec << " ms.\n"; std::cout << "Timings when using a simplex tree: \n"; @@ -124,6 +136,11 @@ int main(int argc, char * argv[]) { timing_persistence(hcpx, q); timing_persistence(hcpx, p, q); + start = std::chrono::system_clock::now(); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Running the complex destructors in " << elapsed_sec << " ms.\n"; return 0; } @@ -132,19 +149,32 @@ void timing_persistence(FilteredComplex & cpx , int p) { std::chrono::time_point start, end; - int enlapsed_sec; - + int elapsed_sec; + { + start = std::chrono::system_clock::now(); Persistent_cohomology< FilteredComplex, Field_Zp > pcoh(cpx); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " 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(end - start).count(); + std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n"; start = std::chrono::system_clock::now(); pcoh.compute_persistent_cohomology(INFINITY); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Compute persistent homology in Z/" << p << "Z in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " 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(end - start).count(); + std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n"; } template< typename FilteredComplex> @@ -153,11 +183,19 @@ timing_persistence(FilteredComplex & cpx , int p , int q) { std::chrono::time_point start, end; - int enlapsed_sec; - + int elapsed_sec; + { + start = std::chrono::system_clock::now(); Persistent_cohomology< FilteredComplex, Multi_field > pcoh(cpx); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " 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(end - start).count(); + std::cout << " 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(); @@ -165,7 +203,12 @@ timing_persistence(FilteredComplex & cpx pcoh.compute_persistent_cohomology(INFINITY); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ " - << "with p in [" << p << ";" << q << "] in " << enlapsed_sec << " sec.\n"; + << "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(end - start).count(); + std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n"; } -- cgit v1.2.3 From da56757d861e0e543b71454615b7266f3f9b84e5 Mon Sep 17 00:00:00 2001 From: glisse Date: Thu, 29 Oct 2015 13:23:25 +0000 Subject: Add an example that computes (non-persistent) homology. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@880 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 21606fab3356681780ad446e73d5da56b29ec31d --- src/Persistent_cohomology/example/CMakeLists.txt | 4 ++ .../example/plain_homology.cpp | 80 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/Persistent_cohomology/example/plain_homology.cpp (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index ea69352e..50d10025 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -5,6 +5,10 @@ project(GUDHIExPersCohom) add_definitions( -DBOOST_ALL_NO_LIB ) add_definitions( -DBOOST_ALL_DYN_LINK ) +add_executable(plain_homology plain_homology.cpp) +target_link_libraries(plain_homology ${Boost_SYSTEM_LIBRARY}) +add_test(plain_homology ${CMAKE_CURRENT_BINARY_DIR}/plain_homology) + add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp) target_link_libraries(persistence_from_simple_simplex_tree ${Boost_SYSTEM_LIBRARY}) add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) diff --git a/src/Persistent_cohomology/example/plain_homology.cpp b/src/Persistent_cohomology/example/plain_homology.cpp new file mode 100644 index 00000000..e293e013 --- /dev/null +++ b/src/Persistent_cohomology/example/plain_homology.cpp @@ -0,0 +1,80 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Marc Glisse + * + * Copyright (C) 2015 INRIA Saclay - Ile-de-France (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include + +using namespace Gudhi; + +struct MyOptions : Simplex_tree_options_full_featured { + // Implicitly use 0 as filtration value for all simplices + static const bool store_filtration = false; + // The persistence algorithm needs this + static const bool store_key = true; + // I have few vertices + typedef short Vertex_handle; +}; +typedef Simplex_tree ST; + +int main() { + ST st; + + /* Complex to build. */ + /* 1 3 */ + /* o---o */ + /* /X\ / */ + /* o---o o */ + /* 2 0 4 */ + + const short triangle012[] = {0, 1, 2}; + const short edge03[] = {0, 3}; + const short edge13[] = {1, 3}; + const short vertex4[] = {4}; + st.insert_simplex_and_subfaces(triangle012); + st.insert_simplex_and_subfaces(edge03); + st.insert_simplex(edge13); + st.insert_simplex(vertex4); + // FIXME: Remove this line + st.set_dimension(2); + + // Sort the simplices in the order of the filtration + st.initialize_filtration(); + + // Class for homology computation + persistent_cohomology::Persistent_cohomology pcoh(st); + + // Initialize the coefficient field Z/2Z for homology + pcoh.init_coefficients(2); + + // Compute the persistence diagram of the complex + pcoh.compute_persistent_cohomology(); + + // Print the result. The format is, on each line: 2 dim 0 inf + // where 2 represents the field, dim the dimension of the feature. + // 2 0 0 inf + // 2 0 0 inf + // 2 1 0 inf + // means that in Z/2Z-homology, the Betti numbers are b0=2 and b1=1. + pcoh.output_diagram(); +} -- cgit v1.2.3