From e7c6a8ae371de46469f0509697572c9f30071281 Mon Sep 17 00:00:00 2001 From: skachano Date: Thu, 11 Feb 2016 14:18:49 +0000 Subject: Added relaxed witness complex + persistence example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1016 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 06f7fec6464e35a6ca0aa18f7a25cbb7a7f68ad5 --- src/Witness_complex/example/CMakeLists.txt | 3 + .../example/relaxed_witness_persistence.cpp | 108 +++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/Witness_complex/example/relaxed_witness_persistence.cpp (limited to 'src/Witness_complex/example') diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt index b304479e..9b874261 100644 --- a/src/Witness_complex/example/CMakeLists.txt +++ b/src/Witness_complex/example/CMakeLists.txt @@ -35,6 +35,9 @@ if(CGAL_FOUND) add_executable ( witness_complex_sphere witness_complex_sphere.cpp ) target_link_libraries(witness_complex_sphere ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) add_test( witness_complex_sphere_10 ${CMAKE_CURRENT_BINARY_DIR}/witness_complex_sphere 10) + add_executable ( relaxed_witness_persistence relaxed_witness_persistence.cpp ) + target_link_libraries(relaxed_witness_persistence ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) + add_test( relaxed_witness_persistence_10 ${CMAKE_CURRENT_BINARY_DIR}/relaxed_witness_persistence 10) else() message(WARNING "Eigen3 not found. Version 3.1.0 is required for witness_complex_sphere example.") endif() diff --git a/src/Witness_complex/example/relaxed_witness_persistence.cpp b/src/Witness_complex/example/relaxed_witness_persistence.cpp new file mode 100644 index 00000000..09fe0d31 --- /dev/null +++ b/src/Witness_complex/example/relaxed_witness_persistence.cpp @@ -0,0 +1,108 @@ +/* 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) 2015 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 +#include +#include "Landmark_choice_random_knn.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "generators.h" +#include "output.h" + +using namespace Gudhi; +using namespace Gudhi::witness_complex; +using namespace Gudhi::persistent_cohomology; + +typedef std::vector Point_Vector; +typedef Relaxed_witness_complex< Simplex_tree<> > RelaxedWitnessComplex; + +int main (int argc, char * const argv[]) +{ + if (argc != 6) { + std::cerr << "Usage: " << argv[0] + << " nbP nbL dim alpha limD\n"; + return 0; + } + /* + boost::filesystem::path p; + for (; argc > 2; --argc, ++argv) + p /= argv[1]; + */ + + int nbP = atoi(argv[1]); + int nbL = atoi(argv[2]); + int dim = atoi(argv[3]); + double alpha = atof(argv[4]); + int limD = atoi(argv[5]); + //Construct the Simplex Tree + clock_t start, end; + + // Construct the Simplex Tree + Simplex_tree<> simplex_tree; + + // Read the point file + Point_Vector point_vector; + generate_points_sphere(point_vector, nbP, dim); + std::cout << "Successfully generated " << point_vector.size() << " points.\n"; + std::cout << "Ambient dimension is " << point_vector[0].size() << ".\n"; + + // Choose landmarks + std::vector > knn; + std::vector > distances; + Gudhi::witness_complex::landmark_choice_by_random_knn(point_vector, nbL, alpha, limD, knn, distances); + + // Compute witness complex + start = clock(); + RelaxedWitnessComplex(distances, + knn, + simplex_tree, + nbL, + alpha, + limD); + end = clock(); + double time = static_cast(end - start) / CLOCKS_PER_SEC; + std::cout << "Witness complex for " << nbL << " landmarks took " + << time << " s. \n"; + // std::cout << simplex_tree << "\n"; + + // Compute the persistence diagram of the complex + persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree, false); + int p = 3; + pcoh.init_coefficients( p ); //initilizes the coefficient field for homology + pcoh.compute_persistent_cohomology( alpha/10 ); + pcoh.output_diagram(); +} -- cgit v1.2.3