summaryrefslogtreecommitdiff
path: root/src/Subsampling
diff options
context:
space:
mode:
authorskachano <skachano@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-06-22 09:42:57 +0000
committerskachano <skachano@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-06-22 09:42:57 +0000
commit83dd60a38920cdf85e4c1108404cfa7c294f98e2 (patch)
treef838d233a7039e85251f22ab0788af313b2bae47 /src/Subsampling
parent4ef423a7a1140f1fe1a2ce1f1bbee03990638be1 (diff)
Took into account Clément's remarks
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
Diffstat (limited to 'src/Subsampling')
-rw-r--r--src/Subsampling/include/gudhi/choose_by_farthest_point.h31
-rw-r--r--src/Subsampling/include/gudhi/pick_random_points.h (renamed from src/Subsampling/include/gudhi/Pick_random_points.h)22
-rw-r--r--src/Subsampling/test/test_choose_farthest_point.cpp8
-rw-r--r--src/Subsampling/test/test_pick_random_points.cpp10
4 files changed, 37 insertions, 34 deletions
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 <random>
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<Closest_landmark_range<Vertex_handle>>, 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
index 98902264..732ae3f7 100644
--- a/src/Subsampling/include/gudhi/Pick_random_points.h
+++ b/src/Subsampling/include/gudhi/pick_random_points.h
@@ -34,26 +34,28 @@
namespace Gudhi {
+namespace subsampling {
+
/**
- * \ingroup witness_complex
- * \brief Landmark choice strategy by taking random vertices for landmarks.
+ * \ingroup subsampling
+ * \brief Subsample a point set by picking random vertices.
*
- * \details It chooses nbL distinct landmarks from a random access range `points`
- * and outputs them to an output iterator.
+ * \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_random_points(Point_container const &points,
- unsigned nbL,
+ unsigned final_size,
OutputIterator output_it) {
-#ifdef GUDHI_LM_PROFILING
+#ifdef GUDHI_SUBS_PROFILING
Gudhi::Clock t;
#endif
unsigned nbP = boost::size(points);
- assert(nbP >= nbL);
+ assert(nbP >= final_size);
std::vector<int> landmarks(nbP);
std::iota(landmarks.begin(), landmarks.end(), 0);
@@ -61,18 +63,20 @@ namespace Gudhi {
std::mt19937 g(rd());
std::shuffle(landmarks.begin(), landmarks.end(), g);
- landmarks.resize(nbL);
+ landmarks.resize(final_size);
for (int l: landmarks)
*output_it++ = points[l];
-#ifdef GUDHI_LM_PROFILING
+#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<FT>({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 <gudhi/Pick_random_points.h>
+#include <gudhi/pick_random_points.h>
#include <vector>
#include <iterator>
@@ -55,11 +55,11 @@ int main() {
vect.push_back(Point_d(std::vector<FT>({1,1,1,1})));
- std::vector<Point_d> landmarks;
- Gudhi::pick_random_points(vect, 5, std::back_inserter(landmarks));
+ std::vector<Point_d> 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);
}