From 9e8db290ff0b3f69f88fa5ed54482bfb6730ad9b Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 14 Dec 2016 14:03:59 +0000 Subject: Improved the documentation for choose_farthest_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1869 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 08223b7d1788c73b0fb3fc7255a6386896b63626 --- .../include/gudhi/choose_n_farthest_points.h | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/Subsampling/include/gudhi') diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index 40c7808d..43bf6402 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -48,15 +48,27 @@ namespace subsampling { * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the * current chosen point set to the subsampling. * The iteration starts with the landmark `starting point`. + * \tparam Kernel must provide a type Kernel::Squared_distance_d which is a model of the + * concept Kernel_d::Squared_distance_d + * concept. + * \tparam Point_range Range whose value type is Kernel::Point_d. It must provide random-access + * via `operator[]` and the points should be stored contiguously in memory. + * \tparam OutputIterator Output iterator whose value type is Kernel::Point_d. * \details It chooses `final_size` points from a random access range `input_pts` and * outputs it in the output iterator `output_it`. + * @param[in] k A kernel object. + * @param[in] input_pts Const reference to the input points. + * @param[in] final_size The size of the subsample to compute. + * @param[in] starting_point The seed in the farthest point algorithm. + * @param[out] output_it The output iterator. * */ template < typename Kernel, -typename Point_container, +typename Point_range, typename OutputIterator> void choose_n_farthest_points(Kernel const &k, - Point_container const &input_pts, + Point_range const &input_pts, std::size_t final_size, std::size_t starting_point, OutputIterator output_it) { @@ -96,15 +108,26 @@ void choose_n_farthest_points(Kernel const &k, * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the * current chosen point set to the subsampling. * The iteration starts with a random landmark. + * \tparam Kernel must provide a type Kernel::Squared_distance_d which is a model of the + * concept Kernel_d::Squared_distance_d + * concept. + * \tparam Point_range Range whose value type is Kernel::Point_d. It must provide random-access + * via `operator[]` and the points should be stored contiguously in memory. + * \tparam OutputIterator Output iterator whose value type is Kernel::Point_d. * \details It chooses `final_size` points from a random access range `input_pts` and * outputs it in the output iterator `output_it`. + * @param[in] k A kernel object. + * @param[in] input_pts Const reference to the input points. + * @param[in] final_size The size of the subsample to compute. + * @param[out] output_it The output iterator. * */ template < typename Kernel, -typename Point_container, +typename Point_range, typename OutputIterator> void choose_n_farthest_points(Kernel const& k, - Point_container const &input_pts, + Point_range const &input_pts, unsigned final_size, OutputIterator output_it) { // Choose randomly the first landmark -- cgit v1.2.3 From 04f4501b35eaa2bd33393ef2445d038251ba1355 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 14 Dec 2016 18:08:09 +0000 Subject: Added an example with a distance matrix for the farthest point algorithm git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1874 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 340e465189dc7ec8f8706e60e2d8097b53bfd5a0 --- src/Subsampling/example/CMakeLists.txt | 1 + src/Subsampling/example/example_custom_kernel.cpp | 69 ++++++++++++++++++++++ .../include/gudhi/choose_n_farthest_points.h | 4 +- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/Subsampling/example/example_custom_kernel.cpp (limited to 'src/Subsampling/include/gudhi') diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 54349f0c..0fd3335c 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -6,6 +6,7 @@ if(CGAL_FOUND) if (EIGEN3_FOUND) add_executable(Subsampling_example_pick_n_random_points example_pick_n_random_points.cpp) add_executable(Subsampling_example_choose_n_farthest_points example_choose_n_farthest_points.cpp) + add_executable(Subsampling_example_custom_kernel example_custom_kernel.cpp) add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY}) diff --git a/src/Subsampling/example/example_custom_kernel.cpp b/src/Subsampling/example/example_custom_kernel.cpp new file mode 100644 index 00000000..05797ebe --- /dev/null +++ b/src/Subsampling/example/example_custom_kernel.cpp @@ -0,0 +1,69 @@ +#include + +#include +#include + +#include +#include + + +/* The class Kernel contains a distance function defined on the set of points {0,1,2,3} + * and computes a distance according to the matrix: + * 0 1 2 4 + * 1 0 4 2 + * 2 4 0 1 + * 4 2 1 0 + */ +class Kernel { +public: + typedef double FT; + typedef unsigned Point_d; + + // Class Squared_distance_d + class Squared_distance_d { + private: + std::vector> matrix_; + + public: + + Squared_distance_d() + { + matrix_.push_back(std::vector({0,1,2,4})); + matrix_.push_back(std::vector({1,0,4,2})); + matrix_.push_back(std::vector({2,4,0,1})); + matrix_.push_back(std::vector({4,2,1,0})); + } + + FT operator()(Point_d p1, Point_d p2) + { + return matrix_[p1][p2]; + } + }; + + // Constructor + Kernel() + {} + + // Object of type Squared_distance_d + Squared_distance_d squared_distance_d_object() const + { + return Squared_distance_d(); + } + +}; + +int main(void) { + typedef Kernel K; + typedef typename K::Point_d Point_d; + + K k; + std::vector points = {0,1,2,3}; + std::vector results; + + Gudhi::subsampling::choose_n_farthest_points(k, points, 2, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + std::cout << "Result table: {" << results[0] << "," << results[1] << "}\n"; + + return 0; +} diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index 43bf6402..b6b7ace3 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -52,6 +52,7 @@ namespace subsampling { * concept Kernel_d::Squared_distance_d * concept. + * It must also contain a public member 'squared_distance_d_object' of this type. * \tparam Point_range Range whose value type is Kernel::Point_d. It must provide random-access * via `operator[]` and the points should be stored contiguously in memory. * \tparam OutputIterator Output iterator whose value type is Kernel::Point_d. @@ -112,6 +113,7 @@ void choose_n_farthest_points(Kernel const &k, * concept Kernel_d::Squared_distance_d * concept. + * It must also contain a public member 'squared_distance_d_object' of this type. * \tparam Point_range Range whose value type is Kernel::Point_d. It must provide random-access * via `operator[]` and the points should be stored contiguously in memory. * \tparam OutputIterator Output iterator whose value type is Kernel::Point_d. @@ -133,7 +135,7 @@ void choose_n_farthest_points(Kernel const& k, // Choose randomly the first landmark std::random_device rd; std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 6); + std::uniform_int_distribution<> dis(0, final_size); int starting_point = dis(gen); choose_n_farthest_points(k, input_pts, final_size, starting_point, output_it); } -- cgit v1.2.3 From 66d5bb10fcbaf75962004dfa34d8f2b8d5d23c0a Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 15 Dec 2016 16:30:50 +0000 Subject: Modify random and limit tests cases git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1883 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 385f334f9358ae62c2ba6ec0d652ecfd52a052a7 --- .../include/gudhi/choose_n_farthest_points.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/Subsampling/include/gudhi') diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index b6b7ace3..ea387bf9 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -73,10 +73,15 @@ void choose_n_farthest_points(Kernel const &k, std::size_t final_size, std::size_t starting_point, OutputIterator output_it) { - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - std::size_t nb_points = boost::size(input_pts); - assert(nb_points >= final_size); + if (final_size > nb_points) + final_size = nb_points; + + // Tests to the limit + if (final_size < 1) + return; + + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); std::size_t current_number_of_landmarks = 0; // counter for landmarks const double infty = std::numeric_limits::infinity(); // infinity (see next entry) @@ -132,10 +137,14 @@ void choose_n_farthest_points(Kernel const& k, Point_range const &input_pts, unsigned final_size, OutputIterator output_it) { + // Tests to the limit + if ((final_size < 1) || (input_pts.size() == 0)) + return; + // Choose randomly the first landmark std::random_device rd; std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(0, final_size); + std::uniform_int_distribution<> dis(0, (input_pts.size() - 1)); int starting_point = dis(gen); choose_n_farthest_points(k, input_pts, final_size, starting_point, output_it); } -- cgit v1.2.3 From c8dbfc68cca3c5462226e5d953f721143fc645f0 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 16 Dec 2016 14:07:02 +0000 Subject: Fix cpplint and warnings git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@1902 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 24c5aacf579eb1ceb35c680770d5168524c4c84b --- .../include/gudhi/Persistent_cohomology.h | 3 +- .../test/betti_numbers_unit_test.cpp | 8 ++--- src/Subsampling/example/example_custom_kernel.cpp | 38 +++++++++------------- src/Subsampling/include/gudhi/sparsify_point_set.h | 2 -- src/common/include/gudhi/random_point_generators.h | 2 -- 5 files changed, 22 insertions(+), 31 deletions(-) (limited to 'src/Subsampling/include/gudhi') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index c3a1535a..681de8c6 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -699,12 +699,13 @@ class Persistent_cohomology { std::vector< std::pair< Filtration_value , Filtration_value > > result; // auto && pair, to avoid unnecessary copying for (auto && pair : persistent_pairs_) { - if (cpx_->dimension( get<0>(pair)) == dimension ) { + if (cpx_->dimension(get<0>(pair)) == dimension) { result.emplace_back(cpx_->filtration(get<0>(pair)), cpx_->filtration(get<1>(pair))); } } return result; } + private: /* * Structure representing a cocycle. diff --git a/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp b/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp index b98a3765..0ed3fddf 100644 --- a/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp +++ b/src/Persistent_cohomology/test/betti_numbers_unit_test.cpp @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE( plain_homology_betti_numbers ) auto intervals_in_dimension_0 = pcoh.intervals_in_dimension(0); std::cout << "intervals_in_dimension_0.size() = " << intervals_in_dimension_0.size() << std::endl; - for (int i = 0; i < intervals_in_dimension_0.size(); i++) + for (std::size_t i = 0; i < intervals_in_dimension_0.size(); i++) std::cout << "intervals_in_dimension_0[" << i << "] = [" << intervals_in_dimension_0[i].first << "," << intervals_in_dimension_0[i].second << "]" << std::endl; BOOST_CHECK(intervals_in_dimension_0.size() == 2); @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE( plain_homology_betti_numbers ) auto intervals_in_dimension_1 = pcoh.intervals_in_dimension(1); std::cout << "intervals_in_dimension_1.size() = " << intervals_in_dimension_1.size() << std::endl; - for (int i = 0; i < intervals_in_dimension_1.size(); i++) + for (std::size_t i = 0; i < intervals_in_dimension_1.size(); i++) std::cout << "intervals_in_dimension_1[" << i << "] = [" << intervals_in_dimension_1[i].first << "," << intervals_in_dimension_1[i].second << "]" << std::endl; BOOST_CHECK(intervals_in_dimension_1.size() == 1); @@ -267,7 +267,7 @@ BOOST_AUTO_TEST_CASE( betti_numbers ) auto intervals_in_dimension_0 = pcoh.intervals_in_dimension(0); std::cout << "intervals_in_dimension_0.size() = " << intervals_in_dimension_0.size() << std::endl; - for (int i = 0; i < intervals_in_dimension_0.size(); i++) + for (std::size_t i = 0; i < intervals_in_dimension_0.size(); i++) std::cout << "intervals_in_dimension_0[" << i << "] = [" << intervals_in_dimension_0[i].first << "," << intervals_in_dimension_0[i].second << "]" << std::endl; BOOST_CHECK(intervals_in_dimension_0.size() == 2); @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE( betti_numbers ) auto intervals_in_dimension_1 = pcoh.intervals_in_dimension(1); std::cout << "intervals_in_dimension_1.size() = " << intervals_in_dimension_1.size() << std::endl; - for (int i = 0; i < intervals_in_dimension_1.size(); i++) + for (std::size_t i = 0; i < intervals_in_dimension_1.size(); i++) std::cout << "intervals_in_dimension_1[" << i << "] = [" << intervals_in_dimension_1[i].first << "," << intervals_in_dimension_1[i].second << "]" << std::endl; BOOST_CHECK(intervals_in_dimension_1.size() == 1); diff --git a/src/Subsampling/example/example_custom_kernel.cpp b/src/Subsampling/example/example_custom_kernel.cpp index 05797ebe..f87ef0b3 100644 --- a/src/Subsampling/example/example_custom_kernel.cpp +++ b/src/Subsampling/example/example_custom_kernel.cpp @@ -7,7 +7,7 @@ #include -/* The class Kernel contains a distance function defined on the set of points {0,1,2,3} +/* The class Kernel contains a distance function defined on the set of points {0, 1, 2, 3} * and computes a distance according to the matrix: * 0 1 2 4 * 1 0 4 2 @@ -15,41 +15,35 @@ * 4 2 1 0 */ class Kernel { -public: + public: typedef double FT; typedef unsigned Point_d; // Class Squared_distance_d class Squared_distance_d { - private: + private: std::vector> matrix_; - - public: - Squared_distance_d() - { - matrix_.push_back(std::vector({0,1,2,4})); - matrix_.push_back(std::vector({1,0,4,2})); - matrix_.push_back(std::vector({2,4,0,1})); - matrix_.push_back(std::vector({4,2,1,0})); - } - - FT operator()(Point_d p1, Point_d p2) - { + public: + Squared_distance_d() { + matrix_.push_back(std::vector({0,1,2,4})); + matrix_.push_back(std::vector({1,0,4,2})); + matrix_.push_back(std::vector({2,4,0,1})); + matrix_.push_back(std::vector({4,2,1,0})); + } + + FT operator()(Point_d p1, Point_d p2) { return matrix_[p1][p2]; } }; // Constructor - Kernel() - {} + Kernel() {} // Object of type Squared_distance_d - Squared_distance_d squared_distance_d_object() const - { + Squared_distance_d squared_distance_d_object() const { return Squared_distance_d(); } - }; int main(void) { @@ -57,9 +51,9 @@ int main(void) { typedef typename K::Point_d Point_d; K k; - std::vector points = {0,1,2,3}; + std::vector points = {0, 1, 2, 3}; std::vector results; - + Gudhi::subsampling::choose_n_farthest_points(k, points, 2, std::back_inserter(results)); std::cout << "Before sparsification: " << points.size() << " points.\n"; std::cout << "After sparsification: " << results.size() << " points.\n"; diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index 7ff11b4c..507f8c79 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -64,8 +64,6 @@ sparsify_point_set( typedef typename Gudhi::spatial_searching::Kd_tree_search< Kernel, Point_range> Points_ds; - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - #ifdef GUDHI_SUBSAMPLING_PROFILING Gudhi::Clock t; #endif diff --git a/src/common/include/gudhi/random_point_generators.h b/src/common/include/gudhi/random_point_generators.h index 3050b7ea..c643a1e3 100644 --- a/src/common/include/gudhi/random_point_generators.h +++ b/src/common/include/gudhi/random_point_generators.h @@ -338,8 +338,6 @@ std::vector generate_points_on_3sphere_and_circle(std: std::vector points; points.reserve(num_points); - typename Kernel::Translated_point_d k_transl = - k.translated_point_d_object(); typename Kernel::Compute_coordinate_d k_coord = k.compute_coordinate_d_object(); for (std::size_t i = 0; i < num_points;) { -- cgit v1.2.3 From de0bdf55c16de11d47809dc6f347773b10cc3673 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 16 Dec 2016 16:11:45 +0000 Subject: Warning fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@1905 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7b7222ebe65fd01fde30f8ba527ebaee633fc87e --- src/Contraction/example/Garland_heckbert.cpp | 12 ++--- src/GudhUI/utils/Critical_points.h | 2 - src/GudhUI/utils/Is_manifold.h | 1 - src/GudhUI/utils/Vertex_collapsor.h | 1 - .../include/gudhi/choose_n_farthest_points.h | 3 +- .../include/gudhi/pick_n_random_points.h | 4 +- .../test/test_choose_n_farthest_points.cpp | 55 ++++++++++++++++++++-- .../include/gudhi/Tangential_complex.h | 10 +--- .../test/test_tangential_complex.cpp | 2 - src/common/include/gudhi/random_point_generators.h | 7 ++- 10 files changed, 63 insertions(+), 34 deletions(-) (limited to 'src/Subsampling/include/gudhi') diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index 5347830c..4689519f 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -63,12 +63,10 @@ typedef Skeleton_blocker_contractor Complex_contractor; * the point minimizing the cost of the quadric. */ class GH_placement : public Gudhi::contraction::Placement_policy { - Complex& complex_; - public: typedef Gudhi::contraction::Placement_policy::Placement_type Placement_type; - GH_placement(Complex& complex) : complex_(complex) { } + GH_placement(Complex& complex) { } Placement_type operator()(const EdgeProfile& profile) const override { auto sum_quad(profile.v0().quadric); @@ -87,12 +85,10 @@ class GH_placement : public Gudhi::contraction::Placement_policy { * which expresses a squared distances with triangles planes. */ class GH_cost : public Gudhi::contraction::Cost_policy { - Complex& complex_; - public: typedef Gudhi::contraction::Cost_policy::Cost_type Cost_type; - GH_cost(Complex& complex) : complex_(complex) { } + GH_cost(Complex& complex) { } Cost_type operator()(EdgeProfile const& profile, boost::optional const& new_point) const override { Cost_type res; @@ -111,10 +107,8 @@ class GH_cost : public Gudhi::contraction::Cost_policy { * and we update them when contracting an edge (the quadric become the sum of both quadrics). */ class GH_visitor : public Gudhi::contraction::Contraction_visitor { - Complex& complex_; - public: - GH_visitor(Complex& complex) : complex_(complex) { } + GH_visitor(Complex& complex) { } // Compute quadrics for every vertex v // The quadric of v consists in the sum of quadric diff --git a/src/GudhUI/utils/Critical_points.h b/src/GudhUI/utils/Critical_points.h index 3021a5fe..b88293e9 100644 --- a/src/GudhUI/utils/Critical_points.h +++ b/src/GudhUI/utils/Critical_points.h @@ -105,8 +105,6 @@ template class Critical_points { if (link.empty()) return 0; - Edge_contractor contractor(link, link.num_vertices() - 1); - if (link.num_connected_components() > 1) // one than more CC -> not contractible return 0; diff --git a/src/GudhUI/utils/Is_manifold.h b/src/GudhUI/utils/Is_manifold.h index 0640ea47..6dd7898e 100644 --- a/src/GudhUI/utils/Is_manifold.h +++ b/src/GudhUI/utils/Is_manifold.h @@ -76,7 +76,6 @@ template class Is_manifold { bool is_k_sphere(Vertex_handle v, int k) { auto link = input_complex_.link(v); - Edge_contractor contractor(link, link.num_vertices() - 1); return (is_sphere_simplex(link) == k); } diff --git a/src/GudhUI/utils/Vertex_collapsor.h b/src/GudhUI/utils/Vertex_collapsor.h index 2b36cb3a..3f0e7ffd 100644 --- a/src/GudhUI/utils/Vertex_collapsor.h +++ b/src/GudhUI/utils/Vertex_collapsor.h @@ -80,7 +80,6 @@ template class Vertex_collapsor { if (link.empty()) return false; if (link.is_cone()) return true; if (link.num_connected_components() > 1) return false; - Edge_contractor contractor(link, link.num_vertices() - 1); return (link.num_vertices() == 1); } }; diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index ea387bf9..5e908090 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -145,7 +145,8 @@ void choose_n_farthest_points(Kernel const& k, std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> dis(0, (input_pts.size() - 1)); - int starting_point = dis(gen); + std::size_t starting_point = dis(gen); + choose_n_farthest_points(k, input_pts, final_size, starting_point, output_it); } diff --git a/src/Subsampling/include/gudhi/pick_n_random_points.h b/src/Subsampling/include/gudhi/pick_n_random_points.h index e89b2b2d..f0e3f1f1 100644 --- a/src/Subsampling/include/gudhi/pick_n_random_points.h +++ b/src/Subsampling/include/gudhi/pick_n_random_points.h @@ -57,7 +57,9 @@ void pick_n_random_points(Point_container const &points, #endif std::size_t nbP = boost::size(points); - assert(nbP >= final_size); + if (final_size > nbP) + final_size = nbP; + std::vector landmarks(nbP); std::iota(landmarks.begin(), landmarks.end(), 0); diff --git a/src/Subsampling/test/test_choose_n_farthest_points.cpp b/src/Subsampling/test/test_choose_n_farthest_points.cpp index d064899a..0bc0dff4 100644 --- a/src/Subsampling/test/test_choose_n_farthest_points.cpp +++ b/src/Subsampling/test/test_choose_n_farthest_points.cpp @@ -39,18 +39,65 @@ typedef CGAL::Epick_d K; typedef typename K::FT FT; typedef typename K::Point_d Point_d; -BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { +typedef boost::mpl::list, CGAL::Epick_d>> list_of_tested_kernels; + +BOOST_AUTO_TEST_CASE_TEMPLATE(test_choose_farthest_point, Kernel, list_of_tested_kernels) { + typedef typename Kernel::FT FT; + typedef typename Kernel::Point_d Point_d; std::vector< Point_d > points, landmarks; // Add grid points (625 points) for (FT i = 0; i < 5; i += 1.0) for (FT j = 0; j < 5; j += 1.0) for (FT k = 0; k < 5; k += 1.0) - for (FT l = 0; l < 5; l += 1.0) - points.push_back(Point_d(std::vector({i, j, k, l}))); + for (FT l = 0; l < 5; l += 1.0) { + std::vector point({i, j, k, l}); + points.push_back(Point_d(point.begin(), point.end())); + } landmarks.clear(); - K k; + Kernel k; Gudhi::subsampling::choose_n_farthest_points(k, points, 100, std::back_inserter(landmarks)); BOOST_CHECK(landmarks.size() == 100); + for (auto landmark : landmarks) + { + // Check all landmarks are in points + BOOST_CHECK(std::find (points.begin(), points.end(), landmark) != points.end()); + } +} + +BOOST_AUTO_TEST_CASE_TEMPLATE(test_choose_farthest_point_limits, Kernel, list_of_tested_kernels) { + typedef typename Kernel::FT FT; + typedef typename Kernel::Point_d Point_d; + std::vector< Point_d > points, landmarks; + landmarks.clear(); + Kernel k; + // Choose -1 farthest points in an empty point cloud + Gudhi::subsampling::choose_n_farthest_points(k, points, -1, std::back_inserter(landmarks)); + BOOST_CHECK(landmarks.size() == 0); + landmarks.clear(); + // Choose 0 farthest points in an empty point cloud + Gudhi::subsampling::choose_n_farthest_points(k, points, 0, std::back_inserter(landmarks)); + BOOST_CHECK(landmarks.size() == 0); + landmarks.clear(); + // Choose 1 farthest points in an empty point cloud + Gudhi::subsampling::choose_n_farthest_points(k, points, 1, std::back_inserter(landmarks)); + BOOST_CHECK(landmarks.size() == 0); + landmarks.clear(); + + std::vector point({0.0, 0.0, 0.0, 0.0}); + points.push_back(Point_d(point.begin(), point.end())); + // Choose -1 farthest points in an empty point cloud + Gudhi::subsampling::choose_n_farthest_points(k, points, -1, std::back_inserter(landmarks)); + BOOST_CHECK(landmarks.size() == 1); + landmarks.clear(); + // Choose 0 farthest points in a one point cloud + Gudhi::subsampling::choose_n_farthest_points(k, points, 0, std::back_inserter(landmarks)); + BOOST_CHECK(landmarks.size() == 0); + landmarks.clear(); + // Choose 1 farthest points in a one point cloud + Gudhi::subsampling::choose_n_farthest_points(k, points, 1, std::back_inserter(landmarks)); + BOOST_CHECK(landmarks.size() == 1); + landmarks.clear(); + } diff --git a/src/Tangential_complex/include/gudhi/Tangential_complex.h b/src/Tangential_complex/include/gudhi/Tangential_complex.h index 65de2743..cfc82eb1 100644 --- a/src/Tangential_complex/include/gudhi/Tangential_complex.h +++ b/src/Tangential_complex/include/gudhi/Tangential_complex.h @@ -1314,14 +1314,6 @@ class Tangential_complex { m_k.construct_vector_d_object(); typename K::Compute_coordinate_d coord = m_k.compute_coordinate_d_object(); - typename K::Squared_length_d sqlen = - m_k.squared_length_d_object(); - typename K::Scaled_vector_d scaled_vec = - m_k.scaled_vector_d_object(); - typename K::Scalar_product_d scalar_pdct = - m_k.scalar_product_d_object(); - typename K::Difference_of_vectors_d diff_vec = - m_k.difference_of_vectors_d_object(); #ifdef GUDHI_TC_USE_ANOTHER_POINT_SET_FOR_TANGENT_SPACE_ESTIM KNS_range kns_range = m_points_ds_for_tse.query_k_nearest_neighbors( @@ -2159,7 +2151,7 @@ class Tangential_complex { typedef std::vector Triangles; Triangles triangles; - std::size_t num_vertices = c.size(); + int num_vertices = static_cast(c.size()); // Do not export smaller dimension simplices if (num_vertices < m_intrinsic_dim + 1) continue; diff --git a/src/Tangential_complex/test/test_tangential_complex.cpp b/src/Tangential_complex/test/test_tangential_complex.cpp index ebe5cdb4..48156440 100644 --- a/src/Tangential_complex/test/test_tangential_complex.cpp +++ b/src/Tangential_complex/test/test_tangential_complex.cpp @@ -71,9 +71,7 @@ BOOST_AUTO_TEST_CASE(test_Spatial_tree_data_structure) { BOOST_AUTO_TEST_CASE(test_mini_tangential) { typedef CGAL::Epick_d Kernel; - typedef Kernel::FT FT; typedef Kernel::Point_d Point; - typedef Kernel::Vector_d Vector; typedef tc::Tangential_complex TC; diff --git a/src/common/include/gudhi/random_point_generators.h b/src/common/include/gudhi/random_point_generators.h index c643a1e3..2ec465ef 100644 --- a/src/common/include/gudhi/random_point_generators.h +++ b/src/common/include/gudhi/random_point_generators.h @@ -192,10 +192,9 @@ static void generate_uniform_points_on_torus_d(const Kernel &k, int dim, std::si double radius_noise_percentage = 0., std::vector current_point = std::vector()) { CGAL::Random rng; - if (current_point.size() == 2 * dim) { - *out++ = k.construct_point_d_object()( - static_cast (current_point.size()), - current_point.begin(), current_point.end()); + int point_size = static_cast(current_point.size()); + if (point_size == 2 * dim) { + *out++ = k.construct_point_d_object()(point_size, current_point.begin(), current_point.end()); } else { for (std::size_t slice_idx = 0; slice_idx < num_slices; ++slice_idx) { double radius_noise_ratio = 1.; -- cgit v1.2.3