summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology
diff options
context:
space:
mode:
Diffstat (limited to 'src/Persistent_cohomology')
-rw-r--r--src/Persistent_cohomology/concept/FilteredComplex.h6
-rw-r--r--src/Persistent_cohomology/example/CMakeLists.txt7
-rw-r--r--src/Persistent_cohomology/example/alpha_shapes_persistence.cpp7
-rw-r--r--src/Persistent_cohomology/example/parallel_rips_persistence.cpp180
-rw-r--r--src/Persistent_cohomology/example/performance_rips_persistence.cpp2
-rw-r--r--src/Persistent_cohomology/example/persistence_from_file.cpp2
-rw-r--r--src/Persistent_cohomology/example/rips_multifield_persistence.cpp5
-rw-r--r--src/Persistent_cohomology/example/rips_persistence.cpp5
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h3
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h1
10 files changed, 201 insertions, 17 deletions
diff --git a/src/Persistent_cohomology/concept/FilteredComplex.h b/src/Persistent_cohomology/concept/FilteredComplex.h
index 1834903b..e124d524 100644
--- a/src/Persistent_cohomology/concept/FilteredComplex.h
+++ b/src/Persistent_cohomology/concept/FilteredComplex.h
@@ -65,9 +65,9 @@ struct FilteredComplex
Simplex_key key ( Simplex_handle sh );
/** \brief Returns the simplex associated to a key.
*
- * If key is different from null_key(), there must be a unique
- * simplex having this key. */
- Simplex_handle simplex ( Simplex_key key );
+ * If key is different from null_key(), returns the simplex that
+ * has index idx in the filtration. */
+ Simplex_handle simplex ( Simplex_key idx );
/** \brief Assign a key to a simplex. */
void assign_key(Simplex_handle sh, Simplex_key key);
diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt
index 9e96adc0..5fec8ad4 100644
--- a/src/Persistent_cohomology/example/CMakeLists.txt
+++ b/src/Persistent_cohomology/example/CMakeLists.txt
@@ -18,6 +18,11 @@ target_link_libraries(rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_O
add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 3 -m 100)
+add_executable(parallel_rips_persistence parallel_rips_persistence.cpp)
+target_link_libraries(parallel_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY})
+
+add_test(parallel_rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/parallel_rips_persistence ${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.txt -r 0.3 -d 3 -p 3 -m 100)
+
add_executable(persistence_from_file persistence_from_file.cpp)
target_link_libraries(persistence_from_file ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY})
add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 2 -m 0)
@@ -77,6 +82,4 @@ if(GMPXX_FOUND AND GMP_FOUND)
# message(WARNING "CGAL not found.")
endif()
-else()
- # message(WARNING "GMP not found.")
endif()
diff --git a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp
index 235ea141..ac208957 100644
--- a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp
+++ b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp
@@ -66,7 +66,8 @@ typedef Alpha_shape_3::Edge Edge_3;
typedef std::list<Alpha_shape_3::Vertex_handle> Vertex_list;
// gudhi type definition
-typedef Simplex_tree<>::Vertex_handle Simplex_tree_vertex;
+typedef Simplex_tree<Simplex_tree_options_fast_persistence> ST;
+typedef ST::Vertex_handle Simplex_tree_vertex;
typedef std::map<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex > Alpha_shape_simplex_tree_map;
typedef std::pair<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex> Alpha_shape_simplex_tree_pair;
typedef std::vector< Simplex_tree_vertex > Simplex_tree_vector_vertex;
@@ -184,7 +185,7 @@ int main(int argc, char * const argv[]) {
// Loop on objects vector
Vertex_list vertex_list;
- Simplex_tree<> simplex_tree;
+ ST simplex_tree;
Alpha_shape_simplex_tree_map map_cgal_simplex_tree;
std::vector<Alpha_value_type>::iterator the_alpha_value_iterator = the_alpha_values.begin();
int dim_max = 0;
@@ -281,7 +282,7 @@ int main(int argc, char * const argv[]) {
std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl;
// Compute the persistence diagram of the complex
- Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree);
+ Persistent_cohomology< ST, Field_Zp > pcoh(simplex_tree);
// initializes the coefficient field for homology
pcoh.init_coefficients(coeff_field_characteristic);
diff --git a/src/Persistent_cohomology/example/parallel_rips_persistence.cpp b/src/Persistent_cohomology/example/parallel_rips_persistence.cpp
new file mode 100644
index 00000000..4c6656f5
--- /dev/null
+++ b/src/Persistent_cohomology/example/parallel_rips_persistence.cpp
@@ -0,0 +1,180 @@
+/* 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): Clément Maria, Marc Glisse
+ *
+ * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France),
+ * 2015 INRIA Saclay Île de 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/>.
+ */
+
+#include <gudhi/reader_utils.h>
+#include <gudhi/graph_simplicial_complex.h>
+#include <gudhi/distance_functions.h>
+#include <gudhi/Simplex_tree.h>
+#include <gudhi/Persistent_cohomology.h>
+#include <gudhi/Hasse_complex.h>
+
+#include <boost/program_options.hpp>
+
+#ifdef GUDHI_USE_TBB
+#include <tbb/task_scheduler_init.h>
+#endif
+
+#include <string>
+#include <vector>
+
+////////////////////////////////////////////////////////////////
+// //
+// WARNING: persistence computation itself is not parallel, //
+// and this uses more memory than rips_persistence. //
+// //
+////////////////////////////////////////////////////////////////
+
+using namespace Gudhi;
+using namespace Gudhi::persistent_cohomology;
+
+typedef int Vertex_handle;
+typedef double Filtration_value;
+
+void program_options(int argc, char * argv[]
+ , std::string & filepoints
+ , std::string & filediag
+ , Filtration_value & threshold
+ , int & dim_max
+ , int & p
+ , Filtration_value & min_persistence);
+
+int main(int argc, char * argv[]) {
+ std::string filepoints;
+ std::string filediag;
+ Filtration_value threshold;
+ int dim_max;
+ int p;
+ Filtration_value min_persistence;
+
+ program_options(argc, argv, filepoints, filediag, threshold, dim_max, p, min_persistence);
+
+ // Extract the points from the file filepoints
+ typedef std::vector<double> Point_t;
+ std::vector< Point_t > points;
+ read_points(filepoints, points);
+
+ // Compute the proximity graph of the points
+ Graph_t prox_graph = compute_proximity_graph(points, threshold
+ , euclidean_distance<Point_t>);
+
+ // Construct the Rips complex in a Simplex Tree
+ Simplex_tree<>& st = *new Simplex_tree<>;
+ // insert the proximity graph in the simplex tree
+ st.insert_graph(prox_graph);
+ // expand the graph until dimension dim_max
+ st.expansion(dim_max);
+
+ std::cout << "The complex contains " << st.num_simplices() << " simplices \n";
+ std::cout << " and has dimension " << st.dimension() << " \n";
+
+#ifdef GUDHI_USE_TBB
+ // Unnecessary, but clarifies which operations are parallel.
+ tbb::task_scheduler_init ts;
+#endif
+
+ // Sort the simplices in the order of the filtration
+ st.initialize_filtration();
+ int count = 0;
+ for (auto sh : st.filtration_simplex_range())
+ st.assign_key(sh, count++);
+
+ // Convert to a more convenient representation.
+ Hasse_complex<> hcpx(st);
+
+#ifdef GUDHI_USE_TBB
+ ts.terminate();
+#endif
+
+ // Free some space.
+ delete &st;
+
+ // Compute the persistence diagram of the complex
+ persistent_cohomology::Persistent_cohomology< Hasse_complex<>, Field_Zp > pcoh(hcpx);
+ // initializes the coefficient field for homology
+ pcoh.init_coefficients(p);
+
+ pcoh.compute_persistent_cohomology(min_persistence);
+
+ // Output the diagram in filediag
+ if (filediag.empty()) {
+ pcoh.output_diagram();
+ } else {
+ std::ofstream out(filediag);
+ pcoh.output_diagram(out);
+ out.close();
+ }
+}
+
+void program_options(int argc, char * argv[]
+ , std::string & filepoints
+ , std::string & filediag
+ , Filtration_value & threshold
+ , int & dim_max
+ , int & p
+ , Filtration_value & min_persistence) {
+ namespace po = boost::program_options;
+ po::options_description hidden("Hidden options");
+ hidden.add_options()
+ ("input-file", po::value<std::string>(&filepoints),
+ "Name of file containing a point set. Format is one point per line: X1 ... Xd ");
+
+ po::options_description visible("Allowed options", 100);
+ visible.add_options()
+ ("help,h", "produce help message")
+ ("output-file,o", po::value<std::string>(&filediag)->default_value(std::string()),
+ "Name of file in which the persistence diagram is written. Default print in std::cout")
+ ("max-edge-length,r", po::value<Filtration_value>(&threshold)->default_value(0),
+ "Maximal length of an edge for the Rips complex construction.")
+ ("cpx-dimension,d", po::value<int>(&dim_max)->default_value(1),
+ "Maximal dimension of the Rips complex we want to compute.")
+ ("field-charac,p", po::value<int>(&p)->default_value(11),
+ "Characteristic p of the coefficient field Z/pZ for computing homology.")
+ ("min-persistence,m", po::value<Filtration_value>(&min_persistence),
+ "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals");
+
+ po::positional_options_description pos;
+ pos.add("input-file", 1);
+
+ po::options_description all;
+ all.add(visible).add(hidden);
+
+ po::variables_map vm;
+ po::store(po::command_line_parser(argc, argv).
+ options(all).positional(pos).run(), vm);
+ po::notify(vm);
+
+ if (vm.count("help") || !vm.count("input-file")) {
+ std::cout << std::endl;
+ std::cout << "Compute the persistent homology with coefficient field Z/pZ \n";
+ std::cout << "of a Rips complex defined on a set of input points.\n \n";
+ std::cout << "The output diagram contains one bar per line, written with the convention: \n";
+ std::cout << " p dim b d \n";
+ std::cout << "where dim is the dimension of the homological feature,\n";
+ std::cout << "b and d are respectively the birth and death of the feature and \n";
+ std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl;
+
+ std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
+ std::cout << visible << std::endl;
+ std::abort();
+ }
+}
diff --git a/src/Persistent_cohomology/example/performance_rips_persistence.cpp b/src/Persistent_cohomology/example/performance_rips_persistence.cpp
index fc48d6b1..b4d282ac 100644
--- a/src/Persistent_cohomology/example/performance_rips_persistence.cpp
+++ b/src/Persistent_cohomology/example/performance_rips_persistence.cpp
@@ -86,7 +86,7 @@ int main(int argc, char * argv[]) {
std::cout << "Compute Rips graph in " << elapsed_sec << " ms.\n";
// Construct the Rips complex in a Simplex Tree
- Simplex_tree<> st;
+ Simplex_tree<Simplex_tree_options_fast_persistence> st;
start = std::chrono::system_clock::now();
// insert the proximity graph in the simplex tree
diff --git a/src/Persistent_cohomology/example/persistence_from_file.cpp b/src/Persistent_cohomology/example/persistence_from_file.cpp
index 8eb8d0f3..67235467 100644
--- a/src/Persistent_cohomology/example/persistence_from_file.cpp
+++ b/src/Persistent_cohomology/example/persistence_from_file.cpp
@@ -54,7 +54,7 @@ int main(int argc, char * argv[]) {
<< std::endl;
std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl;
- // Construct the Rips complex in a Simplex Tree
+ // Read the list of simplices from a file.
Simplex_tree<> simplex_tree;
std::ifstream simplex_tree_stream(simplex_tree_file);
diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp
index 5277bf7a..c5cd775d 100644
--- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp
+++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp
@@ -68,7 +68,8 @@ int main(int argc, char * argv[]) {
, euclidean_distance<Point_t>);
// Construct the Rips complex in a Simplex Tree
- Simplex_tree<> st;
+ typedef Simplex_tree<Simplex_tree_options_fast_persistence> ST;
+ ST st;
// insert the proximity graph in the simplex tree
st.insert_graph(prox_graph);
// expand the graph until dimension dim_max
@@ -78,7 +79,7 @@ int main(int argc, char * argv[]) {
st.initialize_filtration();
// Compute the persistence diagram of the complex
- Persistent_cohomology< Simplex_tree<>, Multi_field > pcoh(st);
+ Persistent_cohomology<ST, Multi_field > pcoh(st);
// initializes the coefficient field for homology
pcoh.init_coefficients(min_p, max_p);
// compute persistent homology, disgarding persistent features of life shorter than min_persistence
diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp
index fa0449a8..cab49395 100644
--- a/src/Persistent_cohomology/example/rips_persistence.cpp
+++ b/src/Persistent_cohomology/example/rips_persistence.cpp
@@ -66,7 +66,8 @@ int main(int argc, char * argv[]) {
, euclidean_distance<Point_t>);
// Construct the Rips complex in a Simplex Tree
- Simplex_tree<> st;
+ typedef Simplex_tree<Simplex_tree_options_fast_persistence> ST;
+ ST st;
// insert the proximity graph in the simplex tree
st.insert_graph(prox_graph);
// expand the graph until dimension dim_max
@@ -79,7 +80,7 @@ int main(int argc, char * argv[]) {
st.initialize_filtration();
// Compute the persistence diagram of the complex
- persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st);
+ persistent_cohomology::Persistent_cohomology<ST, Field_Zp > pcoh(st);
// initializes the coefficient field for homology
pcoh.init_coefficients(p);
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index 3e761473..19417ace 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -27,7 +27,6 @@
#include <gudhi/Persistent_cohomology/Field_Zp.h>
#include <gudhi/Simple_object_pool.h>
-#include <boost/tuple/tuple.hpp>
#include <boost/intrusive/set.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/intrusive/list.hpp>
@@ -223,7 +222,7 @@ class Persistent_cohomology {
// Sparse column type for the annotation of the boundary of an element.
typedef std::vector<std::pair<Simplex_key, Arith_element> > A_ds_type;
// Persistent interval type. The Arith_element field is used for the multi-field framework.
- typedef boost::tuple<Simplex_handle, Simplex_handle, Arith_element> Persistent_interval;
+ typedef std::tuple<Simplex_handle, Simplex_handle, Arith_element> Persistent_interval;
/** \brief Initializes the Persistent_cohomology class.
*
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h
index 612658e6..5deb2d88 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h
@@ -23,7 +23,6 @@
#ifndef PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
#define PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
-#include <boost/tuple/tuple.hpp>
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/list.hpp>