summaryrefslogtreecommitdiff
path: root/src/Subsampling/include/gudhi/choose_n_farthest_points.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Subsampling/include/gudhi/choose_n_farthest_points.h')
-rw-r--r--src/Subsampling/include/gudhi/choose_n_farthest_points.h53
1 files changed, 44 insertions, 9 deletions
diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h
index 40c7808d..5e908090 100644
--- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h
+++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h
@@ -48,22 +48,40 @@ namespace subsampling {
* \brief Subsample by a greedy strategy of iteratively adding the farthest point from the
* current chosen point set to the subsampling.
* The iteration starts with the landmark `starting point`.
+ * \tparam Kernel must provide a type Kernel::Squared_distance_d which is a model of the
+ * concept <a target="_blank"
+ * href="http://doc.cgal.org/latest/Kernel_d/classKernel__d_1_1Squared__distance__d.html">Kernel_d::Squared_distance_d</a>
+ * concept.
+ * It must also contain a public member 'squared_distance_d_object' of this type.
+ * \tparam Point_range Range whose value type is Kernel::Point_d. It must provide random-access
+ * via `operator[]` and the points should be stored contiguously in memory.
+ * \tparam OutputIterator Output iterator whose value type is Kernel::Point_d.
* \details It chooses `final_size` points from a random access range `input_pts` and
* outputs it in the output iterator `output_it`.
+ * @param[in] k A kernel object.
+ * @param[in] input_pts Const reference to the input points.
+ * @param[in] final_size The size of the subsample to compute.
+ * @param[in] starting_point The seed in the farthest point algorithm.
+ * @param[out] output_it The output iterator.
*
*/
template < typename Kernel,
-typename Point_container,
+typename Point_range,
typename OutputIterator>
void choose_n_farthest_points(Kernel const &k,
- Point_container const &input_pts,
+ Point_range const &input_pts,
std::size_t final_size,
std::size_t starting_point,
OutputIterator output_it) {
- typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object();
-
std::size_t nb_points = boost::size(input_pts);
- assert(nb_points >= final_size);
+ if (final_size > nb_points)
+ final_size = nb_points;
+
+ // Tests to the limit
+ if (final_size < 1)
+ return;
+
+ typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object();
std::size_t current_number_of_landmarks = 0; // counter for landmarks
const double infty = std::numeric_limits<double>::infinity(); // infinity (see next entry)
@@ -96,22 +114,39 @@ void choose_n_farthest_points(Kernel const &k,
* \brief Subsample by a greedy strategy of iteratively adding the farthest point from the
* current chosen point set to the subsampling.
* The iteration starts with a random landmark.
+ * \tparam Kernel must provide a type Kernel::Squared_distance_d which is a model of the
+ * concept <a target="_blank"
+ * href="http://doc.cgal.org/latest/Kernel_d/classKernel__d_1_1Squared__distance__d.html">Kernel_d::Squared_distance_d</a>
+ * concept.
+ * It must also contain a public member 'squared_distance_d_object' of this type.
+ * \tparam Point_range Range whose value type is Kernel::Point_d. It must provide random-access
+ * via `operator[]` and the points should be stored contiguously in memory.
+ * \tparam OutputIterator Output iterator whose value type is Kernel::Point_d.
* \details It chooses `final_size` points from a random access range `input_pts` and
* outputs it in the output iterator `output_it`.
+ * @param[in] k A kernel object.
+ * @param[in] input_pts Const reference to the input points.
+ * @param[in] final_size The size of the subsample to compute.
+ * @param[out] output_it The output iterator.
*
*/
template < typename Kernel,
-typename Point_container,
+typename Point_range,
typename OutputIterator>
void choose_n_farthest_points(Kernel const& k,
- Point_container const &input_pts,
+ Point_range const &input_pts,
unsigned final_size,
OutputIterator output_it) {
+ // Tests to the limit
+ if ((final_size < 1) || (input_pts.size() == 0))
+ return;
+
// Choose randomly the first landmark
std::random_device rd;
std::mt19937 gen(rd());
- std::uniform_int_distribution<> dis(1, 6);
- int starting_point = dis(gen);
+ std::uniform_int_distribution<> dis(0, (input_pts.size() - 1));
+ std::size_t starting_point = dis(gen);
+
choose_n_farthest_points(k, input_pts, final_size, starting_point, output_it);
}