summaryrefslogtreecommitdiff
path: root/src/Subsampling
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-10-06 17:19:44 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-10-06 17:19:44 +0000
commit5592d57180bee4cdedbe2e99ffd873184e889559 (patch)
treea6d2acbd2fd7fd58edaffd75b6f742ba54250ba9 /src/Subsampling
parent7e417a80188b8ed4051f73f26e9899f94c33dc1e (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')
-rw-r--r--src/Subsampling/include/gudhi/choose_n_farthest_points.h153
-rw-r--r--src/Subsampling/include/gudhi/pick_n_random_points.h53
-rw-r--r--src/Subsampling/include/gudhi/sparsify_point_set.h18
3 files changed, 111 insertions, 113 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_
diff --git a/src/Subsampling/include/gudhi/pick_n_random_points.h b/src/Subsampling/include/gudhi/pick_n_random_points.h
index 52842a54..e89b2b2d 100644
--- a/src/Subsampling/include/gudhi/pick_n_random_points.h
+++ b/src/Subsampling/include/gudhi/pick_n_random_points.h
@@ -38,45 +38,44 @@
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 <typename Point_container,
- typename OutputIterator>
- void pick_n_random_points(Point_container const &points,
+
+/**
+ * \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 <typename Point_container,
+typename OutputIterator>
+void pick_n_random_points(Point_container const &points,
std::size_t final_size,
OutputIterator output_it) {
#ifdef GUDHI_SUBS_PROFILING
- Gudhi::Clock t;
+ Gudhi::Clock t;
#endif
- std::size_t nbP = boost::size(points);
- assert(nbP >= final_size);
- std::vector<int> landmarks(nbP);
- std::iota(landmarks.begin(), landmarks.end(), 0);
+ std::size_t nbP = boost::size(points);
+ assert(nbP >= final_size);
+ std::vector<int> landmarks(nbP);
+ std::iota(landmarks.begin(), landmarks.end(), 0);
- std::random_device rd;
- std::mt19937 g(rd());
+ std::random_device rd;
+ std::mt19937 g(rd());
- std::shuffle(landmarks.begin(), landmarks.end(), g);
- landmarks.resize(final_size);
+ std::shuffle(landmarks.begin(), landmarks.end(), g);
+ landmarks.resize(final_size);
- for (int l: landmarks)
- *output_it++ = points[l];
+ for (int l : landmarks)
+ *output_it++ = points[l];
#ifdef GUDHI_SUBS_PROFILING
- t.end();
- std::cerr << "Random landmark choice took " << t.num_seconds()
+ t.end();
+ std::cerr << "Random landmark choice took " << t.num_seconds()
<< " seconds." << std::endl;
#endif
- }
+}
} // namespace subsampling
diff --git a/src/Subsampling/include/gudhi/sparsify_point_set.h b/src/Subsampling/include/gudhi/sparsify_point_set.h
index edb9869b..7ff11b4c 100644
--- a/src/Subsampling/include/gudhi/sparsify_point_set.h
+++ b/src/Subsampling/include/gudhi/sparsify_point_set.h
@@ -32,6 +32,7 @@
#include <vector>
namespace Gudhi {
+
namespace subsampling {
/**
@@ -54,15 +55,14 @@ namespace subsampling {
* @param[in] min_squared_dist Minimum squared distance separating the output points.
* @param[out] output_it The output iterator.
*/
-
template <typename Kernel, typename Point_range, typename OutputIterator>
void
sparsify_point_set(
- const Kernel &k, Point_range const& input_pts,
- typename Kernel::FT min_squared_dist,
- OutputIterator output_it) {
+ const Kernel &k, Point_range const& input_pts,
+ typename Kernel::FT min_squared_dist,
+ OutputIterator output_it) {
typedef typename Gudhi::spatial_searching::Kd_tree_search<
- Kernel, Point_range> Points_ds;
+ Kernel, Point_range> Points_ds;
typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object();
@@ -77,9 +77,9 @@ sparsify_point_set(
// Parse the input points, and add them if they are not too close to
// the other points
std::size_t pt_idx = 0;
- for (typename Point_range::const_iterator it_pt = input_pts.begin() ;
- it_pt != input_pts.end();
- ++it_pt, ++pt_idx) {
+ for (typename Point_range::const_iterator it_pt = input_pts.begin();
+ it_pt != input_pts.end();
+ ++it_pt, ++pt_idx) {
if (dropped_points[pt_idx])
continue;
@@ -105,7 +105,7 @@ sparsify_point_set(
#ifdef GUDHI_SUBSAMPLING_PROFILING
t.end();
std::cerr << "Point set sparsified in " << t.num_seconds()
- << " seconds." << std::endl;
+ << " seconds." << std::endl;
#endif
}