From bb56631552ff8cf431d2286470223f7394cb2846 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 31 May 2016 16:09:46 +0000 Subject: Farthest points (from Siargey) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1230 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3093bfd41948fecf5f6ccb2d1d77546c12e628f4 --- src/Subsampling/test/CMakeLists.txt | 22 +++++++++++++++++ src/Subsampling/test/landmarking.cpp | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/Subsampling/test/CMakeLists.txt create mode 100644 src/Subsampling/test/landmarking.cpp (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt new file mode 100644 index 00000000..3a45c685 --- /dev/null +++ b/src/Subsampling/test/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.6) +project(GUDHILandmarkingTest) + +# Landmarking test +if(CGAL_FOUND) + if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + message(STATUS "CGAL version: ${CGAL_VERSION}.") + + find_package(Eigen3 3.1.0) + if (EIGEN3_FOUND) + message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") + include( ${EIGEN3_USE_FILE} ) + include_directories (BEFORE "../../include") + + add_executable( landmarking_UT landmarking.cpp ) + else() + message(WARNING "Eigen3 not found. Version 3.1.0 is required for Landmarking feature.") + endif() + else() + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Landmarking feature. Version 4.8.0 is required.") + endif () +endif() diff --git a/src/Subsampling/test/landmarking.cpp b/src/Subsampling/test/landmarking.cpp new file mode 100644 index 00000000..3131c798 --- /dev/null +++ b/src/Subsampling/test/landmarking.cpp @@ -0,0 +1,47 @@ +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#include +#include +#include +#include + +#include + + +int main() { + 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 landmarks; + Gudhi::landmark_choice_by_random_point(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)); + +} -- 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/Subsampling/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 a3b6dbe9223bc71ebbb763066a1cd9f3359322a8 Mon Sep 17 00:00:00 2001 From: cjamin Date: Mon, 20 Jun 2016 16:54:13 +0000 Subject: Add test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1316 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a597203ec80289750b8faa2d6e5293211125dd3c --- src/Subsampling/test/CMakeLists.txt | 6 ++--- src/Subsampling/test/test_sparsify_point_set.cpp | 34 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/Subsampling/test/test_sparsify_point_set.cpp (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 3a45c685..1785b86d 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 2.6) -project(GUDHILandmarkingTest) +project(Subsampling_tests) -# Landmarking test if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") @@ -13,8 +12,9 @@ if(CGAL_FOUND) include_directories (BEFORE "../../include") add_executable( landmarking_UT landmarking.cpp ) + add_executable( Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for Landmarking feature.") + message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() else() message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Landmarking feature. Version 4.8.0 is required.") diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp new file mode 100644 index 00000000..e9d2a8f6 --- /dev/null +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -0,0 +1,34 @@ +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#include + +#include +#include + +#include +#include +#include + +int main() { + 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::sparsify_point_set(k, points, 0.5, std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + //for (auto p : results) + // std::cout << p << "\n"; + + return 0; +} -- cgit v1.2.3 From 1539aa803375bbb562559ab632d8ce22c6ce940b Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 21 Jun 2016 09:20:44 +0000 Subject: Merged the CMakeLists and added test_choose_by_farthest_point git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1318 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 534a2ac30a2177a780d1f483add2c472d4cedac3 --- .../include/gudhi/choose_by_farthest_point.h | 4 ++- src/Subsampling/test/CMakeLists.txt | 14 ++++++++- .../test/test_choose_farthest_point.cpp | 35 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/Subsampling/test/test_choose_farthest_point.cpp (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 61a21f44..9877d5eb 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -25,6 +25,8 @@ #include +#include + #include #include // for sort #include @@ -73,7 +75,7 @@ namespace Gudhi { 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 *output_it++ = points[curr_max_w]; - std::cout << curr_max_w << "\n"; + // std::cout << curr_max_w << "\n"; unsigned i = 0; for (auto& p : points) { double curr_dist = sqdist(p, *(std::begin(points) + curr_max_w)); diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 1785b86d..3a7fc092 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -1,6 +1,16 @@ cmake_minimum_required(VERSION 2.6) project(Subsampling_tests) +if (GCOVR_PATH) + # for gcovr to make coverage reports - Corbera Jenkins plugin + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") +endif() +if (GPROF_PATH) + # for gprof to make coverage reports - Jenkins + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") +endif() + +# Landmarking test if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") @@ -11,7 +21,9 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - add_executable( landmarking_UT landmarking.cpp ) + add_executable( test_choose_farthest_point test_choose_farthest_point.cpp ) + target_link_libraries(test_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + add_executable( Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp new file mode 100644 index 00000000..2f83fac9 --- /dev/null +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -0,0 +1,35 @@ +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "witness_complex_points" +#include +#include + +#include +#include +#include + +#include + +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) { + 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}))); + + landmarks.clear(); + K k; + Gudhi::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); + + assert(landmarks.size() == 100); +} -- cgit v1.2.3 From 3113edccca8b0ecf1bc3a942abd03f62c7bb0bcb Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 21 Jun 2016 09:29:59 +0000 Subject: Renamed the test for pick_random_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1319 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2210767dc829ba596409170200ba8fce5d39fdf1 --- src/Subsampling/test/CMakeLists.txt | 6 ++- src/Subsampling/test/landmarking.cpp | 47 ------------------------ src/Subsampling/test/test_pick_random_points.cpp | 44 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 49 deletions(-) delete mode 100644 src/Subsampling/test/landmarking.cpp create mode 100644 src/Subsampling/test/test_pick_random_points.cpp (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 3a7fc092..0c591e8b 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -21,8 +21,10 @@ if(CGAL_FOUND) include( ${EIGEN3_USE_FILE} ) include_directories (BEFORE "../../include") - add_executable( test_choose_farthest_point test_choose_farthest_point.cpp ) - target_link_libraries(test_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + add_executable( Subsampling_test_pick_random_points test_pick_random_points.cpp ) + + add_executable( Subsampling_test_choose_farthest_point test_choose_farthest_point.cpp ) + target_link_libraries(Subsampling_test_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable( Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) else() diff --git a/src/Subsampling/test/landmarking.cpp b/src/Subsampling/test/landmarking.cpp deleted file mode 100644 index a2c85349..00000000 --- a/src/Subsampling/test/landmarking.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// #ifdef _DEBUG -// # define TBB_USE_THREADING_TOOL -// #endif - -#include -#include -#include -#include - -#include - - -int main() { - 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 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::choose_by_farthest_point(k, vect, 16, std::back_inserter(landmarks)); - -} diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp new file mode 100644 index 00000000..13c7dcad --- /dev/null +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -0,0 +1,44 @@ +// #ifdef _DEBUG +// # define TBB_USE_THREADING_TOOL +// #endif + +#include +#include +#include +#include + +#include + + +int main() { + 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 landmarks; + Gudhi::pick_random_points(vect, 5, std::back_inserter(landmarks)); + std::cout << "landmark vector contains: "; + for (auto l: landmarks) + std::cout << l << "\n"; + assert(landmarks_size() == 5); + +} -- cgit v1.2.3 From c4bad9f4dcdefb44bb91b80afc06bf3f2039efe2 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 21 Jun 2016 09:34:22 +0000 Subject: Capitalized Pick_random_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1320 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 24995238315de68a9bd93e88d56581e2451ea68e --- src/Subsampling/include/gudhi/Pick_random_points.h | 80 ++++++++++++++++++++++ src/Subsampling/include/gudhi/pick_random_points.h | 80 ---------------------- src/Subsampling/test/test_pick_random_points.cpp | 3 +- .../example/witness_complex_from_file.cpp | 2 +- .../example/witness_complex_sphere.cpp | 2 +- 5 files changed, 83 insertions(+), 84 deletions(-) create mode 100644 src/Subsampling/include/gudhi/Pick_random_points.h delete mode 100644 src/Subsampling/include/gudhi/pick_random_points.h (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/include/gudhi/Pick_random_points.h b/src/Subsampling/include/gudhi/Pick_random_points.h new file mode 100644 index 00000000..9a436ee3 --- /dev/null +++ b/src/Subsampling/include/gudhi/Pick_random_points.h @@ -0,0 +1,80 @@ +/* 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 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 PICK_RANDOM_POINTS_H_ +#define PICK_RANDOM_POINTS_H_ + +#include + +#include // random_device, mt19937 +#include // shuffle +#include // iota +#include +#include + + +namespace Gudhi { + + /** + * \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 them to an output iterator. + * Point_container::iterator should be ValueSwappable and RandomAccessIterator. + */ + + template + void pick_random_points(Point_container const &points, + unsigned nbL, + OutputIterator output_it) { +#ifdef GUDHI_LM_PROFILING + Gudhi::Clock t; +#endif + + unsigned nbP = boost::size(points); + assert(nbP >= nbL); + 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(nbL); + + for (int l: landmarks) + *output_it++ = points[l]; + +#ifdef GUDHI_LM_PROFILING + t.end(); + std::cerr << "Random landmark choice took " << t.num_seconds() + << " seconds." << std::endl; +#endif + + + } + +} // namespace Gudhi + +#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_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 9a436ee3..00000000 --- a/src/Subsampling/include/gudhi/pick_random_points.h +++ /dev/null @@ -1,80 +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 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 PICK_RANDOM_POINTS_H_ -#define PICK_RANDOM_POINTS_H_ - -#include - -#include // random_device, mt19937 -#include // shuffle -#include // iota -#include -#include - - -namespace Gudhi { - - /** - * \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 them to an output iterator. - * Point_container::iterator should be ValueSwappable and RandomAccessIterator. - */ - - template - void pick_random_points(Point_container const &points, - unsigned nbL, - OutputIterator output_it) { -#ifdef GUDHI_LM_PROFILING - Gudhi::Clock t; -#endif - - unsigned nbP = boost::size(points); - assert(nbP >= nbL); - 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(nbL); - - for (int l: landmarks) - *output_it++ = points[l]; - -#ifdef GUDHI_LM_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() - << " seconds." << std::endl; -#endif - - - } - -} // namespace Gudhi - -#endif // LANDMARK_CHOICE_BY_RANDOM_POINT_H_ diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index 13c7dcad..a7466c9e 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -2,8 +2,7 @@ // # define TBB_USE_THREADING_TOOL // #endif -#include -#include +#include #include #include diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index 17b63dcf..ba348f9b 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 diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp index 495a5895..2ea7376f 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 -- cgit v1.2.3 From 1ed4039613bee6d3cd85b312e88af71acdbdc163 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 13:53:51 +0000 Subject: Boostify the test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1323 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 58b2cfba030198debf2831809e430e3bf3251346 --- src/Subsampling/test/CMakeLists.txt | 3 ++- src/Subsampling/test/test_sparsify_point_set.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 0c591e8b..6fd70e39 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -26,7 +26,8 @@ if(CGAL_FOUND) add_executable( Subsampling_test_choose_farthest_point test_choose_farthest_point.cpp ) target_link_libraries(Subsampling_test_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) - add_executable( Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) + add_executable(Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) + target_link_libraries(Subsampling_test_sparsify_point_set ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index e9d2a8f6..8e89f81a 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -2,6 +2,10 @@ // # define TBB_USE_THREADING_TOOL // #endif +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE Subsampling - test sparsify_point_set +#include + #include #include @@ -11,7 +15,8 @@ #include #include -int main() { +BOOST_AUTO_TEST_CASE(test_sparsify_point_set) +{ typedef CGAL::Epick_d > K; typedef typename K::FT FT; typedef typename K::Point_d Point_d; @@ -30,5 +35,5 @@ int main() { //for (auto p : results) // std::cout << p << "\n"; - return 0; + BOOST_CHECK(points.size() > results.size()); } -- cgit v1.2.3 From dbe46f1faf07b6cd074881f92dfea4eb5dde38c7 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 14:01:45 +0000 Subject: Fix/add copyright git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1324 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: dc76efeb44b94b3a3fc1669d8b6636759ab92383 --- .../include/gudhi/Spatial_tree_data_structure.h | 2 +- src/Subsampling/include/gudhi/Pick_random_points.h | 2 +- .../include/gudhi/choose_by_farthest_point.h | 2 +- src/Subsampling/include/gudhi/sparsify_point_set.h | 40 +++++++++++----------- .../test/test_choose_farthest_point.cpp | 22 ++++++++++++ src/Subsampling/test/test_pick_random_points.cpp | 22 ++++++++++++ src/Subsampling/test/test_sparsify_point_set.cpp | 24 +++++++++++-- 7 files changed, 88 insertions(+), 26 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h index b4dbbba1..27418445 100644 --- a/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h +++ b/src/Spatial_searching/include/gudhi/Spatial_tree_data_structure.h @@ -4,7 +4,7 @@ * * Author(s): Clement Jamin * - * Copyright (C) 2016 INRIA Sophia-Antipolis (France) + * 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 diff --git a/src/Subsampling/include/gudhi/Pick_random_points.h b/src/Subsampling/include/gudhi/Pick_random_points.h index 1bc1474b..98902264 100644 --- a/src/Subsampling/include/gudhi/Pick_random_points.h +++ b/src/Subsampling/include/gudhi/Pick_random_points.h @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) + * 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 diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 434b5f7d..2918983f 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -4,7 +4,7 @@ * * Author(s): Siargey Kachanovich * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * 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 diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index d04deb60..bd7f4c56 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -1,24 +1,24 @@ /* 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 Sophia-Antipolis (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 . -*/ + * (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 GUDHI_SPARSIFY_POINT_SET_H #define GUDHI_SPARSIFY_POINT_SET_H diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index 2f83fac9..991fcbfe 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -1,3 +1,25 @@ +/* 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 diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index a7466c9e..81c7ffdb 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -1,3 +1,25 @@ +/* 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 diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index 8e89f81a..61f6fa18 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -1,6 +1,24 @@ -// #ifdef _DEBUG -// # define TBB_USE_THREADING_TOOL -// #endif +/* 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 . + */ #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE Subsampling - test sparsify_point_set -- cgit v1.2.3 From 091796c9be3ac7ddaa96bacc71842a2808da14e4 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 21 Jun 2016 15:15:25 +0000 Subject: Use namespace + improve CMakeLists.txt git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1326 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7481553ea143479fa48b3722370b3d031ad8175a --- src/Subsampling/include/gudhi/sparsify_point_set.h | 6 +++--- src/Subsampling/test/CMakeLists.txt | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h index bd7f4c56..62b1b4b6 100644 --- a/src/Subsampling/include/gudhi/sparsify_point_set.h +++ b/src/Subsampling/include/gudhi/sparsify_point_set.h @@ -40,9 +40,9 @@ sparsify_point_set( const Kernel &k, Point_container const& input_pts, typename Kernel::FT min_squared_dist, OutputIterator output_it) -{ - typedef typename Gudhi::Spatial_tree_data_structure< - Kernel, Point_container> Points_ds; +{ + typedef typename Gudhi::spatial_searching::Spatial_tree_data_structure< + Kernel, Point_container> Points_ds; typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 6fd70e39..80b0ccbb 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -10,7 +10,6 @@ if (GPROF_PATH) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") endif() -# Landmarking test if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") @@ -32,6 +31,8 @@ if(CGAL_FOUND) message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Landmarking feature. Version 4.8.0 is required.") + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.0 is required.") endif () +else() + message(WARNING "CGAL not found. It is required for the Subsampling tests.") endif() -- cgit v1.2.3 From 83dd60a38920cdf85e4c1108404cfa7c294f98e2 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 22 Jun 2016 09:42:57 +0000 Subject: Took into account Clément's remarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1328 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6f1db13d0e8cec8e64c5bb30da53b72b00446de3 --- src/Subsampling/include/gudhi/Pick_random_points.h | 78 -------------------- .../include/gudhi/choose_by_farthest_point.h | 31 ++++---- src/Subsampling/include/gudhi/pick_random_points.h | 82 ++++++++++++++++++++++ .../test/test_choose_farthest_point.cpp | 8 +-- src/Subsampling/test/test_pick_random_points.cpp | 10 +-- 5 files changed, 106 insertions(+), 103 deletions(-) delete mode 100644 src/Subsampling/include/gudhi/Pick_random_points.h create mode 100644 src/Subsampling/include/gudhi/pick_random_points.h (limited to 'src/Subsampling/test') 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 98902264..00000000 --- a/src/Subsampling/include/gudhi/Pick_random_points.h +++ /dev/null @@ -1,78 +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 { - - /** - * \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 them to an output iterator. - * Point_container::iterator should be ValueSwappable and RandomAccessIterator. - */ - - template - void pick_random_points(Point_container const &points, - unsigned nbL, - OutputIterator output_it) { -#ifdef GUDHI_LM_PROFILING - Gudhi::Clock t; -#endif - - unsigned nbP = boost::size(points); - assert(nbP >= nbL); - 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(nbL); - - for (int l: landmarks) - *output_it++ = points[l]; - -#ifdef GUDHI_LM_PROFILING - t.end(); - std::cerr << "Random landmark choice took " << t.num_seconds() - << " seconds." << std::endl; -#endif - } - -} // namespace Gudhi - -#endif // PICK_RANDOM_POINTS_H_ diff --git a/src/Subsampling/include/gudhi/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 2918983f..52647c16 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -31,32 +31,29 @@ #include namespace Gudhi { - + +namespace subsampling { /** - * \ingroup witness_complex - * \brief Landmark choice strategy by iteratively adding the farthest 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 + * \ingroup subsampling + * \brief Subsample by a greedy strategy of iteratively adding the farthest point from the + * current chosen point set to the subsampling. + * \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 nbL, - OutputIterator output_it) + void choose_by_farthest_point( Kernel& k, + Point_container const &points, + int final_size, + OutputIterator output_it) { typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); int nb_points = boost::size(points); - assert(nb_points >= nbL); + assert(nb_points >= final_size); int current_number_of_landmarks = 0; // counter for landmarks double curr_max_dist = 0; // used for defining the furhest point from L @@ -69,7 +66,7 @@ namespace Gudhi { std::uniform_int_distribution<> dis(1, 6); int curr_max_w = dis(gen); - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) { + 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"; @@ -89,6 +86,8 @@ namespace Gudhi { } } } + +} // namespace subsampling } // namespace Gudhi diff --git a/src/Subsampling/include/gudhi/pick_random_points.h b/src/Subsampling/include/gudhi/pick_random_points.h new file mode 100644 index 00000000..732ae3f7 --- /dev/null +++ b/src/Subsampling/include/gudhi/pick_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_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/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index 991fcbfe..87c2c38d 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -41,7 +41,7 @@ typedef typename K::Point_d Point_d; BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { - std::vector< Point_d > points, landmarks; + std::vector< Point_d > points, results; // Add grid points (625 points) for (FT i = 0; i < 5; i += 1.0) for (FT j = 0; j < 5; j += 1.0) @@ -49,9 +49,9 @@ BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { for (FT l = 0; l < 5; l += 1.0) points.push_back(Point_d(std::vector({i, j, k, l}))); - landmarks.clear(); + results.clear(); K k; - Gudhi::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); + Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(results)); - assert(landmarks.size() == 100); + assert(results.size() == 100); } diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index 81c7ffdb..8156160e 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -24,7 +24,7 @@ // # define TBB_USE_THREADING_TOOL // #endif -#include +#include #include #include @@ -55,11 +55,11 @@ int main() { vect.push_back(Point_d(std::vector({1,1,1,1}))); - std::vector landmarks; - Gudhi::pick_random_points(vect, 5, std::back_inserter(landmarks)); + std::vector results; + Gudhi::subsampling::pick_random_points(vect, 5, std::back_inserter(results)); std::cout << "landmark vector contains: "; - for (auto l: landmarks) + for (auto l: results) std::cout << l << "\n"; - assert(landmarks_size() == 5); + assert(results.size() == 5); } -- cgit v1.2.3 From 7928209595af6f7559fde36fa06c031cd47e7179 Mon Sep 17 00:00:00 2001 From: skachano Date: Fri, 24 Jun 2016 13:42:39 +0000 Subject: Copied Clément's example for 2 functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1338 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 42f29038057980965bfead2c73cbc013448493fb --- src/Subsampling/example/CMakeLists.txt | 4 +- .../example/example_choose_by_farthest_point.cpp | 52 +++++++++ .../example/example_pick_random_points.cpp | 52 +++++++++ .../include/gudhi/choose_by_farthest_point.h | 119 +++++++++++++++++++-- .../test/test_choose_farthest_point.cpp | 65 ++++++++--- 5 files changed, 266 insertions(+), 26 deletions(-) create mode 100644 src/Subsampling/example/example_choose_by_farthest_point.cpp create mode 100644 src/Subsampling/example/example_pick_random_points.cpp (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index e7a8a9f7..e1e7cc71 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -11,9 +11,9 @@ 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_random_points example_pick_random_points.cpp ) - #add_executable( Subsampling_example_choose_farthest_point example_choose_farthest_point.cpp ) + add_executable( Subsampling_example_choose_by_farthest_point example_choose_by_farthest_point.cpp ) #target_link_libraries(Subsampling_example_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) diff --git a/src/Subsampling/example/example_choose_by_farthest_point.cpp b/src/Subsampling/example/example_choose_by_farthest_point.cpp new file mode 100644 index 00000000..5b81bc9d --- /dev/null +++ b/src/Subsampling/example/example_choose_by_farthest_point.cpp @@ -0,0 +1,52 @@ +/* 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 +#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::choose_by_farthest_point(k, 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 new file mode 100644 index 00000000..49a027a4 --- /dev/null +++ b/src/Subsampling/example/example_pick_random_points.cpp @@ -0,0 +1,52 @@ +/* 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 +#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/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h index 52647c16..d1db0d1a 100644 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ b/src/Subsampling/include/gudhi/choose_by_farthest_point.h @@ -25,6 +25,14 @@ #include +#include + +#include + +#include +#include +#include + #include #include // for sort #include @@ -45,10 +53,11 @@ namespace subsampling { 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) + void choose_by_farthest_point_old( 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(); @@ -60,11 +69,7 @@ namespace subsampling { 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 - // Choose randomly the first landmark - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, 6); - int curr_max_w = dis(gen); + 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 @@ -86,7 +91,103 @@ 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); + } + + 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); + } + + } // namespace subsampling } // namespace Gudhi diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index 87c2c38d..dff2cd4e 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -24,14 +24,15 @@ // # define TBB_USE_THREADING_TOOL // #endif -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "witness_complex_points" -#include -#include +// #define BOOST_TEST_DYN_LINK +// #define BOOST_TEST_MODULE "test_choose_farthest_point" +//#include +//#include #include #include #include +#include #include @@ -40,18 +41,52 @@ typedef typename K::FT FT; typedef typename K::Point_d Point_d; -BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { - std::vector< Point_d > points, results; - // 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) +//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) points.push_back(Point_d(std::vector({i, j, k, l}))); - results.clear(); - K k; - Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(results)); + 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, "; - assert(results.size() == 100); + // 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; + + 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); + } + } } -- 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/test') 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 8587109e64af7ce1f17d8e7756e078a025a37bcb Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 6 Jul 2016 16:05:39 +0000 Subject: Fix CMake scripts git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1389 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b97e07531b300c47ddefd056cc574d89c71a4400 --- src/Spatial_searching/example/CMakeLists.txt | 1 + src/Spatial_searching/test/CMakeLists.txt | 3 ++- src/Subsampling/example/CMakeLists.txt | 2 +- src/Subsampling/test/CMakeLists.txt | 5 +++-- 4 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index c1190d1b..0885c24c 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -12,6 +12,7 @@ if(CGAL_FOUND) include_directories (BEFORE "../../include") add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) + target_link_libraries(Spatial_searching_example_spatial_searching ${CGAL_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Tangential_complex examples.") endif() diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index 297b6749..41059286 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -18,7 +18,8 @@ if(CGAL_FOUND) include_directories (BEFORE "../../include") add_executable( Spatial_searching_test_Spatial_tree_data_structure test_Spatial_tree_data_structure.cpp ) - target_link_libraries(Spatial_searching_test_Spatial_tree_data_structure ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(Spatial_searching_test_Spatial_tree_data_structure + ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Spatial_searching tests.") endif() diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index e1e7cc71..532440eb 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -17,7 +17,7 @@ if(CGAL_FOUND) #target_link_libraries(Subsampling_example_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) - target_link_libraries(Subsampling_example_sparsify_point_set ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 80b0ccbb..18fc84f4 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -21,12 +21,13 @@ if(CGAL_FOUND) 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_choose_farthest_point test_choose_farthest_point.cpp ) - target_link_libraries(Subsampling_test_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(Subsampling_test_choose_farthest_point ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) add_executable(Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) - target_link_libraries(Subsampling_test_sparsify_point_set ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(Subsampling_test_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() -- cgit v1.2.3 From 2455525b1583b7a7b4c38d0637a1e0507cf5181d Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 4 Aug 2016 13:38:18 +0000 Subject: Use BOOST_CHECK instead of assert git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1401 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6822fcbda4e9fdaa8a5850b4042a79800c8c019a --- src/Subsampling/test/test_choose_farthest_point.cpp | 2 +- src/Subsampling/test/test_pick_random_points.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp index 5f705de6..a1929924 100644 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ b/src/Subsampling/test/test_choose_farthest_point.cpp @@ -53,5 +53,5 @@ BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { K k; Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); - assert(landmarks.size() == 100); + BOOST_CHECK(landmarks.size() == 100); } diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index 8156160e..d74f992f 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -60,6 +60,6 @@ int main() { std::cout << "landmark vector contains: "; for (auto l: results) std::cout << l << "\n"; - assert(results.size() == 5); + BOOST_CHECK(results.size() == 5); } -- cgit v1.2.3 From 4da47219339ce8bee2a42d1ffcf6e5c9d0d61e0b Mon Sep 17 00:00:00 2001 From: cjamin Date: Sat, 27 Aug 2016 08:13:46 +0000 Subject: Fix test of pick_random_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1459 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6963479b6c53c668542313aff2392b8449cb0cc3 --- src/Subsampling/test/test_pick_random_points.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/test/test_pick_random_points.cpp b/src/Subsampling/test/test_pick_random_points.cpp index d74f992f..16841eff 100644 --- a/src/Subsampling/test/test_pick_random_points.cpp +++ b/src/Subsampling/test/test_pick_random_points.cpp @@ -24,6 +24,10 @@ // # define TBB_USE_THREADING_TOOL // #endif +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE Subsampling - test pick_random_points +#include + #include #include #include @@ -31,7 +35,8 @@ #include -int main() { +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; @@ -53,8 +58,7 @@ int main() { 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: "; -- cgit v1.2.3 From d38ddb2d2b6943e1e9b26694ac624f85263ad24b Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 20 Sep 2016 09:45:31 +0000 Subject: Changed choose_by_farthest_point -> choose_n_farthest_points git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1513 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 287ef6f3be6e4db4616ad92ff7369cd7722a1f2d --- src/Subsampling/example/CMakeLists.txt | 4 ++-- src/Subsampling/test/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 532440eb..b6d71dac 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -13,8 +13,8 @@ if(CGAL_FOUND) add_executable( Subsampling_example_pick_random_points example_pick_random_points.cpp ) - add_executable( Subsampling_example_choose_by_farthest_point example_choose_by_farthest_point.cpp ) - #target_link_libraries(Subsampling_example_choose_farthest_point ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + 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}) add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 18fc84f4..95241cd2 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -23,8 +23,8 @@ if(CGAL_FOUND) 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_choose_farthest_point test_choose_farthest_point.cpp ) - target_link_libraries(Subsampling_test_choose_farthest_point ${CGAL_LIBRARY} ${Boost_SYSTEM_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}) add_executable(Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) target_link_libraries(Subsampling_test_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) -- cgit v1.2.3 From e8183d76c99eac5458d8f72cb4479cc680c6a6c4 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 20 Sep 2016 09:59:15 +0000 Subject: Changed the names of files as well git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1514 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: df3b82dc1d07b5d51b1c1bed4b5abd823129d4a8 --- .../example/example_choose_by_farthest_point.cpp | 29 ----- .../example/example_choose_n_farthest_points.cpp | 29 +++++ .../include/gudhi/choose_by_farthest_point.h | 125 --------------------- .../include/gudhi/choose_n_farthest_points.h | 125 +++++++++++++++++++++ .../test/test_choose_farthest_point.cpp | 57 ---------- .../test/test_choose_n_farthest_points.cpp | 57 ++++++++++ 6 files changed, 211 insertions(+), 211 deletions(-) delete mode 100644 src/Subsampling/example/example_choose_by_farthest_point.cpp create mode 100644 src/Subsampling/example/example_choose_n_farthest_points.cpp delete mode 100644 src/Subsampling/include/gudhi/choose_by_farthest_point.h create mode 100644 src/Subsampling/include/gudhi/choose_n_farthest_points.h delete mode 100644 src/Subsampling/test/test_choose_farthest_point.cpp create mode 100644 src/Subsampling/test/test_choose_n_farthest_points.cpp (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/example/example_choose_by_farthest_point.cpp b/src/Subsampling/example/example_choose_by_farthest_point.cpp deleted file mode 100644 index 29ecbf9b..00000000 --- a/src/Subsampling/example/example_choose_by_farthest_point.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::choose_by_farthest_point(k, 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_choose_n_farthest_points.cpp b/src/Subsampling/example/example_choose_n_farthest_points.cpp new file mode 100644 index 00000000..9955d0ec --- /dev/null +++ b/src/Subsampling/example/example_choose_n_farthest_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::choose_n_farthest_points(k, 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/choose_by_farthest_point.h b/src/Subsampling/include/gudhi/choose_by_farthest_point.h deleted file mode 100644 index b09192d9..00000000 --- a/src/Subsampling/include/gudhi/choose_by_farthest_point.h +++ /dev/null @@ -1,125 +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 CHOOSE_BY_FARTHEST_POINT_H_ -#define CHOOSE_BY_FARTHEST_POINT_H_ - -#include - -#include - -#include - -#include -#include -#include - -#include -#include // for sort -#include -#include - -namespace Gudhi { - -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 `input_pts` and - * outputs it in the output iterator `output_it`. - * - */ - - template < typename Kernel, - typename Point_container, - typename OutputIterator> - void choose_by_farthest_point( Kernel const &k, - Point_container const &input_pts, - unsigned final_size, - unsigned starting_point, - OutputIterator output_it) - { - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - - int nb_points = boost::size(input_pts); - assert(nb_points >= final_size); - - unsigned 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 input_pts - - 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++ = input_pts[curr_max_w]; - // std::cout << curr_max_w << "\n"; - unsigned i = 0; - for (auto& p : input_pts) { - double curr_dist = sqdist(p, *(std::begin(input_pts) + curr_max_w)); - if (curr_dist < dist_to_L[i]) - dist_to_L[i] = curr_dist; - ++i; - } - // choose the next curr_max_w - 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; - } - } - } - - /** - * \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 `input_pts` 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 &input_pts, - 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(k, input_pts, final_size, starting_point, output_it); - } - -} // namespace subsampling - -} // namespace Gudhi - -#endif // CHOOSE_BY_FARTHEST_POINT_H_ diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h new file mode 100644 index 00000000..b999213e --- /dev/null +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -0,0 +1,125 @@ +/* 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 CHOOSE_N_FARTHEST_POINTS_H_ +#define CHOOSE_N_FARTHEST_POINTS_H_ + +#include + +#include + +#include + +#include +#include +#include + +#include +#include // for sort +#include +#include + +namespace Gudhi { + +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 `input_pts` and + * outputs it in the output iterator `output_it`. + * + */ + + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void choose_n_farthest_points( Kernel const &k, + Point_container const &input_pts, + unsigned final_size, + unsigned starting_point, + OutputIterator output_it) + { + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); + + int nb_points = boost::size(input_pts); + assert(nb_points >= final_size); + + unsigned 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 input_pts + + 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++ = input_pts[curr_max_w]; + // std::cout << curr_max_w << "\n"; + unsigned i = 0; + for (auto& p : input_pts) { + double curr_dist = sqdist(p, *(std::begin(input_pts) + curr_max_w)); + if (curr_dist < dist_to_L[i]) + dist_to_L[i] = curr_dist; + ++i; + } + // choose the next curr_max_w + 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; + } + } + } + + /** + * \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 `input_pts` and + * outputs it in the output iterator `output_it`. + * + */ + template < typename Kernel, + typename Point_container, + typename OutputIterator> + void choose_n_farthest_points( Kernel& k, + Point_container const &input_pts, + 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_n_farthest_points(k, input_pts, final_size, starting_point, output_it); + } + +} // namespace subsampling + +} // namespace Gudhi + +#endif // CHOOSE_N_FARTHEST_POINTS_H_ diff --git a/src/Subsampling/test/test_choose_farthest_point.cpp b/src/Subsampling/test/test_choose_farthest_point.cpp deleted file mode 100644 index a1929924..00000000 --- a/src/Subsampling/test/test_choose_farthest_point.cpp +++ /dev/null @@ -1,57 +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 "witness_complex_points" -#include -#include - -#include -#include -#include - -#include - -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) { - 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}))); - - landmarks.clear(); - K k; - Gudhi::subsampling::choose_by_farthest_point(k, points, 100, std::back_inserter(landmarks)); - - BOOST_CHECK(landmarks.size() == 100); -} diff --git a/src/Subsampling/test/test_choose_n_farthest_points.cpp b/src/Subsampling/test/test_choose_n_farthest_points.cpp new file mode 100644 index 00000000..f79a4dfb --- /dev/null +++ b/src/Subsampling/test/test_choose_n_farthest_points.cpp @@ -0,0 +1,57 @@ +/* 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 "witness_complex_points" +#include +#include + +#include +#include +#include + +#include + +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) { + 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}))); + + landmarks.clear(); + K k; + Gudhi::subsampling::choose_n_farthest_points(k, points, 100, std::back_inserter(landmarks)); + + BOOST_CHECK(landmarks.size() == 100); +} -- 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/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 From aa994dbd8dadfd4be416f13b13721e7e13c3623a Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 22 Sep 2016 11:58:31 +0000 Subject: Require CGAL 4.8.1 (furthest neighbor is bugged before) See https://github.com/CGAL/cgal/pull/1105 git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1536 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fc980f30c107b39f8a47e18deb23820b411a9201 --- src/Subsampling/example/CMakeLists.txt | 4 ++-- src/Subsampling/test/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 4710cf00..6bf717f7 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6) project(Subsampling_examples) if(CGAL_FOUND) - if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") find_package(Eigen3 3.1.0) @@ -22,7 +22,7 @@ if(CGAL_FOUND) message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling examples. Version 4.8.0 is required.") + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling examples. Version 4.8.1 is required.") endif () else() message(WARNING "CGAL not found. It is required for the Subsampling examples.") diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index c9e48416..72de5ac7 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -11,7 +11,7 @@ if (GPROF_PATH) endif() if(CGAL_FOUND) - if (NOT CGAL_VERSION VERSION_LESS 4.8.0) + if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") find_package(Eigen3 3.1.0) @@ -32,7 +32,7 @@ if(CGAL_FOUND) message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.0 is required.") + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.1 is required.") endif () else() message(WARNING "CGAL not found. It is required for the Subsampling tests.") -- cgit v1.2.3 From 39a0577d06d7d5349a08a64e4a73d0eaf67e6d1c Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 22 Sep 2016 15:27:44 +0000 Subject: Clean-up CMakeLists.txt git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1541 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3204fef66b8a8358820531f8d6d2494c96a7226e --- src/Spatial_searching/example/CMakeLists.txt | 5 ----- src/Spatial_searching/test/CMakeLists.txt | 4 ---- src/Subsampling/example/CMakeLists.txt | 15 ++++----------- src/Subsampling/test/CMakeLists.txt | 9 ++------- 4 files changed, 6 insertions(+), 27 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index 0c41d56c..3c3970d8 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -5,12 +5,7 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") - add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) target_link_libraries(Spatial_searching_example_spatial_searching ${CGAL_LIBRARY}) else() diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index ed61cc64..0f2c5ae4 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -14,11 +14,7 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") add_executable( Spatial_searching_test_Kd_tree_search test_Kd_tree_search.cpp ) target_link_libraries(Spatial_searching_test_Kd_tree_search diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 6bf717f7..81b39d6e 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -5,19 +5,12 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") - 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}) - - add_executable(Subsampling_example_sparsify_point_set example_sparsify_point_set.cpp) - target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + 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_sparsify_point_set example_sparsify_point_set.cpp) + target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY}) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") endif() diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 72de5ac7..91d4ed8f 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -14,18 +14,13 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) message(STATUS "CGAL version: ${CGAL_VERSION}.") - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") - 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}) - + target_link_libraries(Subsampling_test_choose_n_farthest_points ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + add_executable(Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) target_link_libraries(Subsampling_test_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) else() -- cgit v1.2.3 From 9356208327a9784b570b96ce5007f785c2abebef Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 4 Oct 2016 13:55:48 +0000 Subject: Don't use Point_d(std::array... git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1624 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b91315785cc6fbab1843b8f0e2d1778e920998b9 --- src/Subsampling/example/example_choose_n_farthest_points.cpp | 2 +- src/Subsampling/example/example_pick_n_random_points.cpp | 2 +- src/Subsampling/example/example_sparsify_point_set.cpp | 2 +- src/Subsampling/test/test_sparsify_point_set.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/example/example_choose_n_farthest_points.cpp b/src/Subsampling/example/example_choose_n_farthest_points.cpp index 9955d0ec..7afc8033 100644 --- a/src/Subsampling/example/example_choose_n_farthest_points.cpp +++ b/src/Subsampling/example/example_choose_n_farthest_points.cpp @@ -17,7 +17,7 @@ int main (void) 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)}))); + points.push_back(Point_d(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; diff --git a/src/Subsampling/example/example_pick_n_random_points.cpp b/src/Subsampling/example/example_pick_n_random_points.cpp index d2f063ba..e0d3b789 100644 --- a/src/Subsampling/example/example_pick_n_random_points.cpp +++ b/src/Subsampling/example/example_pick_n_random_points.cpp @@ -17,7 +17,7 @@ int main (void) 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)}))); + points.push_back(Point_d(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; diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index cb5ccf0b..7c8cf8b0 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -17,7 +17,7 @@ int main (void) 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)}))); + points.push_back(Point_d(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; diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index 61f6fa18..9eebbcc8 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(test_sparsify_point_set) 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)}))); + points.push_back(Point_d(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; -- cgit v1.2.3 From fb71b41cb649e0c2242bd1997cb5e7285c1633a6 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 6 Oct 2016 07:38:18 +0000 Subject: is not used anymore git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1651 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 20e9d24cb091c436d951b8a396b684a849231bc4 --- src/Spatial_searching/test/test_Kd_tree_search.cpp | 1 - src/Subsampling/example/example_sparsify_point_set.cpp | 1 - src/Subsampling/test/test_sparsify_point_set.cpp | 1 - 3 files changed, 3 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Spatial_searching/test/test_Kd_tree_search.cpp b/src/Spatial_searching/test/test_Kd_tree_search.cpp index df00d2b9..16b72c68 100644 --- a/src/Spatial_searching/test/test_Kd_tree_search.cpp +++ b/src/Spatial_searching/test/test_Kd_tree_search.cpp @@ -29,7 +29,6 @@ #include #include -#include #include BOOST_AUTO_TEST_CASE(test_Kd_tree_search) diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index 7c8cf8b0..ccf83bc0 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index 9eebbcc8..04a055ff 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -29,7 +29,6 @@ #include #include -#include #include #include -- cgit v1.2.3 From a1d8a8b08002d7d2067b76b7109cae4c20618540 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 10:50:47 +0000 Subject: Add unitary tests in make test target Fix doxygen warning fix compilation warning (typedef not used) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1652 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d080543ea90aa089e2f09933a44156f07ae82eb4 --- src/Spatial_searching/example/CMakeLists.txt | 12 +++--------- src/Spatial_searching/test/CMakeLists.txt | 13 ++++--------- src/Subsampling/doc/Intro_subsampling.h | 2 +- src/Subsampling/example/CMakeLists.txt | 22 ++++++++++------------ .../example/example_sparsify_point_set.cpp | 1 - src/Subsampling/test/CMakeLists.txt | 20 ++++++++++++-------- src/Subsampling/test/test_sparsify_point_set.cpp | 1 - 7 files changed, 30 insertions(+), 41 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index 3c3970d8..6238a0ec 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -3,17 +3,11 @@ project(Spatial_searching_examples) if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - if (EIGEN3_FOUND) add_executable( Spatial_searching_example_spatial_searching example_spatial_searching.cpp ) target_link_libraries(Spatial_searching_example_spatial_searching ${CGAL_LIBRARY}) - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Tangential_complex examples.") + add_test(Spatial_searching_example_spatial_searching + ${CMAKE_CURRENT_BINARY_DIR}/Spatial_searching_example_spatial_searching) endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Spatial_searching examples. Version 4.8.1 is required.") - endif () -else() - message(WARNING "CGAL not found. It is required for the Spatial_searching examples.") + endif() endif() diff --git a/src/Spatial_searching/test/CMakeLists.txt b/src/Spatial_searching/test/CMakeLists.txt index 0f2c5ae4..2c685c72 100644 --- a/src/Spatial_searching/test/CMakeLists.txt +++ b/src/Spatial_searching/test/CMakeLists.txt @@ -12,19 +12,14 @@ endif() if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - if (EIGEN3_FOUND) - add_executable( Spatial_searching_test_Kd_tree_search test_Kd_tree_search.cpp ) target_link_libraries(Spatial_searching_test_Kd_tree_search ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for the Spatial_searching tests.") + + add_test(Spatial_searching_test_Kd_tree_search ${CMAKE_CURRENT_BINARY_DIR}/Spatial_searching_test_Kd_tree_search + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Spatial_searching_UT.xml --log_level=test_suite --report_level=no) endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.1 is required.") endif () -else() - message(WARNING "CGAL not found. It is required for the Spatial_searching tests.") endif() diff --git a/src/Subsampling/doc/Intro_subsampling.h b/src/Subsampling/doc/Intro_subsampling.h index f8eb2fdd..c84616dd 100644 --- a/src/Subsampling/doc/Intro_subsampling.h +++ b/src/Subsampling/doc/Intro_subsampling.h @@ -34,7 +34,7 @@ namespace subsampling { * * @{ * - * \section introduction Introduction + * \section subsamplingintroduction Introduction * * This Gudhi component offers methods to subsample a set of points. * diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 81b39d6e..54349f0c 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -3,20 +3,18 @@ project(Subsampling_examples) if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - 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_sparsify_point_set example_sparsify_point_set.cpp) + target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY}) - 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_sparsify_point_set example_sparsify_point_set.cpp) - target_link_libraries(Subsampling_example_sparsify_point_set ${CGAL_LIBRARY}) - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") + add_test(Subsampling_example_pick_n_random_points + ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_example_pick_n_random_points) + add_test(Subsampling_example_choose_n_farthest_points + ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_example_choose_n_farthest_points) + add_test(Subsampling_example_sparsify_point_set + ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_example_sparsify_point_set) endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling examples. Version 4.8.1 is required.") endif () -else() - message(WARNING "CGAL not found. It is required for the Subsampling examples.") endif() diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index ccf83bc0..ad68b4c1 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -9,7 +9,6 @@ int main (void) { typedef CGAL::Epick_d > K; - typedef typename K::FT FT; typedef typename K::Point_d Point_d; CGAL::Random rd; diff --git a/src/Subsampling/test/CMakeLists.txt b/src/Subsampling/test/CMakeLists.txt index 91d4ed8f..3a2fb649 100644 --- a/src/Subsampling/test/CMakeLists.txt +++ b/src/Subsampling/test/CMakeLists.txt @@ -12,8 +12,6 @@ endif() if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - if (EIGEN3_FOUND) 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}) @@ -23,12 +21,18 @@ if(CGAL_FOUND) add_executable(Subsampling_test_sparsify_point_set test_sparsify_point_set.cpp) target_link_libraries(Subsampling_test_sparsify_point_set ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for Subsampling feature.") + + add_test(Subsampling_test_pick_n_random_points ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_test_pick_n_random_points + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Subsampling_test_pick_n_random_points_UT.xml --log_level=test_suite --report_level=no) + + add_test(Subsampling_test_choose_n_farthest_points ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_test_choose_n_farthest_points + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Subsampling_test_choose_n_farthest_points_UT.xml --log_level=test_suite --report_level=no) + + add_test(Subsampling_test_sparsify_point_set ${CMAKE_CURRENT_BINARY_DIR}/Subsampling_test_sparsify_point_set + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Subsampling_test_sparsify_point_set_UT.xml --log_level=test_suite --report_level=no) endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Subsampling tests. Version 4.8.1 is required.") endif () -else() - message(WARNING "CGAL not found. It is required for the Subsampling tests.") endif() diff --git a/src/Subsampling/test/test_sparsify_point_set.cpp b/src/Subsampling/test/test_sparsify_point_set.cpp index 04a055ff..f993d6d6 100644 --- a/src/Subsampling/test/test_sparsify_point_set.cpp +++ b/src/Subsampling/test/test_sparsify_point_set.cpp @@ -35,7 +35,6 @@ BOOST_AUTO_TEST_CASE(test_sparsify_point_set) { typedef CGAL::Epick_d > K; - typedef typename K::FT FT; typedef typename K::Point_d Point_d; CGAL::Random rd; -- cgit v1.2.3 From 7e417a80188b8ed4051f73f26e9899f94c33dc1e Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 6 Oct 2016 17:13:24 +0000 Subject: fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1663 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 78cab9749df2feaf6d47bf253d4449b043e026e7 --- .../example/example_choose_n_farthest_points.cpp | 14 +++++++------- src/Subsampling/example/example_pick_n_random_points.cpp | 14 +++++++------- src/Subsampling/example/example_sparsify_point_set.cpp | 14 +++++++------- src/Subsampling/test/test_choose_n_farthest_points.cpp | 9 ++++----- 4 files changed, 25 insertions(+), 26 deletions(-) (limited to 'src/Subsampling/test') diff --git a/src/Subsampling/example/example_choose_n_farthest_points.cpp b/src/Subsampling/example/example_choose_n_farthest_points.cpp index 4bcb0eb9..533aba74 100644 --- a/src/Subsampling/example/example_choose_n_farthest_points.cpp +++ b/src/Subsampling/example/example_choose_n_farthest_points.cpp @@ -6,16 +6,16 @@ #include #include -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::Point_d Point_d; - +int main(void) { + typedef CGAL::Epick_d > K; + 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(rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1))); + for (int i = 0; i < 500; ++i) + points.push_back(Point_d(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; diff --git a/src/Subsampling/example/example_pick_n_random_points.cpp b/src/Subsampling/example/example_pick_n_random_points.cpp index 7b4379e4..1e38e405 100644 --- a/src/Subsampling/example/example_pick_n_random_points.cpp +++ b/src/Subsampling/example/example_pick_n_random_points.cpp @@ -6,16 +6,16 @@ #include #include -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::Point_d Point_d; - +int main(void) { + typedef CGAL::Epick_d > K; + 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(rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1))); + for (int i = 0; i < 500; ++i) + points.push_back(Point_d(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; diff --git a/src/Subsampling/example/example_sparsify_point_set.cpp b/src/Subsampling/example/example_sparsify_point_set.cpp index ad68b4c1..b35a18d9 100644 --- a/src/Subsampling/example/example_sparsify_point_set.cpp +++ b/src/Subsampling/example/example_sparsify_point_set.cpp @@ -6,16 +6,16 @@ #include #include -int main (void) -{ - typedef CGAL::Epick_d > K; - typedef typename K::Point_d Point_d; - +int main(void) { + typedef CGAL::Epick_d > K; + 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(rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1),rd.get_double(-1.,1))); + for (int i = 0; i < 500; ++i) + points.push_back(Point_d(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; diff --git a/src/Subsampling/test/test_choose_n_farthest_points.cpp b/src/Subsampling/test/test_choose_n_farthest_points.cpp index f79a4dfb..d064899a 100644 --- a/src/Subsampling/test/test_choose_n_farthest_points.cpp +++ b/src/Subsampling/test/test_choose_n_farthest_points.cpp @@ -35,10 +35,9 @@ #include -typedef CGAL::Epick_d K; -typedef typename K::FT FT; -typedef typename K::Point_d Point_d; - +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) { std::vector< Point_d > points, landmarks; @@ -52,6 +51,6 @@ BOOST_AUTO_TEST_CASE(test_choose_farthest_point) { landmarks.clear(); K k; Gudhi::subsampling::choose_n_farthest_points(k, points, 100, std::back_inserter(landmarks)); - + BOOST_CHECK(landmarks.size() == 100); } -- cgit v1.2.3