From a034f774490ea06c018726ed58a0cfbe9d12d97c Mon Sep 17 00:00:00 2001 From: Vincent Rouvreau Date: Mon, 26 Sep 2022 13:40:57 +0200 Subject: Cech_persistence utility for safe/exact/fast mode --- src/Cech_complex/utilities/cech_persistence.cpp | 67 ++++++++++++++++++------- 1 file changed, 49 insertions(+), 18 deletions(-) (limited to 'src/Cech_complex/utilities/cech_persistence.cpp') diff --git a/src/Cech_complex/utilities/cech_persistence.cpp b/src/Cech_complex/utilities/cech_persistence.cpp index 75d10c0f..a07ba212 100644 --- a/src/Cech_complex/utilities/cech_persistence.cpp +++ b/src/Cech_complex/utilities/cech_persistence.cpp @@ -16,6 +16,7 @@ #include #include // For EXACT or SAFE version +#include // For FAST version #include #include @@ -25,41 +26,66 @@ using Simplex_tree = Gudhi::Simplex_tree; using Filtration_value = Simplex_tree::Filtration_value; -using Kernel = CGAL::Epeck_d; -using Point = typename Kernel::Point_d; -using Points_off_reader = Gudhi::Points_off_reader; -using Cech_complex = Gudhi::cech_complex::Cech_complex; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -void program_options(int argc, char* argv[], std::string& off_file_points, std::string& filediag, - Filtration_value& max_radius, int& dim_max, int& p, Filtration_value& min_persistence); +void program_options(int argc, char* argv[], std::string& off_file_points, bool& exact, bool& fast, + std::string& filediag, Filtration_value& max_radius, int& dim_max, int& p, + Filtration_value& min_persistence); + +template +Simplex_tree create_simplex_tree(const std::string &off_file_points, bool exact_version, + Filtration_value max_radius, int dim_max) { + using Point = typename Kernel::Point_d; + using Points_off_reader = Gudhi::Points_off_reader; + using Cech_complex = Gudhi::cech_complex::Cech_complex; + + Simplex_tree stree; + + Points_off_reader off_reader(off_file_points); + Cech_complex cech_complex_from_file(off_reader.get_point_cloud(), max_radius, exact_version); + cech_complex_from_file.create_complex(stree, dim_max); + + return stree; +} int main(int argc, char* argv[]) { std::string off_file_points; std::string filediag; + bool exact_version = false; + bool fast_version = false; Filtration_value max_radius; int dim_max; int p; Filtration_value min_persistence; - program_options(argc, argv, off_file_points, filediag, max_radius, dim_max, p, min_persistence); + program_options(argc, argv, off_file_points, exact_version, fast_version, filediag, max_radius, dim_max, p, + min_persistence); - Points_off_reader off_reader(off_file_points); - Cech_complex cech_complex_from_file(off_reader.get_point_cloud(), max_radius); + if ((exact_version) && (fast_version)) { + std::cerr << "You cannot set the exact and the fast version." << std::endl; + exit(-1); + } - // Construct the Cech complex in a Simplex Tree - Simplex_tree simplex_tree; + Simplex_tree stree; + if (fast_version) { + // WARNING : CGAL::Epick_d is fast but not safe (unlike CGAL::Epeck_d) + // (i.e. when the points are on a grid) + using Fast_kernel = CGAL::Epick_d; + stree = create_simplex_tree(off_file_points, exact_version, max_radius, dim_max); + } else { + using Kernel = CGAL::Epeck_d; + stree = create_simplex_tree(off_file_points, exact_version, max_radius, dim_max); + } - cech_complex_from_file.create_complex(simplex_tree, dim_max); - std::clog << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; - std::clog << " and has dimension " << simplex_tree.dimension() << " \n"; + std::clog << "The complex contains " << stree.num_simplices() << " simplices \n"; + std::clog << " and has dimension " << stree.dimension() << " \n"; // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); + stree.initialize_filtration(); // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree); + Persistent_cohomology pcoh(stree); // initializes the coefficient field for homology pcoh.init_coefficients(p); @@ -77,8 +103,9 @@ int main(int argc, char* argv[]) { return 0; } -void program_options(int argc, char* argv[], std::string& off_file_points, std::string& filediag, - Filtration_value& max_radius, int& dim_max, int& p, Filtration_value& min_persistence) { +void program_options(int argc, char* argv[], std::string& off_file_points, bool& exact, bool& fast, + std::string& filediag, Filtration_value& max_radius, int& dim_max, int& p, + Filtration_value& min_persistence) { namespace po = boost::program_options; po::options_description hidden("Hidden options"); hidden.add_options()("input-file", po::value(&off_file_points), @@ -86,6 +113,10 @@ void program_options(int argc, char* argv[], std::string& off_file_points, std:: po::options_description visible("Allowed options", 100); visible.add_options()("help,h", "produce help message")( + "exact,e", po::bool_switch(&exact), + "To activate exact version of Cech complex (default is false, not available if fast is set)")( + "fast,f", po::bool_switch(&fast), + "To activate fast version of Cech complex (default is false, not available if exact is set)")( "output-file,o", po::value(&filediag)->default_value(std::string()), "Name of file in which the persistence diagram is written. Default print in std::clog")( "max-radius,r", -- cgit v1.2.3 From 0a183262e27e133bc8a77c91f5c97506497cd380 Mon Sep 17 00:00:00 2001 From: Vincent Rouvreau Date: Wed, 19 Oct 2022 08:28:02 +0200 Subject: persistence diagram default output is std::cout, not std::clog. Modify utilities help to be in agreement with this --- src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp | 2 +- src/Alpha_complex/utilities/alpha_complex_persistence.cpp | 2 +- src/Cech_complex/utilities/cech_persistence.cpp | 2 +- .../utilities/distance_matrix_edge_collapse_rips_persistence.cpp | 2 +- src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp | 2 +- src/Persistent_cohomology/example/persistence_from_file.cpp | 2 +- src/Persistent_cohomology/example/rips_multifield_persistence.cpp | 2 +- src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp | 2 +- .../example/rips_persistence_via_boundary_matrix.cpp | 2 +- src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp | 2 +- src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp | 2 +- src/Rips_complex/utilities/rips_persistence.cpp | 2 +- src/Rips_complex/utilities/sparse_rips_persistence.cpp | 2 +- src/Witness_complex/utilities/strong_witness_persistence.cpp | 2 +- src/Witness_complex/utilities/weak_witness_persistence.cpp | 2 +- src/Witness_complex/utilities/witnesscomplex.md | 4 ++-- 16 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/Cech_complex/utilities/cech_persistence.cpp') diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp index 91899040..e65d8c6f 100644 --- a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp @@ -263,7 +263,7 @@ void program_options(int argc, char *argv[], std::string &off_file_points, bool "cuboid-file,c", po::value(&cuboid_file), "Name of file describing the periodic domain. Format is:\n min_hx min_hy min_hz\n max_hx max_hy max_hz")( "output-file,o", po::value(&output_file_diag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-alpha-square-value,r", po::value(&alpha_square_max_value) ->default_value(std::numeric_limits::infinity()), diff --git a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp index e86b34e2..29edbd8e 100644 --- a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp @@ -163,7 +163,7 @@ void program_options(int argc, char *argv[], std::string &off_file_points, bool "weight-file,w", po::value(&weight_file)->default_value(std::string()), "Name of file containing a point weights. Format is one weight per line:\n W1\n ...\n Wn ")( "output-file,o", po::value(&output_file_diag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-alpha-square-value,r", po::value(&alpha_square_max_value) ->default_value(std::numeric_limits::infinity()), "Maximal alpha square value for the Alpha complex construction.")( diff --git a/src/Cech_complex/utilities/cech_persistence.cpp b/src/Cech_complex/utilities/cech_persistence.cpp index a07ba212..e6419f3d 100644 --- a/src/Cech_complex/utilities/cech_persistence.cpp +++ b/src/Cech_complex/utilities/cech_persistence.cpp @@ -118,7 +118,7 @@ void program_options(int argc, char* argv[], std::string& off_file_points, bool& "fast,f", po::bool_switch(&fast), "To activate fast version of Cech complex (default is false, not available if exact is set)")( "output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-radius,r", po::value(&max_radius)->default_value(std::numeric_limits::infinity()), "Maximal length of an edge for the Cech complex construction.")( diff --git a/src/Collapse/utilities/distance_matrix_edge_collapse_rips_persistence.cpp b/src/Collapse/utilities/distance_matrix_edge_collapse_rips_persistence.cpp index 38efb9e6..70b489b5 100644 --- a/src/Collapse/utilities/distance_matrix_edge_collapse_rips_persistence.cpp +++ b/src/Collapse/utilities/distance_matrix_edge_collapse_rips_persistence.cpp @@ -111,7 +111,7 @@ void program_options(int argc, char* argv[], std::string& csv_matrix_file, std:: 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")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-edge-length,r", po::value(&threshold)->default_value(std::numeric_limits::infinity()), "Maximal length of an edge for the Rips complex construction.")( diff --git a/src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp b/src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp index d8f42ab6..a8fd6f14 100644 --- a/src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp +++ b/src/Collapse/utilities/point_cloud_edge_collapse_rips_persistence.cpp @@ -140,7 +140,7 @@ void program_options(int argc, char* argv[], std::string& off_file_points, std:: 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")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-edge-length,r", po::value(&threshold)->default_value(std::numeric_limits::infinity()), "Maximal length of an edge for the Rips complex construction.")( diff --git a/src/Persistent_cohomology/example/persistence_from_file.cpp b/src/Persistent_cohomology/example/persistence_from_file.cpp index 38c44514..7f89c001 100644 --- a/src/Persistent_cohomology/example/persistence_from_file.cpp +++ b/src/Persistent_cohomology/example/persistence_from_file.cpp @@ -93,7 +93,7 @@ void program_options(int argc, char * argv[] 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::clog") + "Name of file in which the persistence diagram is written. Default print in standard output") ("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), diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index ca26a5b9..84453898 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -96,7 +96,7 @@ void program_options(int argc, char * argv[] 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::clog") + "Name of file in which the persistence diagram is written. Default print in standard output") ("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), 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 a503d983..6f37cf5c 100644 --- a/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp +++ b/src/Persistent_cohomology/example/rips_persistence_step_by_step.cpp @@ -112,7 +112,7 @@ void program_options(int argc, char * argv[] 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::clog") + "Name of file in which the persistence diagram is written. Default print in standard output") ("max-edge-length,r", po::value(&threshold)->default_value(std::numeric_limits::infinity()), "Maximal length of an edge for the Rips complex construction.") 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 8c5742aa..6b60f603 100644 --- a/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp +++ b/src/Persistent_cohomology/example/rips_persistence_via_boundary_matrix.cpp @@ -109,7 +109,7 @@ void program_options(int argc, char * argv[] 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::clog") + "Name of file in which the persistence diagram is written. Default print in standard output") ("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), diff --git a/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp b/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp index b473738e..72ddc797 100644 --- a/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp +++ b/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp @@ -118,7 +118,7 @@ void program_options(int argc, char* argv[], std::string& csv_matrix_file, std:: 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::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "min-edge-corelation,c", po::value(&correlation_min)->default_value(0), "Minimal corelation of an edge for the Rips complex construction.")( "cpx-dimension,d", po::value(&dim_max)->default_value(1), diff --git a/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp b/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp index 6306755d..77ad841a 100644 --- a/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp +++ b/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp @@ -79,7 +79,7 @@ void program_options(int argc, char* argv[], std::string& csv_matrix_file, std:: 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::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-edge-length,r", po::value(&threshold)->default_value(std::numeric_limits::infinity()), "Maximal length of an edge for the Rips complex construction.")( diff --git a/src/Rips_complex/utilities/rips_persistence.cpp b/src/Rips_complex/utilities/rips_persistence.cpp index 9d7490b3..43194821 100644 --- a/src/Rips_complex/utilities/rips_persistence.cpp +++ b/src/Rips_complex/utilities/rips_persistence.cpp @@ -81,7 +81,7 @@ void program_options(int argc, char* argv[], std::string& off_file_points, std:: 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::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-edge-length,r", po::value(&threshold)->default_value(std::numeric_limits::infinity()), "Maximal length of an edge for the Rips complex construction.")( diff --git a/src/Rips_complex/utilities/sparse_rips_persistence.cpp b/src/Rips_complex/utilities/sparse_rips_persistence.cpp index ac935b41..829c85e6 100644 --- a/src/Rips_complex/utilities/sparse_rips_persistence.cpp +++ b/src/Rips_complex/utilities/sparse_rips_persistence.cpp @@ -84,7 +84,7 @@ void program_options(int argc, char* argv[], std::string& off_file_points, std:: 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::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-edge-length,r", po::value(&threshold)->default_value(std::numeric_limits::infinity()), "Maximal length of an edge for the Rips complex construction.")( diff --git a/src/Witness_complex/utilities/strong_witness_persistence.cpp b/src/Witness_complex/utilities/strong_witness_persistence.cpp index 614de0d4..b2ecad82 100644 --- a/src/Witness_complex/utilities/strong_witness_persistence.cpp +++ b/src/Witness_complex/utilities/strong_witness_persistence.cpp @@ -108,7 +108,7 @@ void program_options(int argc, char* argv[], int& nbL, std::string& file_name, s visible.add_options()("help,h", "produce help message")("landmarks,l", po::value(&nbL), "Number of landmarks to choose from the point cloud.")( "output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), "Maximal squared relaxation parameter.")( "field-charac,p", po::value(&p)->default_value(11), diff --git a/src/Witness_complex/utilities/weak_witness_persistence.cpp b/src/Witness_complex/utilities/weak_witness_persistence.cpp index 5ea31d6b..c7ead7de 100644 --- a/src/Witness_complex/utilities/weak_witness_persistence.cpp +++ b/src/Witness_complex/utilities/weak_witness_persistence.cpp @@ -108,7 +108,7 @@ void program_options(int argc, char* argv[], int& nbL, std::string& file_name, s visible.add_options()("help,h", "produce help message")("landmarks,l", po::value(&nbL), "Number of landmarks to choose from the point cloud.")( "output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::clog")( + "Name of file in which the persistence diagram is written. Default print in standard output")( "max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), "Maximal squared relaxation parameter.")( "field-charac,p", po::value(&p)->default_value(11), diff --git a/src/Witness_complex/utilities/witnesscomplex.md b/src/Witness_complex/utilities/witnesscomplex.md index 3a3a7d83..e994e0b8 100644 --- a/src/Witness_complex/utilities/witnesscomplex.md +++ b/src/Witness_complex/utilities/witnesscomplex.md @@ -29,7 +29,7 @@ and `p` is the characteristic of the field *Z/pZ* used for homology coefficients * `-h [ --help ]` Produce help message * `-l [ --landmarks ]` Number of landmarks to choose from the point cloud. -* `-o [ --output-file ]` Name of file in which the persistence diagram is written. By default, print in std::clog. +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. By default, print in standard output. * `-a [ --max-sq-alpha ]` (default = inf) Maximal squared relaxation parameter. * `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. * `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. @@ -60,7 +60,7 @@ and `p` is the characteristic of the field *Z/pZ* used for homology coefficients * `-h [ --help ]` Produce help message * `-l [ --landmarks ]` Number of landmarks to choose from the point cloud. -* `-o [ --output-file ]` Name of file in which the persistence diagram is written. By default, print in std::clog. +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. By default, print in standard output. * `-a [ --max-sq-alpha ]` (default = inf) Maximal squared relaxation parameter. * `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. * `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. -- cgit v1.2.3