From 58e633f51ffa06aa219231cd1c08eab59457a12f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 8 Oct 2015 15:24:27 +0000 Subject: Fix cpplint on examples. Bug fix on persistence_from_simple_simplex_tree. Add persistence examples tests. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@843 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9b7b73abb4a5d6bb110376deb689247bfdae035c --- src/Persistent_cohomology/example/CMakeLists.txt | 1 + .../example/alpha_shapes_persistence.cpp | 230 ++++++++++---------- .../example/performance_rips_persistence.cpp | 168 ++++++++------- .../example/persistence_from_file.cpp | 239 +++++++++++---------- .../persistence_from_simple_simplex_tree.cpp | 135 +++++------- .../example/rips_multifield_persistence.cpp | 234 ++++++++++---------- .../example/rips_persistence.cpp | 222 +++++++++---------- 7 files changed, 602 insertions(+), 627 deletions(-) (limited to 'src/Persistent_cohomology/example') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index 3276989d..435d2f58 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -5,6 +5,7 @@ project(GUDHIExPersCohom) if (NOT MSVC) 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) add_executable(rips_persistence rips_persistence.cpp) target_link_libraries(rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) diff --git a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp index 1e907040..6d5eebcf 100644 --- a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp @@ -1,24 +1,29 @@ - /* 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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (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 . - */ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (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 +#include #include #include @@ -27,36 +32,37 @@ #include #include - -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include +#include +#include +#include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; // Alpha_shape_3 templates type definitions typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; -typedef CGAL::Alpha_shape_vertex_base_3 Vb; -typedef CGAL::Alpha_shape_cell_base_3 Fb; -typedef CGAL::Triangulation_data_structure_3 Tds; -typedef CGAL::Delaunay_triangulation_3 Triangulation_3; -typedef CGAL::Alpha_shape_3 Alpha_shape_3; +typedef CGAL::Alpha_shape_vertex_base_3 Vb; +typedef CGAL::Alpha_shape_cell_base_3 Fb; +typedef CGAL::Triangulation_data_structure_3 Tds; +typedef CGAL::Delaunay_triangulation_3 Triangulation_3; +typedef CGAL::Alpha_shape_3 Alpha_shape_3; // From file type definition -typedef Kernel::Point_3 Point_3; +typedef Kernel::Point_3 Point_3; // filtration with alpha values needed type definition typedef Alpha_shape_3::FT Alpha_value_type; -typedef CGAL::Object Object; +typedef CGAL::Object Object; typedef CGAL::Dispatch_output_iterator< - CGAL::cpp11::tuple, - CGAL::cpp11::tuple >, std::back_insert_iterator< std::vector > - > > Dispatch; -typedef Alpha_shape_3::Cell_handle Cell_handle; -typedef Alpha_shape_3::Facet Facet; -typedef Alpha_shape_3::Edge Edge_3; +CGAL::cpp11::tuple, +CGAL::cpp11::tuple >, + std::back_insert_iterator< std::vector > > > Dispatch; +typedef Alpha_shape_3::Cell_handle Cell_handle; +typedef Alpha_shape_3::Facet Facet; +typedef Alpha_shape_3::Edge Edge_3; typedef std::list Vertex_list; // gudhi type definition @@ -65,70 +71,60 @@ typedef std::map Alpha_shape typedef std::pair Alpha_shape_simplex_tree_pair; typedef std::vector< Simplex_tree_vertex > Simplex_tree_vector_vertex; -//#define DEBUG_TRACES - -Vertex_list from (const Cell_handle& ch) -{ +Vertex_list from(const Cell_handle& ch) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { + for (auto i = 0; i < 4; i++) { #ifdef DEBUG_TRACES std::cout << "from cell[" << i << "]=" << ch->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(ch->vertex(i)); } return the_list; } -Vertex_list from (const Facet& fct) -{ + +Vertex_list from(const Facet& fct) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { - if (fct.second != i) - { + for (auto i = 0; i < 4; i++) { + if (fct.second != i) { #ifdef DEBUG_TRACES std::cout << "from facet=[" << i << "]" << fct.first->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(fct.first->vertex(i)); } } return the_list; } -Vertex_list from (const Edge_3& edg) -{ + +Vertex_list from(const Edge_3& edg) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { - if ((edg.second == i) ||(edg.third == i)) - { + for (auto i = 0; i < 4; i++) { + if ((edg.second == i) || (edg.third == i)) { #ifdef DEBUG_TRACES std::cout << "from edge[" << i << "]=" << edg.first->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(edg.first->vertex(i)); } } return the_list; } -Vertex_list from (const Alpha_shape_3::Vertex_handle& vh) -{ + +Vertex_list from(const Alpha_shape_3::Vertex_handle& vh) { Vertex_list the_list; #ifdef DEBUG_TRACES std::cout << "from vertex=" << vh->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(vh); return the_list; } -void usage(char * const progName) -{ - std::cerr << "Usage: " << progName << " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; - exit(-1); // ----- >> +void usage(char * const progName) { + std::cerr << "Usage: " << progName << + " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; + exit(-1); } -int main (int argc, char * const argv[]) -{ - - int coeff_field_characteristic=0; +int main(int argc, char * const argv[]) { + int coeff_field_characteristic = 0; int returnedScanValue = sscanf(argv[2], "%d", &coeff_field_characteristic); if ((returnedScanValue == EOF) || (coeff_field_characteristic <= 0)) { std::cerr << "Error: " << argv[2] << " is not correct\n"; @@ -149,102 +145,96 @@ int main (int argc, char * const argv[]) } // Read points from file - std::string filegraph = argv[1]; + std::string filegraph = argv[1]; std::list lp; std::ifstream is(filegraph.c_str()); int n; is >> n; #ifdef DEBUG_TRACES std::cout << "Reading " << n << " points " << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES Point_3 p; - for( ; n>0 ; n--) { + for (; n > 0; n--) { is >> p; lp.push_back(p); } // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. - Alpha_shape_3 as(lp.begin(),lp.end(),0,Alpha_shape_3::GENERAL); + Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); #ifdef DEBUG_TRACES std::cout << "Alpha shape computed in GENERAL mode" << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES // filtration with alpha values from alpha shape std::vector the_objects; std::vector the_alpha_values; - Dispatch disp = CGAL::dispatch_output( std::back_inserter(the_objects), std::back_inserter(the_alpha_values)); + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); as.filtration_with_alpha_values(disp); #ifdef DEBUG_TRACES std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; // Loop on objects vector Vertex_list vertex_list; Simplex_tree<> simplex_tree; Alpha_shape_simplex_tree_map map_cgal_simplex_tree; std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max=0; - Filtration_value filtration_max=0.0; - for(auto object_iterator: the_objects) - { + int dim_max = 0; + Filtration_value filtration_max = 0.0; + for (auto object_iterator : the_objects) { // Retrieve Alpha shape vertex list from object - if (const Cell_handle* cell = CGAL::object_cast(&object_iterator)) - { + if (const Cell_handle * cell = CGAL::object_cast(&object_iterator)) { vertex_list = from(*cell); count_cells++; if (dim_max < 3) { - dim_max=3; // Cell is of dim 3 + // Cell is of dim 3 + dim_max = 3; } - } - else if (const Facet* facet = CGAL::object_cast(&object_iterator)) - { + } else if (const Facet * facet = CGAL::object_cast(&object_iterator)) { vertex_list = from(*facet); count_facets++; if (dim_max < 2) { - dim_max=2; // Facet is of dim 2 + // Facet is of dim 2 + dim_max = 2; } - } - else if (const Edge_3* edge = CGAL::object_cast(&object_iterator)) - { + } else if (const Edge_3 * edge = CGAL::object_cast(&object_iterator)) { vertex_list = from(*edge); count_edges++; if (dim_max < 1) { - dim_max=1; // Edge_3 is of dim 1 + // Edge_3 is of dim 1 + dim_max = 1; } - } - else if (const Alpha_shape_3::Vertex_handle* vertex = CGAL::object_cast(&object_iterator)) - { + } else if (const Alpha_shape_3::Vertex_handle * vertex = + CGAL::object_cast(&object_iterator)) { count_vertices++; vertex_list = from(*vertex); } // Construction of the vector of simplex_tree vertex from list of alpha_shapes vertex Simplex_tree_vector_vertex the_simplex_tree; - for (auto the_alpha_shape_vertex:vertex_list) - { + for (auto the_alpha_shape_vertex : vertex_list) { Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) - { + if (the_map_iterator == map_cgal_simplex_tree.end()) { // alpha shape not found Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); #ifdef DEBUG_TRACES std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex,vertex)); - } else - { + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { // alpha shape found Simplex_tree_vertex vertex = the_map_iterator->second; #ifdef DEBUG_TRACES std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_simplex_tree.push_back(vertex); } } @@ -252,7 +242,7 @@ int main (int argc, char * const argv[]) Filtration_value filtr = std::sqrt(*the_alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES if (filtr > filtration_max) { filtration_max = filtr; } @@ -267,9 +257,9 @@ int main (int argc, char * const argv[]) #ifdef DEBUG_TRACES std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; std::cout << "Information of the Simplex Tree: " << std::endl; @@ -277,23 +267,25 @@ int main (int argc, char * const argv[]) std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; std::cout << " Dimension = " << simplex_tree.dimension() << " "; std::cout << " filtration = " << simplex_tree.filtration() << std::endl << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES #ifdef DEBUG_TRACES std::cout << "Iterator on vertices: " << std::endl; - for( auto vertex : simplex_tree.complex_vertex_range() ) - { std::cout << vertex << " "; } -#endif // DEBUG_TRACES + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; // Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh( simplex_tree ); - pcoh.init_coefficients( coeff_field_characteristic ); //initializes the coefficient field for homology + Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); - pcoh.compute_persistent_cohomology( min_persistence ); + pcoh.compute_persistent_cohomology(min_persistence); pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/performance_rips_persistence.cpp b/src/Persistent_cohomology/example/performance_rips_persistence.cpp index 077c2b07..0e912d57 100644 --- a/src/Persistent_cohomology/example/performance_rips_persistence.cpp +++ b/src/Persistent_cohomology/example/performance_rips_persistence.cpp @@ -1,49 +1,51 @@ - /* 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): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (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 "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include "gudhi/Persistent_cohomology/Multi_field.h" -#include "gudhi/Hasse_complex.h" +/* 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): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (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 +#include +#include +#include +#include #include +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; /* Compute the persistent homology of the complex cpx with coefficients in Z/pZ. */ template< typename FilteredComplex> -void timing_persistence( FilteredComplex & cpx - , int p ); +void timing_persistence(FilteredComplex & cpx + , int p); /* Compute multi-field persistent homology of the complex cpx with coefficients in * Z/rZ for all prime number r in [p;q].*/ template< typename FilteredComplex> -void timing_persistence( FilteredComplex & cpx - , int p - , int q ); +void timing_persistence(FilteredComplex & cpx + , int p + , int q); /* Timings for the computation of persistent homology with different * representations of a Rips complex and different coefficient fields. The @@ -59,111 +61,111 @@ void timing_persistence( FilteredComplex & cpx * We present also timings for the computation of multi-field persistent * homology in all fields Z/rZ for r prime between 2 and 1223. */ -int main (int argc, char * argv[]) -{ +int main(int argc, char * argv[]) { std::chrono::time_point start, end; int enlapsed_sec; - std::string filepoints = "../examples/Kl.txt"; - Filtration_value threshold = 0.3; - int dim_max = 3; - int p = 2; - int q = 1223; + std::string filepoints = "../examples/Kl.txt"; + Filtration_value threshold = 0.3; + int dim_max = 3; + int p = 2; + int q = 1223; -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points + // Compute the proximity graph of the points start = std::chrono::system_clock::now(); - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + 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(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Compute Rips graph in " << enlapsed_sec << " sec.\n"; -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; start = std::chrono::system_clock::now(); - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Compute Rips complex in " << enlapsed_sec << " sec.\n"; std::cout << " - dimension = " << st.dimension() << std::endl; std::cout << " - number of simplices = " << st.num_simplices() << std::endl; -// Sort the simplices in the order of the filtration + // Sort the simplices in the order of the filtration start = std::chrono::system_clock::now(); st.initialize_filtration(); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Order the simplices of the filtration in " << enlapsed_sec << " sec.\n"; -// Convert the simplex tree into a hasse diagram + // 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(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Convert the simplex tree into a Hasse diagram in " << enlapsed_sec << " sec.\n"; std::cout << "Timings when using a simplex tree: \n"; - timing_persistence(st,p); - timing_persistence(st,q); - timing_persistence(st,p,q); + timing_persistence(st, p); + timing_persistence(st, q); + timing_persistence(st, p, q); std::cout << "Timings when using a Hasse complex: \n"; - timing_persistence(hcpx,p); - timing_persistence(hcpx,q); - timing_persistence(hcpx,p,q); + timing_persistence(hcpx, p); + timing_persistence(hcpx, q); + timing_persistence(hcpx, p, q); return 0; } - template< typename FilteredComplex> void -timing_persistence( FilteredComplex & cpx - , int p ) -{ +timing_persistence(FilteredComplex & cpx + , int p) { std::chrono::time_point start, end; int enlapsed_sec; - Persistent_cohomology< FilteredComplex, Field_Zp > pcoh (cpx); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - + Persistent_cohomology< FilteredComplex, Field_Zp > pcoh(cpx); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + start = std::chrono::system_clock::now(); - - pcoh.compute_persistent_cohomology( INFINITY ); - + + 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/"<(end - start).count(); + std::cout << " Compute persistent homology in Z/" << p << "Z in " << enlapsed_sec << " sec.\n"; } template< typename FilteredComplex> void -timing_persistence( FilteredComplex & cpx - , int p - , int q ) -{ +timing_persistence(FilteredComplex & cpx + , int p + , int q) { std::chrono::time_point start, end; int enlapsed_sec; - Persistent_cohomology< FilteredComplex, Multi_field > pcoh (cpx); - pcoh.init_coefficients( p, q ); //initilizes the coefficient field for homology + Persistent_cohomology< FilteredComplex, Multi_field > pcoh(cpx); + // initializes the coefficient field for homology + pcoh.init_coefficients(p, q); // compute persistent homology, disgarding persistent features of life shorter than min_persistence start = std::chrono::system_clock::now(); - pcoh.compute_persistent_cohomology( INFINITY ); + pcoh.compute_persistent_cohomology(INFINITY); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ " - << "with p in ["<. - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (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 +#include +#include #include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; -typedef double Filtration_value; - -void program_options( int argc, char * argv[] - , std::string & simplex_tree_file - , std::string & output_file - , int & p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string simplex_tree_file; - std::string output_file ; - int p ; - Filtration_value min_persistence; - - 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::endl; - std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl; - - // Construct the Rips complex in a Simplex Tree - Simplex_tree<> simplex_tree; - - 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() << " - filtration " << simplex_tree.filtration() << std::endl; - - /* - std::cout << 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) << "] "; - for( auto vertex : simplex_tree.simplex_vertex_range(f_simplex) ) - { std::cout << vertex << " "; } - std::cout << 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 ); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - - pcoh.compute_persistent_cohomology( min_persistence ); - - // Output the diagram in output_file - if(output_file.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(output_file); - pcoh.output_diagram(out); - out.close(); } +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & simplex_tree_file + , std::string & output_file + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string simplex_tree_file; + std::string output_file; + int p; + Filtration_value min_persistence; + + 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::endl; + std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl; + + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> simplex_tree; + + 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() << " - filtration " << simplex_tree.filtration() + << std::endl; + + /* + std::cout << 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) << "] "; + for( auto vertex : simplex_tree.simplex_vertex_range(f_simplex) ) + { std::cout << vertex << " "; } + std::cout << 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 + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in output_file + if (output_file.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(output_file); + pcoh.output_diagram(out); + out.close(); + } - return 0; + return 0; } - - -void program_options( int argc, char * argv[] - , std::string & simplex_tree_file - , std::string & output_file - , int & p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & simplex_tree_file + , std::string & output_file + , int & p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&simplex_tree_file), - "Name of file containing a simplex set. Format is one simplex per line (cf. reader_utils.h - read_simplex): Dim1 X11 X12 ... X1d Fil1 "); - + ("input-file", po::value(&simplex_tree_file), + "Name of file containing a simplex set. Format is one simplex per line (cf. reader_utils.h - read_simplex): Dim1 X11 X12 ... X1d Fil1 "); + po::options_description visible("Allowed options", 100); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&output_file)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0"); + ("help,h", "produce help message") + ("output-file,o", po::value(&output_file)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); 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::abort(); + 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::abort(); } } 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 ba82e4e6..ba772f04 100644 --- a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp +++ b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp @@ -20,11 +20,14 @@ * along with this program. If not, see . */ +#include +#include +#include + #include #include -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; @@ -34,15 +37,19 @@ typedef std::pair typeSimplex; typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; typedef Simplex_tree<> typeST; -void usage(char * const progName) -{ +void usage(char * const progName) { std::cerr << "Usage: " << progName << " coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; - exit(-1); // ----- >> + exit(-1); } -int main (int argc, char * const argv[]) -{ - int coeff_field_characteristic=0; +int main(int argc, char * const argv[]) { + // program args management + if (argc != 3) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = 0; int returnedScanValue = sscanf(argv[1], "%d", &coeff_field_characteristic); if ((returnedScanValue == EOF) || (coeff_field_characteristic <= 0)) { std::cerr << "Error: " << argv[1] << " is not correct\n"; @@ -56,101 +63,65 @@ int main (int argc, char * const argv[]) usage(argv[0]); } - // program args management - if (argc != 3) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF INSERTION" << std::endl; typeST st; // ++ FIRST - std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex SimplexVector1; - SimplexVector1.push_back(2); - SimplexVector1.push_back(1); - SimplexVector1.push_back(0); - st.insert_simplex_and_subfaces ( SimplexVector1, 0.3); + std::cout << " - 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; - typeVectorVertex SimplexVector2; - SimplexVector2.push_back(3); - st.insert_simplex_and_subfaces ( SimplexVector2, 0.1); + SimplexVector = {3}; + st.insert_simplex_and_subfaces(SimplexVector, 0.1); // ++ THIRD std::cout << " - INSERT (0,3)" << std::endl; - typeVectorVertex SimplexVector3; - SimplexVector3.push_back(3); - SimplexVector3.push_back(0); - st.insert_simplex_and_subfaces ( SimplexVector3, 0.2); + SimplexVector = {0, 3}; + st.insert_simplex_and_subfaces(SimplexVector, 0.2); // ++ FOURTH - std::cout << " - INSERT (1,0) (already inserted)" << std::endl; - typeVectorVertex SimplexVector4; - SimplexVector4.push_back(1); - SimplexVector4.push_back(0); - st.insert_simplex_and_subfaces ( SimplexVector4, 0.2); + std::cout << " - 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; - typeVectorVertex SimplexVector5; - SimplexVector5.push_back(3); - SimplexVector5.push_back(4); - SimplexVector5.push_back(5); - st.insert_simplex_and_subfaces ( SimplexVector5, 0.3); + SimplexVector = {3, 4, 5}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); // ++ SIXTH std::cout << " - INSERT (0,1,6,7)" << std::endl; - typeVectorVertex SimplexVector6; - SimplexVector6.push_back(0); - SimplexVector6.push_back(1); - SimplexVector6.push_back(6); - SimplexVector6.push_back(7); - st.insert_simplex_and_subfaces ( SimplexVector6, 0.4); + SimplexVector = {0, 1, 6, 7}; + st.insert_simplex_and_subfaces(SimplexVector, 0.4); // ++ SEVENTH std::cout << " - INSERT (4,5,8,9)" << std::endl; - typeVectorVertex SimplexVector7; - SimplexVector7.push_back(4); - SimplexVector7.push_back(5); - SimplexVector7.push_back(8); - SimplexVector7.push_back(9); - st.insert_simplex_and_subfaces ( SimplexVector7, 0.4); + SimplexVector = {4, 5, 8, 9}; + st.insert_simplex_and_subfaces(SimplexVector, 0.4); // ++ EIGHTH std::cout << " - INSERT (9,10,11)" << std::endl; - typeVectorVertex SimplexVector8; - SimplexVector8.push_back(9); - SimplexVector8.push_back(10); - SimplexVector8.push_back(11); - st.insert_simplex_and_subfaces ( SimplexVector8, 0.3); - + SimplexVector = {9, 10, 11}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); + // ++ NINETH std::cout << " - INSERT (2,10,12)" << std::endl; - typeVectorVertex SimplexVector9; - SimplexVector9.push_back(2); - SimplexVector9.push_back(10); - SimplexVector9.push_back(12); - st.insert_simplex_and_subfaces ( SimplexVector9, 0.3); - + SimplexVector = {2, 10, 12}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); + // ++ TENTH std::cout << " - INSERT (11,6)" << std::endl; - typeVectorVertex SimplexVector10; - SimplexVector10.push_back(11); - SimplexVector10.push_back(6); - st.insert_simplex_and_subfaces ( SimplexVector10, 0.2); + SimplexVector = {6, 11}; + st.insert_simplex_and_subfaces(SimplexVector, 0.2); // ++ ELEVENTH std::cout << " - INSERT (13,14,15)" << std::endl; - typeVectorVertex SimplexVector11; - SimplexVector11.push_back(13); - SimplexVector11.push_back(14); - SimplexVector11.push_back(15); - st.insert_simplex_and_subfaces ( SimplexVector11, 0.25); + SimplexVector = {13, 14, 15}; + st.insert_simplex_and_subfaces(SimplexVector, 0.25); /* Inserted simplex: */ /* 1 6 */ @@ -175,33 +146,31 @@ int main (int argc, char * const argv[]) st.set_dimension(2); st.set_filtration(0.4); - std::cout << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices " << std::endl; + std::cout << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices " + << std::endl; std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + std::cout << 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; - for( auto f_simplex : st.filtration_simplex_range() ) - { + for (auto f_simplex : st.filtration_simplex_range()) { std::cout << " " << "[" << st.filtration(f_simplex) << "] "; - for( auto vertex : st.simplex_vertex_range(f_simplex) ) - { - std::cout << (int)vertex << " -- "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << static_cast(vertex) << " -- "; } std::cout << ";" << std::endl; } std::cout << "}" << std::endl; - //std::cout << "**************************************************************" << std::endl; - //st.print_hasse(std::cout); std::cout << "**************************************************************" << std::endl; - // Compute the persistence diagram of the complex persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st); - pcoh.init_coefficients( coeff_field_characteristic ); //initiliazes the coefficient field for homology + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); - pcoh.compute_persistent_cohomology( min_persistence ); + pcoh.compute_persistent_cohomology(min_persistence); // Output the diagram in filediag pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index 297a8f98..5277bf7a 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -1,153 +1,157 @@ - /* 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): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (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 "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include "gudhi/Persistent_cohomology/Multi_field.h" +/* 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): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (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 +#include +#include +#include #include +#include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; +typedef int Vertex_handle; typedef double Filtration_value; -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & min_p - , int & max_p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string filepoints; - std::string filediag; +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & min_p + , int & max_p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string filepoints; + std::string filediag; Filtration_value threshold; - int dim_max; - int min_p; - int max_p; + int dim_max; + int min_p; + int max_p; Filtration_value min_persistence; - program_options(argc,argv,filepoints,filediag,threshold,dim_max,min_p,max_p,min_persistence); + program_options(argc, argv, filepoints, filediag, threshold, dim_max, min_p, max_p, min_persistence); -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); -// Sort the simplices in the order of the filtration + // Sort the simplices in the order of the filtration st.initialize_filtration(); -// Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Multi_field > pcoh( st ); - pcoh.init_coefficients( min_p, max_p ); //initilizes the coefficient field for homology + // Compute the persistence diagram of the complex + Persistent_cohomology< Simplex_tree<>, Multi_field > pcoh(st); + // initializes the coefficient field for homology + pcoh.init_coefficients(min_p, max_p); // compute persistent homology, disgarding persistent features of life shorter than min_persistence - pcoh.compute_persistent_cohomology( min_persistence ); - -// Output the diagram in filediag - if(filediag.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); } + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } return 0; } - - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & min_p - , int & max_p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & min_p + , int & max_p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&filepoints), - "Name of file containing a point set. Format is one point per line: X1 ... Xd \n"); - + ("input-file", po::value(&filepoints), + "Name of file containing a point set. Format is one point per line: X1 ... Xd \n"); + po::options_description visible("Allowed options"); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", po::value(&threshold)->default_value(0), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("min-field-charac,p", po::value(&min_p)->default_value(2), - "Minimal characteristic p of the coefficient field Z/pZ.") - ("max-field-charac,q", po::value(&max_p)->default_value(1223), - "Minimial characteristic q of the coefficient field Z/pZ.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0"); + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", po::value(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("min-field-charac,p", po::value(&min_p)->default_value(2), + "Minimal characteristic p of the coefficient field Z/pZ.") + ("max-field-charac,q", po::value(&max_p)->default_value(1223), + "Minimial characteristic q of the coefficient field Z/pZ.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); 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::abort(); + 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::abort(); } } diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp index 4253def9..9b1ef42f 100644 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_persistence.cpp @@ -1,147 +1,151 @@ - /* 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): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (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 "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" +/* 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): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (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 +#include +#include #include +#include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; -typedef double Filtration_value; - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string filepoints; - std::string filediag ; - Filtration_value threshold ; - int dim_max ; - int p ; +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string filepoints; + std::string filediag; + Filtration_value threshold; + int dim_max; + int p; Filtration_value min_persistence; - program_options(argc,argv,filepoints,filediag,threshold,dim_max,p,min_persistence); + program_options(argc, argv, filepoints, filediag, threshold, dim_max, p, min_persistence); -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // 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 + // Sort the simplices in the order of the filtration st.initialize_filtration(); -// Compute the persistence diagram of the complex + // Compute the persistence diagram of the complex persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - - pcoh.compute_persistent_cohomology( min_persistence ); - -// Output the diagram in filediag - if(filediag.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); } + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } return 0; } - - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&filepoints), - "Name of file containing a point set. Format is one point per line: X1 ... Xd "); - + ("input-file", po::value(&filepoints), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + po::options_description visible("Allowed options", 100); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", po::value(&threshold)->default_value(0), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", po::value(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); 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::abort(); + 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::abort(); } } -- cgit v1.2.3