diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-10-06 17:19:44 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-10-06 17:19:44 +0000 |
commit | 5592d57180bee4cdedbe2e99ffd873184e889559 (patch) | |
tree | a6d2acbd2fd7fd58edaffd75b6f742ba54250ba9 /src/Subsampling/include/gudhi/choose_n_farthest_points.h | |
parent | 7e417a80188b8ed4051f73f26e9899f94c33dc1e (diff) |
fixcpplint
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/subsampling_and_spatialsearching@1667 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: c6974fc881cae681326777d1e6f8bd7f475f235e
Diffstat (limited to 'src/Subsampling/include/gudhi/choose_n_farthest_points.h')
-rw-r--r-- | src/Subsampling/include/gudhi/choose_n_farthest_points.h | 153 |
1 files changed, 76 insertions, 77 deletions
diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index a4719f56..60816a29 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -37,89 +37,88 @@ #include <algorithm> // for sort #include <vector> #include <random> +#include <limits> // for numeric_limits<> 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, - std::size_t final_size, - std::size_t starting_point, - OutputIterator output_it) - { - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - - std::size_t nb_points = boost::size(input_pts); - assert(nb_points >= final_size); - - std::size_t 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<double>::infinity(); // infinity (see next entry) - std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from input_pts - - std::size_t 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"; - std::size_t 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 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, + std::size_t final_size, + std::size_t starting_point, + OutputIterator output_it) { + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); + + std::size_t nb_points = boost::size(input_pts); + assert(nb_points >= final_size); + + std::size_t 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<double>::infinity(); // infinity (see next entry) + std::vector< double > dist_to_L(nb_points, infty); // vector of current distances to L from input_pts + + std::size_t 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"; + std::size_t 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 const& k, - Point_container const &input_pts, - unsigned 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 - +} + +/** + * \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 const& k, + Point_container const &input_pts, + unsigned 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_ |