From d5e1760353e7d6ba66975a90f9a2768a48f0abf8 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Tue, 8 Mar 2022 15:27:19 +0100 Subject: Modify cech benchmark to include both Epick and Epeck cases --- .../benchmark/cech_complex_benchmark.cpp | 177 +++++++++++++-------- 1 file changed, 109 insertions(+), 68 deletions(-) (limited to 'src/Cech_complex/benchmark/cech_complex_benchmark.cpp') diff --git a/src/Cech_complex/benchmark/cech_complex_benchmark.cpp b/src/Cech_complex/benchmark/cech_complex_benchmark.cpp index bf013a81..9cf24542 100644 --- a/src/Cech_complex/benchmark/cech_complex_benchmark.cpp +++ b/src/Cech_complex/benchmark/cech_complex_benchmark.cpp @@ -18,6 +18,7 @@ #include #include +#include #include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations @@ -32,10 +33,6 @@ using Point_cloud = std::vector; using Points_off_reader = Gudhi::Points_off_reader; using Proximity_graph = Gudhi::Proximity_graph; using Rips_complex = Gudhi::rips_complex::Rips_complex; -using Kernel = CGAL::Epick_d>; -using Point_cgal = typename Kernel::Point_d; -using Points_off_reader_cgal = Gudhi::Points_off_reader; -using Cech_complex = Gudhi::cech_complex::Cech_complex; class Minimal_enclosing_ball_radius { public: @@ -61,79 +58,123 @@ class Minimal_enclosing_ball_radius { } }; -int main(int argc, char* argv[]) { - std::string off_file_points = "tore3D_1307.off"; - Filtration_value threshold = 1e20; +enum distance_type { Euclidean_dist, Minimal_enclosing_ball_dist, CGAL_dist }; - // Extract the points from the file filepoints - Points_off_reader off_reader(off_file_points); - Points_off_reader_cgal off_reader_cgal(off_file_points); +template> +void benchmark_prox_graph(const std::string& off_file_points, const Filtration_value& threshold, const std::string& msg, distance_type dist = CGAL_dist) { + if (dist != CGAL_dist) { + std::cerr << "Error: when CGAL is used, the distance should be CGAL_dist" << std::endl; + exit(-1); + } + if (!use_cgal) { + std::cerr << "Warning: if kernel is given, CGAL will be used" << std::endl; + } + using Point_cgal = typename Kernel::Point_d; + using Points_off_reader_cgal = Gudhi::Points_off_reader; - Gudhi::Clock euclidean_clock("Gudhi::Euclidean_distance"); - // Compute the proximity graph of the points - Proximity_graph euclidean_prox_graph = Gudhi::compute_proximity_graph( - off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); + // Extract the points from the file filepoints + Points_off_reader_cgal off_reader_cgal(off_file_points); - std::clog << euclidean_clock << std::endl; + Gudhi::Clock cgal_circumsphere_clock("Gudhi::cech_complex::Sphere_circumradius_cgal()"); + // Compute the proximity graph of the points + Proximity_graph cgal_circumsphere_prox_graph = Gudhi::compute_proximity_graph(off_reader_cgal.get_point_cloud(), threshold, + Gudhi::cech_complex::Sphere_circumradius()); + std::clog << msg << " - " << cgal_circumsphere_clock << std::endl; +} - Gudhi::Clock miniball_clock("Minimal_enclosing_ball_radius"); - // Compute the proximity graph of the points - Proximity_graph miniball_prox_graph = Gudhi::compute_proximity_graph( - off_reader.get_point_cloud(), threshold, Minimal_enclosing_ball_radius()); - std::clog << miniball_clock << std::endl; +template +void benchmark_prox_graph(const std::string& off_file_points, const Filtration_value& threshold, const std::string& msg, distance_type dist) { + // Extract the points from the file filepoints + Points_off_reader off_reader(off_file_points); + + if (dist == Euclidean_dist) { + Gudhi::Clock euclidean_clock("Gudhi::Euclidean_distance"); + // Compute the proximity graph of the points + Proximity_graph euclidean_prox_graph = Gudhi::compute_proximity_graph(off_reader.get_point_cloud(), threshold, + Gudhi::Euclidean_distance()); + std::clog << msg << " - " << euclidean_clock << std::endl; + } + else if (dist == Minimal_enclosing_ball_dist) { + Gudhi::Clock miniball_clock("Minimal_enclosing_ball_radius"); + // Compute the proximity graph of the points + Proximity_graph miniball_prox_graph = Gudhi::compute_proximity_graph(off_reader.get_point_cloud(), threshold, + Minimal_enclosing_ball_radius()); + std::clog << msg << " - " << miniball_clock << std::endl; + } + else { + std::cerr << "Error: when CGAL is not used, the distance should be either Euclidean_dist or Minimal_enclosing_ball_dist" << std::endl; + exit(-1); + } +} + +template +void benchmark_cech(const std::string& off_file_points, const Filtration_value& radius, const int& dim_max) { + using Point_cgal = typename Kernel::Point_d; + using Points_off_reader_cgal = Gudhi::Points_off_reader; + using Cech_complex = Gudhi::cech_complex::Cech_complex; + + // Extract the points from the file filepoints + Points_off_reader_cgal off_reader_cgal(off_file_points); + + Gudhi::Clock cech_clock("Cech computation"); + Cech_complex cech_complex_from_points(off_reader_cgal.get_point_cloud(), radius); + Simplex_tree cech_stree; + cech_complex_from_points.create_complex(cech_stree, dim_max); + + // ------------------------------------------ + // Display information about the Cech complex + // ------------------------------------------ + double cech_sec = cech_clock.num_seconds(); + std::clog << cech_sec << " ; "; + std::clog << cech_stree.num_simplices() << " ; "; +} - Gudhi::Clock cgal_circumsphere_clock("Gudhi::cech_complex::Sphere_circumradius_cgal()"); - // Compute the proximity graph of the points - Proximity_graph cgal_circumsphere_prox_graph = Gudhi::compute_proximity_graph( - off_reader_cgal.get_point_cloud(), threshold, Gudhi::cech_complex::Sphere_circumradius()); - std::clog << cgal_circumsphere_clock << std::endl; +int main(int argc, char* argv[]) { + std::string off_file_points = "tore3D_1307.off"; + Filtration_value threshold = 1e20; + + benchmark_prox_graph(off_file_points, threshold, "Euclidean distance", Euclidean_dist); + benchmark_prox_graph(off_file_points, threshold, "Minimal_enclosing_ball", Minimal_enclosing_ball_dist); + benchmark_prox_graph>>(off_file_points, threshold, "Epick"); + benchmark_prox_graph>>(off_file_points, threshold, "Epeck"); - boost::filesystem::path full_path(boost::filesystem::current_path()); - std::clog << "Current path is : " << full_path << std::endl; + boost::filesystem::path full_path(boost::filesystem::current_path()); + std::clog << "Current path is : " << full_path << std::endl; - std::clog << "File name; Radius; Rips time; Cech time; Ratio Rips/Cech time; Rips nb simplices; Cech nb simplices;" + std::clog << "File name ; Radius ; Rips time ; Epick Cech time ; Epick Cech nb simplices ; Epeck Cech time ; Epeck Cech nb simplices ; Rips nb simplices;" << std::endl; - boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end - for (boost::filesystem::directory_iterator itr(boost::filesystem::current_path()); itr != end_itr; ++itr) { - if (!boost::filesystem::is_directory(itr->status())) { - if (itr->path().extension() == ".off") // see below - { - Points_off_reader off_reader(itr->path().string()); - Points_off_reader_cgal off_reader_cgal(itr->path().string()); - - Point p0 = off_reader.get_point_cloud()[0]; - - for (Filtration_value radius = 0.1; radius < 0.4; radius += 0.1) { - std::clog << itr->path().stem() << ";"; - std::clog << radius << ";"; - Gudhi::Clock rips_clock("Rips computation"); - Rips_complex rips_complex_from_points(off_reader.get_point_cloud(), radius, Gudhi::Euclidean_distance()); - Simplex_tree rips_stree; - rips_complex_from_points.create_complex(rips_stree, p0.size() - 1); - // ------------------------------------------ - // Display information about the Rips complex - // ------------------------------------------ - double rips_sec = rips_clock.num_seconds(); - std::clog << rips_sec << ";"; - - Gudhi::Clock cech_clock("Cech computation"); - Cech_complex cech_complex_from_points(off_reader_cgal.get_point_cloud(), radius); - Simplex_tree cech_stree; - cech_complex_from_points.create_complex(cech_stree, p0.size() - 1); - // ------------------------------------------ - // Display information about the Cech complex - // ------------------------------------------ - double cech_sec = cech_clock.num_seconds(); - std::clog << cech_sec << ";"; - std::clog << cech_sec / rips_sec << ";"; - - assert(rips_stree.num_simplices() >= cech_stree.num_simplices()); - std::clog << rips_stree.num_simplices() << ";"; - std::clog << cech_stree.num_simplices() << ";" << std::endl; + boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end + for (boost::filesystem::directory_iterator itr(boost::filesystem::current_path()); itr != end_itr; ++itr) { + if (!boost::filesystem::is_directory(itr->status())) { + if (itr->path().extension() == ".off") { + Points_off_reader off_reader(itr->path().string()); + Point p0 = off_reader.get_point_cloud()[0]; + + for (Filtration_value radius = 0.1; radius < 0.4; radius += 0.1) { + std::clog << itr->path().stem() << " ; "; + std::clog << radius << " ; "; + + Gudhi::Clock rips_clock("Rips computation"); + Rips_complex rips_complex_from_points(off_reader.get_point_cloud(), radius, Gudhi::Euclidean_distance()); + Simplex_tree rips_stree; + rips_complex_from_points.create_complex(rips_stree, p0.size() - 1); + // ------------------------------------------ + // Display information about the Rips complex + // ------------------------------------------ + double rips_sec = rips_clock.num_seconds(); + std::clog << rips_sec << " ; "; + + // -------------- + // Cech complex + // -------------- + benchmark_cech>>(itr->path().string(), radius, p0.size() - 1); + benchmark_cech>>(itr->path().string(), radius, p0.size() - 1); + + std::clog << rips_stree.num_simplices() << ";" << std::endl; + } + } } - } } - } - return 0; + return 0; } -- cgit v1.2.3