summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology
diff options
context:
space:
mode:
authorpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-11-03 05:10:17 +0000
committerpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-11-03 05:10:17 +0000
commit0729a55a67503c068e4843c63930d6b29e76f7ac (patch)
tree5084d6162b571f66e39ec8ce1eee36d3f6176cbb /src/Persistent_cohomology
parentaf51e15aadd1c97da1767a2404fd1d60a105c191 (diff)
a few more changes
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_from_correlation_matrix@2823 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d12b2413620003883e82b3022f8d933aa05e2856
Diffstat (limited to 'src/Persistent_cohomology')
-rw-r--r--src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp56
1 files changed, 50 insertions, 6 deletions
diff --git a/src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp b/src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp
index 41cf915a..6f12dada 100644
--- a/src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp
+++ b/src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp
@@ -24,6 +24,7 @@
#include <gudhi/Simplex_tree.h>
#include <gudhi/Persistent_cohomology.h>
#include <gudhi/reader_utils.h>
+#include <gudhi/file_writer.h>
#include <boost/program_options.hpp>
@@ -38,6 +39,7 @@ using Rips_complex = Gudhi::rips_complex::Rips_complex<Filtration_value>;
using Field_Zp = Gudhi::persistent_cohomology::Field_Zp;
using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology<Simplex_tree, Field_Zp>;
using Correlation_matrix = std::vector<std::vector<Filtration_value>>;
+using intervals_common = Gudhi::Persistence_interval_common< double , int >;
void program_options(int argc, char* argv[], std::string& csv_matrix_file, std::string& filediag,
Filtration_value& threshold, int& dim_max, int& p, Filtration_value& min_persistence);
@@ -66,6 +68,13 @@ int main(int argc, char* argv[]) {
}
}
+ //If the treshold, being minimal corelation is in the range [0,1],
+ //change it to 1-threshold
+ if ( ( threshold>=0 ) && ( threshold<=1 ) )
+ {
+ threshold = 1-threshold;
+ }
+
Rips_complex rips_complex_from_file(correlations, threshold);
// Construct the Rips complex in a Simplex Tree
@@ -82,15 +91,34 @@ int main(int argc, char* argv[]) {
Persistent_cohomology pcoh(simplex_tree);
// initializes the coefficient field for homology
pcoh.init_coefficients(p);
-
+ //compute persistence
pcoh.compute_persistent_cohomology(min_persistence);
-
- // Output the diagram in filediag
+
+
+ //invert the persistence diagram
+ auto pairs = pcoh.get_persistent_pairs();
+ std::vector< intervals_common > processed_persistence_intervals;
+ processed_persistence_intervals.reserve( pairs.size() );
+ for (auto pair :pairs )
+ {
+ double birth = 1-simplex_tree.filtration( get<0>(pair) );
+ double death = 1-simplex_tree.filtration( get<1>(pair) );
+ unsigned dimension = (unsigned)simplex_tree.dimension( get<0>(pair) );
+ int field = get<2>(pair);
+ processed_persistence_intervals.push_back(
+ intervals_common(birth, death,dimension,field)
+ );
+ }
+
+ //sort the processed intervals:
+ std::sort( processed_persistence_intervals.begin() , processed_persistence_intervals.end() );
+
+ //and write them to a file
if (filediag.empty()) {
- pcoh.output_diagram();
+ write_persistence_intervals_to_stream(processed_persistence_intervals);
} else {
std::ofstream out(filediag);
- pcoh.output_diagram(out);
+ write_persistence_intervals_to_stream(processed_persistence_intervals,out);
out.close();
}
return 0;
@@ -103,6 +131,9 @@ void program_options(int argc, char* argv[], std::string& csv_matrix_file, std::
hidden.add_options()(
"input-file", po::value<std::string>(&csv_matrix_file),
"Name of file containing a distance matrix. Can be square or lower triangular matrix. Separator is ';'.");
+ hidden.add_options()
+ ("input-file", po::value<std::string>(&csv_matrix_file),
+ "Name of file containing a corelation matrix. Can be square or lower triangular matrix. Separator is ';'.");
po::options_description visible("Allowed options", 100);
visible.add_options()("help,h", "produce help message")(
@@ -118,6 +149,19 @@ void program_options(int argc, char* argv[], std::string& csv_matrix_file, std::
"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");
+ 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")
+ ("min-edge-corelation,c",
+ po::value<Filtration_value>(&threshold)->default_value(std::numeric_limits<Filtration_value>::infinity()),
+ "Minimal corelation 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);
@@ -132,7 +176,7 @@ void program_options(int argc, char* argv[], std::string& csv_matrix_file, std::
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 distance matrix.\n \n";
+ std::cout << "of a Rips complex defined on a corelation matrix.\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";