summaryrefslogtreecommitdiff
path: root/src/Witness_complex/example
diff options
context:
space:
mode:
authorskachano <skachano@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-12-10 09:29:52 +0000
committerskachano <skachano@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-12-10 09:29:52 +0000
commitf3fa597138156c3b925ac970555f8482e964c968 (patch)
treeb54d3337b473f96c029814a8e8228108d304b36a /src/Witness_complex/example
parent8f54c437e0b895368c6151584811ce7df1575ea0 (diff)
Added things
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@937 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4f0ae39ee1f68d8cce565ad0855edb3bff1e7f3f
Diffstat (limited to 'src/Witness_complex/example')
-rw-r--r--src/Witness_complex/example/CMakeLists.txt26
-rw-r--r--src/Witness_complex/example/simple_witness_complex.cpp4
-rw-r--r--src/Witness_complex/example/witness_complex_from_file.cpp90
3 files changed, 53 insertions, 67 deletions
diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt
index 83f9c71c..4f5e33d4 100644
--- a/src/Witness_complex/example/CMakeLists.txt
+++ b/src/Witness_complex/example/CMakeLists.txt
@@ -6,6 +6,30 @@ project(GUDHIWitnessComplex)
add_test(simple_witness_complex ${CMAKE_CURRENT_BINARY_DIR}/simple_witness_complex)
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_bench witness_complex_bench.cpp )
+ add_test( witness_complex_bench_from_bunny &{CMAKE_CURRENT_BINARY_DIR}/witness_complex_bench ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 100)
+
+if(CGAL_FOUND)
+ if (NOT CGAL_VERSION VERSION_LESS 4.6.0)
+ message(STATUS "CGAL version: ${CGAL_VERSION}.")
+
+ include( ${CGAL_USE_FILE} )
+
+ find_package(Eigen3 3.1.0)
+ if (EIGEN3_FOUND)
+ message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.")
+ include( ${EIGEN3_USE_FILE} )
+ message(STATUS "Eigen3 use file: ${EIGEN3_USE_FILE}.")
+ include_directories (BEFORE "../../include")
+
+ add_executable ( witness_complex_bench2 witness_complex_bench2.cpp )
+ target_link_libraries(witness_complex_bench2 ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
+ else()
+ message(WARNING "Eigen3 not found. Version 3.1.0 is required for Alpha shapes feature.")
+ endif()
+ else()
+ message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Alpha shapes feature. Version 4.6.0 is required.")
+ endif ()
+endif()
diff --git a/src/Witness_complex/example/simple_witness_complex.cpp b/src/Witness_complex/example/simple_witness_complex.cpp
index 6731f135..bcbf2362 100644
--- a/src/Witness_complex/example/simple_witness_complex.cpp
+++ b/src/Witness_complex/example/simple_witness_complex.cpp
@@ -50,8 +50,8 @@ int main (int argc, char * const argv[])
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);
- if (witnessComplex.is_witness_complex(knn))
+ 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/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp
index 70c81528..6add4e0a 100644
--- a/src/Witness_complex/example/witness_complex_from_file.cpp
+++ b/src/Witness_complex/example/witness_complex_from_file.cpp
@@ -26,21 +26,18 @@
#include <sys/types.h>
#include <sys/stat.h>
-//#include <stdlib.h>
-//#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/reader_utils.h"
-//#include <boost/filesystem.hpp>
using namespace Gudhi;
-//using namespace boost::filesystem;
typedef std::vector< Vertex_handle > typeVectorVertex;
typedef std::vector< std::vector <double> > Point_Vector;
-//typedef std::pair<typeVectorVertex, Filtration_value> typeSimplex;
-//typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool;
+typedef Witness_complex< Simplex_tree<> > WitnessComplex;
/**
* \brief Customized version of read_points
@@ -69,15 +66,15 @@ read_points_cust ( std::string file_name , std::vector< std::vector< double > >
in_file.close();
}
-void write_wl( std::string file_name, std::vector< std::vector <int> > & WL)
+/** Write a gnuplot readable file.
+ * Data range is a random access range of pairs (arg, value)
+ */
+template < typename Data_range >
+void write_data( Data_range & data, std::string filename )
{
- std::ofstream ofs (file_name, std::ofstream::out);
- for (auto w : WL)
- {
- for (auto l: w)
- ofs << l << " ";
- ofs << "\n";
- }
+ std::ofstream ofs(filename, std::ofstream::out);
+ for (auto entry: data)
+ ofs << entry.first << ", " << entry.second << "\n";
ofs.close();
}
@@ -89,68 +86,33 @@ int main (int argc, char * const argv[])
<< " path_to_point_file nbL \n";
return 0;
}
- /*
- boost::filesystem::path p;
- for (; argc > 2; --argc, ++argv)
- p /= argv[1];
- */
std::string file_name = argv[1];
int nbL = atoi(argv[2]);
-
clock_t start, end;
- //Construct the Simplex Tree
- Witness_complex<> witnessComplex;
-
- std::cout << "Let the carnage begin!\n";
+
+ // Construct the Simplex Tree
+ Simplex_tree<> simplex_tree;
+
+ // Read the point file
Point_Vector point_vector;
read_points_cust(file_name, point_vector);
- //std::cout << "Successfully read the points\n";
- witnessComplex.setNbL(nbL);
- // witnessComplex.witness_complex_from_points(point_vector);
- std::vector<std::vector< int > > WL;
- std::set<int> L;
+ std::cout << "Successfully read " << point_vector.size() << " points.\n";
+ std::cout << "Ambient dimension is " << point_vector[0].size() << ".\n";
+
+ // Choose landmarks
start = clock();
- //witnessComplex.landmark_choice_by_furthest_points(point_vector, point_vector.size(), WL);
- witnessComplex.landmark_choice_by_random_points(point_vector, point_vector.size(), L);
- witnessComplex.nearest_landmarks(point_vector,L,WL);
+ std::vector<std::vector< int > > knn;
+ Landmark_choice_by_random_point(point_vector, nbL, knn);
end = clock();
std::cout << "Landmark choice for " << nbL << " landmarks took "
<< (double)(end-start)/CLOCKS_PER_SEC << " s. \n";
- // Write the WL matrix in a file
- mkdir("output", S_IRWXU);
- const size_t last_slash_idx = file_name.find_last_of("/");
- if (std::string::npos != last_slash_idx)
- {
- file_name.erase(0, last_slash_idx + 1);
- }
- std::string out_file = "output/"+file_name+"_"+argv[2]+".wl";
- write_wl(out_file,WL);
+
+ // Compute witness complex
start = clock();
- witnessComplex.witness_complex(WL);
- //
+ WitnessComplex(knn, simplex_tree, nbL, point_vector[0].size());
end = clock();
- std::cout << "Howdy world! The process took "
+ std::cout << "Witness complex took "
<< (double)(end-start)/CLOCKS_PER_SEC << " s. \n";
- /*
- char buffer[100];
- int i = sprintf(buffer,"%s_%s_result.txt",argv[1],argv[2]);
- if (i >= 0)
- {
- std::string out_file = (std::string)buffer;
- std::ofstream ofs (out_file, std::ofstream::out);
- witnessComplex.st_to_file(ofs);
- ofs.close();
- }
- */
-
- out_file = "output/"+file_name+"_"+argv[2]+".stree";
- std::ofstream ofs (out_file, std::ofstream::out);
- witnessComplex.st_to_file(ofs);
- ofs.close();
- out_file = "output/"+file_name+"_"+argv[2]+".badlinks";
- std::ofstream ofs2(out_file, std::ofstream::out);
- witnessComplex.write_bad_links(ofs2);
- ofs2.close();
}