From 7e40efa04f1cc528f49da82df1502af85feb78d1 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 13 Jan 2016 19:08:03 +0000 Subject: Added a test, moved the old test from example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@964 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5744fdd3d30735cebdbd7442f023585a70bf0fca --- src/Witness_complex/example/CMakeLists.txt | 3 - .../example/simple_witness_complex.cpp | 58 ------------------ .../gudhi/Landmark_choice_by_furthest_point.h | 71 +++++++++++----------- .../test/simple_witness_complex.cpp | 55 +++++++++++++++++ .../test/witness_complex_points.cpp | 64 +++++++++++++++++++ 5 files changed, 155 insertions(+), 96 deletions(-) delete mode 100644 src/Witness_complex/example/simple_witness_complex.cpp create mode 100644 src/Witness_complex/test/simple_witness_complex.cpp create mode 100644 src/Witness_complex/test/witness_complex_points.cpp (limited to 'src/Witness_complex') diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt index 4f5e33d4..4473078a 100644 --- a/src/Witness_complex/example/CMakeLists.txt +++ b/src/Witness_complex/example/CMakeLists.txt @@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 2.6) project(GUDHIWitnessComplex) # A simple example - add_executable ( simple_witness_complex simple_witness_complex.cpp ) - add_test(simple_witness_complex ${CMAKE_CURRENT_BINARY_DIR}/simple_witness_complex) - add_executable( witness_complex_from_file witness_complex_from_file.cpp ) add_test( witness_complex_from_bunny &{CMAKE_CURRENT_BINARY_DIR}/witness_complex_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 100) diff --git a/src/Witness_complex/example/simple_witness_complex.cpp b/src/Witness_complex/example/simple_witness_complex.cpp deleted file mode 100644 index bcbf2362..00000000 --- a/src/Witness_complex/example/simple_witness_complex.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): Vincent Rouvreau - * - * Copyright (C) 2014 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 . - */ - -#include -#include -//#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Witness_complex.h" - -using namespace Gudhi; - -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef Witness_complex> WitnessComplex; -//typedef std::pair typeSimplex; -//typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; - -int main (int argc, char * const argv[]) -{ - Simplex_tree<> complex; - std::vector< typeVectorVertex > knn; - typeVectorVertex witness0 = {1,0,5,2,6,3,4}; knn.push_back(witness0 ); - typeVectorVertex witness1 = {2,6,4,5,0,1,3}; knn.push_back(witness1 ); - typeVectorVertex witness2 = {3,4,2,1,5,6,0}; knn.push_back(witness2 ); - typeVectorVertex witness3 = {4,2,1,3,5,6,0}; knn.push_back(witness3 ); - typeVectorVertex witness4 = {5,1,6,0,2,3,4}; knn.push_back(witness4 ); - typeVectorVertex witness5 = {6,0,5,2,1,3,4}; knn.push_back(witness5 ); - typeVectorVertex witness6 = {0,5,6,1,2,3,4}; knn.push_back(witness6 ); - typeVectorVertex witness7 = {2,6,4,5,3,1,0}; knn.push_back(witness7 ); - typeVectorVertex witness8 = {1,2,5,4,3,6,0}; knn.push_back(witness8 ); - typeVectorVertex witness9 = {3,4,0,6,5,1,2}; knn.push_back(witness9 ); - typeVectorVertex witness10 = {5,0,1,3,6,2,4}; knn.push_back(witness10); - typeVectorVertex witness11 = {5,6,1,0,2,3,4}; knn.push_back(witness11); - typeVectorVertex witness12 = {1,6,0,5,2,3,4}; knn.push_back(witness12); - WitnessComplex witnessComplex(knn, complex, 7, 7); - if (witnessComplex.is_witness_complex(knn, true)) - std::cout << "Witness complex is good\n"; - else - std::cout << "Witness complex is bad\n"; -} diff --git a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h b/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h index 0b196f18..ebee96ad 100644 --- a/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h +++ b/src/Witness_complex/include/gudhi/Landmark_choice_by_furthest_point.h @@ -33,6 +33,9 @@ class Landmark_choice_by_furthest_point { +private: + typedef std::vector typeVectorVertex; + public: /** @@ -57,45 +60,43 @@ public: double curr_max_dist = 0; // used for defining the furhest point from L const double infty = std::numeric_limits::infinity(); // infinity (see next entry) std::vector< double > dist_to_L(nb_points,infty); // vector of current distances to L from points + int dim = points.begin()->size(); - //CHOICE OF THE FIRST LANDMARK - int rand_int = rand() % nb_points; - int curr_max_w = rand_int; //For testing purposes a pseudo-random number is used here - - for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) - { - //curr_max_w at this point is the next landmark - chosen_landmarks.push_back(curr_max_w); - for (auto v: knn) - v.push_back(current_number_of_landmarks); - int i = 0; - for (const auto& p: points) - { - // used to stock the distance from the current point to L - double curr_dist = euclidean_distance(p, points.begin() + chosen_landmarks[current_number_of_landmarks]); - wit_land_dist[i].push_back(curr_dist); - knn[i].push_back(current_number_of_landmarks); - if (curr_dist < dist_to_L[i]) - dist_to_L[i] = curr_dist; - int j = current_number_of_landmarks; - while (j > 0 && wit_land_dist[i][j-1] > wit_land_dist[i][j]) - { - std::swap(knn[i][j], knn[i][j-1]); - std::swap(wit_land_dist[i][j-1], wit_land_dist[i][j-1]); - --j; - } - ++i; - } - curr_max_dist = 0; - for (auto dist: dist_to_L) { - if (dist > curr_max_dist) + int rand_int = rand() % nb_points; + int curr_max_w = rand_int; //For testing purposes a pseudo-random number is used here + + for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) + { + //curr_max_w at this point is the next landmark + chosen_landmarks.push_back(curr_max_w); + for (auto& v: knn) + v.push_back(current_number_of_landmarks); + unsigned i = 0; + for (auto& p: points) { - curr_max_dist = dist; - curr_max_w = i; + double curr_dist = euclidean_distance(p, *(points.begin() + chosen_landmarks[current_number_of_landmarks])); + wit_land_dist[i].push_back(curr_dist); + knn[i].push_back(current_number_of_landmarks); + if (curr_dist < dist_to_L[i]) + dist_to_L[i] = curr_dist; + int j = current_number_of_landmarks; + while (j > 0 && wit_land_dist[i][j-1] > wit_land_dist[i][j]) + { + std::swap(knn[i][j], knn[i][j-1]); + std::swap(wit_land_dist[i][j-1], wit_land_dist[i][j-1]); + --j; + } + ++i; } + curr_max_dist = 0; + for (i = 0; i < dist_to_L.size(); i++) + if (dist_to_L[i] > curr_max_dist) + { + curr_max_dist = dist_to_L[i]; + curr_max_w = i; + } } - } - } + } }; diff --git a/src/Witness_complex/test/simple_witness_complex.cpp b/src/Witness_complex/test/simple_witness_complex.cpp new file mode 100644 index 00000000..c7d85a4d --- /dev/null +++ b/src/Witness_complex/test/simple_witness_complex.cpp @@ -0,0 +1,55 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 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 . + */ + +#include +#include +//#include "gudhi/graph_simplicial_complex.h" +#include "gudhi/Simplex_tree.h" +#include "gudhi/Witness_complex.h" + +using namespace Gudhi; + +typedef std::vector< Vertex_handle > typeVectorVertex; +typedef Witness_complex> WitnessComplex; +//typedef std::pair typeSimplex; +//typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; + +int main (int argc, char * const argv[]) +{ + Simplex_tree<> complex; + std::vector< typeVectorVertex > knn; + typeVectorVertex witness0 = {1,0,5,2,6,3,4}; knn.push_back(witness0 ); + typeVectorVertex witness1 = {2,6,4,5,0,1,3}; knn.push_back(witness1 ); + typeVectorVertex witness2 = {3,4,2,1,5,6,0}; knn.push_back(witness2 ); + typeVectorVertex witness3 = {4,2,1,3,5,6,0}; knn.push_back(witness3 ); + typeVectorVertex witness4 = {5,1,6,0,2,3,4}; knn.push_back(witness4 ); + typeVectorVertex witness5 = {6,0,5,2,1,3,4}; knn.push_back(witness5 ); + typeVectorVertex witness6 = {0,5,6,1,2,3,4}; knn.push_back(witness6 ); + typeVectorVertex witness7 = {2,6,4,5,3,1,0}; knn.push_back(witness7 ); + typeVectorVertex witness8 = {1,2,5,4,3,6,0}; knn.push_back(witness8 ); + typeVectorVertex witness9 = {3,4,0,6,5,1,2}; knn.push_back(witness9 ); + typeVectorVertex witness10 = {5,0,1,3,6,2,4}; knn.push_back(witness10); + typeVectorVertex witness11 = {5,6,1,0,2,3,4}; knn.push_back(witness11); + typeVectorVertex witness12 = {1,6,0,5,2,3,4}; knn.push_back(witness12); + WitnessComplex witnessComplex(knn, complex, 7, 7); + assert(witnessComplex.is_witness_complex(knn, true)); +} diff --git a/src/Witness_complex/test/witness_complex_points.cpp b/src/Witness_complex/test/witness_complex_points.cpp new file mode 100644 index 00000000..f9680874 --- /dev/null +++ b/src/Witness_complex/test/witness_complex_points.cpp @@ -0,0 +1,64 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 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 . + */ + +#include +#include +//#include "gudhi/graph_simplicial_complex.h" +#include "gudhi/Simplex_tree.h" +#include "gudhi/Witness_complex.h" +#include "gudhi/Landmark_choice_by_random_point.h" +#include "gudhi/Landmark_choice_by_furthest_point.h" + + +using namespace Gudhi; + +typedef std::vector< Vertex_handle > typeVectorVertex; +typedef Witness_complex> WitnessComplex; +typedef std::vector Point; +//typedef std::pair typeSimplex; +//typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; + +int main (int argc, char * const argv[]) +{ + std::vector< typeVectorVertex > knn; + std::vector< Point > points; + // 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 = true; + // First test: random choice + Simplex_tree<> complex1; + Landmark_choice_by_random_point lcrp(points, 100, knn); + assert(!knn.empty()); + WitnessComplex witnessComplex1(knn, complex1, 100, 3); + assert(witnessComplex1.is_witness_complex(knn, b_print_output)); + + // Second test: furthest choice + knn.clear(); + Simplex_tree<> complex2; + Landmark_choice_by_furthest_point lcfp(points, 100, knn); + WitnessComplex witnessComplex2(knn, complex2, 100, 3); + assert(witnessComplex2.is_witness_complex(knn, b_print_output)); +} -- cgit v1.2.3