From 6536cb935d5702425f33d10f514fa450c470096a Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 18 Mar 2015 17:35:25 +0000 Subject: Added witness_complex function carcas git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@489 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 542dd6740b0ae233ea5fb8ea5c6fe313bf1f27d9 --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 3afec463..0c8f6ea3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ else() include_directories(src/Persistent_cohomology/include/) include_directories(src/Simplex_tree/include/) include_directories(src/Skeleton_blocker/include/) + include_directories(src/Witness_complex/include/) add_subdirectory(src/Simplex_tree/test) add_subdirectory(src/Simplex_tree/example) @@ -83,6 +84,7 @@ else() add_subdirectory(src/Skeleton_blocker/example) add_subdirectory(src/Contraction/example) add_subdirectory(src/Hasse_complex/example) + add_subdirectory(src/Witness_complex/example) endif() -- cgit v1.2.3 From b11daa7d34fc4f3870d8f247895dd5da28526ada Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 23 Mar 2015 15:28:11 +0000 Subject: Fixed the print bug git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@498 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 89201b558bfb27542e9e187b53a2307fb0054fbc --- CMakeLists.txt | 1 + src/Simplex_tree/include/gudhi/Simplex_tree.h | 1 + src/Witness_complex/include/gudhi/Witness_complex.h | 20 ++++++++++++++------ 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c8f6ea3..f3b29994 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,7 @@ else() add_subdirectory(src/Skeleton_blocker/example) add_subdirectory(src/Contraction/example) add_subdirectory(src/Hasse_complex/example) + add_subdirectory(src/Witness_complex/test) add_subdirectory(src/Witness_complex/example) endif() diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index a1758680..e52fe1ae 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace Gudhi { diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 3deb8bc3..e999928f 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -174,14 +174,14 @@ void witness_complex(KNearestNeighbours & knn) /* TODO Filtration */ //simplex = std::make_pair(vv, Filtration_value(0.0)); //returnValue = this->insert_simplex(simplex.first, simplex.second); - //returnValue = insert_simplex(vv, Filtration_value(0.0)); + returnValue = insert_simplex(vv, Filtration_value(0.0)); /* TODO Error if not inserted : normally no need here though*/ } - vv = {0}; - returnValue = insert_simplex(vv,Filtration_value(0.0)); + //vv = {0}; + //returnValue = insert_simplex(vv,Filtration_value(0.0)); std::cout << "Successfully added landmarks" << std::endl; // PRINT2 - print_sc(root()); + print_sc(root()); std::cout << std::endl; int u,v; // two extremities of an edge if (nbL > 1) // if the supposed dimension of the complex is >0 /* @@ -215,6 +215,7 @@ void witness_complex(KNearestNeighbours & knn) //vh = (Vertex_handle)i; vv = {u,v}; returnValue = this->insert_simplex(vv,Filtration_value(0.0)); + print_sc(root()); std::cout << std::endl; //std::cout << "Added edges" << std::endl; } //print_sc(root()); @@ -272,14 +273,21 @@ private: if (!map.empty()) { std::cout << map.begin()->first; - print_sc(map.begin()->second.children()); + if (map.begin()->second.children() == root()) + std::cout << "Sweet potato"; + if (has_children(map.begin())) + print_sc(map.begin()->second.children()); typename Dictionary::iterator it; for (it = map.begin()+1; it != map.end(); ++it) { std::cout << "," << it->first; + if (map.begin()->second.children() == root()) + std::cout << "Sweet potato"; + if (has_children(it)) + print_sc(it->second.children()); } } - std::cout << ")\n"; + std::cout << ")"; } -- cgit v1.2.3 From 244d9ce5a5cb9050255cf519def9bdb273646f81 Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 8 Apr 2015 14:50:03 +0000 Subject: Added rock-age style off reader git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@553 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 74462161c45893cfbfcc1875569b93b365445e35 --- CMakeLists.txt | 12 +++--- .../example/witness_complex_from_file.cpp | 43 +++++++++++++++++++++- .../include/gudhi/Witness_complex.h | 4 +- 3 files changed, 50 insertions(+), 9 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index fabba412..0684b18e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ if(MSVC) # Turn off some VC++ warnings SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wpedantic -Wsign-compare") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wsign-compare") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") endif() @@ -24,12 +24,12 @@ set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost) -find_package(GMP) -if(GMP_FOUND) - find_package(GMPXX) -endif() +#find_package(GMP) +#if(GMP_FOUND) + #find_package(GMPXX) +#endif() -find_package(CGAL) +#find_package(CGAL) # Required programs for unitary tests purpose FIND_PROGRAM( LCOV_PATH lcov ) diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp index cec1d1b8..b1d7575a 100644 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ b/src/Witness_complex/example/witness_complex_from_file.cpp @@ -28,7 +28,7 @@ //#include "gudhi/graph_simplicial_complex.h" #include "gudhi/Witness_complex.h" - +#include "gudhi/reader_utils.h" using namespace Gudhi; @@ -65,6 +65,44 @@ read_points_cust ( std::string file_name , std::vector< std::vector< double > > in_file.close(); } +/** + * \brief Rock age method of reading off file + * + */ +inline void +off_reader_cust ( std::string file_name , std::vector< std::vector< double > > & points) +{ + std::ifstream in_file (file_name.c_str(),std::ios::in); + if(!in_file.is_open()) + { + std::cerr << "Unable to open file " << file_name << std::endl; + return; + } + std::string line; + double x; + // Line OFF. No need in it + if (!getline(in_file, line)) + { + std::cerr << "No line OFF\n"; + return; + } + // Line with 3 numbers. No need + if (!getline(in_file, line)) + { + std::cerr << "No line with 3 numbers\n"; + return; + } + // Reading points + while( getline ( in_file , line ) ) + { + std::vector< double > point; + std::istringstream iss( line ); + while(iss >> x) { point.push_back(x); } + points.push_back(point); + } + in_file.close(); +} + int main (int argc, char * const argv[]) { if (argc != 3) @@ -83,7 +121,8 @@ int main (int argc, char * const argv[]) std::cout << "Let the carnage begin!\n"; start = clock(); Point_Vector point_vector; - read_points_cust(file_name, point_vector); + off_reader_cust(file_name, point_vector); + std::cout << "Successfully read the points\n"; witnessComplex.setNbL(nbL); witnessComplex.witness_complex_from_points(point_vector); end = clock(); diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index 1b50ca95..f4b1d62c 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -184,6 +184,7 @@ namespace Gudhi { active_w.push_back(i); } } + std::cout << "k=1, active witnesses: " << active_w.size() << std::endl; //std::cout << "Successfully added edges" << std::endl; while (!active_w.empty() && k < nbL ) { @@ -206,6 +207,7 @@ namespace Gudhi { else active_w.erase(it++); //First increase the iterator and then erase the previous element } + std::cout << "k=" << k << ", active witnesses: " << active_w.size() << std::endl; k++; } //print_sc(root()); std::cout << std::endl; @@ -453,7 +455,7 @@ private: template void landmark_choice_by_random_points(Point_Vector &W, int nbP, KNearestNeighbours &WL) { - //std::cout << "Enter landmark_choice_by_random_points "<< std::endl; + std::cout << "Enter landmark_choice_by_random_points "<< std::endl; //std::cout << "W="; print_vvector(W); std::unordered_set< int > chosen_landmarks; // landmark set -- cgit v1.2.3 From eaedaf52122a397f35fb75df93f83ae9ffdceb7c Mon Sep 17 00:00:00 2001 From: skachano Date: Mon, 27 Apr 2015 10:24:05 +0000 Subject: Struggled with CMake... git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@579 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 38b558196806b226cba5e1ef30abb927619bbe33 --- CMakeLists.txt | 2 +- src/Witness_complex/example/CMakeLists.txt | 48 +++++++++++++++------- .../include/gudhi/Witness_complex.h | 42 +++++++++++-------- 3 files changed, 60 insertions(+), 32 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 0684b18e..57cb14d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ find_package(Boost) #find_package(GMPXX) #endif() -#find_package(CGAL) +find_package(CGAL) # Required programs for unitary tests purpose FIND_PROGRAM( LCOV_PATH lcov ) diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt index 51f7976b..14d23551 100644 --- a/src/Witness_complex/example/CMakeLists.txt +++ b/src/Witness_complex/example/CMakeLists.txt @@ -1,23 +1,41 @@ cmake_minimum_required(VERSION 2.6) project(GUDHIWitnessComplex) +#cmake -DCGAL_DIR=~/GitDrive/CGAL/ ../../.. -add_executable ( simple_witness_complex simple_witness_complex.cpp ) -add_test(simple_witness_complex ${CMAKE_CURRENT_BINARY_DIR}/simple_witness_complex) +#if (CGAL_FOUND) + #message(STATUS "CGAL version: ${CGAL_VERSION}.") + #include( ${CGAL_USE_FILE} ) -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 ) + #find_package(Eigen3 3.1.0) + #include( ${EIGEN3_USE_FILE} ) -add_executable( witness_complex_from_off witness_complex_from_off.cpp ) + #INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIR}) + #INCLUDE_DIRECTORIES(${CGAL_INCLUDE_DIRS}) + 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_wl_matrix witness_complex_from_wl_matrix.cpp ) + #add_executable( witness_complex_from_file witness_complex_from_file.cpp ) + #target_link_libraries(witness_complex_from_file ${EIGEN3_LIBRARIES} ${CGAL_LIBRARY}) + #add_test( witness_complex_from_bunny &{CMAKE_CURRENT_BINARY_DIR}/witness_complex_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 100) + + add_executable( witness_complex_from_off witness_complex_from_off.cpp ) + + add_executable( witness_complex_from_wl_matrix witness_complex_from_wl_matrix.cpp ) +#endif() # An example with Simplex-tree using CGAL alpha_shapes_3 -#if(GMP_FOUND AND CGAL_FOUND) -# message("CGAL_lib = ${CGAL_LIBRARIES_DIR}") -# message("GMP_LIBRARIES = ${GMP_LIBRARIES}") -# INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR}) -# INCLUDE_DIRECTORIES(${CGAL_INCLUDE_DIRS}) -# add_executable ( simplex_tree_from_alpha_shapes_3 simplex_tree_from_alpha_shapes_3.cpp ) -# target_link_libraries(simplex_tree_from_alpha_shapes_3 ${GMP_LIBRARIES} ${CGAL_LIBRARY}) -# add_test(simplex_tree_from_alpha_shapes_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_alpha_shapes_3 ${CMAKE_SOURCE_DIR}/data/points/bunny_5000) -#endif() + +include( ${CGAL_USE_FILE} ) +find_package(Eigen3 3.1.0) +if(GMP_FOUND AND CGAL_FOUND) + message("CGAL_lib = ${CGAL_LIBRARIES_DIR}") + message("GMP_LIBRARIES = ${GMP_LIBRARIES}") + message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") + #message("EIGEN3_LIBRARIES = ${EIGEN3_LIBRARIES}") + INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIRS}) + INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR}) + INCLUDE_DIRECTORIES(${CGAL_INCLUDE_DIRS}) + add_executable (witness_complex_from_file witness_complex_from_file.cpp ) + target_link_libraries(witness_complex_from_file ${GMP_LIBRARIES} ${EIGEN3_LIBRARIES} ${CGAL_LIBRARY}) + add_test(witness_complex_from_file ${CMAKE_CURRENT_BINARY_DIR}/witness_complex_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 100) +endif() diff --git a/src/Witness_complex/include/gudhi/Witness_complex.h b/src/Witness_complex/include/gudhi/Witness_complex.h index c633691b..3c030c45 100644 --- a/src/Witness_complex/include/gudhi/Witness_complex.h +++ b/src/Witness_complex/include/gudhi/Witness_complex.h @@ -38,6 +38,13 @@ #include #include +// Needed for nearest neighbours +//#include +#include +#include +#include + +// Needed for the adjacency graph in bad link search #include #include #include @@ -477,9 +484,9 @@ private: int chosen_landmark = rand()%nbP; double curr_dist; - int j; - int temp_swap_int; - double temp_swap_double; + //int j; + //int temp_swap_int; + //double temp_swap_double; for (current_number_of_landmarks = 0; current_number_of_landmarks != nbL; current_number_of_landmarks++) @@ -508,7 +515,7 @@ private: wit_land_dist[i].push_back(curr_dist); WL[i].push_back(current_number_of_landmarks); //std::cout << "Push't back\n"; - j = current_number_of_landmarks; + //j = current_number_of_landmarks; //std::cout << "First half complete\n"; //std::cout << "result WL="; print_vvector(WL); //std::cout << "result WLD="; print_vvector(wit_land_dist); @@ -517,21 +524,24 @@ private: } for (int i = 0; i < nbP; i++) { - // sort the closest landmark vector for every witness sort(WL[i].begin(), WL[i].end(), [&](int j1, int j2){return wit_land_dist[i][j1] < wit_land_dist[i][j2];}); - /* - temp_swap_int = WL[i][j]; - WL[i][j] = WL[i][j-1]; - WL[i][j-1] = temp_swap_int; - temp_swap_double = wit_land_dist[i][j]; - wit_land_dist[i][j] = wit_land_dist[i][j-1]; - wit_land_dist[i][j-1] = temp_swap_double; - --j; - */ } //std::cout << endl; } + /** \brief Construct the matrix |W|x(D+1) of D+1 closest landmarks + * where W is the set of witnesses and D is the ambient dimension + */ + template + void nearest_landmarks(Point_Vector &W, std::unordered_set &L, KNearestNeighbours &WL) + { + int D = W[0].size(); + + } + + /** \brief Search and output links around vertices that are not pseudomanifolds + * + */ void write_bad_links(std::ofstream& out_file) { out_file << "Bad links list\n"; @@ -565,14 +575,14 @@ private: //out_file << "Number of bad links: " << count << "/" << root()->size(); //std::cout << "Number of bad links: " << count << "/" << root()->size() << std::endl; nc = nbL; - for (int i = 0; i != count_good.size(); i++) + for (unsigned int i = 0; i != count_good.size(); i++) { out_file << "count_good[" << i << "] = " << count_good[i] << std::endl; nc -= count_good[i]; if (count_good[i] != 0) std::cout << "count_good[" << i << "] = " << count_good[i] << std::endl; } - for (int i = 0; i != count_bad.size(); i++) + for (unsigned int i = 0; i != count_bad.size(); i++) { out_file << "count_bad[" << i << "] = " << count_bad[i] << std::endl; nc -= count_bad[i]; -- cgit v1.2.3