diff options
author | pdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2017-04-07 10:45:13 +0000 |
---|---|---|
committer | pdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2017-04-07 10:45:13 +0000 |
commit | 85b1a1b1befa27b288ec410e1e308ed2277abf47 (patch) | |
tree | 86bf9fcf8e574ac74e04a382f6ef18b1145218ca /src | |
parent | 032b937da93d45ca55464092f25c104790dd75a6 (diff) |
Answers to Marc's comments.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2319 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 51b36668541a99c43ad801a9449d7208135f83b7
Diffstat (limited to 'src')
15 files changed, 168 insertions, 18 deletions
diff --git a/src/Gudhi_stat/example/CMakeLists.txt b/src/Gudhi_stat/example/CMakeLists.txt index 5ae6cd6a..61ea6d4f 100644 --- a/src/Gudhi_stat/example/CMakeLists.txt +++ b/src/Gudhi_stat/example/CMakeLists.txt @@ -10,8 +10,8 @@ target_link_libraries(persistence_landscape ${Boost_SYSTEM_LIBRARY}) add_executable ( persistence_intervals persistence_intervals.cpp ) target_link_libraries(persistence_intervals ${Boost_SYSTEM_LIBRARY}) -add_executable ( vector_representation vector_representation.cpp ) -target_link_libraries(vector_representation ${Boost_SYSTEM_LIBRARY}) +add_executable ( persistence_vectors persistence_vectors.cpp ) +target_link_libraries(persistence_vectors ${Boost_SYSTEM_LIBRARY}) add_executable ( persistence_heat_maps persistence_heat_maps.cpp ) target_link_libraries(persistence_heat_maps ${Boost_SYSTEM_LIBRARY}) diff --git a/src/Gudhi_stat/example/vector_representation.cpp b/src/Gudhi_stat/example/persistence_vectors.cpp index e1225726..9373dcf0 100644 --- a/src/Gudhi_stat/example/vector_representation.cpp +++ b/src/Gudhi_stat/example/persistence_vectors.cpp @@ -22,7 +22,7 @@ -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> #include <iostream> diff --git a/src/Gudhi_stat/include/gudhi/multiplicative_bootstrap.h b/src/Gudhi_stat/include/gudhi/multiplicative_bootstrap.h index c350349c..d6f39cd8 100644 --- a/src/Gudhi_stat/include/gudhi/multiplicative_bootstrap.h +++ b/src/Gudhi_stat/include/gudhi/multiplicative_bootstrap.h @@ -24,7 +24,7 @@ #define BOOTSTRAP_H //concretizations -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> #include <gudhi/persistence_representations/Persistence_landscape.h> #include <gudhi/persistence_representations/Persistence_landscape_on_grid.h> #include <gudhi/persistence_representations/Persistence_heat_maps.h> diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape_on_grid.h b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape_on_grid.h index b70ef1d9..51f432c6 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape_on_grid.h +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape_on_grid.h @@ -1,7 +1,7 @@ -/* This file is part of the Gudhi Library. The Gudhi library +/** This file is part of the Gudhi Library. The Gudhi library * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. - *h + * * Author(s): Pawel Dlotko * * Copyright (C) 2015 INRIA (France) @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ + **/ #ifndef Persistence_landscape_on_grid_H_ #define Persistence_landscape_on_grid_H_ diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/Vector_distances_in_diagram.h b/src/Gudhi_stat/include/gudhi/persistence_representations/persistence_vectors.h index 83402d0f..83402d0f 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_representations/Vector_distances_in_diagram.h +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/persistence_vectors.h diff --git a/src/Gudhi_stat/include/gudhi/read_persitence_from_file.h b/src/Gudhi_stat/include/gudhi/read_persitence_from_file.h index 38cdecd5..a340b40c 100644 --- a/src/Gudhi_stat/include/gudhi/read_persitence_from_file.h +++ b/src/Gudhi_stat/include/gudhi/read_persitence_from_file.h @@ -42,7 +42,7 @@ namespace Gudhi_stat * This procedure reads birth-death dagta from a file. We assume that in the file, there may be one type of string 'inf' or 'Inf'. If the second parameter of the program is set to -1, * then those vales are ignored. If the second parameter of this program is set to a positive value, then the infinite intervals will be substituted by that number. **/ -std::vector< std::pair< double,double > > read_persistence_file_that_may_contain_inf_string( char* filename , double what_to_substitute_for_infinite_bar = -1 ) +std::vector< std::pair< double,double > > read_persistence_file_that_may_contain_inf_string( const char* filename , double what_to_substitute_for_infinite_bar = -1 ) { bool dbg = true; @@ -203,7 +203,12 @@ std::vector< std::pair< double , double > > read_standard_persistence_file( cons **/ std::vector< std::pair< double , double > > read_gudhi_persistence_file_in_one_dimension( const char* filename , size_t dimension = 0 , double what_to_substitute_for_infinite_bar = -1) { - bool dbg = false; + bool dbg = false; + if ( !( access( filename, F_OK ) != -1 ) ) + { + std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; + throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + } std::ifstream in; in.open( filename ); @@ -306,6 +311,151 @@ std::vector< std::vector< double > > read_numbers_from_file_line_by_line( const return result; }//read_numbers_from_file_line_by_line + +/** + * Universal procedure to read files with persistence. It ignores the lines starting from # (treat them as comments). + * It reads the fist line which is not a comment and assume that there are some numerical entries over there. The program assume + * that each other line in the file, which is not a comment, have the same number of numerical entries. + * If there are two numerical entries per line, then the function assume that they are birth/death coordinates. + * If there are three numerical entries per line, then the function assume that they are: dimension and birth/death coordinates. + * If there are four numerical entries per line, then the function assume that they are: thc characteristic of a filed over which + * persistence was computed, dimension and birth/death coordinates. + * The procedure returns vector of persistence pairs. +**/ +std::vector<std::pair<double,double>> read_persistence_intervals_in_one_dimension_from_file(std::string const& filename, int dimension=-1 , double what_to_substitute_for_infinite_bar = -1 ) +{ + bool dbg = false; + + //checking if the file exist: + if ( !( access( filename.c_str() , F_OK ) != -1 ) ) + { + std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; + throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + } + + + std::ifstream in; + in.open( filename ); + + std::string line; + std::vector< std::pair<double,double> > barcode; + + int number_of_entries_per_line = -1; + + while (!in.eof()) + { + getline(in,line); + if ( dbg )std::cerr << "Reading line : " << line << std::endl; + if ( !(line.length() == 0 || line[0] == '#') ) + { + if ( number_of_entries_per_line == -1 ) + { + //check how many entries we have in the line. + std::stringstream ss( line ); + int number; + std::vector<int> this_line; + while ( ss >> number ) + { + this_line.push_back( number ); + } + number_of_entries_per_line = (int)this_line.size(); + //if thie line contains 'inf' string, then we need to increment number_of_entries_per_line + if ( line.find("inf") != std::string::npos )++number_of_entries_per_line; + if ( dbg ) + { + std::cerr << "number_of_entries_per_line : " << number_of_entries_per_line << ". This number was obtained by analyzing this line : " << line << std::endl; + } + if ( (number_of_entries_per_line < 2) || ( number_of_entries_per_line > 4 ) ) + { + std::cerr << "The input file you have provided have wrong number of numerical entries per line. The program will now terminate. \n"; + throw "The input file you have provided have wrong number of numerical entries per line. The program will now terminate. \n"; + } + } + if ( line.find("inf") != std::string::npos ) + { + if ( dbg ) + { + std::cerr << "This line: " << line << " contains infinite interval. \n"; + } + if ( what_to_substitute_for_infinite_bar != -1 ) + { + double beginn, field, dim; + std::stringstream lineSS(line); + if ( number_of_entries_per_line == 4 )lineSS >> field; + if ( number_of_entries_per_line >= 3 ) + { + lineSS >> dim; + } + else + { + dim = dimension; + } + lineSS >> beginn; + if ( dim == dimension ) + { + if ( beginn > what_to_substitute_for_infinite_bar ) + { + barcode.push_back( std::make_pair( what_to_substitute_for_infinite_bar , beginn ) ); + } + else + { + barcode.push_back( std::make_pair( beginn , what_to_substitute_for_infinite_bar ) ); + } + if (dbg) + { + std::cerr << "this is the line that is going to the output : " << beginn << " , " << what_to_substitute_for_infinite_bar << std::endl; + } + } + } + else + { + if ( dbg ) + { + std::cerr << "We will skip it \n"; + } + } + continue; + } + std::stringstream lineSS(line); + double beginn, endd, field, dim; + if ( number_of_entries_per_line == 4 )lineSS >> field; + if ( number_of_entries_per_line >= 3 ) + { + lineSS >> dim; + } + else + { + dim = dimension; + } + lineSS >> beginn; + lineSS >> endd; + if ( beginn > endd ) + { + std::swap(beginn,endd); + } + if ( dim == dimension ) + { + barcode.push_back( std::make_pair( beginn , endd ) ); + if (dbg) + { + std::cerr << "This is a line that is going to the output : " << beginn << " , " << endd << std::endl; + } + } + } + else + { + if ( dbg ) + { + std::cerr << "This is a comment line \n"; + } + } + } + in.close(); + if ( dbg )std::cerr << "End of reading \n"; + + return barcode; +}//read_persistence_intervals_in_one_dimension_from_file + }//namespace Gudhi_stat }//namespace Gudhi diff --git a/src/Gudhi_stat/test/vector_representation_test.cpp b/src/Gudhi_stat/test/vector_representation_test.cpp index fd512a8c..c3b15d05 100644 --- a/src/Gudhi_stat/test/vector_representation_test.cpp +++ b/src/Gudhi_stat/test/vector_representation_test.cpp @@ -21,7 +21,7 @@ */ -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> #include <gudhi/common_gudhi_stat.h> #include <iostream> diff --git a/src/Gudhi_stat/utilities/Hausdorff_subsampling.cpp b/src/Gudhi_stat/utilities/Hausdorff_subsampling.cpp index b05a7adb..e80caaec 100644 --- a/src/Gudhi_stat/utilities/Hausdorff_subsampling.cpp +++ b/src/Gudhi_stat/utilities/Hausdorff_subsampling.cpp @@ -24,7 +24,7 @@ #include <gudhi/Hausdorff_distances.h> #include <gudhi/bootstrap.h> #include <gudhi/read_persitence_from_file.h> -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> using namespace Gudhi; diff --git a/src/Gudhi_stat/utilities/Landscape_bootstrap.cpp b/src/Gudhi_stat/utilities/Landscape_bootstrap.cpp index e6e96e68..53552184 100644 --- a/src/Gudhi_stat/utilities/Landscape_bootstrap.cpp +++ b/src/Gudhi_stat/utilities/Landscape_bootstrap.cpp @@ -25,7 +25,7 @@ #include <gudhi/bootstrap.h> #include <gudhi/persistence_representations/Persistence_landscape.h> #include <gudhi/read_persitence_from_file.h> -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> //persistence part: #include <gudhi/reader_utils.h> #include <gudhi/Rips_complex.h> diff --git a/src/Gudhi_stat/utilities/Multiplicative_bootstrap.cpp b/src/Gudhi_stat/utilities/Multiplicative_bootstrap.cpp index 33b6c9dc..5a0a7b23 100644 --- a/src/Gudhi_stat/utilities/Multiplicative_bootstrap.cpp +++ b/src/Gudhi_stat/utilities/Multiplicative_bootstrap.cpp @@ -24,7 +24,7 @@ #include <gudhi/Hausdorff_distances.h> #include <gudhi/multiplicative_bootstrap.h> #include <gudhi/read_persitence_from_file.h> -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> using namespace Gudhi; using namespace Gudhi::Gudhi_stat; diff --git a/src/Gudhi_stat/utilities/persistence_vectors/average_persistence_vectors.cpp b/src/Gudhi_stat/utilities/persistence_vectors/average_persistence_vectors.cpp index b6b11211..245676cd 100644 --- a/src/Gudhi_stat/utilities/persistence_vectors/average_persistence_vectors.cpp +++ b/src/Gudhi_stat/utilities/persistence_vectors/average_persistence_vectors.cpp @@ -21,7 +21,7 @@ */ -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> diff --git a/src/Gudhi_stat/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp b/src/Gudhi_stat/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp index d61c6753..feba2429 100644 --- a/src/Gudhi_stat/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp +++ b/src/Gudhi_stat/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp @@ -20,7 +20,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> diff --git a/src/Gudhi_stat/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp b/src/Gudhi_stat/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp index 7607c518..775f4913 100644 --- a/src/Gudhi_stat/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp +++ b/src/Gudhi_stat/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp @@ -20,7 +20,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> diff --git a/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp b/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp index b016f2e2..fc434ba8 100644 --- a/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp +++ b/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp @@ -20,7 +20,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> diff --git a/src/Gudhi_stat/utilities/persistence_vectors/plot_persistence_vectors.cpp b/src/Gudhi_stat/utilities/persistence_vectors/plot_persistence_vectors.cpp index 4f19877c..c642d22d 100644 --- a/src/Gudhi_stat/utilities/persistence_vectors/plot_persistence_vectors.cpp +++ b/src/Gudhi_stat/utilities/persistence_vectors/plot_persistence_vectors.cpp @@ -20,7 +20,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <gudhi/persistence_representations/Vector_distances_in_diagram.h> +#include <gudhi/persistence_representations/persistence_vectors.h> |