diff options
author | MathieuCarriere <mathieu.carriere3@gmail.com> | 2022-06-24 15:06:52 +0200 |
---|---|---|
committer | MathieuCarriere <mathieu.carriere3@gmail.com> | 2022-06-24 15:06:52 +0200 |
commit | b93fbe5e7c246a6ee23a8686f9b5983624a6ab42 (patch) | |
tree | 2f769cf245c5f1300bd5897382a6d0b9697fafe9 /src/Cech_complex/benchmark/cech_complex_benchmark.cpp | |
parent | e0f359c4386a1f8cb24045c02c4ed96fb919dd4d (diff) | |
parent | 9fc4f5e2ba50287979fc6e56708ec469d29c968c (diff) |
Merge branch 'master' of https://github.com/GUDHI/gudhi-devel into diff
Diffstat (limited to 'src/Cech_complex/benchmark/cech_complex_benchmark.cpp')
-rw-r--r-- | src/Cech_complex/benchmark/cech_complex_benchmark.cpp | 169 |
1 files changed, 72 insertions, 97 deletions
diff --git a/src/Cech_complex/benchmark/cech_complex_benchmark.cpp b/src/Cech_complex/benchmark/cech_complex_benchmark.cpp index 2e4adce4..a9dc5d0d 100644 --- a/src/Cech_complex/benchmark/cech_complex_benchmark.cpp +++ b/src/Cech_complex/benchmark/cech_complex_benchmark.cpp @@ -10,12 +10,13 @@ #include <gudhi/Points_off_io.h> #include <gudhi/distance_functions.h> -#include <gudhi/graph_simplicial_complex.h> #include <gudhi/Clock.h> #include <gudhi/Rips_complex.h> #include <gudhi/Cech_complex.h> #include <gudhi/Simplex_tree.h> -#include <gudhi/Miniball.hpp> + +#include <CGAL/Epick_d.h> +#include <CGAL/Epeck_d.h> #include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations @@ -26,107 +27,81 @@ using Simplex_tree = Gudhi::Simplex_tree<>; using Filtration_value = Simplex_tree::Filtration_value; using Point = std::vector<Filtration_value>; -using Point_cloud = std::vector<Point>; using Points_off_reader = Gudhi::Points_off_reader<Point>; -using Proximity_graph = Gudhi::Proximity_graph<Simplex_tree>; using Rips_complex = Gudhi::rips_complex::Rips_complex<Filtration_value>; -using Cech_complex = Gudhi::cech_complex::Cech_complex<Simplex_tree, Point_cloud>; - -class Minimal_enclosing_ball_radius { - public: - // boost::range_value is not SFINAE-friendly so we cannot use it in the return type - template <typename Point> - typename std::iterator_traits<typename boost::range_iterator<Point>::type>::value_type operator()( - const Point& p1, const Point& p2) const { - // Type def - using Point_cloud = std::vector<Point>; - using Point_iterator = typename Point_cloud::const_iterator; - using Coordinate_iterator = typename Point::const_iterator; - using Min_sphere = - typename Gudhi::Miniball::Miniball<Gudhi::Miniball::CoordAccessor<Point_iterator, Coordinate_iterator>>; - - Point_cloud point_cloud; - point_cloud.push_back(p1); - point_cloud.push_back(p2); - - GUDHI_CHECK((p1.end() - p1.begin()) == (p2.end() - p2.begin()), "inconsistent point dimensions"); - Min_sphere min_sphere(p1.end() - p1.begin(), point_cloud.begin(), point_cloud.end()); - return std::sqrt(min_sphere.squared_radius()); - } -}; +template<typename Kernel> +Simplex_tree benchmark_cech(const std::string& off_file_points, const Filtration_value& radius, const int& dim_max, const bool exact) { + using Point_cgal = typename Kernel::Point_d; + using Points_off_reader_cgal = Gudhi::Points_off_reader<Point_cgal>; + using Cech_complex = Gudhi::cech_complex::Cech_complex<Kernel, Simplex_tree>; + + // 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, exact); + + // ------------------------------------------ + // Display information about the Cech complex + // ------------------------------------------ + double cech_sec = cech_clock.num_seconds(); + std::clog << cech_sec << " ; "; + return cech_stree; +} int main(int argc, char* argv[]) { - std::string off_file_points = "tore3D_1307.off"; - Filtration_value threshold = 1e20; - - // Extract the points from the file filepoints - Points_off_reader off_reader(off_file_points); - - Gudhi::Clock euclidean_clock("Gudhi::Euclidean_distance"); - // Compute the proximity graph of the points - Proximity_graph euclidean_prox_graph = Gudhi::compute_proximity_graph<Simplex_tree>( - off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); - - std::clog << euclidean_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<Simplex_tree>( - off_reader.get_point_cloud(), threshold, Minimal_enclosing_ball_radius()); - std::clog << miniball_clock << std::endl; - - Gudhi::Clock common_miniball_clock("Gudhi::Minimal_enclosing_ball_radius()"); - // Compute the proximity graph of the points - Proximity_graph common_miniball_prox_graph = Gudhi::compute_proximity_graph<Simplex_tree>( - off_reader.get_point_cloud(), threshold, Gudhi::Minimal_enclosing_ball_radius()); - std::clog << common_miniball_clock << 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::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()); - 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::Minimal_enclosing_ball_radius()); - 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.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::path full_path(boost::filesystem::current_path()); + std::clog << "Current path is : " << full_path << std::endl; + + std::clog << "File name ; Radius ; Rips time ; Dim-3 Fast Cech time ; Dynamic_dim Fast Cech time ; " + "Dim-3 Safe Cech time ; Dynamic_dim Safe Cech time ; Dim-3 Exact Cech time ; Dynamic_dim Exact Cech time ; " + "Cech nb simplices ; Rips nb simplices;" + << std::endl; + boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end + // For every ".off" file in the current directory, and for 3 predefined thresholds, compare Rips and various Cech constructions + 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]; + // Loop over the different thresholds + for (Filtration_value radius = 0.1; radius < 0.35; 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; + int dim_max = p0.size() - 1; + rips_complex_from_points.create_complex(rips_stree, dim_max); + // ------------------------------------------ + // Display information about the Rips complex + // ------------------------------------------ + double rips_sec = rips_clock.num_seconds(); + std::clog << rips_sec << " ; "; + + // -------------- + // Cech complex + // -------------- + // Fast + benchmark_cech<CGAL::Epick_d<CGAL::Dimension_tag<3>>>(itr->path().string(), radius, dim_max, false); + benchmark_cech<CGAL::Epick_d<CGAL::Dynamic_dimension_tag>>(itr->path().string(), radius, dim_max, false); + // Safe + benchmark_cech<CGAL::Epeck_d<CGAL::Dimension_tag<3>>>(itr->path().string(), radius, dim_max, false); + benchmark_cech<CGAL::Epeck_d<CGAL::Dynamic_dimension_tag>>(itr->path().string(), radius, dim_max, false); + // Exact + benchmark_cech<CGAL::Epeck_d<CGAL::Dimension_tag<3>>>(itr->path().string(), radius, dim_max, true); + auto cech_stree = benchmark_cech<CGAL::Epeck_d<CGAL::Dynamic_dimension_tag>>(itr->path().string(), radius, dim_max, true); + + std::clog << cech_stree.num_simplices() << " ; "; + std::clog << rips_stree.num_simplices() << ";" << std::endl; + } + } } - } } - } - return 0; + return 0; } |