From ead71ec7ab6f5b1d23a0102289530d5f99572fe0 Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 2 Jun 2016 14:59:04 +0000 Subject: Deleted Landmark choices from witness complex, modified the test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1238 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f3072037b5e931a4e8fcfeadaae3499074377f01 --- src/Witness_complex/test/witness_complex_points.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/Witness_complex/test') diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp index bd3df604..c0006142 100644 --- a/src/Witness_complex/test/witness_complex_points.cpp +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -27,8 +27,9 @@ #include #include +#include #include -#include +#include #include #include @@ -40,7 +41,7 @@ typedef Gudhi::witness_complex::Witness_complex WitnessComplex; BOOST_AUTO_TEST_CASE(witness_complex_points) { std::vector< typeVectorVertex > knn; - std::vector< Point > points; + std::vector< Point > points, landmarks; // Add grid points as witnesses for (double i = 0; i < 10; i += 1.0) for (double j = 0; j < 10; j += 1.0) @@ -50,15 +51,9 @@ BOOST_AUTO_TEST_CASE(witness_complex_points) { bool b_print_output = false; // First test: random choice Simplex_tree complex1; - Gudhi::witness_complex::landmark_choice_by_random_point(points, 100, knn); + Gudhi::landmark_choice_by_random_point(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); BOOST_CHECK(witnessComplex1.is_witness_complex(knn, b_print_output)); - - // Second test: furthest choice - knn.clear(); - Simplex_tree complex2; - Gudhi::witness_complex::landmark_choice_by_furthest_point(points, 100, knn); - WitnessComplex witnessComplex2(knn, 100, 3, complex2); - BOOST_CHECK(witnessComplex2.is_witness_complex(knn, b_print_output)); } -- cgit v1.2.3 From 3c65ebebc4bfc32ec1b436c3d99a1f97a94b60d7 Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 20 Jun 2016 13:24:52 +0000 Subject: Renamed the two landmarking functions git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1314 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5025e0aff02306d61fa809eac10b7db27947b120 --- src/Subsampling/test/landmarking.cpp | 8 +- .../example/witness_complex_from_file.cpp | 4 +- .../example/witness_complex_sphere.cpp | 4 +- .../gudhi/Landmark_choice_by_furthest_point.h | 105 --------------------- .../gudhi/Landmark_choice_by_random_point.h | 96 ------------------- .../test/witness_complex_points.cpp | 5 +- 6 files changed, 10 insertions(+), 212 deletions(-) delete mode 100644 src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h delete mode 100644 src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h (limited to 'src/Witness_complex/test') diff --git a/src/Subsampling/test/landmarking.cpp b/src/Subsampling/test/landmarking.cpp index 3131c798..a2c85349 100644 --- a/src/Subsampling/test/landmarking.cpp +++ b/src/Subsampling/test/landmarking.cpp @@ -2,8 +2,8 @@ // # define TBB_USE_THREADING_TOOL // #endif -#include -#include +#include +#include #include #include @@ -35,13 +35,13 @@ int main() { std::vector landmarks; - Gudhi::landmark_choice_by_random_point(vect, 5, std::back_inserter(landmarks)); + Gudhi::pick_random_points(vect, 5, std::back_inserter(landmarks)); std::cout << "landmark vector contains: "; for (auto l: landmarks) std::cout << l << "\n"; landmarks.clear(); K k; - Gudhi::landmark_choice_by_farthest_point(k, vect, 16, std::back_inserter(landmarks)); + Gudhi::choose_by_farthest_point(k, vect, 16, std::back_inserter(landmarks)); } diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index fbc3cf1d..17b63dcf 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::landmark_choice_by_random_point(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::pick_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 9cf2f119..495a5895 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::landmark_choice_by_random_point(point_vector, 100, std::back_inserter(landmarks)); + Gudhi::pick_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/include/gudhi/Landmark_choice_by_furthest_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h deleted file mode 100644 index df93155b..00000000 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h +++ /dev/null @@ -1,105 +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) 2015 INRIA Sophia Antipolis-Méditerranée (France) - * - * 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 LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ -#define LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ - -#include - -#include // for numeric_limits<> -#include -#include // for sort -#include - -namespace Gudhi { - -namespace witness_complex { - - typedef std::vector typeVectorVertex; - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by iteratively adding the furthest witness from the - * current landmark set as the new landmark. - * \details It chooses nbL landmarks from a random access range `points` and - * writes {witness}*{closest landmarks} matrix in `knn`. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges - * - */ - - template - void landmark_choice_by_furthest_point(Point_random_access_range const &points, - int nbL, - KNearestNeighbours &knn) { - int nb_points = boost::size(points); - assert(nb_points >= nbL); - // distance matrix witness x landmarks - std::vector> wit_land_dist(nb_points, std::vector()); - // landmark list - typeVectorVertex chosen_landmarks; - - knn = KNearestNeighbours(nb_points, std::vector()); - int current_number_of_landmarks = 0; // counter for landmarks - double curr_max_dist = 0; // used for defining the furhest point from L - const double infty = std::numeric_limits::infinity(); // infinity (see next entry) - std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from points - - // TODO(SK) Consider using rand_r(...) instead of rand(...) for improved thread safety - // or better yet std::uniform_int_distribution - int rand_int = rand() % nb_points; - int curr_max_w = rand_int; // For testing purposes a pseudo-random number is used here - - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { - // curr_max_w at this point is the next landmark - chosen_landmarks.push_back(curr_max_w); - unsigned i = 0; - for (auto& p : points) { - double curr_dist = euclidean_distance(p, *(std::begin(points) + chosen_landmarks[current_number_of_landmarks])); - wit_land_dist[i].push_back(curr_dist); - knn[i].push_back(current_number_of_landmarks); - if (curr_dist < dist_to_L[i]) - dist_to_L[i] = curr_dist; - ++i; - } - curr_max_dist = 0; - for (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; - } - } - for (int i = 0; i < nb_points; ++i) - std::sort(std::begin(knn[i]), - std::end(knn[i]), - [&wit_land_dist, i](int a, int b) { - return wit_land_dist[i][a] < wit_land_dist[i][b]; }); - } - -} // namespace witness_complex - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_FURTHEST_POINT_H_ diff --git a/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h deleted file mode 100644 index ebf6aad1..00000000 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_random_point.h +++ /dev/null @@ -1,96 +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) 2015 INRIA Sophia Antipolis-Méditerranée (France) - * - * 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 LANDMARK_CHOICE_BY_RANDOM_POINT_H_ -#define LANDMARK_CHOICE_BY_RANDOM_POINT_H_ - -#include - -#include // for priority_queue<> -#include // for pair<> -#include -#include -#include - -namespace Gudhi { - -namespace witness_complex { - - /** - * \ingroup witness_complex - * \brief Landmark choice strategy by taking random vertices for landmarks. - * \details It chooses nbL distinct landmarks from a random access range `points` - * and outputs a matrix {witness}*{closest landmarks} in knn. - * - * The type KNearestNeighbors can be seen as - * Witness_range>, where - * Witness_range and Closest_landmark_range are random access ranges and - * Vertex_handle is the label type of a vertex in a simplicial complex. - * Closest_landmark_range needs to have push_back operation. - */ - - template - void landmark_choice_by_random_point(Point_random_access_range const &points, - int nbL, - KNearestNeighbours &knn) { - int nbP = boost::size(points); - assert(nbP >= nbL); - std::set landmarks; - int current_number_of_landmarks = 0; // counter for landmarks - - // TODO(SK) Consider using rand_r(...) instead of rand(...) for improved thread safety - int chosen_landmark = rand() % nbP; - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { - while (landmarks.find(chosen_landmark) != landmarks.end()) - chosen_landmark = rand() % nbP; - landmarks.insert(chosen_landmark); - } - - int dim = boost::size(*std::begin(points)); - typedef std::pair dist_i; - typedef bool (*comp)(dist_i, dist_i); - knn = KNearestNeighbours(nbP); - for (int points_i = 0; points_i < nbP; points_i++) { - std::priority_queue, comp> l_heap([](dist_i j1, dist_i j2) { - return j1.first > j2.first; - }); - std::set::iterator landmarks_it; - int landmarks_i = 0; - for (landmarks_it = landmarks.begin(), landmarks_i = 0; landmarks_it != landmarks.end(); - ++landmarks_it, landmarks_i++) { - dist_i dist = std::make_pair(euclidean_distance(points[points_i], points[*landmarks_it]), landmarks_i); - l_heap.push(dist); - } - for (int i = 0; i < dim + 1; i++) { - dist_i dist = l_heap.top(); - knn[points_i].push_back(dist.second); - l_heap.pop(); - } - } - } - -} // namespace witness_complex - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp index c0006142..596152f4 100644 --- a/src/Witness_complex/test/witness_complex_points.cpp +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -28,8 +28,7 @@ #include #include #include -#include -#include +#include #include #include @@ -51,7 +50,7 @@ BOOST_AUTO_TEST_CASE(witness_complex_points) { bool b_print_output = false; // First test: random choice Simplex_tree complex1; - Gudhi::landmark_choice_by_random_point(points, 100, std::back_inserter(landmarks)); + Gudhi::pick_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 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/Witness_complex/test') 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