summaryrefslogtreecommitdiff
path: root/src/Witness_complex/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/Witness_complex/test')
-rw-r--r--src/Witness_complex/test/CMakeLists.txt21
-rw-r--r--src/Witness_complex/test/simple_witness_complex.cpp59
-rw-r--r--src/Witness_complex/test/test_simple_witness_complex.cpp135
-rw-r--r--src/Witness_complex/test/witness_complex_points.cpp58
4 files changed, 141 insertions, 132 deletions
diff --git a/src/Witness_complex/test/CMakeLists.txt b/src/Witness_complex/test/CMakeLists.txt
index bb55b0f1..084761e2 100644
--- a/src/Witness_complex/test/CMakeLists.txt
+++ b/src/Witness_complex/test/CMakeLists.txt
@@ -10,21 +10,12 @@ if (GPROF_PATH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
endif()
-add_executable ( simple_witness_complexUT simple_witness_complex.cpp )
-target_link_libraries(simple_witness_complexUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+add_executable ( Witness_complex_test_simple_witness_complex test_simple_witness_complex.cpp )
+target_link_libraries(Witness_complex_test_simple_witness_complex ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Witness_complex_test_simple_witness_complex ${TBB_LIBRARIES})
# Unitary tests definition and xml result file generation
-add_test(NAME simple_witness_complexUT
- COMMAND ${CMAKE_CURRENT_BINARY_DIR}/simple_witness_complexUT
+add_test(NAME simple_witness_complex
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/Witness_complex_test_simple_witness_complex
# XML format for Jenkins xUnit plugin
- --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/simple_witness_complexUT.xml --log_level=test_suite --report_level=no)
-
-add_executable ( witness_complex_pointsUT witness_complex_points.cpp )
-target_link_libraries(witness_complex_pointsUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
-
-# Unitary tests definition and xml result file generation
-add_test(NAME witness_complex_pointsUT
- COMMAND ${CMAKE_CURRENT_BINARY_DIR}/witness_complex_pointsUT
- # XML format for Jenkins xUnit plugin
- --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/witness_complex_pointsUT.xml --log_level=test_suite --report_level=no)
-
+ --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Witness_complex_test_simple_witness_complexUT.xml --log_level=test_suite --report_level=no)
diff --git a/src/Witness_complex/test/simple_witness_complex.cpp b/src/Witness_complex/test/simple_witness_complex.cpp
deleted file mode 100644
index 6be39f58..00000000
--- a/src/Witness_complex/test/simple_witness_complex.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/* This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
- * library for computational topology.
- *
- * Author(s): Siargey Kachanovich
- *
- * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE "simple_witness_complex"
-#include <boost/test/unit_test.hpp>
-#include <boost/mpl/list.hpp>
-
-#include <gudhi/Simplex_tree.h>
-#include <gudhi/Witness_complex.h>
-
-#include <iostream>
-#include <ctime>
-#include <vector>
-
-typedef Gudhi::Simplex_tree<> Simplex_tree;
-typedef std::vector< Simplex_tree::Vertex_handle > typeVectorVertex;
-typedef Gudhi::witness_complex::Witness_complex<Simplex_tree> WitnessComplex;
-
-BOOST_AUTO_TEST_CASE(simple_witness_complex) {
- Simplex_tree complex;
- std::vector< typeVectorVertex > knn;
-
- knn.push_back({1, 0, 5, 2, 6, 3, 4});
- knn.push_back({2, 6, 4, 5, 0, 1, 3});
- knn.push_back({3, 4, 2, 1, 5, 6, 0});
- knn.push_back({4, 2, 1, 3, 5, 6, 0});
- knn.push_back({5, 1, 6, 0, 2, 3, 4});
- knn.push_back({6, 0, 5, 2, 1, 3, 4});
- knn.push_back({0, 5, 6, 1, 2, 3, 4});
- knn.push_back({2, 6, 4, 5, 3, 1, 0});
- knn.push_back({1, 2, 5, 4, 3, 6, 0});
- knn.push_back({3, 4, 0, 6, 5, 1, 2});
- knn.push_back({5, 0, 1, 3, 6, 2, 4});
- knn.push_back({5, 6, 1, 0, 2, 3, 4});
- knn.push_back({1, 6, 0, 5, 2, 3, 4});
- WitnessComplex witnessComplex(knn, 7, 7, complex);
-
- BOOST_CHECK(witnessComplex.is_witness_complex(knn, false));
-}
diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp
new file mode 100644
index 00000000..bb1df72d
--- /dev/null
+++ b/src/Witness_complex/test/test_simple_witness_complex.cpp
@@ -0,0 +1,135 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "simple_witness_complex"
+#include <boost/test/unit_test.hpp>
+#include <boost/mpl/list.hpp>
+
+#include <CGAL/Epick_d.h>
+
+#include <gudhi/Simplex_tree.h>
+
+#include <gudhi/Witness_complex.h>
+#include <gudhi/Euclidean_witness_complex.h>
+#include <gudhi/Strong_witness_complex.h>
+#include <gudhi/Euclidean_strong_witness_complex.h>
+
+#include <gudhi/Kd_tree_search.h>
+
+#include <iostream>
+#include <ctime>
+#include <vector>
+
+typedef Gudhi::Simplex_tree<> Simplex_tree;
+typedef typename Simplex_tree::Vertex_handle Vertex_handle;
+typedef std::vector< Vertex_handle > typeVectorVertex;
+typedef CGAL::Epick_d<CGAL::Dynamic_dimension_tag> Kernel;
+typedef typename Kernel::FT FT;
+typedef typename Kernel::Point_d Point_d;
+typedef Gudhi::witness_complex::Euclidean_witness_complex<Kernel> EuclideanWitnessComplex;
+typedef Gudhi::witness_complex::Euclidean_strong_witness_complex<Kernel> EuclideanStrongWitnessComplex;
+
+typedef std::vector<Point_d> Point_range;
+typedef Gudhi::spatial_searching::Kd_tree_search<Kernel, Point_range> Kd_tree;
+typedef Kd_tree::INS_range Nearest_landmark_range;
+typedef std::vector<Nearest_landmark_range> Nearest_landmark_table;
+typedef Gudhi::witness_complex::Witness_complex<Nearest_landmark_table> WitnessComplex;
+typedef Gudhi::witness_complex::Strong_witness_complex<Nearest_landmark_table> StrongWitnessComplex;
+
+
+/* All landmarks and witnesses are taken on the grid in the following manner.
+ LWLWL
+ WW.WW
+ L...L
+ WW.WW
+ LWLWL
+
+ Witness complex consists of 8 vertices, 12 edges and 4 triangles
+ */
+
+BOOST_AUTO_TEST_CASE(simple_witness_complex) {
+ Simplex_tree complex, relaxed_complex, strong_relaxed_complex, strong_relaxed_complex2;
+ 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<FT>{-2,-2}));
+ landmarks.push_back(Point_d(std::vector<FT>{-2, 0}));
+ landmarks.push_back(Point_d(std::vector<FT>{-2, 2}));
+ landmarks.push_back(Point_d(std::vector<FT>{ 0,-2}));
+ landmarks.push_back(Point_d(std::vector<FT>{ 0, 2}));
+ landmarks.push_back(Point_d(std::vector<FT>{ 2,-2}));
+ landmarks.push_back(Point_d(std::vector<FT>{ 2, 0}));
+ landmarks.push_back(Point_d(std::vector<FT>{ 2, 2}));
+ witnesses.push_back(Point_d(std::vector<FT>{-2,-1}));
+ witnesses.push_back(Point_d(std::vector<FT>{-2, 1}));
+ witnesses.push_back(Point_d(std::vector<FT>{-1,-2}));
+ witnesses.push_back(Point_d(std::vector<FT>{-1,-1}));
+ witnesses.push_back(Point_d(std::vector<FT>{-1, 1}));
+ witnesses.push_back(Point_d(std::vector<FT>{-1, 2}));
+ witnesses.push_back(Point_d(std::vector<FT>{ 1,-2}));
+ witnesses.push_back(Point_d(std::vector<FT>{ 1,-1}));
+ witnesses.push_back(Point_d(std::vector<FT>{ 1, 1}));
+ witnesses.push_back(Point_d(std::vector<FT>{ 1, 2}));
+ witnesses.push_back(Point_d(std::vector<FT>{ 2,-1}));
+ witnesses.push_back(Point_d(std::vector<FT>{ 2, 1}));
+
+ 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);
+
+ 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);
+
+
+ // Strong complex : Euclidean version
+ EuclideanStrongWitnessComplex eucl_strong_witness_complex(landmarks,
+ witnesses);
+
+ eucl_strong_witness_complex.create_complex(strong_relaxed_complex, 9.1);
+ eucl_strong_witness_complex.create_complex(strong_relaxed_complex2, 9.1, 2);
+
+ std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex.num_simplices() << std::endl;
+ BOOST_CHECK(strong_relaxed_complex.num_simplices() == 239);
+
+ std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2.num_simplices() << std::endl;
+ BOOST_CHECK(strong_relaxed_complex2.num_simplices() == 92);
+
+
+ // Strong complex : non-Euclidean version
+ StrongWitnessComplex strong_witness_complex(nearest_landmark_table);
+
+ strong_witness_complex.create_complex(strong_relaxed_complex_ne, 9.1);
+ strong_witness_complex.create_complex(strong_relaxed_complex2_ne, 9.1, 2);
+
+ std::cout << "strong_relaxed_complex.num_simplices() = " << strong_relaxed_complex_ne.num_simplices() << std::endl;
+ BOOST_CHECK(strong_relaxed_complex_ne.num_simplices() == 239);
+
+ std::cout << "strong_relaxed_complex2.num_simplices() = " << strong_relaxed_complex2_ne.num_simplices() << std::endl;
+ BOOST_CHECK(strong_relaxed_complex2_ne.num_simplices() == 92);
+
+
+ // 8 vertices, 28 edges, 56 triangles
+}
diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp
deleted file mode 100644
index 92f53417..00000000
--- a/src/Witness_complex/test/witness_complex_points.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/* This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
- * library for computational topology.
- *
- * Author(s): Siargey Kachanovich
- *
- * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE "witness_complex_points"
-#include <boost/test/unit_test.hpp>
-#include <boost/mpl/list.hpp>
-
-#include <gudhi/Simplex_tree.h>
-#include <gudhi/Witness_complex.h>
-#include <gudhi/Construct_closest_landmark_table.h>
-#include <gudhi/pick_n_random_points.h>
-
-#include <iostream>
-#include <vector>
-
-typedef std::vector<double> Point;
-typedef Gudhi::Simplex_tree<> Simplex_tree;
-typedef std::vector< Simplex_tree::Vertex_handle > typeVectorVertex;
-typedef Gudhi::witness_complex::Witness_complex<Simplex_tree> WitnessComplex;
-
-BOOST_AUTO_TEST_CASE(witness_complex_points) {
- std::vector< typeVectorVertex > knn;
- std::vector< Point > points, landmarks;
- // Add grid points as witnesses
- for (double i = 0; i < 10; i += 1.0)
- for (double j = 0; j < 10; j += 1.0)
- for (double k = 0; k < 10; k += 1.0)
- points.push_back(Point({i, j, k}));
-
- bool b_print_output = false;
- // First test: random choice
- Simplex_tree complex1;
- Gudhi::subsampling::pick_n_random_points(points, 100, std::back_inserter(landmarks));
- Gudhi::witness_complex::construct_closest_landmark_table<Simplex_tree::Filtration_value>(points, landmarks, knn);
- assert(!knn.empty());
- WitnessComplex witnessComplex1(knn, 100, 3, complex1);
- BOOST_CHECK(witnessComplex1.is_witness_complex(knn, b_print_output));
-}