diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-10-17 09:16:07 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-10-17 09:16:07 +0000 |
commit | 1a58961f77efe53b1d57e0bbfe6bd3da22e6d01e (patch) | |
tree | 5fa9ac8a8703731e55251ebd38dfd251fc666933 /src/cython/include/Rips_complex_interface.h | |
parent | f1d0acdc9f3f8d886996cc078242b48598a3275a (diff) | |
parent | 07c214f675595b75a2a9d1f8dc2888487aa6086a (diff) |
Merge branch sparserips-python
Fix doxygen bad link on sparsify point set function
Fix some lines too long
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@3961 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 94946e2dd7853bd65d6790546ad2ef8a35d298c1
Diffstat (limited to 'src/cython/include/Rips_complex_interface.h')
-rw-r--r-- | src/cython/include/Rips_complex_interface.h | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/cython/include/Rips_complex_interface.h b/src/cython/include/Rips_complex_interface.h index 8b6c9c35..1a6e2477 100644 --- a/src/cython/include/Rips_complex_interface.h +++ b/src/cython/include/Rips_complex_interface.h @@ -25,8 +25,11 @@ #include <gudhi/Simplex_tree.h> #include <gudhi/Rips_complex.h> +#include <gudhi/Sparse_rips_complex.h> #include <gudhi/distance_functions.h> +#include <boost/optional.hpp> + #include "Simplex_tree_interface.h" #include <iostream> @@ -43,28 +46,40 @@ class Rips_complex_interface { using Distance_matrix = std::vector<std::vector<Simplex_tree_interface<>::Filtration_value>>; public: - Rips_complex_interface(const std::vector<std::vector<double>>& values, double threshold, bool euclidean) { - if (euclidean) { - // Rips construction where values is a vector of points - rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(values, threshold, - Gudhi::Euclidean_distance()); - } else { - // Rips construction where values is a distance matrix - rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(values, threshold); - } + void init_points(const std::vector<std::vector<double>>& points, double threshold) { + rips_complex_.emplace(points, threshold, Gudhi::Euclidean_distance()); + } + void init_matrix(const std::vector<std::vector<double>>& matrix, double threshold) { + rips_complex_.emplace(matrix, threshold); } - ~Rips_complex_interface() { - delete rips_complex_; + void init_points_sparse(const std::vector<std::vector<double>>& points, double threshold, double epsilon) { + sparse_rips_complex_.emplace(points, Gudhi::Euclidean_distance(), epsilon); + threshold_ = threshold; + } + void init_matrix_sparse(const std::vector<std::vector<double>>& matrix, double threshold, double epsilon) { + sparse_rips_complex_.emplace(matrix, epsilon); + threshold_ = threshold; } void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, int dim_max) { - rips_complex_->create_complex(*simplex_tree, dim_max); + if (rips_complex_) + rips_complex_->create_complex(*simplex_tree, dim_max); + else { + sparse_rips_complex_->create_complex(*simplex_tree, dim_max); + // This pruning should be done much earlier! It isn't that useful for sparse Rips, + // but it would be inconsistent not to do it. + simplex_tree->prune_above_filtration(threshold_); + } simplex_tree->initialize_filtration(); } private: - Rips_complex<Simplex_tree_interface<>::Filtration_value>* rips_complex_; + // std::variant would work, but we don't require C++17 yet, and boost::variant is not super convenient. + // Anyway, storing a graph would make more sense. Or changing the interface completely so there is no such storage. + boost::optional<Rips_complex<Simplex_tree_interface<>::Filtration_value>> rips_complex_; + boost::optional<Sparse_rips_complex<Simplex_tree_interface<>::Filtration_value>> sparse_rips_complex_; + double threshold_; }; } // namespace rips_complex |