From f6992f0e5eb53d67a567ee0f12d2c16099bcaf1b Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 17 Jan 2017 22:58:28 +0000 Subject: Added a non-Euclidean version of Witness. Compiles, but doesn't work git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1943 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a825e1ad183ae40170414038e70ce37d38e09689 --- .../include/gudhi/Witness_complex.h | 68 ++++++---------------- .../test/test_simple_witness_complex.cpp | 52 +++++++++++++---- 2 files changed, 61 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 56ea8613..22f0f590 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -47,37 +47,22 @@ namespace witness_complex { * href="http://doc.cgal.org/latest/Kernel_d/classCGAL_1_1Epick__d.html">CGAL::Epick_d class, which * can be static if you know the ambiant dimension at compile-time, or dynamic if you don't. */ -template< class Kernel_ > +template< class Nearest_landmark_table_ > class Witness_complex { private: - typedef Kernel_ K; - typedef typename K::Point_d Point_d; - typedef typename K::FT FT; - typedef std::vector Point_range; - typedef gss::Kd_tree_search Kd_tree; - typedef typename Kd_tree::INS_range Nearest_landmark_range; - //typedef typename std::vector Nearest_landmark_table; - //typedef typename Nearest_landmark_range::iterator Nearest_landmark_row_iterator; - - typedef std::vector< double > Point_t; - typedef std::vector< Point_t > Point_Vector; - - typedef FT Filtration_value; - - - typedef std::size_t Witness_id; - typedef typename Nearest_landmark_range::Point_with_transformed_distance Id_distance_pair; - typedef typename Id_distance_pair::first_type Landmark_id; - typedef Active_witness ActiveWitness; - typedef std::list< ActiveWitness > ActiveWitnessList; - typedef std::vector< Landmark_id > typeVectorVertex; - typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; + typedef typename Nearest_landmark_table_::value_type Nearest_landmark_range; + typedef std::size_t Witness_id; + typedef std::size_t Landmark_id; + typedef std::pair Id_distance_pair; + typedef Active_witness ActiveWitness; + typedef std::list< ActiveWitness > ActiveWitnessList; + typedef std::vector< Landmark_id > typeVectorVertex; + typedef std::pair< typeVectorVertex, Filtration_value> typeSimplex; typedef Landmark_id Vertex_handle; private: - Point_range witnesses_, landmarks_; - Kd_tree landmark_tree_; + Nearest_landmark_table_& nearest_landmark_table_; public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -92,22 +77,13 @@ private: * table internally, as well as witnesses from the range 'witnesses'. * Both ranges should have value_type Kernel_::Point_d. */ - template< typename LandmarkRange, - typename WitnessRange > - Witness_complex(const LandmarkRange & landmarks, - const WitnessRange & witnesses) - : witnesses_(witnesses), landmarks_(landmarks), landmark_tree_(landmarks_) + + Witness_complex(Nearest_landmark_table_ & nearest_landmark_table) + : nearest_landmark_table_(nearest_landmark_table) { } - /** \brief Returns the point corresponding to the given vertex. - * @param[in] vertex Vertex handle of the point to retrieve. - */ - Point_d get_point( Vertex_handle vertex ) const - { - return landmarks_[vertex]; - } - + /** \brief Outputs the (weak) witness complex of relaxation 'max_alpha_square' * in a simplicial complex data structure. * \details The function returns true if the construction is successful and false otherwise. @@ -119,10 +95,10 @@ private: */ template < typename SimplicialComplexForWitness > bool create_complex(SimplicialComplexForWitness& complex, - FT max_alpha_square, + double max_alpha_square, Landmark_id limit_dimension = std::numeric_limits::max()) { - std::size_t nbL = landmarks_.size(); + // std::size_t nbL = landmarks_.size(); if (complex.num_vertices() > 0) { std::cerr << "Witness complex cannot create complex - complex is not empty.\n"; return false; @@ -137,15 +113,9 @@ private: } typeVectorVertex vv; ActiveWitnessList active_witnesses; - for (unsigned i = 0; i != nbL; ++i) { - // initial fill of 0-dimensional simplices - // by doing it we don't assume that landmarks are necessarily witnesses themselves anymore - vv = {i}; - complex.insert_simplex(vv, Filtration_value(0.0)); - } - Landmark_id k = 1; /* current dimension in iterative construction */ - for (auto w: witnesses_) - active_witnesses.push_back(ActiveWitness(landmark_tree_.query_incremental_nearest_neighbors(w))); + Landmark_id k = 0; /* current dimension in iterative construction */ + for (auto w: nearest_landmark_table_) + active_witnesses.push_back(ActiveWitness(w)); ActiveWitness aw_copy(active_witnesses.front()); while (!active_witnesses.empty() && k <= limit_dimension ) { typename ActiveWitnessList::iterator aw_it = active_witnesses.begin(); diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp index aff6949e..c50e829a 100644 --- a/src/Witness_complex/test/test_simple_witness_complex.cpp +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -6,8 +6,13 @@ #include #include + #include +#include #include +#include + +#include #include #include @@ -18,8 +23,15 @@ typedef std::vector< Vertex_handle > typeVectorVertex; typedef CGAL::Epick_d Kernel; typedef typename Kernel::FT FT; typedef typename Kernel::Point_d Point_d; -typedef Gudhi::witness_complex::Witness_complex WitnessComplex; -typedef Gudhi::witness_complex::Strong_witness_complex StrongWitnessComplex; +typedef Gudhi::witness_complex::Euclidean_witness_complex EuclideanWitnessComplex; +typedef Gudhi::witness_complex::Euclidean_strong_witness_complex EuclideanStrongWitnessComplex; + +typedef std::vector Point_range; +typedef Gudhi::spatial_searching::Kd_tree_search Kd_tree; +typedef Kd_tree::INS_range Nearest_landmark_range; +typedef std::vector Nearest_landmark_table; +typedef Gudhi::witness_complex::Witness_complex WitnessComplex; + /* All landmarks and witnesses are taken on the grid in the following manner. LWLWL @@ -33,8 +45,9 @@ typedef Gudhi::witness_complex::Strong_witness_complex StrongWitnessComp BOOST_AUTO_TEST_CASE(simple_witness_complex) { Simplex_tree complex, relaxed_complex, strong_relaxed_complex, strong_relaxed_complex2; - - std::vector witnesses, landmarks; + Simplex_tree complex_ne, relaxed_complex_ne, strong_relaxed_complex_ne, strong_relaxed_complex2_ne; + + Point_range witnesses, landmarks; landmarks.push_back(Point_d(std::vector{-2,-2})); landmarks.push_back(Point_d(std::vector{-2, 0})); @@ -56,22 +69,41 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { witnesses.push_back(Point_d(std::vector{ 1, 2})); witnesses.push_back(Point_d(std::vector{ 2,-1})); witnesses.push_back(Point_d(std::vector{ 2, 1})); - - WitnessComplex witness_complex(landmarks, - witnesses); - witness_complex.create_complex(complex, 0); + + Kd_tree landmark_tree(landmarks); + Nearest_landmark_table nearest_landmark_table; + for (auto w: witnesses) + nearest_landmark_table.push_back(landmark_tree.query_incremental_nearest_neighbors(w)); + + // Weak witness complex: Euclidean version + EuclideanWitnessComplex eucl_witness_complex(landmarks, + witnesses); + eucl_witness_complex.create_complex(complex, 0); std::cout << "complex.num_simplices() = " << complex.num_simplices() << std::endl; BOOST_CHECK(complex.num_simplices() == 24); - witness_complex.create_complex(relaxed_complex, 8.01); + eucl_witness_complex.create_complex(relaxed_complex, 8.01); std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex.num_simplices() << std::endl; BOOST_CHECK(relaxed_complex.num_simplices() == 239); // The corner simplex {0,2,5,7} and its cofaces are missing. + // Weak witness complex: non-Euclidean version + WitnessComplex witness_complex(nearest_landmark_table); + witness_complex.create_complex(complex_ne, 0); + + std::cout << "complex.num_simplices() = " << complex_ne.num_simplices() << std::endl; + BOOST_CHECK(complex_ne.num_simplices() == 24); + + witness_complex.create_complex(relaxed_complex_ne, 8.01); + + std::cout << "relaxed_complex.num_simplices() = " << relaxed_complex_ne.num_simplices() << std::endl; + BOOST_CHECK(relaxed_complex_ne.num_simplices() == 239); + + - StrongWitnessComplex strong_witness_complex(landmarks, + EuclideanStrongWitnessComplex strong_witness_complex(landmarks, witnesses); strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); -- cgit v1.2.3