diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2020-12-10 23:36:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-10 23:36:58 +0100 |
commit | 10794c300e349fef918b9b8e91d4c2aee7a01890 (patch) | |
tree | 1ccbbaa9b31c98d4921f2745eb88ae45f9d43aef /src/Subsampling/example/example_custom_distance.cpp | |
parent | d1b7c8fd3e66c19203967d559582af713417aeca (diff) | |
parent | a2783dd8db753a407cfad329d03e2a56b2095f3d (diff) |
Merge pull request #409 from mglisse/fardist
Pass a distance function instead of a kernel to choose_n_farthest_points
Diffstat (limited to 'src/Subsampling/example/example_custom_distance.cpp')
-rw-r--r-- | src/Subsampling/example/example_custom_distance.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Subsampling/example/example_custom_distance.cpp b/src/Subsampling/example/example_custom_distance.cpp new file mode 100644 index 00000000..3325b12d --- /dev/null +++ b/src/Subsampling/example/example_custom_distance.cpp @@ -0,0 +1,44 @@ +#include <gudhi/choose_n_farthest_points.h> + +#include <iostream> +#include <vector> +#include <iterator> + + +typedef unsigned Point; + +/* The class Distance contains a distance function defined on the set of points {0, 1, 2, 3} + * and computes a distance according to the matrix: + * 0 1 2 4 + * 1 0 4 2 + * 2 4 0 1 + * 4 2 1 0 + */ +class Distance { + private: + std::vector<std::vector<double>> matrix_; + + public: + Distance() { + matrix_.push_back({0, 1, 2, 4}); + matrix_.push_back({1, 0, 4, 2}); + matrix_.push_back({2, 4, 0, 1}); + matrix_.push_back({4, 2, 1, 0}); + } + + double operator()(Point p1, Point p2) const { + return matrix_[p1][p2]; + } +}; + +int main(void) { + std::vector<Point> points = {0, 1, 2, 3}; + std::vector<Point> results; + + Gudhi::subsampling::choose_n_farthest_points(Distance(), points, 2, + Gudhi::subsampling::random_starting_point, + std::back_inserter(results)); + std::clog << "Before sparsification: " << points.size() << " points.\n"; + std::clog << "After sparsification: " << results.size() << " points.\n"; + std::clog << "Result table: {" << results[0] << "," << results[1] << "}\n"; +} |