From 8d7329f3e5ad843e553c3c5503cecc28ef2eead6 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Thu, 20 Apr 2017 11:10:45 +0200 Subject: GUDHI 2.0.0 as released by upstream in a tarball. --- example/Subsampling/example_custom_kernel.cpp | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 example/Subsampling/example_custom_kernel.cpp (limited to 'example/Subsampling/example_custom_kernel.cpp') diff --git a/example/Subsampling/example_custom_kernel.cpp b/example/Subsampling/example_custom_kernel.cpp new file mode 100644 index 00000000..2d42bdde --- /dev/null +++ b/example/Subsampling/example_custom_kernel.cpp @@ -0,0 +1,65 @@ +#include + +#include +#include + +#include +#include + + +/* The class Kernel 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 Kernel { + public: + typedef double FT; + typedef unsigned Point_d; + + // Class Squared_distance_d + class Squared_distance_d { + private: + std::vector> matrix_; + + public: + Squared_distance_d() { + matrix_.push_back(std::vector({0, 1, 2, 4})); + matrix_.push_back(std::vector({1, 0, 4, 2})); + matrix_.push_back(std::vector({2, 4, 0, 1})); + matrix_.push_back(std::vector({4, 2, 1, 0})); + } + + FT operator()(Point_d p1, Point_d p2) { + return matrix_[p1][p2]; + } + }; + + // Constructor + Kernel() {} + + // Object of type Squared_distance_d + Squared_distance_d squared_distance_d_object() const { + return Squared_distance_d(); + } +}; + +int main(void) { + typedef Kernel K; + typedef typename K::Point_d Point_d; + + K k; + std::vector points = {0, 1, 2, 3}; + std::vector results; + + Gudhi::subsampling::choose_n_farthest_points(k, points, 2, + Gudhi::subsampling::random_starting_point, + std::back_inserter(results)); + std::cout << "Before sparsification: " << points.size() << " points.\n"; + std::cout << "After sparsification: " << results.size() << " points.\n"; + std::cout << "Result table: {" << results[0] << "," << results[1] << "}\n"; + + return 0; +} -- cgit v1.2.3