From 37fab7af9e25e4a6eb20542bd591d680f5e363b2 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 24 Jun 2016 12:25:52 +0000 Subject: Doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1335 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 67d3d81e429cf62b0fd0755cd3f8c3d81ad2c1b6 --- src/Subsampling/doc/Intro_subsampling.h | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Subsampling/doc/Intro_subsampling.h (limited to 'src/Subsampling/doc/Intro_subsampling.h') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h new file mode 100644 index 00000000..658a45ed --- /dev/null +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -0,0 +1,58 @@ +/* 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): Clement Jamin + * + * Copyright (C) 2016 INRIA + * + * 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 . + */ + +#ifndef DOC_SUBSAMPLING_INTRO_SUBSAMPLING_H_ +#define DOC_SUBSAMPLING_INTRO_SUBSAMPLING_H_ + +// needs namespace for Doxygen to link on classes +namespace Gudhi { +// needs namespace for Doxygen to link on classes +namespace subsampling { + +/** \defgroup subsampling Subsampling + * + * \author Clément Jamin, Siargey Kachanovich + * + * @{ + * + * \section introduction Introduction + * + * This Gudhi component offers methods to subsample a set of points. + * + * \section sparsifyexamples Example: `sparsify_point_set` + * + * This example Outputs a subset of the input points so that the + * squared distance between any two points + * is greater than or equal to 0.4. + * + * \include Subsampling/example_sparsify_point_set.cpp + * + * \copyright GNU General Public License v3. + * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim + */ +/** @} */ // end defgroup subsampling + +} // namespace subsampling + +} // namespace Gudhi + +#endif // DOC_SUBSAMPLING_INTRO_SUBSAMPLING_H_ -- cgit v1.2.3 From 9eaa65136751ab3362c13455163187bd60e7a1aa Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 24 Jun 2016 12:42:11 +0000 Subject: Fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1337 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e2b4d4c10b9daacab7841cc6c1c85473ec15c979 --- src/Subsampling/doc/Intro_subsampling.h | 6 +++--- .../example/example_sparsify_point_set.cpp | 22 ---------------------- 2 files changed, 3 insertions(+), 25 deletions(-) (limited to 'src/Subsampling/doc/Intro_subsampling.h') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index 658a45ed..e62ebc61 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -30,7 +30,7 @@ namespace subsampling { /** \defgroup subsampling Subsampling * - * \author Clément Jamin, Siargey Kachanovich + * \author Clément Jamin, Siargey Kachanovich * * @{ * @@ -38,9 +38,9 @@ namespace subsampling { * * This Gudhi component offers methods to subsample a set of points. * - * \section sparsifyexamples Example: `sparsify_point_set` + * \section sparsifyexamples Example: sparsify_point_set * - * This example Outputs a subset of the input points so that the + * This example outputs a subset of the input points so that the * squared distance between any two points * is greater than or equal to 0.4. * diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index 57171082..cb5ccf0b 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -1,25 +1,3 @@ -/* 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): Clement Jamin - * - * Copyright (C) 2016 INRIA - * - * 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 -- cgit v1.2.3 From 96b7e2ec76b94aa8d609c816f3adab63f0b6caa9 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 24 Jun 2016 14:08:26 +0000 Subject: Removed headers in the examples git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1339 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 835003033dc15ce8fd2d8efdc7bfdf3e0be7760d --- src/Subsampling/doc/Intro_subsampling.h | 7 ++ .../example/example_choose_by_farthest_point.cpp | 23 ----- .../example/example_pick_random_points.cpp | 23 ----- .../include/gudhi/choose_by_farthest_point.h | 102 ++++----------------- .../test/test_choose_farthest_point.cpp | 65 +++---------- 5 files changed, 38 insertions(+), 182 deletions(-) (limited to 'src/Subsampling/doc/Intro_subsampling.h') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index e62ebc61..5ccab3af 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -46,6 +46,13 @@ namespace subsampling { * * \include Subsampling/example_sparsify_point_set.cpp * + * \section farthestpointexamples Example: choose_by_farthest_point + * + * This example outputs a subset of 100 points obtained by González algorithm, + * starting with a random point. + * + * \include Subsampling/example_choose_by_farthest_point.cpp + * * \copyright GNU General Public License v3. * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim */ diff --git a/src/Subsampling/example/example_choose_by_farthest_point.cpp b/src/Subsampling/example/example_choose_by_farthest_point.cpp index 5b81bc9d..29ecbf9b 100644 --- a/src/Subsampling/example/example_choose_by_farthest_point.cpp +++ b/src/Subsampling/example/example_choose_by_farthest_point.cpp @@ -1,26 +1,3 @@ -/* 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): Siargey Kachanovich - * - * Copyright (C) 2016 INRIA - * - * 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 diff --git a/src/Subsampling/example/example_pick_random_points.cpp b/src/Subsampling/example/example_pick_random_points.cpp index 49a027a4..348b1b81 100644 --- a/src/Subsampling/example/example_pick_random_points.cpp +++ b/src/Subsampling/example/example_pick_random_points.cpp @@ -1,26 +1,3 @@ -/* 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): Siargey Kachanovich - * - * Copyright (C) 2016 INRIA - * - * 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 diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index d1db0d1a..8dea19be 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -45,6 +45,7 @@ namespace subsampling { * \ingroup 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`. * \details It chooses `final_size` points from a random access range `points` and * outputs it in the output iterator `output_it`. * @@ -53,11 +54,11 @@ namespace subsampling { template < typename Kernel, typename Point_container, typename OutputIterator> - void choose_by_farthest_point_old( Kernel& k, - Point_container const &points, - int final_size, - int starting_point, - OutputIterator output_it) + void choose_by_farthest_point( Kernel& k, + Point_container const &points, + int final_size, + int starting_point, + OutputIterator output_it) { typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); @@ -92,101 +93,30 @@ namespace subsampling { } } - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_by_farthest_point_old( Kernel& k, - Point_container const &points, - int final_size, - OutputIterator output_it) - { - // Choose randomly the first landmark - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 6); - int starting_point = dis(gen); - choose_by_farthest_point_old(k, points, final_size, starting_point, output_it); - } - + /** + * \ingroup 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 a random landmark. + * \details It chooses `final_size` points from a random access range `points` and + * outputs it in the output iterator `output_it`. + * + */ template < typename Kernel, typename Point_container, typename OutputIterator> void choose_by_farthest_point( Kernel& k, Point_container const &points, int final_size, - int starting_point, OutputIterator output_it) { - // typedef typename Kernel::Point_d Point_d; - // typedef typename Kernel::FT FT; - // typedef CGAL::Search_traits< - // FT, Point_d, - // typename Kernel::Cartesian_const_iterator_d, - // typename Kernel::Construct_cartesian_const_iterator_d> Traits_base; - - // typedef CGAL::Search_traits_adapter< std::ptrdiff_t, Point_d*, Traits_base > STraits; - // typedef CGAL::Fuzzy_sphere< STraits > Fuzzy_sphere; - - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - - int nb_points = boost::size(points); - assert(nb_points >= final_size); - - Clock t; - Gudhi::spatial_searching::Spatial_tree_data_structure< Kernel, Point_container> tree(points); - t.end(); - //std::cout << "Constructed the Kd tree: " << t.num_seconds() << " s." << std::endl; - - //CGAL::Fuzzy_sphere< CGAL::Search_trai> - - int current_number_of_landmarks = 0; // counter for landmarks - const double infty = std::numeric_limits::infinity(); // infinity (see next entry) - double curr_max_dist = infty; // used for defining the furhest point from L - std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from points - - // Choose randomly the first landmark - int curr_max_w = starting_point; - - for (current_number_of_landmarks = 0; current_number_of_landmarks != final_size; current_number_of_landmarks++) { - // curr_max_w at this point is the next landmark - *output_it++ = points[curr_max_w]; - // std::cout << curr_max_w << "\n"; - //for (auto& p : points) { - auto search = tree.query_incremental_ANN(points[curr_max_w]); - auto search_it = search.begin(); - while (search_it != search.end() && search_it->second <= curr_max_dist ) { - //std::cout << search_it->second << " " << curr_max_dist << "\n"; - if (dist_to_L[search_it->first] > search_it->second) - dist_to_L[search_it->first] = search_it->second; - search_it++; - } - // choose the next curr_max_w - curr_max_dist = 0; - for (unsigned i = 0; i < dist_to_L.size(); i++) - if (dist_to_L[i] > curr_max_dist) { - curr_max_dist = dist_to_L[i]; - curr_max_w = i; - } - } - } - - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_by_farthest_point( Kernel& k, - Point_container const &points, - int final_size, - OutputIterator output_it) - { // Choose randomly the first landmark std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> dis(1, 6); int starting_point = dis(gen); - - choose_by_farthest_point_old(k, points, final_size, starting_point, output_it); + choose_by_farthest_point(k, points, final_size, starting_point, output_it); } - } // namespace subsampling diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index dff2cd4e..5f705de6 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -24,15 +24,14 @@ // # define TBB_USE_THREADING_TOOL // #endif -// #define BOOST_TEST_DYN_LINK -// #define BOOST_TEST_MODULE "test_choose_farthest_point" -//#include -//#include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "witness_complex_points" +#include +#include #include #include #include -#include #include @@ -41,52 +40,18 @@ typedef typename K::FT FT; typedef typename K::Point_d Point_d; -//BOOST_AUTO_TEST_CASE(test_choose_farthest_point) -int main() { - std::vector< Point_d > points, results, results2; - K k; - Clock t; - // Add grid points (810000 points) - for (FT i = 0; i < 30; i += 1.0) - for (FT j = 0; j < 30; j += 1.0) - for (FT k = 0; k < 30; k += 1.0) - for (FT l = 0; l < 30; l += 1.0) +BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { + 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}))); - unsigned final_size = 100, numeral = 1; - std::cout << "Test New Old\n"; - while (final_size < 100001) { - std::cout << final_size << ": "; - results.clear(); - t.begin(); - Gudhi::subsampling::choose_by_farthest_point(k, points, final_size, 0, std::back_inserter(results)); - t.end(); - std::cout << t.num_seconds() << " s, "; - - // std::cout << "New algorithm result:\n"; - // for (auto p: results) - // std::cout << p << std::endl; - - results2.clear(); - t.begin(); - Gudhi::subsampling::choose_by_farthest_point_old(k, points, final_size, 0, std::back_inserter(results2)); - t.end(); - std::cout << t.num_seconds() << " s" << std::endl; - - - // std::cout << "Old algorithm result:\n"; - // for (auto p: results2) - // std::cout << p << std::endl; + landmarks.clear(); + K k; + Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); - assert(results.size() == final_size); - assert(results2.size() == final_size); - assert(results == results2); - - switch (numeral) { - case 1: numeral = 2; final_size *= 2; break; - case 2: numeral = 5; final_size = final_size/2*5; break; - case 5: numeral = 1; final_size *= 2; break; - default: assert(false); - } - } + assert(landmarks.size() == 100); } -- cgit v1.2.3 From 6cdf1246015e1ce8c87a938f7fb2ccde787e5d4c Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 5 Aug 2016 08:30:29 +0000 Subject: Added the random_pick_example to the doc intro git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1417 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 19f7562d5c499f2967e371610067ba0e1c74306c --- src/Subsampling/doc/Intro_subsampling.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/Subsampling/doc/Intro_subsampling.h') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index 5ccab3af..aed41430 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -53,6 +53,11 @@ namespace subsampling { * * \include Subsampling/example_choose_by_farthest_point.cpp * + * \section randompointexamples Example: pick_random_points + * + * This example outputs a subset of 100 points picked randomly. + * + * \include Subsampling/example_pick_random_points.cpp * \copyright GNU General Public License v3. * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim */ -- cgit v1.2.3 From 6ad5ac6794ebc46638cd1f0862a553f40d2557d7 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 20 Sep 2016 16:14:38 +0000 Subject: Renamed pick_random_points -> pick_n_random_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1516 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 45cc8cca9debf56dd0d21762e537649dd92d9a4d --- src/Subsampling/doc/Intro_subsampling.h | 4 +- src/Subsampling/example/CMakeLists.txt | 2 +- .../example/example_pick_n_random_points.cpp | 29 ++++++++ .../example/example_pick_random_points.cpp | 29 -------- .../include/gudhi/pick_n_random_points.h | 82 ++++++++++++++++++++++ src/Subsampling/include/gudhi/pick_random_points.h | 82 ---------------------- src/Subsampling/test/CMakeLists.txt | 4 +- src/Subsampling/test/test_pick_n_random_points.cpp | 69 ++++++++++++++++++ src/Subsampling/test/test_pick_random_points.cpp | 69 ------------------ .../example/witness_complex_from_file.cpp | 4 +- .../example/witness_complex_sphere.cpp | 4 +- .../test/witness_complex_points.cpp | 4 +- 12 files changed, 191 insertions(+), 191 deletions(-) create mode 100644 src/Subsampling/example/example_pick_n_random_points.cpp delete mode 100644 src/Subsampling/example/example_pick_random_points.cpp create mode 100644 src/Subsampling/include/gudhi/pick_n_random_points.h delete mode 100644 src/Subsampling/include/gudhi/pick_random_points.h create mode 100644 src/Subsampling/test/test_pick_n_random_points.cpp delete mode 100644 src/Subsampling/test/test_pick_random_points.cpp (limited to 'src/Subsampling/doc/Intro_subsampling.h') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index aed41430..06aee2fc 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -53,11 +53,11 @@ namespace subsampling { * * \include Subsampling/example_choose_by_farthest_point.cpp * - * \section randompointexamples Example: pick_random_points + * \section randompointexamples Example: pick_n_random_points * * This example outputs a subset of 100 points picked randomly. * - * \include Subsampling/example_pick_random_points.cpp + * \include Subsampling/example_pick_n_random_points.cpp * \copyright GNU General Public License v3. * \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim */ diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index b6d71dac..4710cf00 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -11,7 +11,7 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - add_executable( Subsampling_example_pick_random_points example_pick_random_points.cpp ) + 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 ) #target_link_libraries(Subsampling_example_choose_n_farthest_points ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) diff --git a/src/Subsampling/example/example_pick_n_random_points.cpp b/src/Subsampling/example/example_pick_n_random_points.cpp new file mode 100644 index 00000000..d2f063ba --- /dev/null +++ b/src/Subsampling/example/example_pick_n_random_points.cpp @@ -0,0 +1,29 @@ +#include + +#include +#include + +#include +#include +#include + +int main (void) +{ + typedef CGAL::Epick_d > K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + CGAL::Random rd; + + std::vector points; + for (int i = 0 ; i < 500 ; ++i) + points.push_back(Point_d(std::array({rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1)}))); + + K k; + std::vector results; + Gudhi::subsampling::pick_n_random_points(points, 100, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + + return 0; +} diff --git a/src/Subsampling/example/example_pick_random_points.cpp b/src/Subsampling/example/example_pick_random_points.cpp deleted file mode 100644 index 348b1b81..00000000 --- a/src/Subsampling/example/example_pick_random_points.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include -#include - -#include -#include -#include - -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::FT FT; - typedef typename K::Point_d Point_d; - - CGAL::Random rd; - - std::vector points; - for (int i = 0 ; i < 500 ; ++i) - points.push_back(Point_d(std::array({rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1)}))); - - K k; - std::vector results; - Gudhi::subsampling::pick_random_points(points, 100, std::back_inserter(results)); - std::cout << "Before sparsification: " << points.size() << " points.\n"; - std::cout << "After sparsification: " << results.size() << " points.\n"; - - return 0; -} diff --git a/src/Subsampling/include/gudhi/pick_n_random_points.h b/src/Subsampling/include/gudhi/pick_n_random_points.h new file mode 100644 index 00000000..4ca1fafc --- /dev/null +++ b/src/Subsampling/include/gudhi/pick_n_random_points.h @@ -0,0 +1,82 @@ +/* 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): Siargey Kachanovich + * + * Copyright (C) 2016 INRIA + * + * 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 . + */ + +#ifndef PICK_RANDOM_POINTS_H_ +#define PICK_RANDOM_POINTS_H_ + +#include + +#include // random_device, mt19937 +#include // shuffle +#include // iota +#include +#include + + +namespace Gudhi { + +namespace subsampling { + + /** + * \ingroup subsampling + * \brief Subsample a point set by picking random vertices. + * + * \details It chooses `final_size` distinct points from a random access range `points` + * and outputs them to the output iterator `output_it`. + * Point_container::iterator should be ValueSwappable and RandomAccessIterator. + */ + + template + void pick_n_random_points(Point_container const &points, + unsigned final_size, + OutputIterator output_it) { +#ifdef GUDHI_SUBS_PROFILING + Gudhi::Clock t; +#endif + + unsigned nbP = boost::size(points); + assert(nbP >= final_size); + std::vector landmarks(nbP); + std::iota(landmarks.begin(), landmarks.end(), 0); + + std::random_device rd; + std::mt19937 g(rd()); + + std::shuffle(landmarks.begin(), landmarks.end(), g); + landmarks.resize(final_size); + + for (int l: landmarks) + *output_it++ = points[l]; + +#ifdef GUDHI_SUBS_PROFILING + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() + << " seconds." << std::endl; +#endif + } + +} // namesapce subsampling + +} // namespace Gudhi + +#endif // PICK_RANDOM_POINTS_H_ diff --git a/src/Subsampling/include/gudhi/pick_random_points.h b/src/Subsampling/include/gudhi/pick_random_points.h deleted file mode 100644 index 732ae3f7..00000000 --- a/src/Subsampling/include/gudhi/pick_random_points.h +++ /dev/null @@ -1,82 +0,0 @@ -/* 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): Siargey Kachanovich - * - * Copyright (C) 2016 INRIA - * - * 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 . - */ - -#ifndef PICK_RANDOM_POINTS_H_ -#define PICK_RANDOM_POINTS_H_ - -#include - -#include // random_device, mt19937 -#include // shuffle -#include // iota -#include -#include - - -namespace Gudhi { - -namespace subsampling { - - /** - * \ingroup subsampling - * \brief Subsample a point set by picking random vertices. - * - * \details It chooses `final_size` distinct points from a random access range `points` - * and outputs them to the output iterator `output_it`. - * Point_container::iterator should be ValueSwappable and RandomAccessIterator. - */ - - template - void pick_random_points(Point_container const &points, - unsigned final_size, - OutputIterator output_it) { -#ifdef GUDHI_SUBS_PROFILING - Gudhi::Clock t; -#endif - - unsigned nbP = boost::size(points); - assert(nbP >= final_size); - std::vector landmarks(nbP); - std::iota(landmarks.begin(), landmarks.end(), 0); - - std::random_device rd; - std::mt19937 g(rd()); - - std::shuffle(landmarks.begin(), landmarks.end(), g); - landmarks.resize(final_size); - - for (int l: landmarks) - *output_it++ = points[l]; - -#ifdef GUDHI_SUBS_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() - << " seconds." << std::endl; -#endif - } - -} // namesapce subsampling - -} // namespace Gudhi - -#endif // PICK_RANDOM_POINTS_H_ diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 95241cd2..c9e48416 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -20,8 +20,8 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - add_executable( Subsampling_test_pick_random_points test_pick_random_points.cpp ) - target_link_libraries(Subsampling_test_pick_random_points ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + add_executable( Subsampling_test_pick_n_random_points test_pick_n_random_points.cpp ) + target_link_libraries(Subsampling_test_pick_n_random_points ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable( Subsampling_test_choose_n_farthest_points test_choose_n_farthest_points.cpp ) target_link_libraries(Subsampling_test_choose_n_farthest_points ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) diff --git a/src/Subsampling/test/test_pick_n_random_points.cpp b/src/Subsampling/test/test_pick_n_random_points.cpp new file mode 100644 index 00000000..6c8dbea2 --- /dev/null +++ b/src/Subsampling/test/test_pick_n_random_points.cpp @@ -0,0 +1,69 @@ +/* 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): Siargey Kachanovich + * + * Copyright (C) 2016 INRIA + * + * 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 . + */ + +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE Subsampling - test pick_n_random_points +#include + +#include +#include +#include + +#include + + +BOOST_AUTO_TEST_CASE(test_pick_n_random_points) +{ + typedef CGAL::Epick_d K; + typedef typename K::FT FT; + typedef typename K::Point_d Point_d; + + std::vector vect; + vect.push_back(Point_d(std::vector({0,0,0,0}))); + vect.push_back(Point_d(std::vector({0,0,0,1}))); + vect.push_back(Point_d(std::vector({0,0,1,0}))); + vect.push_back(Point_d(std::vector({0,0,1,1}))); + vect.push_back(Point_d(std::vector({0,1,0,0}))); + vect.push_back(Point_d(std::vector({0,1,0,1}))); + vect.push_back(Point_d(std::vector({0,1,1,0}))); + vect.push_back(Point_d(std::vector({0,1,1,1}))); + vect.push_back(Point_d(std::vector({1,0,0,0}))); + vect.push_back(Point_d(std::vector({1,0,0,1}))); + vect.push_back(Point_d(std::vector({1,0,1,0}))); + vect.push_back(Point_d(std::vector({1,0,1,1}))); + vect.push_back(Point_d(std::vector({1,1,0,0}))); + vect.push_back(Point_d(std::vector({1,1,0,1}))); + vect.push_back(Point_d(std::vector({1,1,1,0}))); + vect.push_back(Point_d(std::vector({1,1,1,1}))); + + std::vector results; + Gudhi::subsampling::pick_n_random_points(vect, 5, std::back_inserter(results)); + std::cout << "landmark vector contains: "; + for (auto l: results) + std::cout << l << "\n"; + + BOOST_CHECK(results.size() == 5); +} diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp deleted file mode 100644 index 16841eff..00000000 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* 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): Siargey Kachanovich - * - * Copyright (C) 2016 INRIA - * - * 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 . - */ - -// #ifdef _DEBUG -// # define TBB_USE_THREADING_TOOL -// #endif - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE Subsampling - test pick_random_points -#include - -#include -#include -#include - -#include - - -BOOST_AUTO_TEST_CASE(test_pick_random_points) -{ - typedef CGAL::Epick_d K; - typedef typename K::FT FT; - typedef typename K::Point_d Point_d; - - std::vector vect; - vect.push_back(Point_d(std::vector({0,0,0,0}))); - vect.push_back(Point_d(std::vector({0,0,0,1}))); - vect.push_back(Point_d(std::vector({0,0,1,0}))); - vect.push_back(Point_d(std::vector({0,0,1,1}))); - vect.push_back(Point_d(std::vector({0,1,0,0}))); - vect.push_back(Point_d(std::vector({0,1,0,1}))); - vect.push_back(Point_d(std::vector({0,1,1,0}))); - vect.push_back(Point_d(std::vector({0,1,1,1}))); - vect.push_back(Point_d(std::vector({1,0,0,0}))); - vect.push_back(Point_d(std::vector({1,0,0,1}))); - vect.push_back(Point_d(std::vector({1,0,1,0}))); - vect.push_back(Point_d(std::vector({1,0,1,1}))); - vect.push_back(Point_d(std::vector({1,1,0,0}))); - vect.push_back(Point_d(std::vector({1,1,0,1}))); - vect.push_back(Point_d(std::vector({1,1,1,0}))); - vect.push_back(Point_d(std::vector({1,1,1,1}))); - - std::vector results; - Gudhi::subsampling::pick_random_points(vect, 5, std::back_inserter(results)); - std::cout << "landmark vector contains: "; - for (auto l: results) - std::cout << l << "\n"; - - BOOST_CHECK(results.size() == 5); -} diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index 0d82ee38..5e9f0e81 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -87,7 +87,7 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::subsampling::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::pick_n_random_points(point_vector, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); end = clock(); std::cout << "Landmark choice for " << nbL << " landmarks took " diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index d0c4b4c4..e6f88274 100644 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ b/src/Witness_complex/example/witness_complex_sphere.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -76,7 +76,7 @@ int main(int argc, char * const argv[]) { // Choose landmarks start = clock(); std::vector > knn; - Gudhi::subsampling::pick_random_points(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::pick_n_random_points(point_vector, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(point_vector, landmarks, knn); // Compute witness complex diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp index 596152f4..d40bbf14 100644 --- a/src/Witness_complex/test/witness_complex_points.cpp +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(witness_complex_points) { bool b_print_output = false; // First test: random choice Simplex_tree complex1; - Gudhi::pick_random_points(points, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::pick_n_random_points(points, 100, std::back_inserter(landmarks)); Gudhi::witness_complex::construct_closest_landmark_table(points, landmarks, knn); assert(!knn.empty()); WitnessComplex witnessComplex1(knn, 100, 3, complex1); -- cgit v1.2.3 From a79e15a3581a26cd09fd22fe589ae9ee2315ea0b Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 20 Sep 2016 16:20:32 +0000 Subject: Changed the name of farthest point in intro doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1517 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 83ad658d6fa02e8a1524bf0f363c8bac522c9406 --- src/Subsampling/doc/Intro_subsampling.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Subsampling/doc/Intro_subsampling.h') diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index 06aee2fc..f8eb2fdd 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -46,12 +46,12 @@ namespace subsampling { * * \include Subsampling/example_sparsify_point_set.cpp * - * \section farthestpointexamples Example: choose_by_farthest_point + * \section farthestpointexamples Example: choose_n_farthest_points * * This example outputs a subset of 100 points obtained by González algorithm, * starting with a random point. * - * \include Subsampling/example_choose_by_farthest_point.cpp + * \include Subsampling/example_choose_n_farthest_points.cpp * * \section randompointexamples Example: pick_n_random_points * -- cgit v1.2.3