From 4a5332dfb88ec27157c82f77df87f588f7016736 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Thu, 9 Nov 2017 14:48:39 +0000 Subject: Answer to Vincent's comments. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_from_correlation_matrix@2859 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1a049ce98ccf893fc6af6c2631e508d3a9dc6c09 --- .../rips_correlation_matrix_persistence.cpp | 63 +++++++++------------- 1 file changed, 26 insertions(+), 37 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp b/src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp index 94d5b8d4..676ef793 100644 --- a/src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_correlation_matrix_persistence.cpp @@ -42,17 +42,17 @@ using Correlation_matrix = std::vector>; 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); + Filtration_value& correlation_min, int& dim_max, int& p, Filtration_value& min_persistence); int main(int argc, char* argv[]) { std::string csv_matrix_file; std::string filediag; - Filtration_value threshold; + Filtration_value correlation_min; int dim_max; int p; Filtration_value min_persistence; - program_options(argc, argv, csv_matrix_file, filediag, threshold, dim_max, p, min_persistence); + program_options(argc, argv, csv_matrix_file, filediag, correlation_min, dim_max, p, min_persistence); Correlation_matrix correlations = Gudhi::read_lower_triangular_matrix_from_csv_file(csv_matrix_file); @@ -68,13 +68,19 @@ int main(int argc, char* argv[]) { } } - // If the threshold, being minimal correlation is in the range [0,1], - // change it to 1-threshold - if ( ( threshold>=0 ) && ( threshold<=1 ) ) + Filtration_value threshold; + //If the correlation_min, being minimal corelation is in the range [0,1], + //change it to 1-correlation_min + if ( ( correlation_min>=0 ) && ( correlation_min<=1 ) ) { - threshold = 1-threshold; + threshold = 1-correlation_min; } - + else + { + std::cout << "Wrong value of the treshold corelation (should be between 0 and 1). The program will now terminate.\n"; + return 1; + } + Rips_complex rips_complex_from_file(correlations, threshold); // Construct the Rips complex in a Simplex Tree @@ -93,9 +99,9 @@ int main(int argc, char* argv[]) { pcoh.init_coefficients(p); //compute persistence pcoh.compute_persistent_cohomology(min_persistence); - - - // invert the persistence diagram + + + //invert the persistence diagram auto pairs = pcoh.get_persistent_pairs(); std::vector< intervals_common > processed_persistence_intervals; processed_persistence_intervals.reserve( pairs.size() ); @@ -108,12 +114,12 @@ int main(int argc, char* argv[]) { 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 + //and write them to a file if (filediag.empty()) { write_persistence_intervals_to_stream(processed_persistence_intervals); } else { @@ -125,37 +131,20 @@ int main(int argc, char* argv[]) { } 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) { + Filtration_value& correlation_min, 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(&csv_matrix_file), - // "Name of file containing a correlation matrix. Can be square or lower triangular matrix. Separator is ';'."); hidden.add_options() ("input-file", po::value(&csv_matrix_file), - "Name of file containing a correlation matrix. Can be square or lower triangular matrix. Separator is ';'."); - + "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")( - // "output-file,o", po::value(&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(&threshold)->default_value(std::numeric_limits::infinity()), - // "Maximal length of an edge for the Rips complex construction.")( - // "cpx-dimension,d", po::value(&dim_max)->default_value(1), - // "Maximal dimension of the Rips complex we want to compute.")( - // "field-charac,p", po::value(&p)->default_value(11), - // "Characteristic p of the coefficient field Z/pZ for computing homology.")( - // "min-persistence,m", po::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(&filediag)->default_value(std::string()), "Name of file in which the persistence diagram is written. Default print in std::cout") - ("min-edge-correlation,c", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Minimal correlation of an edge for the Rips complex construction.") + ("min-edge-corelation,c", + po::value(&correlation_min)->default_value(0), + "Minimal corelation of an edge for the Rips complex construction.") ("cpx-dimension,d", po::value(&dim_max)->default_value(1), "Maximal dimension of the Rips complex we want to compute.") ("field-charac,p", po::value(&p)->default_value(11), @@ -176,7 +165,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 correlation 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"; -- cgit v1.2.3