Subsampling_interface.h
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2  * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3  * Author(s): Vincent Rouvreau
4  *
5  * Copyright (C) 2016 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef INCLUDE_SUBSAMPLING_INTERFACE_H_
12 #define INCLUDE_SUBSAMPLING_INTERFACE_H_
13 
15 #include <gudhi/choose_n_farthest_points.h>
16 #include <gudhi/pick_n_random_points.h>
17 #include <gudhi/sparsify_point_set.h>
18 #include <gudhi/Points_off_io.h>
19 #include <CGAL/Epick_d.h>
20 
21 #include <iostream>
22 #include <vector>
23 #include <string>
24 
25 namespace Gudhi {
26 
27 namespace subsampling {
28 
29 using Subsampling_dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >;
30 using Subsampling_point_d = Subsampling_dynamic_kernel::Point_d;
31 
32 // ------ choose_n_farthest_points ------
33 std::vector<std::vector<double>> subsampling_n_farthest_points(const std::vector<std::vector<double>>& points,
34  unsigned nb_points) {
35  std::vector<std::vector<double>> landmarks;
36  choose_n_farthest_points(Euclidean_distance(), points, nb_points,
37  random_starting_point, std::back_inserter(landmarks));
38 
39  return landmarks;
40 }
41 
42 std::vector<std::vector<double>> subsampling_n_farthest_points(const std::vector<std::vector<double>>& points,
43  unsigned nb_points, unsigned starting_point) {
44  std::vector<std::vector<double>> landmarks;
45  choose_n_farthest_points(Euclidean_distance(), points, nb_points,
46  starting_point, std::back_inserter(landmarks));
47 
48  return landmarks;
49 }
50 
51 std::vector<std::vector<double>> subsampling_n_farthest_points_from_file(const std::string& off_file,
52  unsigned nb_points) {
54  std::vector<std::vector<double>> points = off_reader.get_point_cloud();
55  return subsampling_n_farthest_points(points, nb_points);
56 }
57 
58 std::vector<std::vector<double>> subsampling_n_farthest_points_from_file(const std::string& off_file,
59  unsigned nb_points, unsigned starting_point) {
61  std::vector<std::vector<double>> points = off_reader.get_point_cloud();
62  return subsampling_n_farthest_points(points, nb_points, starting_point);
63 }
64 
65 // ------ pick_n_random_points ------
66 std::vector<std::vector<double>> subsampling_n_random_points(const std::vector<std::vector<double>>& points,
67  unsigned nb_points) {
68  std::vector<std::vector<double>> landmarks;
69  pick_n_random_points(points, nb_points, std::back_inserter(landmarks));
70 
71  return landmarks;
72 }
73 
74 std::vector<std::vector<double>> subsampling_n_random_points_from_file(const std::string& off_file,
75  unsigned nb_points) {
77  std::vector<std::vector<double>> points = off_reader.get_point_cloud();
78  return subsampling_n_random_points(points, nb_points);
79 }
80 
81 // ------ sparsify_point_set ------
82 std::vector<std::vector<double>> subsampling_sparsify_points(const std::vector<std::vector<double>>& points,
83  double min_squared_dist) {
84  std::vector<Subsampling_point_d> input, output;
85  for (auto point : points)
86  input.push_back(Subsampling_point_d(point.size(), point.begin(), point.end()));
87  Subsampling_dynamic_kernel k;
88  sparsify_point_set(k, input, min_squared_dist, std::back_inserter(output));
89 
90  std::vector<std::vector<double>> landmarks;
91  for (auto point : output)
92  landmarks.push_back(std::vector<double>(point.cartesian_begin(), point.cartesian_end()));
93  return landmarks;
94 }
95 
96 std::vector<std::vector<double>> subsampling_sparsify_points_from_file(const std::string& off_file,
97  double min_squared_dist) {
99  std::vector<std::vector<double>> points = off_reader.get_point_cloud();
100  return subsampling_sparsify_points(points, min_squared_dist);
101 }
102 
103 } // namespace subsampling
104 
105 } // namespace Gudhi
106 
107 #endif // INCLUDE_SUBSAMPLING_INTERFACE_H_
Compute the Euclidean distance between two Points given by a range of coordinates....
Definition: distance_functions.h:34
OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:122
Global distance functions.
void sparsify_point_set(const Kernel &k, Point_range const &input_pts, typename Kernel::FT min_squared_dist, OutputIterator output_it)
Outputs a subset of the input points so that the squared distance between any two points is greater t...
Definition: sparsify_point_set.h:55
void choose_n_farthest_points(Distance dist, Point_range const &input_pts, std::size_t final_size, std::size_t starting_point, PointOutputIterator output_it, DistanceOutputIterator dist_it={})
Subsample by a greedy strategy of iteratively adding the farthest point from the current chosen point...
Definition: choose_n_farthest_points.h:69
void pick_n_random_points(Point_container const &points, std::size_t final_size, OutputIterator output_it)
Subsample a point set by picking random vertices.
Definition: pick_n_random_points.h:42
@ random_starting_point
Definition: choose_n_farthest_points.h:34
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Fri Jan 14 2022 18:28:42 for GUDHIdev by Doxygen 1.9.1