From 305e25eb80fab69188e04336fc55635cd58e8273 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Tue, 28 Jun 2016 11:31:34 +0000 Subject: now it compiles! git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@1347 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 11d98fbee0ac009d75a1c101f2e28208a199f4a7 --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'src/CMakeLists.txt') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e55e4395..e1db3a3b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,6 +92,7 @@ else() add_subdirectory(example/Bitmap_cubical_complex) add_subdirectory(example/Witness_complex) add_subdirectory(example/Alpha_complex) + add_subdirectory(example/Gudhi_stat) # data points generator add_subdirectory(data/points/generator) -- cgit v1.2.3 From c7697cbc6bb80b18d3319c0310d3cf4afe58e8ef Mon Sep 17 00:00:00 2001 From: pdlotko Date: Tue, 26 Jul 2016 07:13:08 +0000 Subject: aaa git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@1395 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 0adfec650245761402f8a062f0682c4f7afd6513 --- src/CMakeLists.txt | 3 +- src/Gudhi_stat/example/CMakeLists.txt | 11 + src/Gudhi_stat/example/persistence_intervals.cpp | 2 +- .../gudhi/concretizations/Persistence_intervals.h | 1234 ++++++++++---------- .../gudhi/concretizations/Persistence_landscapes.h | 95 +- .../concretizations/Vector_distances_in_diagram.h | 25 +- 6 files changed, 713 insertions(+), 657 deletions(-) (limited to 'src/CMakeLists.txt') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e1db3a3b..fcf38a51 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,7 +92,8 @@ else() add_subdirectory(example/Bitmap_cubical_complex) add_subdirectory(example/Witness_complex) add_subdirectory(example/Alpha_complex) - add_subdirectory(example/Gudhi_stat) + add_subdirectory(example/Bottleneck) + # data points generator add_subdirectory(data/points/generator) diff --git a/src/Gudhi_stat/example/CMakeLists.txt b/src/Gudhi_stat/example/CMakeLists.txt index ec2afc09..aadfc83b 100644 --- a/src/Gudhi_stat/example/CMakeLists.txt +++ b/src/Gudhi_stat/example/CMakeLists.txt @@ -4,10 +4,21 @@ project(GUDHI_STAT) add_executable ( persistence_landscape persistence_landscape.cpp ) target_link_libraries(persistence_landscape ${Boost_SYSTEM_LIBRARY}) +add_executable ( average_landscapes average_landscapes.cpp ) +target_link_libraries(average_landscapes ${Boost_SYSTEM_LIBRARY}) + +add_executable ( create_landscapes create_landscapes.cpp ) +target_link_libraries(create_landscapes ${Boost_SYSTEM_LIBRARY}) + +add_executable ( plot_landscapes plot_landscapes.cpp ) +target_link_libraries(plot_landscapes ${Boost_SYSTEM_LIBRARY}) + add_executable ( persistence_intervals persistence_intervals.cpp ) target_link_libraries(persistence_intervals ${Boost_SYSTEM_LIBRARY}) +add_executable ( plot_persistence_intervals plot_persistence_intervals.cpp ) +target_link_libraries( plot_persistence_intervals ${Boost_SYSTEM_LIBRARY}) add_executable ( vector_representation vector_representation.cpp ) target_link_libraries(vector_representation ${Boost_SYSTEM_LIBRARY}) diff --git a/src/Gudhi_stat/example/persistence_intervals.cpp b/src/Gudhi_stat/example/persistence_intervals.cpp index 0f374b07..cf8c37c6 100644 --- a/src/Gudhi_stat/example/persistence_intervals.cpp +++ b/src/Gudhi_stat/example/persistence_intervals.cpp @@ -24,7 +24,7 @@ #include #include -#include "gudhi/concretizations/Persistence_intervals.h" +#include #include diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_intervals.h b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_intervals.h index a2d16aa0..ecb69a2f 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_intervals.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_intervals.h @@ -1,599 +1,637 @@ -/* 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): Pawel Dlotko - * - * Copyright (C) 2015 INRIA Sophia-Saclay (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 . - */ - -#ifndef Persistence_intervals_H_ -#define Persistence_intervals_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Gudhi -{ -namespace Gudhi_stat -{ - -class Persistence_intervals : public Abs_Vectorized_topological_data , public Abs_Topological_data_with_distances, public Abs_Real_valued_topological_data -{ -public: - /** - * This is a constructor of a class Persistence_intervals from a text file. Each line of the input file is supposed to contain two numbers of a type doube (or convertable to double) - * representing the birth and the death of the persistence interval. If the pairs are not sorted so that birth <= death, then the constructor will sort then that way. - **/ - Persistence_intervals( const char* filename ); - - /** - * This is a constructor of a class Persistence_intervals from a vector of pairs. Each pair is assumed to represent a persistence interval. We assume that the first elemnets of pairs - * are smaller or equal the second elements of pairs. - **/ - Persistence_intervals( const std::vector< std::pair< double,double > >& intervals ); - - /** - * The procedure returns a pair the first element of which is the leftmost end of the interval, and the second element of which is the rightmost end of the interval. - **/ - std::pair min_max(); - - /** - * Procedure that compute the vector of lengths of the dominant (i.e. the longest) persistence intervals. The list is truncated at the parameter of the call where_to_cut (set by default to 100). - **/ - std::vector length_of_dominant_intervals( size_t where_to_cut = 100 ); - - - /** - * Procedure that compute the vector of the dominant (i.e. the longest) persistence intervals. The parameter of the procedure (set by default to 100) is the number of dominant intervals returned by the procedure. - **/ - std::vector< std::pair > dominant_intervals( size_t where_to_cut = 100 ); - - /** - * Procedure to compute a histogram of interva's length. A histogram is a block plot. The number of blocks is determined by the first parameter of the function (set by default to 10). - * For the sake of argument let us assume that the length of the longest interval is 1 and the number of bins is 10. In this case the i-th block correspond to a range between i-1/10 and i10. - * The vale of a block supported at the interval is the number of persistence intervals of a length between x_0 and x_1. - **/ - std::vector< size_t > histograms_of_lengths( size_t number_of_bins = 10 ); - - /** - * Based on a histogram of intervals lengts computed by the function histograms_of_lengths H the procedure below computes the cumulative histogram. The i-th position of the resulting histogram - * is the sume of values of H for the positions from 0 to i. - **/ - std::vector< size_t > cumulative_histograms_of_lengths( size_t number_of_bins = 10 ); - - /** - * In this procedure we assume that each barcode is a characteristic function of a hight equal to its length. The persistence diagram is a sum of such a functions. The procedure below construct a function being a - * sum of the characteristic functions of persistence intervals. The first two parameters are the range in which the function is to be computed and the last parameter is the number of bins in - * the discretization of the interval [_min,_max]. - **/ - std::vector< double > characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins = 10 ); - - /** - * Cumulative version of the function characteristic_function_of_diagram - **/ - std::vector< double > cumulative_characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins = 10 ); - - /** - * Compute the funtion of persistence Betti numbers. The returned value is a vector of pair. First element of each pair is a place where persistence Betti numbers change. - * Second element of each pair is the value of Persistence Betti numbers at that point. - **/ - std::vector< std::pair< double , size_t > > compute_persistent_betti_numbers(); - - /** - *This is a non optimal procedure that compute vector of distances from each point of diagram to its k-th nearest neighbor (k is a parameted of the program). The resulting vector is by default truncated to 10 - *elements (this value can be changed by using the second parameter of the program). The points are returned in order from the ones which are farthest away from their k-th nearest neighbors. - **/ - std::vector< double > k_n_n( size_t k , size_t where_to_cut = 10 ); - - /** - * Operator that send the diagram to a stream. - **/ - - friend ostream& operator << ( ostream& out , const Persistence_intervals& intervals ) - { - for ( size_t i = 0 ; i != intervals.intervals.size() ; ++i ) - { - out << intervals.intervals[i].first << " " << intervals.intervals[i].second << endl; - } - return out; - } - - - /** - * Return a familly of vectors obtained from the persistence diagram. The i-th vector consist of the lenfth of i dominant persistence intervals. - **/ - std::vector vectorize( int number_of_function )//comment: in this case, number_of_functions (a static member of Abs_Vectorized_topological_data cannot be set a priori. - //In this cas, maybe it is better not to make this parameter static. - { - return this->length_of_dominant_intervals( number_of_function ); - } - - /** - * Retun numbr of points in the diagram. - **/ - size_t size()const{return this->intervals.size();} - - /** - * Return the persistence interval at the given position. Note that intervals are not sorted with respect to their lengths. - **/ - inline std::pair< double,double > operator [](size_t i) - { - if ( i >= this->intervals.size() )throw("Index out of range! Operator [], one_d_gaussians class\n"); - return this->intervals[i]; - } - - /** - *Computations of distance from the current persistnce diagram to the persistence diagram given as a parameter of this function. - *The last parameter, power, is here in case we would like to compute p=th Wasserstein distance. At the moment, for the bottleneck distances, it will be ignored. - **/ - double distance( const Abs_Topological_data_with_distances* second , double power = 1) - { - return 1; - //waiting for Francois Godi for the code. We will compute here the Bottleneck distnace. - } - - /** - * This is a simple function projectig the persistence intervals to a real number. The function we use here is a sum of squared lendgths of intervals. It can be naturally interpreted as - * sum of step function, where the step hight it equal to the length of the interval. - **/ - double project_to_R( int number_of_function ); - - - //For visualization use output from vectorize and build histograms. - std::vector< std::pair< double,double > > output_for_visualization() - { - return this->intervals; - } - -protected: - - void set_up_numbers_of_functions_for_vectorization_and_projections_to_reals() - { - //warning, this function can be only called after filling in the intervals vector. - this->number_of_functions_for_vectorization = this->intervals.size(); - this->number_of_functions_for_projections_to_reals = 1; - } - - std::vector< std::pair< double,double > > intervals; -}; - - -Persistence_intervals::Persistence_intervals( const char* filename ) -{ - bool dbg = false; - ifstream in; - in.open( filename ); - - if ( !in.good() ) - { - throw("File with the persistence diagram do not exist, the program will now terminate.\n"); - } - - while ( true ) - { - double first; - double second; - in >> first >> second; - - if ( first > second ) - { - double buf = first; - first = second; - second = buf; - } - - if ( in.eof() )break; - this->intervals.push_back( std::make_pair( first,second ) ); - if ( dbg ) - { - cerr << "Adding interval [ " << first << " , " << second << " ]\n"; - getchar(); - } - } - in.close(); - this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); -}//Persistence_intervals - - -Persistence_intervals::Persistence_intervals( const std::vector< std::pair< double , double > >& intervals_ ) -{ - std::vector< std::pair< double,double > > aaa( intervals_ ); - this->intervals = aaa; - this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); -} - - -std::vector< double > Persistence_intervals::length_of_dominant_intervals( size_t where_to_cut ) -{ - this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); - std::vector< double > result( this->intervals.size() ); - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - result[i] = this->intervals[i].second - this->intervals[i].first; - } - std::sort( result.begin() , result.end() , std::greater() ); - - - result.resize( std::min(where_to_cut,result.size()) ); +/* 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): Pawel Dlotko + * + * Copyright (C) 2015 INRIA Sophia-Saclay (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 . + */ + +#ifndef Persistence_intervals_H_ +#define Persistence_intervals_H_ + +//gudhi include +#include +#include +#include +#include + +//standard include +#include +#include +#include +#include +#include +#include +#include + +namespace Gudhi +{ +namespace Gudhi_stat +{ + +class Persistence_intervals : public Abs_Vectorized_topological_data , public Abs_Topological_data_with_distances, public Abs_Real_valued_topological_data +{ +public: + /** + * This is a constructor of a class Persistence_intervals from a text file. Each line of the input file is supposed to contain two numbers of a type doube (or convertable to double) + * representing the birth and the death of the persistence interval. If the pairs are not sorted so that birth <= death, then the constructor will sort then that way. + **/ + Persistence_intervals( const char* filename ); + + /** + * This is a constructor of a class Persistence_intervals from a vector of pairs. Each pair is assumed to represent a persistence interval. We assume that the first elemnets of pairs + * are smaller or equal the second elements of pairs. + **/ + Persistence_intervals( const std::vector< std::pair< double,double > >& intervals ); + + /** + * The procedure returns a pair the first element of which is the leftmost end of the interval, and the second element of which is the rightmost end of the interval. + **/ + std::pair min_max(); + + /** + * Procedure that compute the vector of lengths of the dominant (i.e. the longest) persistence intervals. The list is truncated at the parameter of the call where_to_cut (set by default to 100). + **/ + std::vector length_of_dominant_intervals( size_t where_to_cut = 100 ); + + + /** + * Procedure that compute the vector of the dominant (i.e. the longest) persistence intervals. The parameter of the procedure (set by default to 100) is the number of dominant intervals returned by the procedure. + **/ + std::vector< std::pair > dominant_intervals( size_t where_to_cut = 100 ); + + /** + * Procedure to compute a histogram of interva's length. A histogram is a block plot. The number of blocks is determined by the first parameter of the function (set by default to 10). + * For the sake of argument let us assume that the length of the longest interval is 1 and the number of bins is 10. In this case the i-th block correspond to a range between i-1/10 and i10. + * The vale of a block supported at the interval is the number of persistence intervals of a length between x_0 and x_1. + **/ + std::vector< size_t > histograms_of_lengths( size_t number_of_bins = 10 ); + + /** + * Based on a histogram of intervals lengts computed by the function histograms_of_lengths H the procedure below computes the cumulative histogram. The i-th position of the resulting histogram + * is the sume of values of H for the positions from 0 to i. + **/ + std::vector< size_t > cumulative_histograms_of_lengths( size_t number_of_bins = 10 ); + + /** + * In this procedure we assume that each barcode is a characteristic function of a hight equal to its length. The persistence diagram is a sum of such a functions. The procedure below construct a function being a + * sum of the characteristic functions of persistence intervals. The first two parameters are the range in which the function is to be computed and the last parameter is the number of bins in + * the discretization of the interval [_min,_max]. + **/ + std::vector< double > characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins = 10 ); + + /** + * Cumulative version of the function characteristic_function_of_diagram + **/ + std::vector< double > cumulative_characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins = 10 ); + + /** + * Compute the funtion of persistence Betti numbers. The returned value is a vector of pair. First element of each pair is a place where persistence Betti numbers change. + * Second element of each pair is the value of Persistence Betti numbers at that point. + **/ + std::vector< std::pair< double , size_t > > compute_persistent_betti_numbers(); + + /** + *This is a non optimal procedure that compute vector of distances from each point of diagram to its k-th nearest neighbor (k is a parameted of the program). The resulting vector is by default truncated to 10 + *elements (this value can be changed by using the second parameter of the program). The points are returned in order from the ones which are farthest away from their k-th nearest neighbors. + **/ + std::vector< double > k_n_n( size_t k , size_t where_to_cut = 10 ); + + /** + * Operator that send the diagram to a stream. + **/ + friend ostream& operator << ( ostream& out , const Persistence_intervals& intervals ) + { + for ( size_t i = 0 ; i != intervals.intervals.size() ; ++i ) + { + out << intervals.intervals[i].first << " " << intervals.intervals[i].second << endl; + } + return out; + } + + /** + * Generating gnuplot script to plot the interval. + **/ + void plot( const char* filename ) + { + //this program create a gnuplot script file that allows to plot persistence diagram. + ofstream out; + + std::ostringstream nameSS; + nameSS << filename << "_GnuplotScript"; + std::string nameStr = nameSS.str(); + out.open( (char*)nameStr.c_str() ); + std::pair min_max_values = this->min_max(); + out << "set xrange [" << min_max_values.first - 0.1*(min_max_values.second-min_max_values.first) << " : " << min_max_values.second + 0.1*(min_max_values.second-min_max_values.first) << " ]" << endl; + out << "set yrange [" << min_max_values.first - 0.1*(min_max_values.second-min_max_values.first) << " : " << min_max_values.second + 0.1*(min_max_values.second-min_max_values.first) << " ]" << endl; + out << "plot '-' using 1:2 notitle \"" << filename << "\", \\" << endl; + out << " '-' using 1:2 notitle with lp" << endl; + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + out << this->intervals[i].first << " " << this->intervals[i].second << endl; + } + out << "EOF" << endl; + out << min_max_values.first - 0.1*(min_max_values.second-min_max_values.first) << " " << min_max_values.first - 0.1*(min_max_values.second-min_max_values.first) << endl; + out << min_max_values.second + 0.1*(min_max_values.second-min_max_values.first) << " " << min_max_values.second + 0.1*(min_max_values.second-min_max_values.first) << endl; + + out.close(); + + cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '" << nameStr << "' in gnuplot to visualize." << endl; + } + + /** + * Return a familly of vectors obtained from the persistence diagram. The i-th vector consist of the lenfth of i dominant persistence intervals. + **/ + std::vector vectorize( int number_of_function )//comment: in this case, number_of_functions (a static member of Abs_Vectorized_topological_data cannot be set a priori. + //In this cas, maybe it is better not to make this parameter static. + { + return this->length_of_dominant_intervals( number_of_function ); + } + + /** + * Retun numbr of points in the diagram. + **/ + size_t size()const{return this->intervals.size();} + + /** + * Return the persistence interval at the given position. Note that intervals are not sorted with respect to their lengths. + **/ + inline std::pair< double,double > operator [](size_t i) + { + if ( i >= this->intervals.size() )throw("Index out of range! Operator [], one_d_gaussians class\n"); + return this->intervals[i]; + } + + /** + *Computations of distance from the current persistnce diagram to the persistence diagram given as a parameter of this function. + *The last parameter, power, is here in case we would like to compute p=th Wasserstein distance. At the moment, for the bottleneck distances, it will be ignored. + **/ + double distance( const Abs_Topological_data_with_distances* second , double power = 1) + { + return 1; + //waiting for Francois Godi for the code. We will compute here the Bottleneck distnace. + } + + /** + * This is a simple function projectig the persistence intervals to a real number. The function we use here is a sum of squared lendgths of intervals. It can be naturally interpreted as + * sum of step function, where the step hight it equal to the length of the interval. + **/ + double project_to_R( int number_of_function ); + + + //For visualization use output from vectorize and build histograms. + std::vector< std::pair< double,double > > output_for_visualization() + { + return this->intervals; + } + +protected: + + void set_up_numbers_of_functions_for_vectorization_and_projections_to_reals() + { + //warning, this function can be only called after filling in the intervals vector. + this->number_of_functions_for_vectorization = this->intervals.size(); + this->number_of_functions_for_projections_to_reals = 1; + } + + std::vector< std::pair< double,double > > intervals; +}; + + +Persistence_intervals::Persistence_intervals( const char* filename ) +{ + //bool dbg = false; + //ifstream in; + //in.open( filename ); + + //if ( !in.good() ) + //{ + // throw("File with the persistence diagram do not exist, the program will now terminate.\n"); + //} + + //while ( true ) + //{ + // double first; + // double second; + // in >> first >> second; + + // if ( first > second ) + // { + // double buf = first; + // first = second; + // second = buf; + // } + + // if ( in.eof() )break; + // this->intervals.push_back( std::make_pair( first,second ) ); + // if ( dbg ) + // { + // cerr << "Adding interval [ " << first << " , " << second << " ]\n"; + // getchar(); + // } + //} + //in.close(); + //standard file with barcode + std::vector< std::pair< double , double > > barcode = read_standard_file( filename ); + //gudhi file with barcode + //std::vector< std::pair< double , double > > barcode = read_gudhi_file( filename , dimension ); + + this->intervals = barcode; + this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); +}//Persistence_intervals + + +Persistence_intervals::Persistence_intervals( const std::vector< std::pair< double , double > >& intervals_ ) +{ + std::vector< std::pair< double,double > > aaa( intervals_ ); + this->intervals = aaa; + this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); +} + + +std::vector< double > Persistence_intervals::length_of_dominant_intervals( size_t where_to_cut ) +{ + this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); + std::vector< double > result( this->intervals.size() ); + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + result[i] = this->intervals[i].second - this->intervals[i].first; + } + std::sort( result.begin() , result.end() , std::greater() ); + + + result.resize( std::min(where_to_cut,result.size()) ); + return result; +}//length_of_dominant_intervals + + + +bool compare( const std::pair< size_t , double >& first , const std::pair< size_t , double >& second ) +{ + return first.second > second.second; +} + + +std::vector< std::pair > Persistence_intervals::dominant_intervals( size_t where_to_cut ) +{ + bool dbg = false; + std::vector< std::pair< size_t , double > > position_length_vector( this->intervals.size() ); + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + position_length_vector[i] = std::make_pair( i , this->intervals[i].second - this->intervals[i].first ); + } + + std::sort( position_length_vector.begin() , position_length_vector.end() , compare ); + + std::vector< std::pair > result; + result.reserve( std::min( where_to_cut , position_length_vector.size() ) ); + + for ( size_t i = 0 ; i != std::min( where_to_cut , position_length_vector.size() ) ; ++i ) + { + result.push_back( this->intervals[ position_length_vector[i].first ] ); + if ( dbg )cerr << "Position : " << position_length_vector[i].first << " length : " << position_length_vector[i].second << endl; + } + + return result; +}//dominant_intervals + + +std::vector< size_t > Persistence_intervals::histograms_of_lengths( size_t number_of_bins ) +{ + bool dbg = false; + + if ( dbg )cerr << "this->intervals.size() : " << this->intervals.size() << endl; + //first find the length of the longest interval: + double lengthOfLongest = 0; + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + if ( (this->intervals[i].second - this->intervals[i].first) > lengthOfLongest ) + { + lengthOfLongest = this->intervals[i].second - this->intervals[i].first; + } + } + + if ( dbg ){cerr << "lengthOfLongest : " << lengthOfLongest << endl;} + + //this is a container we will use to store the resulting histogram + std::vector< size_t > result( number_of_bins + 1 , 0 ); + + //for every persistence interval in our collection. + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + //compute its length relative to the length of the dominant interval: + double relative_length_of_this_interval = (this->intervals[i].second - this->intervals[i].first)/lengthOfLongest; + + //given the relative length (between 0 and 1) compute to which bin should it contribute. + size_t position = (size_t)(relative_length_of_this_interval*number_of_bins); + + + ++result[position]; + + if ( dbg ) + { + cerr << "i : " << i << endl; + cerr << "Interval : [" << this->intervals[i].first << " , " << this->intervals[i].second << " ] \n"; + cerr << "relative_length_of_this_interval : " << relative_length_of_this_interval << endl; + cerr << "position : " << position << endl; + getchar(); + } + } + + + if ( dbg ){for ( size_t i = 0 ; i != result.size() ; ++i )cerr << result[i] << endl;} + return result; +} + + +std::vector< size_t > Persistence_intervals::cumulative_histograms_of_lengths( size_t number_of_bins ) +{ + std::vector< size_t > histogram = this->histograms_of_lengths( number_of_bins ); + std::vector< size_t > result( histogram.size() ); + + size_t sum = 0; + for ( size_t i = 0 ; i != histogram.size() ; ++i ) + { + sum += histogram[i]; + result[i] = sum; + } + return result; +} + + +std::vector< double > Persistence_intervals::characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins ) +{ + bool dbg = false; + + std::vector< double > result( number_of_bins ); + std::fill( result.begin() , result.end() , 0 ); + + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + if ( dbg ) + { + cerr << "Interval : " << this->intervals[i].first << " , " << this->intervals[i].second << endl; + } + + size_t beginIt = 0; + if ( this->intervals[i].first < x_min )beginIt = 0; + if ( this->intervals[i].first >= x_max )beginIt = result.size(); + if ( ( this->intervals[i].first > x_min ) && ( this->intervals[i].first < x_max ) ) + { + beginIt = number_of_bins*(this->intervals[i].first-x_min)/(x_max - x_min); + } + + size_t endIt; + if ( this->intervals[i].second < x_min )endIt = 0; + if ( this->intervals[i].second >= x_max )endIt = result.size(); + if ( ( this->intervals[i].second > x_min ) && ( this->intervals[i].second < x_max ) ) + { + endIt = number_of_bins*( this->intervals[i].second - x_min )/(x_max - x_min); + } + + if ( beginIt > endIt ){beginIt = endIt;} + + if ( dbg ) + { + cerr << "beginIt : " << beginIt << endl; + cerr << "endIt : " << endIt << endl; + } + + + for ( size_t pos = beginIt ; pos != endIt ; ++pos ) + { + result[pos] += ( (x_max - x_min)/(double)number_of_bins ) * ( this->intervals[i].second - this->intervals[i].first ); + } + //cerr << "x_max : " << x_max << " x_min : " << x_min << " , number_of_bins : " << number_of_bins << " this->intervals[i].second : " << this->intervals[i].second << " this->intervals[i].first : " << this->intervals[i].first << endl; + if ( dbg ) + { + cerr << "Result at this stage \n"; + for ( size_t aa = 0 ; aa != result.size() ; ++aa ) + { + cerr << result[aa] << " "; + } + cerr << endl; + //getchar(); + } + } + return result; +}//characteristic_function_of_diagram + + + +std::vector< double > Persistence_intervals::cumulative_characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins ) +{ + std::vector< double > intsOfBars = this->characteristic_function_of_diagram( x_min , x_max , number_of_bins ); + std::vector< double > result( intsOfBars.size() ); + double sum = 0; + for ( size_t i = 0 ; i != intsOfBars.size() ; ++i ) + { + sum += intsOfBars[i]; + result[i] = sum; + } + return result; +}//cumulative_characteristic_function_of_diagram + + +template +bool compare_first_element_of_pair( const std::pair< T , bool >& f, const std::pair< T , bool >& s ) +{ + return (f.first < s.first); +} + + +std::vector< std::pair< double , size_t > > Persistence_intervals::compute_persistent_betti_numbers() +{ + std::vector< std::pair< double , bool > > places_where_pbs_change( 2*this->intervals.size() ); + + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + places_where_pbs_change[2*i] = std::make_pair( this->intervals[i].first , true ); + places_where_pbs_change[2*i+1] = std::make_pair( this->intervals[i].second , false ); + } + + std::sort( places_where_pbs_change.begin() , places_where_pbs_change.end() , compare_first_element_of_pair ); + size_t pbn = 0; + std::vector< std::pair< double , size_t > > pbns( places_where_pbs_change.size() ); + for ( size_t i = 0 ; i != places_where_pbs_change.size() ; ++i ) + { + if ( places_where_pbs_change[i].second == true ) + { + ++pbn; + } + else + { + --pbn; + } + pbns[i] = std::make_pair( places_where_pbs_change[i].first , pbn ); + } + return pbns; +} + + + + + + +inline double compute_euclidean_distance( const std::pair< double,double > & f , const std::pair< double,double > & s ) +{ + return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); +} + + +std::vector< double > Persistence_intervals::k_n_n( size_t k , size_t where_to_cut ) +{ + bool dbg = false; + if ( dbg ) + { + cerr << "Here are the intervals : \n"; + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + cerr << "[ " << this->intervals[i].first << " , " << this->intervals[i].second << "] \n"; + } + getchar(); + } + + std::vector< double > result; + //compute all to all distance between point in the diagram. Also, consider points in the diagonal with the infinite multiplicity. + std::vector< std::vector< double > > distances( this->intervals.size() ); + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + std::vector aa(this->intervals.size()); + std::fill( aa.begin() , aa.end() , 0 ); + distances[i] = aa; + } + std::vector< double > distances_from_diagonal( this->intervals.size() ); + std::fill( distances_from_diagonal.begin() , distances_from_diagonal.end() , 0 ); + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + std::vector< double > distancesFromI; + for ( size_t j = i+1 ; j != this->intervals.size() ; ++j ) + { + distancesFromI.push_back( compute_euclidean_distance( this->intervals[i] , this->intervals[j] ) ); + } + //distances.push_back( distancesFromI ); + //also add a distance from this guy to daigonal: + double distanceToDiagonal = compute_euclidean_distance( this->intervals[i] , std::make_pair( 0.5*(this->intervals[i].first + this->intervals[i].second) , 0.5*(this->intervals[i].first + this->intervals[i].second) ) ); + distances_from_diagonal[i] = distanceToDiagonal; + + if ( dbg ) + { + cerr << "Here are the distances form the point : [" << this->intervals[i].first << " , " << this->intervals[i].second << "] in the diagram \n"; + for ( size_t aa = 0 ; aa != distancesFromI.size() ; ++aa ) + { + cerr << "To : " << i+aa << " : " << distancesFromI[aa] << " "; + } + cerr << endl; + getchar(); + } + + //filling in the distances matrix: + for ( size_t j = i+1 ; j != this->intervals.size() ; ++j ) + { + distances[i][j] = distancesFromI[j-i-1]; + distances[j][i] = distancesFromI[j-i-1]; + } + } + if ( dbg ) + { + cerr << "Here is the distance matrix : \n"; + for ( size_t i = 0 ; i != distances.size() ; ++i ) + { + for ( size_t j = 0 ; j != distances.size() ; ++j ) + { + cerr << distances[i][j] << " "; + } + cerr << endl; + } + cerr << endl << endl << "And here are the distances to the diagonal : " << endl; + for ( size_t i = 0 ; i != distances_from_diagonal. size() ; ++i ) + { + cerr << distances_from_diagonal[i] << " "; + } + cerr << endl << endl; + getchar(); + } + + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + std::vector< double > distancesFromI = distances[i]; + distancesFromI.push_back( distances_from_diagonal[i] ); + + //sort it: + std::sort( distancesFromI.begin() , distancesFromI.end() , std::greater() ); + + if ( k > distancesFromI.size() ) + { + if ( dbg ) + { + cerr << "There are not enough neighbors in your set. We set the result to plus infty \n"; + } + result.push_back( std::numeric_limits::max() ); + } + else + { + if ( distances_from_diagonal[i] > distancesFromI[k] ) + { + if ( dbg ) + { + cerr << "The k-th n.n. is on a diagonal. Therefore we set up a distance to diagonal \n"; + } + result.push_back( distances_from_diagonal[i] ); + } + else + { + result.push_back( distancesFromI[k] ); + } + } + } + std::sort( result.begin() , result.end() , std::greater() ); + result.resize( std::min( result.size() , where_to_cut ) ); + return result; -}//length_of_dominant_intervals - - - -bool compare( const std::pair< size_t , double >& first , const std::pair< size_t , double >& second ) -{ - return first.second > second.second; -} - - -std::vector< std::pair > Persistence_intervals::dominant_intervals( size_t where_to_cut ) -{ - bool dbg = false; - std::vector< std::pair< size_t , double > > position_length_vector( this->intervals.size() ); - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - position_length_vector[i] = std::make_pair( i , this->intervals[i].second - this->intervals[i].first ); - } - - std::sort( position_length_vector.begin() , position_length_vector.end() , compare ); - - std::vector< std::pair > result; - result.reserve( std::min( where_to_cut , position_length_vector.size() ) ); - - for ( size_t i = 0 ; i != std::min( where_to_cut , position_length_vector.size() ) ; ++i ) - { - result.push_back( this->intervals[ position_length_vector[i].first ] ); - if ( dbg )cerr << "Position : " << position_length_vector[i].first << " length : " << position_length_vector[i].second << endl; - } - - return result; -}//dominant_intervals - - -std::vector< size_t > Persistence_intervals::histograms_of_lengths( size_t number_of_bins ) -{ - bool dbg = false; - - if ( dbg )cerr << "this->intervals.size() : " << this->intervals.size() << endl; - //first find the length of the longest interval: - double lengthOfLongest = 0; - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - if ( (this->intervals[i].second - this->intervals[i].first) > lengthOfLongest ) - { - lengthOfLongest = this->intervals[i].second - this->intervals[i].first; - } - } - - if ( dbg ){cerr << "lengthOfLongest : " << lengthOfLongest << endl;} - - //this is a container we will use to store the resulting histogram - std::vector< size_t > result( number_of_bins + 1 , 0 ); - - //for every persistence interval in our collection. - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - //compute its length relative to the length of the dominant interval: - double relative_length_of_this_interval = (this->intervals[i].second - this->intervals[i].first)/lengthOfLongest; - - //given the relative length (between 0 and 1) compute to which bin should it contribute. - size_t position = (size_t)(relative_length_of_this_interval*number_of_bins); - - - ++result[position]; - - if ( dbg ) - { - cerr << "i : " << i << endl; - cerr << "Interval : [" << this->intervals[i].first << " , " << this->intervals[i].second << " ] \n"; - cerr << "relative_length_of_this_interval : " << relative_length_of_this_interval << endl; - cerr << "position : " << position << endl; - getchar(); - } - } - - - if ( dbg ){for ( size_t i = 0 ; i != result.size() ; ++i )cerr << result[i] << endl;} - return result; -} - - -std::vector< size_t > Persistence_intervals::cumulative_histograms_of_lengths( size_t number_of_bins ) -{ - std::vector< size_t > histogram = this->histograms_of_lengths( number_of_bins ); - std::vector< size_t > result( histogram.size() ); - - size_t sum = 0; - for ( size_t i = 0 ; i != histogram.size() ; ++i ) - { - sum += histogram[i]; - result[i] = sum; - } - return result; -} - - -std::vector< double > Persistence_intervals::characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins ) -{ - bool dbg = false; - - std::vector< double > result( number_of_bins ); - std::fill( result.begin() , result.end() , 0 ); - - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - if ( dbg ) - { - cerr << "Interval : " << this->intervals[i].first << " , " << this->intervals[i].second << endl; - } - - size_t beginIt = 0; - if ( this->intervals[i].first < x_min )beginIt = 0; - if ( this->intervals[i].first >= x_max )beginIt = result.size(); - if ( ( this->intervals[i].first > x_min ) && ( this->intervals[i].first < x_max ) ) - { - beginIt = number_of_bins*(this->intervals[i].first-x_min)/(x_max - x_min); - } - - size_t endIt; - if ( this->intervals[i].second < x_min )endIt = 0; - if ( this->intervals[i].second >= x_max )endIt = result.size(); - if ( ( this->intervals[i].second > x_min ) && ( this->intervals[i].second < x_max ) ) - { - endIt = number_of_bins*( this->intervals[i].second - x_min )/(x_max - x_min); - } - - if ( beginIt > endIt ){beginIt = endIt;} - - if ( dbg ) - { - cerr << "beginIt : " << beginIt << endl; - cerr << "endIt : " << endIt << endl; - } - - - for ( size_t pos = beginIt ; pos != endIt ; ++pos ) - { - result[pos] += ( (x_max - x_min)/(double)number_of_bins ) * ( this->intervals[i].second - this->intervals[i].first ); - } - //cerr << "x_max : " << x_max << " x_min : " << x_min << " , number_of_bins : " << number_of_bins << " this->intervals[i].second : " << this->intervals[i].second << " this->intervals[i].first : " << this->intervals[i].first << endl; - if ( dbg ) - { - cerr << "Result at this stage \n"; - for ( size_t aa = 0 ; aa != result.size() ; ++aa ) - { - cerr << result[aa] << " "; - } - cerr << endl; - //getchar(); - } - } - return result; -}//characteristic_function_of_diagram - - - -std::vector< double > Persistence_intervals::cumulative_characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins ) -{ - std::vector< double > intsOfBars = this->characteristic_function_of_diagram( x_min , x_max , number_of_bins ); - std::vector< double > result( intsOfBars.size() ); - double sum = 0; - for ( size_t i = 0 ; i != intsOfBars.size() ; ++i ) - { - sum += intsOfBars[i]; - result[i] = sum; - } - return result; -}//cumulative_characteristic_function_of_diagram - - -template -bool compare_first_element_of_pair( const std::pair< T , bool >& f, const std::pair< T , bool >& s ) -{ - return (f.first < s.first); -} - - -std::vector< std::pair< double , size_t > > Persistence_intervals::compute_persistent_betti_numbers() -{ - std::vector< std::pair< double , bool > > places_where_pbs_change( 2*this->intervals.size() ); - - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - places_where_pbs_change[2*i] = std::make_pair( this->intervals[i].first , true ); - places_where_pbs_change[2*i+1] = std::make_pair( this->intervals[i].second , false ); - } - - std::sort( places_where_pbs_change.begin() , places_where_pbs_change.end() , compare_first_element_of_pair ); - size_t pbn = 0; - std::vector< std::pair< double , size_t > > pbns( places_where_pbs_change.size() ); - for ( size_t i = 0 ; i != places_where_pbs_change.size() ; ++i ) - { - if ( places_where_pbs_change[i].second == true ) - { - ++pbn; - } - else - { - --pbn; - } - pbns[i] = std::make_pair( places_where_pbs_change[i].first , pbn ); - } - return pbns; -} - - - - - - -inline double compute_euclidean_distance( const std::pair< double,double > & f , const std::pair< double,double > & s ) -{ - return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); -} - - -std::vector< double > Persistence_intervals::k_n_n( size_t k , size_t where_to_cut ) -{ - bool dbg = false; - if ( dbg ) - { - cerr << "Here are the intervals : \n"; - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - cerr << "[ " << this->intervals[i].first << " , " << this->intervals[i].second << "] \n"; - } - getchar(); - } - - std::vector< double > result; - //compute all to all distance between point in the diagram. Also, consider points in the diagonal with the infinite multiplicity. - std::vector< std::vector< double > > distances( this->intervals.size() ); - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - std::vector aa(this->intervals.size()); - std::fill( aa.begin() , aa.end() , 0 ); - distances[i] = aa; - } - std::vector< double > distances_from_diagonal( this->intervals.size() ); - std::fill( distances_from_diagonal.begin() , distances_from_diagonal.end() , 0 ); - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - std::vector< double > distancesFromI; - for ( size_t j = i+1 ; j != this->intervals.size() ; ++j ) - { - distancesFromI.push_back( compute_euclidean_distance( this->intervals[i] , this->intervals[j] ) ); - } - //distances.push_back( distancesFromI ); - //also add a distance from this guy to daigonal: - double distanceToDiagonal = compute_euclidean_distance( this->intervals[i] , std::make_pair( 0.5*(this->intervals[i].first + this->intervals[i].second) , 0.5*(this->intervals[i].first + this->intervals[i].second) ) ); - distances_from_diagonal[i] = distanceToDiagonal; - - if ( dbg ) - { - cerr << "Here are the distances form the point : [" << this->intervals[i].first << " , " << this->intervals[i].second << "] in the diagram \n"; - for ( size_t aa = 0 ; aa != distancesFromI.size() ; ++aa ) - { - cerr << "To : " << i+aa << " : " << distancesFromI[aa] << " "; - } - cerr << endl; - getchar(); - } - - //filling in the distances matrix: - for ( size_t j = i+1 ; j != this->intervals.size() ; ++j ) - { - distances[i][j] = distancesFromI[j-i-1]; - distances[j][i] = distancesFromI[j-i-1]; - } - } - if ( dbg ) - { - cerr << "Here is the distance matrix : \n"; - for ( size_t i = 0 ; i != distances.size() ; ++i ) - { - for ( size_t j = 0 ; j != distances.size() ; ++j ) - { - cerr << distances[i][j] << " "; - } - cerr << endl; - } - cerr << endl << endl << "And here are the distances to the diagonal : " << endl; - for ( size_t i = 0 ; i != distances_from_diagonal. size() ; ++i ) - { - cerr << distances_from_diagonal[i] << " "; - } - cerr << endl << endl; - getchar(); - } - - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - std::vector< double > distancesFromI = distances[i]; - distancesFromI.push_back( distances_from_diagonal[i] ); - - //sort it: - std::sort( distancesFromI.begin() , distancesFromI.end() , std::greater() ); - - if ( k > distancesFromI.size() ) - { - if ( dbg ) - { - cerr << "There are not enough neighbors in your set. We set the result to plus infty \n"; - } - result.push_back( std::numeric_limits::max() ); - } - else - { - if ( distances_from_diagonal[i] > distancesFromI[k] ) - { - if ( dbg ) - { - cerr << "The k-th n.n. is on a diagonal. Therefore we set up a distance to diagonal \n"; - } - result.push_back( distances_from_diagonal[i] ); - } - else - { - result.push_back( distancesFromI[k] ); - } - } - } - std::sort( result.begin() , result.end() , std::greater() ); - result.resize( std::min( result.size() , where_to_cut ) ); - - return result; -} - - -std::pair Persistence_intervals::min_max() -{ - double min_ = INT_MAX; - double max_ = -INT_MAX; - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - if ( this->intervals[i].first < min_ )min_ = this->intervals[i].first; - if ( this->intervals[i].second > max_ )max_ = this->intervals[i].second; - } - return std::make_pair( min_ , max_ ); -} - -double Persistence_intervals::project_to_R( int number_of_function ) -{ - double result = 0; - - for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) - { - result += ( this->intervals[i].second - this->intervals[i].first )*( this->intervals[i].second - this->intervals[i].first ); - } - - return result; -} - - -}//namespace gudhi stat -}//namespace gudhi - -#endif +} + + +std::pair Persistence_intervals::min_max() +{ + double min_ = INT_MAX; + double max_ = -INT_MAX; + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + if ( this->intervals[i].first < min_ )min_ = this->intervals[i].first; + if ( this->intervals[i].second > max_ )max_ = this->intervals[i].second; + } + return std::make_pair( min_ , max_ ); +} + +double Persistence_intervals::project_to_R( int number_of_function ) +{ + double result = 0; + + for ( size_t i = 0 ; i != this->intervals.size() ; ++i ) + { + result += ( this->intervals[i].second - this->intervals[i].first )*( this->intervals[i].second - this->intervals[i].first ); + } + + return result; +} + + +}//namespace gudhi stat +}//namespace gudhi + +#endif diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscapes.h b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscapes.h index f728bfbe..403ca455 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscapes.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscapes.h @@ -24,7 +24,7 @@ #ifndef Persistence_landscapes_H #define Persistence_landscapes_H - +//standard include #include #include #include @@ -35,12 +35,13 @@ #include - +//gudhi include #include #include #include #include #include +#include using namespace std; @@ -205,7 +206,7 @@ public: * Constructor that reads persistence intervals from file and creates persistence landscape. The format of the input file is the following: in each line we put birth-death pair. Last line is assumed * to be empty. Even if the points within a line are not ordered, they will be ordered while the input is read. **/ - Persistence_landscape(const char* filename); + Persistence_landscape(const char* filename , size_t dimension = 0); @@ -530,6 +531,10 @@ public: { return this->land; } + + + //a function used to create a gnuplot script for visualization of landscapes + void plot( const char* filename ,int from = -1, int to = -1 , double xRangeBegin = -1 , double xRangeEnd = -1 , double yRangeBegin = -1 , double yRangeEnd = -1 ); private: @@ -566,47 +571,18 @@ Persistence_landscape::Persistence_landscape(const Persistence_landscape& orygin -Persistence_landscape::Persistence_landscape(const char* filename) +Persistence_landscape::Persistence_landscape(const char* filename , size_t dimension) { bool dbg = false; if ( dbg ) { std::cerr << "Using constructor : Persistence_landscape(char* filename)" << std::endl; - } - - //this constructor reads persistence landscape form a file. This file have to be created by this software beforehead - std::ifstream in; - in.open( filename ); - - std::string line; - std::vector< std::pair > barcode; - - while (!in.eof()) - { - getline(in,line); - if ( !(line.length() == 0 || line[0] == '#') ) - { - std::stringstream lineSS; - lineSS << line; - double beginn, endd; - lineSS >> beginn; - lineSS >> endd; - if ( beginn > endd ) - { - double b = beginn; - beginn = endd; - endd = b; - } - barcode.push_back( std::make_pair( beginn , endd ) ); - if (dbg) - { - std::cerr << beginn << " , " << endd << std::endl; - } - } - } - in.close(); - + } + //standard file with barcode + //std::vector< std::pair< double , double > > barcode = read_standard_file( filename ); + //gudhi file with barcode + std::vector< std::pair< double , double > > barcode = read_gudhi_file( filename , dimension ); this->construct_persistence_landscape_from_barcode( barcode ); this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); } @@ -1473,6 +1449,49 @@ double compute_inner_product( const Persistence_landscape& l1 , const Persistenc } +void Persistence_landscape::plot( const char* filename , int from, int to , double xRangeBegin , double xRangeEnd , double yRangeBegin , double yRangeEnd ) +{ + //this program create a gnuplot script file that allows to plot persistence diagram. + ofstream out; + + std::ostringstream nameSS; + nameSS << filename << "_GnuplotScript"; + std::string nameStr = nameSS.str(); + out.open( (char*)nameStr.c_str() ); + + if ( (xRangeBegin != -1) || (xRangeEnd != -1) || (yRangeBegin != -1) || (yRangeEnd != -1) ) + { + out << "set xrange [" << xRangeBegin << " : " << xRangeEnd << "]" << endl; + out << "set yrange [" << yRangeBegin << " : " << yRangeEnd << "]" << endl; + } + + if ( from == -1 ){from = 0;} + if ( to == -1 ){to = this->land.size();} + + out << "plot "; + for ( size_t lambda= std::min((size_t)from,this->land.size()) ; lambda != std::min((size_t)to,this->land.size()) ; ++lambda ) + { + out << " '-' using 1:2 title 'l" << lambda << "' with lp"; + if ( lambda+1 != std::min((size_t)to,this->land.size()) ) + { + out << ", \\"; + } + out << endl; + } + + for ( size_t lambda= std::min((size_t)from,this->land.size()) ; lambda != std::min((size_t)to,this->land.size()) ; ++lambda ) + { + for ( size_t i = 1 ; i != this->land[lambda].size()-1 ; ++i ) + { + out << this->land[lambda][i].first << " " << this->land[lambda][i].second << endl; + } + out << "EOF" << endl; + } + cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '" << nameStr << "' in gnuplot to visualize." << endl; +} + + + }//namespace gudhi stat }//namespace gudhi diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h b/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h index bcabadac..ce111426 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h @@ -37,6 +37,7 @@ #include #include #include +#include using namespace std; namespace Gudhi @@ -203,27 +204,13 @@ Vector_distances_in_diagram& Vector_distances_in_diagram::operator =( cons template Vector_distances_in_diagram::Vector_distances_in_diagram( const char* filename , size_t where_to_cut ):Abs_Vectorized_topological_data(where_to_cut) -{ - std::vector< std::pair< double , double > > intervals; - ifstream in; - in.open( filename ); - - if ( !in.good() ) - { - std::cerr << "File : " << filename << " do not exist. The program will now terminate \n"; - throw("File with the persistence diagram do not exist, the program will now terminate.\n"); - } +{ + //standard file with barcode + std::vector< std::pair< double , double > > intervals = read_standard_file( filename ); + //gudhi file with barcode + //std::vector< std::pair< double , double > > intervals = read_gudhi_file( filename , dimension ); - while ( true ) - { - double first; - double second; - in >> first >> second; - if ( in.eof() )break; - intervals.push_back( std::make_pair( first,second ) ); - } this->intervals = intervals; - in.close(); this->compute_sorted_vector_of_distnaces_via_heap( where_to_cut ); set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); } -- cgit v1.2.3 From 8f4c961a93fe928d06c7776a9e8f5ecd00fab9ca Mon Sep 17 00:00:00 2001 From: pdlotko Date: Wed, 12 Apr 2017 13:07:58 +0000 Subject: a few more correction. First of all, bottleneck distance is added (although there is something strange in the results, FG has been pinged about this). Second of all, all the programs in utylites should now read general files (and dimension of persistence to be read is one of the parameteds of files). This still need to be tested and will be tested soon. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2339 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e60d14f07db223646597230d7f0bd78dd090bc0b --- src/CMakeLists.txt | 1 + src/Doxyfile | 3 +- src/Gudhi_stat/doc/average_landscape.png | Bin 0 -> 14917 bytes src/Gudhi_stat/include/gudhi/permutation_test.h | 2 + .../gudhi/persistence_representations/PSSK.h | 12 ++- .../Persistence_heat_maps.h | 16 ++- .../Persistence_intervals.h | 39 ++----- .../Persistence_intervals_with_distances.h | 76 ++++++++++++++ .../Persistence_landscape.h | 21 ++-- .../Persistence_landscape_on_grid.h | 82 +++++++++------ .../persistence_vectors.h | 20 ++-- src/Gudhi_stat/include/gudhi/topological_process.h | 5 +- .../test/persistence_lanscapes_on_grid_test.cpp | 35 ++++--- .../utilities/Multiplicative_bootstrap.cpp | 2 +- src/Gudhi_stat/utilities/permutation_test.cpp | 2 +- .../create_persistence_heat_maps.cpp | 20 ++-- ...aps_weighted_by_arctan_of_their_persistence.cpp | 18 +++- ...eat_maps_weighted_by_distance_from_diagonal.cpp | 14 ++- ..._weighted_by_squared_distance_from_diagonal.cpp | 18 +++- .../persistence_heat_maps/create_pssk.cpp | 17 ++- .../utilities/persistence_intervals/CMakeLists.txt | 15 ++- ...te_birth_death_range_in_persistence_diagram.cpp | 24 +++-- .../compute_bottleneck_distance.cpp | 115 +++++++++++++++++++++ .../compute_number_of_dominant_intervals.cpp | 15 ++- .../plot_histogram_of_intervals_lengths.cpp | 13 ++- .../plot_persistence_Betti_numbers.cpp | 100 ++++++++++++++++++ .../plot_persistence_Betti_numebrs.cpp | 90 ---------------- .../plot_persistence_intervals.cpp | 16 ++- .../persistence_landscapes/create_landscapes.cpp | 17 ++- .../create_landscapes_on_grid.cpp | 17 ++- .../create_persistence_vectors.cpp | 16 ++- 31 files changed, 593 insertions(+), 248 deletions(-) create mode 100644 src/Gudhi_stat/doc/average_landscape.png create mode 100644 src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_intervals_with_distances.h create mode 100644 src/Gudhi_stat/utilities/persistence_intervals/compute_bottleneck_distance.cpp create mode 100644 src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp delete mode 100644 src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numebrs.cpp (limited to 'src/CMakeLists.txt') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3779cb80..c94110a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,7 @@ add_subdirectory(example/Subsampling) add_subdirectory(example/Tangential_complex) add_subdirectory(example/Bottleneck_distance) add_subdirectory(example/Gudhi_stat) +add_subdirectory(example/Gudhi_stat/utilities) # data points generator add_subdirectory(data/points/generator) diff --git a/src/Doxyfile b/src/Doxyfile index d2d0a447..f3782148 100644 --- a/src/Doxyfile +++ b/src/Doxyfile @@ -851,7 +851,8 @@ IMAGE_PATH = doc/Skeleton_blocker/ \ doc/Subsampling/ \ doc/Spatial_searching/ \ doc/Tangential_complex/ \ - doc/Bottleneck_distance/ + doc/Bottleneck_distance/ \ + doc/Gudhi_stat/ # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program diff --git a/src/Gudhi_stat/doc/average_landscape.png b/src/Gudhi_stat/doc/average_landscape.png new file mode 100644 index 00000000..ea59926b Binary files /dev/null and b/src/Gudhi_stat/doc/average_landscape.png differ diff --git a/src/Gudhi_stat/include/gudhi/permutation_test.h b/src/Gudhi_stat/include/gudhi/permutation_test.h index b4c1a8ba..69b0790b 100644 --- a/src/Gudhi_stat/include/gudhi/permutation_test.h +++ b/src/Gudhi_stat/include/gudhi/permutation_test.h @@ -37,6 +37,8 @@ namespace Gudhi namespace Gudhi_stat { +//TODO change the reading procedures so that they accept the dimension value (by default std::nnumeric_limits::max(). + template double permutation_test( const std::vector& data_1 , const std::vector& data_2 , size_t number_of_permutations , double exponent = 1 ) { diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/PSSK.h b/src/Gudhi_stat/include/gudhi/persistence_representations/PSSK.h index 7a299a86..d2fd3a86 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_representations/PSSK.h +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/PSSK.h @@ -53,10 +53,18 @@ public: } - PSSK( const char* filename , std::vector< std::vector > filter = create_Gaussian_filter(5,1) , size_t number_of_pixels = 1000 , double min_ = -1 , double max_ = -1 ): + PSSK( const char* filename , std::vector< std::vector > filter = create_Gaussian_filter(5,1) , size_t number_of_pixels = 1000 , double min_ = -1 , double max_ = -1 , unsigned dimension = std::numeric_limits::max() ): Persistence_heat_maps() { - std::vector< std::pair< double , double > > intervals_ = read_standard_persistence_file( filename ); + std::vector< std::pair< double , double > > intervals_; + if ( dimension == std::numeric_limits::max() ) + { + intervals_ = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + intervals_ = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } this->construct( intervals_ , filter , number_of_pixels , min_ , max_ ); } diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_heat_maps.h b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_heat_maps.h index f82f3100..3cfd52f5 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_heat_maps.h +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_heat_maps.h @@ -230,14 +230,14 @@ public: **/ /** * Construction that takes at the input the following parameters: - * (1) A a name of a file with persistence intervals. The file shold be readable by the function read_standard_persistence_file. All other parameters are optional. They are: + * (1) A a name of a file with persistence intervals. The file shold be readable by the function read_persistence_intervals_in_one_dimension_from_file. All other parameters are optional. They are: * (2) a Gausian filter generated by create_Gaussian_filter filter (the default value of this vaiable is a Gaussian filter of a radius 5), * (3) a boolean value which determines if the area of image below diagonal should, or should not be erased (it will be erased by default). * (4) a number of pixels in each direction (set to 1000 by default). * (5) a min x and y value of points that are to be taken into account. By default it is set to std::numeric_limits::max(), in which case the program compute the values based on the data, * (6) a max x and y value of points that are to be taken into account. By default it is set to std::numeric_limits::max(), in which case the program compute the values based on the data. **/ - Persistence_heat_maps( const char* filename , std::vector< std::vector > filter = create_Gaussian_filter(5,1), bool erase_below_diagonal = false , size_t number_of_pixels = 1000 , double min_ = std::numeric_limits::max() , double max_ = std::numeric_limits::max() ); + Persistence_heat_maps( const char* filename , std::vector< std::vector > filter = create_Gaussian_filter(5,1), bool erase_below_diagonal = false , size_t number_of_pixels = 1000 , double min_ = std::numeric_limits::max() , double max_ = std::numeric_limits::max() , unsigned dimension = std::numeric_limits::max() ); /** @@ -695,9 +695,17 @@ Persistence_heat_maps::Persistence_heat_maps( const std::ve template Persistence_heat_maps::Persistence_heat_maps( const char* filename , std::vector< std::vector > filter, - bool erase_below_diagonal , size_t number_of_pixels , double min_ , double max_ ) + bool erase_below_diagonal , size_t number_of_pixels , double min_ , double max_ , unsigned dimension ) { - std::vector< std::pair< double , double > > intervals_ = read_standard_persistence_file( filename ); + std::vector< std::pair< double , double > > intervals_; + if ( dimension == std::numeric_limits::max() ) + { + intervals_ = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + intervals_ = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } this->construct( intervals_ , filter, erase_below_diagonal , number_of_pixels , min_ , max_ ); this->set_up_parameters_for_basic_classes(); } diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_intervals.h b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_intervals.h index 2c3e4803..2ff4d7f7 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_intervals.h +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_intervals.h @@ -25,8 +25,6 @@ //gudhi include #include -//Bottleneck distance: -//#include //standard include #include @@ -51,8 +49,9 @@ public: /** * This is a constructor of a class Persistence_intervals from a text file. Each line of the input file is supposed to contain two numbers of a type doube (or convertable to double) * representing the birth and the death of the persistence interval. If the pairs are not sorted so that birth <= death, then the constructor will sort then that way. + * * The second parameter of a constructor is a dimension of intervals to be read from a file. If your file contains only birt-death pairs, use the default value. **/ - Persistence_intervals( const char* filename ); + Persistence_intervals( const char* filename , unsigned dimension = std::numeric_limits::max() ); /** * This is a constructor of a class Persistence_intervals from a vector of pairs. Each pair is assumed to represent a persistence interval. We assume that the first elemnets of pairs @@ -247,26 +246,6 @@ public: return this->number_of_functions_for_vectorization; } - /** - *Computations of distance from the current persistnce diagram to the persistence diagram given as a parameter of this function. - *The last but one parameter, power, is here in case we would like to compute p=th Wasserstein distance. At the moment, this method only implement Bottleneck distance, - * which is infinity Wasserstein distance. Therefore any power which is not the default std::numeric_limits< double >::max() will be ignored and an - * exception will be thrown. - * The last parameter, tolerance, it is an additiv error of the approimation, set by default to zero. - **/ - double distance( const Persistence_intervals& second , double power = std::numeric_limits< double >::max() , double tolerance = 0) const - { - if ( power >= std::numeric_limits< double >::max() ) - { - //return Gudhi::persistence_diagram::bottleneck_distance(this->intervals, second.intervals, tolerance); - return 1; - } - else - { - std::cerr << "At the moment Gudhi do not support Wasserstein distances. We only support Bottleneck distance." << std::endl; - throw "At the moment Gudhi do not support Wasserstein distances. We only support Bottleneck distance."; - } - } //end of implementation of functions needed for concepts. //end of implementation of functions needed for concepts. @@ -303,7 +282,7 @@ protected: }; -Persistence_intervals::Persistence_intervals( const char* filename ) +Persistence_intervals::Persistence_intervals( const char* filename , unsigned dimension ) { //bool dbg = false; //ifstream in; @@ -336,10 +315,14 @@ Persistence_intervals::Persistence_intervals( const char* filename ) // } //} //in.close(); - //standard file with barcode - this->intervals = read_standard_persistence_file( filename ); - //gudhi file with barcode - //this->intervals = read_gudhi_persistence_file_in_one_dimension( filename , dimension ); + if ( dimension == std::numeric_limits::max() ) + { + this->intervals = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + this->intervals = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); }//Persistence_intervals diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_intervals_with_distances.h b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_intervals_with_distances.h new file mode 100644 index 00000000..84a95e95 --- /dev/null +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_intervals_with_distances.h @@ -0,0 +1,76 @@ +/* This file is part of the Gudhi hiLibrary. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (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 . + */ + +#ifndef Persistence_intervals_WITH_DISTANCES_H_ +#define Persistence_intervals_WITH_DISTANCES_H_ + + +#include +#include + +namespace Gudhi +{ +namespace Gudhi_stat +{ + +class Persistence_intervals_with_distances : public Persistence_intervals +{ +public: + /** + * This is a constructor of a class Persistence_intervals_with_distances from a text file. Each line of the input file is supposed to contain two numbers of a type doube (or convertable to double) + * representing the birth and the death of the persistence interval. If the pairs are not sorted so that birth <= death, then the constructor will sort then that way. + * The second parameter of a constructor is a dimension of intervals to be read from a file. If your file contains only birt-death pairs, use the default value. + **/ + Persistence_intervals_with_distances( const char* filename , unsigned dimension = std::numeric_limits::max() ):Persistence_intervals( filename , dimension ){} + + /** + * This is a constructor of a class Persistence_intervals_with_distances from a vector of pairs. Each pair is assumed to represent a persistence interval. We assume that the first elemnets of pairs + * are smaller or equal the second elements of pairs. + **/ + Persistence_intervals_with_distances( const std::vector< std::pair< double,double > >& intervals ):Persistence_intervals( intervals ){} + + /** + *Computations of distance from the current persistnce diagram to the persistence diagram given as a parameter of this function. + *The last but one parameter, power, is here in case we would like to compute p=th Wasserstein distance. At the moment, this method only implement Bottleneck distance, + * which is infinity Wasserstein distance. Therefore any power which is not the default std::numeric_limits< double >::max() will be ignored and an + * exception will be thrown. + * The last parameter, tolerance, it is an additiv error of the approimation, set by default to zero. + **/ + double distance( const Persistence_intervals_with_distances& second , double power = std::numeric_limits< double >::max() , double tolerance = 0) const + { + if ( power >= std::numeric_limits< double >::max() ) + { + return Gudhi::persistence_diagram::bottleneck_distance(this->intervals, second.intervals, tolerance); + } + else + { + std::cerr << "At the moment Gudhi do not support Wasserstein distances. We only support Bottleneck distance." << std::endl; + throw "At the moment Gudhi do not support Wasserstein distances. We only support Bottleneck distance."; + } + } +}; + + +}//namespace gudhi stat +}//namespace gudhi + +#endif diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape.h b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape.h index 0d8fe5fe..681f5d8d 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape.h +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape.h @@ -80,7 +80,7 @@ public: * Constructor that reads persistence intervals from file and creates persistence landscape. The format of the input file is the following: in each line we put birth-death pair. Last line is assumed * to be empty. Even if the points within a line are not ordered, they will be ordered while the input is read. **/ - Persistence_landscape(const char* filename , size_t dimension = 0); + Persistence_landscape(const char* filename , size_t dimension = std::numeric_limits::max() ); @@ -548,13 +548,18 @@ Persistence_landscape::Persistence_landscape(const char* filename , size_t dimen if ( dbg ) { std::cerr << "Using constructor : Persistence_landscape(char* filename)" << std::endl; - } - //standard file with barcode - //std::vector< std::pair< double , double > > barcode = read_standard_persistence_file( filename ); - //gudhi file with barcode - std::vector< std::pair< double , double > > barcode = read_gudhi_persistence_file_in_one_dimension( filename , dimension ); - this->construct_persistence_landscape_from_barcode( barcode ); - this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); + } + std::vector< std::pair< double , double > > barcode; + if ( dimension == std::numeric_limits::max() ) + { + barcode = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + barcode = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } + this->construct_persistence_landscape_from_barcode( barcode ); + this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); } 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 02a80435..1f4cb3ff 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 @@ -33,6 +33,7 @@ #include #include #include +#include //gudhi include @@ -84,14 +85,14 @@ public: * to be empty. Even if the points within a line are not ordered, they will be ordered while the input is read. The additional parameters of this procedure are: ranges of grid, resoltion of a grid * number of landscape functions to be created and the dimension of intervals that are need to be read from a file (in case of Gudhi format files). **/ - Persistence_landscape_on_grid(const char* filename , double grid_min_, double grid_max_ , size_t number_of_points_ , unsigned number_of_levels_of_landscape , size_t dimension_ = 0 ); + Persistence_landscape_on_grid(const char* filename , double grid_min_, double grid_max_ , size_t number_of_points_ , unsigned number_of_levels_of_landscape , unsigned short dimension_ = std::numeric_limits::max() ); /** * Constructor that reads persistence intervals from file and creates persistence landscape. The format of the input file is the following: in each line we put birth-death pair. Last line is assumed * to be empty. Even if the points within a line are not ordered, they will be ordered while the input is read. The additional parameters of this procedure are: ranges of grid, resoltion of a grid * and the dimension of intervals that are need to be read from a file (in case of Gudhi format files). **/ - Persistence_landscape_on_grid(const char* filename , double grid_min_, double grid_max_ , size_t number_of_points_ , size_t dimension_ = 0 ); + Persistence_landscape_on_grid(const char* filename , double grid_min_, double grid_max_ , size_t number_of_points_ , unsigned short dimension_ = std::numeric_limits::max() ); /** @@ -99,14 +100,15 @@ public: * to be empty. Even if the points within a line are not ordered, they will be ordered while the input is read. The additional parameter is the resoution of a grid and the number of landscape * functions to be created. The remaning parameters are calculated based on data. **/ - Persistence_landscape_on_grid(const char* filename , size_t number_of_points , unsigned number_of_levels_of_landscape ); + Persistence_landscape_on_grid(const char* filename , size_t number_of_points , unsigned number_of_levels_of_landscape , unsigned short dimension = std::numeric_limits::max() ); /** * Constructor that reads persistence intervals from file and creates persistence landscape. The format of the input file is the following: in each line we put birth-death pair. Last line is assumed - * to be empty. Even if the points within a line are not ordered, they will be ordered while the input is read. The additional parameter is the resoution of a grid. The remaning paraameters are - * calculated based on data. + * to be empty. Even if the points within a line are not ordered, they will be ordered while the input is read. The additional parameter is the resoution of a grid. The last parameter is the dimension + * of a persistence to read from the file. If your file contains only persistence pair in a single dimension, please set it up to std::numeric_limits::max(). + * The remaning parameters are calculated based on data. **/ - Persistence_landscape_on_grid(const char* filename , size_t number_of_points ); + Persistence_landscape_on_grid(const char* filename , size_t number_of_points , unsigned short dimension = std::numeric_limits::max() ); /** @@ -1256,33 +1258,45 @@ Persistence_landscape_on_grid::Persistence_landscape_on_grid( const std::vector< } -Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filename , double grid_min_, double grid_max_ , size_t number_of_points_ , size_t dimension ) +Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filename , double grid_min_, double grid_max_ , size_t number_of_points_ , unsigned short dimension ) { - //standard file with barcode - std::vector< std::pair< double , double > > p = read_standard_persistence_file( filename ); - //gudhi file with barcode - //std::vector< std::pair< double , double > > p = read_gudhi_persistence_file_in_one_dimension( filename , dimension ); - - this->set_up_values_of_landscapes( p , grid_min_ , grid_max_ , number_of_points_ ); + std::vector< std::pair< double , double > > p; + if ( dimension == std::numeric_limits::max() ) + { + p = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + p = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } + this->set_up_values_of_landscapes( p , grid_min_ , grid_max_ , number_of_points_ ); } -Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filename , double grid_min_, double grid_max_ , size_t number_of_points_, unsigned number_of_levels_of_landscape, size_t dimension ) +Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filename , double grid_min_, double grid_max_ , size_t number_of_points_, unsigned number_of_levels_of_landscape, unsigned short dimension ) { - //standard file with barcode - std::vector< std::pair< double , double > > p = read_standard_persistence_file( filename ); - //gudhi file with barcode - //std::vector< std::pair< double , double > > p = read_gudhi_persistence_file_in_one_dimension( filename , dimension ); - - this->set_up_values_of_landscapes( p , grid_min_ , grid_max_ , number_of_points_ , number_of_levels_of_landscape ); + std::vector< std::pair< double , double > > p; + if ( dimension == std::numeric_limits::max() ) + { + p = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + p = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } + this->set_up_values_of_landscapes( p , grid_min_ , grid_max_ , number_of_points_ , number_of_levels_of_landscape ); } -Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filename , size_t number_of_points_ ) +Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filename , size_t number_of_points_ , unsigned short dimension ) { - //standard file with barcode - std::vector< std::pair< double , double > > p = read_standard_persistence_file( filename ); - //gudhi file with barcode - //std::vector< std::pair< double , double > > p = read_gudhi_persistence_file_in_one_dimension( filename , dimension ); - + std::vector< std::pair< double , double > > p; + if ( dimension == std::numeric_limits::max() ) + { + p = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + p = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } double grid_min_ = std::numeric_limits::max(); double grid_max_ = -std::numeric_limits::max(); for ( size_t i = 0 ; i != p.size() ; ++i ) @@ -1293,13 +1307,17 @@ Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filenam this->set_up_values_of_landscapes( p , grid_min_ , grid_max_ , number_of_points_ ); } -Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filename , size_t number_of_points_ , unsigned number_of_levels_of_landscape ) +Persistence_landscape_on_grid::Persistence_landscape_on_grid(const char* filename , size_t number_of_points_ , unsigned number_of_levels_of_landscape , unsigned short dimension ) { - //standard file with barcode - std::vector< std::pair< double , double > > p = read_standard_persistence_file( filename ); - //gudhi file with barcode - //std::vector< std::pair< double , double > > p = read_gudhi_persistence_file_in_one_dimension( filename , dimension ); - + std::vector< std::pair< double , double > > p; + if ( dimension == std::numeric_limits::max() ) + { + p = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + p = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } double grid_min_ = std::numeric_limits::max(); double grid_max_ = -std::numeric_limits::max(); for ( size_t i = 0 ; i != p.size() ; ++i ) diff --git a/src/Gudhi_stat/include/gudhi/persistence_representations/persistence_vectors.h b/src/Gudhi_stat/include/gudhi/persistence_representations/persistence_vectors.h index b1a3e4fd..aa1f23c2 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_representations/persistence_vectors.h +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/persistence_vectors.h @@ -105,7 +105,7 @@ public: /** * The constructor taking as an input a file with birth-death pairs. The second parameter is the desiered length of the output vectors. **/ - Vector_distances_in_diagram( const char* filename , size_t where_to_cut ); + Vector_distances_in_diagram( const char* filename , size_t where_to_cut , unsigned dimension = std::numeric_limits::max() ); /** @@ -432,13 +432,17 @@ Vector_distances_in_diagram::Vector_distances_in_diagram( const std::vector< } template -Vector_distances_in_diagram::Vector_distances_in_diagram( const char* filename , size_t where_to_cut ):where_to_cut(where_to_cut) -{ - //standard file with barcode - std::vector< std::pair< double , double > > intervals = read_standard_persistence_file( filename ); - //gudhi file with barcode - //std::vector< std::pair< double , double > > intervals = read_gudhi_persistence_file( filename , dimension ); - +Vector_distances_in_diagram::Vector_distances_in_diagram( const char* filename , size_t where_to_cut , unsigned dimension ):where_to_cut(where_to_cut) +{ + std::vector< std::pair< double , double > > intervals; + if ( dimension == std::numeric_limits::max() ) + { + intervals = read_persistence_intervals_in_one_dimension_from_file( filename ); + } + else + { + intervals = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } this->intervals = intervals; this->compute_sorted_vector_of_distances_via_heap( where_to_cut ); //this->compute_sorted_vector_of_distances_via_vector_sorting( where_to_cut ); diff --git a/src/Gudhi_stat/include/gudhi/topological_process.h b/src/Gudhi_stat/include/gudhi/topological_process.h index 17bea5ab..03edbb85 100644 --- a/src/Gudhi_stat/include/gudhi/topological_process.h +++ b/src/Gudhi_stat/include/gudhi/topological_process.h @@ -39,6 +39,9 @@ namespace Gudhi { namespace Gudhi_stat { + + +//TODO, change reading procedures so that they also accept the value of dimension. //over here we will need a few version of construct_representation_from_file procedure, since different representations may require different parameters. This is a procedure that in my //oppinion cannot be standarize, since construction of representation cannot. But, the remaining part of the code in my opinion is free from any details of representation. @@ -62,7 +65,7 @@ std::vector< std::vector< std::pair< double , double > > > read_persistence_pair for ( size_t i = 0 ; i != files.size() ; ++i ) { - std::vector< std::pair< double , double > > diag = read_standard_persistence_file( files[i].c_str() ); + std::vector< std::pair< double , double > > diag = read_persistence_intervals_in_one_dimension_from_file( files[i].c_str() ); result.push_back( diag ); if ( dbg ) { diff --git a/src/Gudhi_stat/test/persistence_lanscapes_on_grid_test.cpp b/src/Gudhi_stat/test/persistence_lanscapes_on_grid_test.cpp index ae771149..54fb2b84 100644 --- a/src/Gudhi_stat/test/persistence_lanscapes_on_grid_test.cpp +++ b/src/Gudhi_stat/test/persistence_lanscapes_on_grid_test.cpp @@ -44,7 +44,7 @@ double epsilon = 0.0000005; BOOST_AUTO_TEST_CASE(check_construction_of_landscape) { - Persistence_landscape_on_grid l( "data/file_with_diagram_1" , 100 ); + Persistence_landscape_on_grid l( "data/file_with_diagram_1" , 100 , std::numeric_limits::max()); l.print_to_file( "landscape_from_file_with_diagram_1" ); Persistence_landscape_on_grid g; @@ -57,8 +57,8 @@ BOOST_AUTO_TEST_CASE(check_construction_of_landscape_using_only_ten_levels) { //TODO unsigned number = 10; - Persistence_landscape_on_grid l( "data/file_with_diagram_1" , 100 ,number ); - Persistence_landscape_on_grid g( "data/file_with_diagram_1" , 100 ); + Persistence_landscape_on_grid l( "data/file_with_diagram_1" , 100 , number ); + Persistence_landscape_on_grid g( "data/file_with_diagram_1" , 100 , std::numeric_limits::max()); //cut all the elements of order > 10 in g. for ( size_t level = 0 ; level != number ; ++level ) @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(check_construction_of_landscape_using_only_ten_levels) BOOST_AUTO_TEST_CASE(check_computations_of_integrals) { - Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 100 ); + Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 100 , std::numeric_limits::max()); double integral = p.compute_integral_of_landscape(); //cerr << "integral : " << integral << endl;getchar(); BOOST_CHECK( fabs( integral - 27.343 ) <= 0.00005 ); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals) BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) { - Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 100 ); + Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 100, std::numeric_limits::max() ); std::vector< double > integrals_fir_different_levels; //integrals_fir_different_levels.push_back(); @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) BOOST_AUTO_TEST_CASE(check_computations_of_integrals_of_powers_of_landscape) { - Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 100 ); + Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 100, std::numeric_limits::max() ); std::vector integrals_fir_different_powers; integrals_fir_different_powers.push_back( 0.241168); @@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_of_powers_of_landscape) BOOST_AUTO_TEST_CASE(check_computations_of_values_on_different_points) { - Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 100 ); + Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 100, std::numeric_limits::max() ); std::vector< double > results_level_0; results_level_0.push_back(0.00997867); @@ -184,8 +184,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_values_on_different_points) BOOST_AUTO_TEST_CASE(check_computations_sum_differences_and_multiplications) { - Persistence_landscape_on_grid p( "data/file_with_diagram_1" ,100 ); - Persistence_landscape_on_grid second("data/file_with_diagram_1" , 100 ); + Persistence_landscape_on_grid p( "data/file_with_diagram_1" ,100 , std::numeric_limits::max()); + Persistence_landscape_on_grid second("data/file_with_diagram_1" , 100, std::numeric_limits::max() ); Persistence_landscape_on_grid sum = p + second; Persistence_landscape_on_grid difference = p - second; @@ -210,8 +210,8 @@ BOOST_AUTO_TEST_CASE(check_computations_sum_differences_and_multiplications) BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) { - Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 0 , 1 , 100 ); - Persistence_landscape_on_grid second("data/file_with_diagram_2" , 0 , 1 , 100 ); + Persistence_landscape_on_grid p( "data/file_with_diagram_1" , 0. , 1. , 100 ); + Persistence_landscape_on_grid second("data/file_with_diagram_2" , 0. , 1. , 100 ); Persistence_landscape_on_grid sum = p + second; //cerr << p.compute_maximum() << endl; @@ -236,8 +236,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) BOOST_AUTO_TEST_CASE(check_computations_of_averages) { - Persistence_landscape_on_grid p( "data/file_with_diagram", 0,1,100 ); - Persistence_landscape_on_grid q( "data/file_with_diagram_1", 0,1,100 ); + Persistence_landscape_on_grid p( "data/file_with_diagram", 0.,1.,100 ); + Persistence_landscape_on_grid q( "data/file_with_diagram_1", 0.,1.,100 ); Persistence_landscape_on_grid av; av.compute_average( {&p,&q} ); @@ -251,8 +251,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_averages) BOOST_AUTO_TEST_CASE(check_computations_of_distances) { - Persistence_landscape_on_grid p( "data/file_with_diagram", 0,1,10000 ); - Persistence_landscape_on_grid q( "data/file_with_diagram_1", 0,1,10000 ); + Persistence_landscape_on_grid p( "data/file_with_diagram", 0.,1.,10000 ); + Persistence_landscape_on_grid q( "data/file_with_diagram_1", 0.,1.,10000 ); BOOST_CHECK( fabs( p.distance( q )- 25.5779) <= 0.00005 ); BOOST_CHECK( fabs( p.distance( q , 2) - 2.04891) <= 0.00001 ); BOOST_CHECK( fabs( p.distance( q , std::numeric_limits::max() )-0.359 ) <= 0.00001 ); @@ -261,8 +261,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_distances) BOOST_AUTO_TEST_CASE(check_computations_of_scalar_product) { - Persistence_landscape_on_grid p( "data/file_with_diagram" , 0,1,10000); - Persistence_landscape_on_grid q( "data/file_with_diagram_1", 0,1,10000 ); + Persistence_landscape_on_grid p( "data/file_with_diagram" , 0.,1.,10000); + Persistence_landscape_on_grid q( "data/file_with_diagram_1", 0.,1.,10000 ); //std::cerr << p.compute_scalar_product( q ) << std::endl; BOOST_CHECK( almost_equal( p.compute_scalar_product( q ) , 0.754367 ) ); } @@ -375,3 +375,4 @@ BOOST_AUTO_TEST_CASE(check_computations_of_scalar_product) //Persistence_landscape_on_grid q( aa, 0,1,10 ); cerr << p.compute_scalar_product( &q ) << endl; */ + diff --git a/src/Gudhi_stat/utilities/Multiplicative_bootstrap.cpp b/src/Gudhi_stat/utilities/Multiplicative_bootstrap.cpp index 42534752..7ee389f8 100644 --- a/src/Gudhi_stat/utilities/Multiplicative_bootstrap.cpp +++ b/src/Gudhi_stat/utilities/Multiplicative_bootstrap.cpp @@ -51,7 +51,7 @@ int main( int argc , char** argv ) std::vector< Persistence_landscape* > collection_of_landscapes( filenames.size() ); for ( size_t i = 0 ; i != filenames.size() ; ++i ) { - std::vector< std::pair< double , double > > diag = read_gudhi_persistence_file_in_one_dimension( filenames[i].c_str() , 1 );//read_standard_persistence_file( filenames[i].c_str() ); + std::vector< std::pair< double , double > > diag = read_persistence_intervals_in_one_dimension_from_file( filenames[i].c_str() ); collection_of_landscapes[i] = new Persistence_landscape( diag ); } diff --git a/src/Gudhi_stat/utilities/permutation_test.cpp b/src/Gudhi_stat/utilities/permutation_test.cpp index e431026f..62cd3f10 100644 --- a/src/Gudhi_stat/utilities/permutation_test.cpp +++ b/src/Gudhi_stat/utilities/permutation_test.cpp @@ -62,7 +62,7 @@ int main( int argc , char** argv ) std::vector< Persistence_landscape* > first_collection( first_group.size() ); for ( size_t i = 0 ; i != first_group.size() ; ++i ) { - std::vector< std::pair< double , double > > diag = read_standard_persistence_file( first_group[i].c_str() ); + std::vector< std::pair< double , double > > diag = read_persistence_intervals_in_one_dimension_from_file( first_group[i].c_str() ); Persistence_landscape* l = new Persistence_landscape( diag ); first_collection[i] = l; } diff --git a/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp b/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp index 5d2100aa..d9c7aded 100644 --- a/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp +++ b/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp @@ -40,26 +40,32 @@ int main( int argc , char** argv ) std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed based on the data, set them both to -1 \n"; std::cerr << "The fourth parameter is an integer, the standard deviation of a gaussian kernel expressed in a number of pixels \n"; - std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; + std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the persistence heat maps."; + std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the procedure please provide the dimension of persistence you want to use."; + std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." << std::endl; + std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; if ( argc < 5 ) { std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; - } - + } size_t size_of_grid = (size_t)atoi( argv[1] ); double min_ = atof( argv[2] ); double max_ = atof( argv[3] ); size_t stdiv = atof( argv[4] ); + unsigned dimension = std::numeric_limits::max(); + int dim = atoi( argv[5] ); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } std::vector< const char* > filenames; - for ( int i = 5 ; i < argc ; ++i ) + for ( int i = 6 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } - - std::cout << "Creating persistence heat maps...\n"; std::vector< std::vector > filter = create_Gaussian_filter(stdiv,1); @@ -67,7 +73,7 @@ int main( int argc , char** argv ) for ( size_t i = 0 ; i != filenames.size() ; ++i ) { std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; - Persistence_heat_maps l( filenames[i] , filter, false , size_of_grid , min_ , max_ ); + Persistence_heat_maps l( filenames[i] , filter, false , size_of_grid , min_ , max_ , dimension ); std::stringstream ss; ss << filenames[i] << ".mps"; diff --git a/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_arctan_of_their_persistence.cpp b/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_arctan_of_their_persistence.cpp index 8496e33e..7cb7eeb7 100644 --- a/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_arctan_of_their_persistence.cpp +++ b/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_arctan_of_their_persistence.cpp @@ -1,4 +1,4 @@ -/* 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. * @@ -40,8 +40,11 @@ int main( int argc , char** argv ) std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed based on the data, set them both to -1 \n"; std::cerr << "The fourth parameter is an integer, the standard deviation of a gaussian kernel expressed in a number of pixels \n"; + std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the persistence heat maps."; + std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the procedure please provide the dimension of persistence you want to use."; + std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." << std::endl; std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; - + if ( argc < 5 ) { std::cout << "Wrong parameter list, the program will now terminate \n"; @@ -53,8 +56,15 @@ int main( int argc , char** argv ) double max_ = atof( argv[3] ); size_t stdiv = atof( argv[4] ); + unsigned dimension = std::numeric_limits::max(); + int dim = atoi( argv[5] ); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + std::vector< const char* > filenames; - for ( int i = 5 ; i < argc ; ++i ) + for ( int i = 6 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } @@ -67,7 +77,7 @@ int main( int argc , char** argv ) for ( size_t i = 0 ; i != filenames.size() ; ++i ) { std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; - Persistence_heat_maps l( filenames[i] , filter, false , size_of_grid , min_ , max_ ); + Persistence_heat_maps l( filenames[i] , filter, false , size_of_grid , min_ , max_ , dimension ); std::stringstream ss; ss << filenames[i] << ".mps"; diff --git a/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_distance_from_diagonal.cpp b/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_distance_from_diagonal.cpp index 83d4f3bc..3242e106 100644 --- a/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_distance_from_diagonal.cpp +++ b/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_distance_from_diagonal.cpp @@ -39,6 +39,9 @@ int main( int argc , char** argv ) std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed based on the data, set them both to -1 \n"; std::cerr << "The fourth parameter is an integer, the standard deviation of a gaussian kernel expressed in a number of pixels \n"; + std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the persistence heat maps."; + std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the procedure please provide the dimension of persistence you want to use."; + std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." << std::endl; std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; if ( argc < 5 ) @@ -52,8 +55,15 @@ int main( int argc , char** argv ) double max_ = atof( argv[3] ); size_t stdiv = atof( argv[4] ); + unsigned dimension = std::numeric_limits::max(); + int dim = atoi( argv[5] ); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + std::vector< const char* > filenames; - for ( int i = 5 ; i < argc ; ++i ) + for ( int i = 6 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } @@ -66,7 +76,7 @@ int main( int argc , char** argv ) for ( size_t i = 0 ; i != filenames.size() ; ++i ) { std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; - Persistence_heat_maps l( filenames[i] , filter , size_of_grid , min_ , max_ ); + Persistence_heat_maps l( filenames[i] , filter , size_of_grid , min_ , max_ , dimension ); std::stringstream ss; ss << filenames[i] << ".mps"; diff --git a/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_squared_distance_from_diagonal.cpp b/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_squared_distance_from_diagonal.cpp index f62615f5..27846a99 100644 --- a/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_squared_distance_from_diagonal.cpp +++ b/src/Gudhi_stat/utilities/persistence_heat_maps/create_persistence_heat_maps_weighted_by_squared_distance_from_diagonal.cpp @@ -39,8 +39,11 @@ int main( int argc , char** argv ) std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed based on the data, set them both to -1 \n"; std::cerr << "The fourth parameter is an integer, the standard deviation of a gaussian kernel expressed in a number of pixels \n"; + std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the persistence heat maps."; + std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the procedure please provide the dimension of persistence you want to use."; + std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." << std::endl; std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; - + if ( argc < 5 ) { std::cout << "Wrong parameter list, the program will now terminate \n"; @@ -51,14 +54,19 @@ int main( int argc , char** argv ) double min_ = atof( argv[2] ); double max_ = atof( argv[3] ); size_t stdiv = atof( argv[4] ); + + unsigned dimension = std::numeric_limits::max(); + int dim = atoi( argv[5] ); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } std::vector< const char* > filenames; - for ( int i = 5 ; i < argc ; ++i ) + for ( int i = 6 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } - - std::cout << "Creating persistence heat maps...\n"; std::vector< std::vector > filter = create_Gaussian_filter(stdiv,1); @@ -66,7 +74,7 @@ int main( int argc , char** argv ) for ( size_t i = 0 ; i != filenames.size() ; ++i ) { std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; - Persistence_heat_maps l( filenames[i] , filter, false , size_of_grid , min_ , max_ ); + Persistence_heat_maps l( filenames[i] , filter, false , size_of_grid , min_ , max_ , dimension ); std::stringstream ss; ss << filenames[i] << ".mps"; diff --git a/src/Gudhi_stat/utilities/persistence_heat_maps/create_pssk.cpp b/src/Gudhi_stat/utilities/persistence_heat_maps/create_pssk.cpp index d38bb8b9..404a4be3 100644 --- a/src/Gudhi_stat/utilities/persistence_heat_maps/create_pssk.cpp +++ b/src/Gudhi_stat/utilities/persistence_heat_maps/create_pssk.cpp @@ -38,8 +38,12 @@ int main( int argc , char** argv ) std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed based on the data, set them both to -1 \n"; std::cerr << "The fourth parameter is an integer, the standard deviation of a gaussian kernel expressed in a number of pixels \n"; + std::cerr << "The fourth parameter is an integer, the standard deviation of a gaussian kernel expressed in a number of pixels \n"; + std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the persistence heat maps."; + std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the procedure please provide the dimension of persistence you want to use."; + std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." << std::endl; std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; - + if ( argc < 5 ) { std::cout << "Wrong parameter list, the program will now terminate \n"; @@ -51,8 +55,15 @@ int main( int argc , char** argv ) double max_ = atof( argv[3] ); size_t stdiv = atof( argv[4] ); + unsigned dimension = std::numeric_limits::max(); + int dim = atoi( argv[5] ); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + std::vector< const char* > filenames; - for ( int i = 5 ; i < argc ; ++i ) + for ( int i = 6 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } @@ -63,7 +74,7 @@ int main( int argc , char** argv ) for ( size_t i = 0 ; i != filenames.size() ; ++i ) { std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl; - PSSK l( filenames[i] , filter , size_of_grid , min_ , max_ ); + PSSK l( filenames[i] , filter , size_of_grid , min_ , max_ , dimension ); std::stringstream ss; ss << filenames[i] << ".pssk"; diff --git a/src/Gudhi_stat/utilities/persistence_intervals/CMakeLists.txt b/src/Gudhi_stat/utilities/persistence_intervals/CMakeLists.txt index 96cb1a5e..9420a8ea 100644 --- a/src/Gudhi_stat/utilities/persistence_intervals/CMakeLists.txt +++ b/src/Gudhi_stat/utilities/persistence_intervals/CMakeLists.txt @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 2.6) project(GUDHI_STAT) - - #persitence diagrams add_executable ( plot_persistence_intervals plot_persistence_intervals.cpp ) target_link_libraries( plot_persistence_intervals ${Boost_SYSTEM_LIBRARY}) @@ -16,7 +14,14 @@ target_link_libraries( compute_number_of_dominant_intervals ${Boost_SYSTEM_LIBRA add_executable ( plot_histogram_of_intervals_lengths plot_histogram_of_intervals_lengths.cpp ) target_link_libraries( plot_histogram_of_intervals_lengths ${Boost_SYSTEM_LIBRARY}) -add_executable ( plot_persistence_Betti_numebrs plot_persistence_Betti_numebrs.cpp ) -target_link_libraries( plot_persistence_Betti_numebrs ${Boost_SYSTEM_LIBRARY}) +add_executable ( plot_persistence_Betti_numbers plot_persistence_Betti_numbers.cpp ) +target_link_libraries( plot_persistence_Betti_numbers ${Boost_SYSTEM_LIBRARY}) + +if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) +add_executable ( compute_bottleneck_distance compute_bottleneck_distance.cpp ) +target_link_libraries( compute_bottleneck_distance ${Boost_SYSTEM_LIBRARY}) +if (TBB_FOUND) +target_link_libraries(compute_bottleneck_distance ${TBB_LIBRARIES}) +endif(TBB_FOUND) -#when we have bottleneck and wasserstein distance computations, add suitable programs here. +endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) diff --git a/src/Gudhi_stat/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp b/src/Gudhi_stat/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp index 145040fe..426a9b7b 100644 --- a/src/Gudhi_stat/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp +++ b/src/Gudhi_stat/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp @@ -37,18 +37,20 @@ using namespace Gudhi::Gudhi_stat; int main( int argc , char** argv ) { - //std::cout << "This program compute minimum birth and the maximum death time for a collection of persistence intervals \n"; - //if ( argc != 2 ) - //{ - // std::cout << "To run this program, please provide the name of a file with persistence diagram \n"; - // return 1; - //} - //Persistence_intervals p( argv[1] ); - //std::pair min_max_ = p.min_max(); - //std::cout << "Birth-death range : min: " << min_max_.first << ", max: " << min_max_.second << endl; + std::cout << "This program compute the range of birth and death times of persistence pairs in diagrams provided as an input. \n"; + std::cout << "The first parameter of the program is the dimension of persistence to be used. If your file contains "; + std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence pairs you want to use. If your input files consist only "; + std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; + std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n"; + int dim = atoi( argv[1] ); + unsigned dimension = std::numeric_limits::max(); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } std::vector< const char* > filenames; - for ( int i = 1 ; i < argc ; ++i ) + for ( int i = 2 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } @@ -59,7 +61,7 @@ int main( int argc , char** argv ) for ( size_t file_no = 0 ; file_no != filenames.size() ; ++file_no ) { std::cout << "Creating diagram based on a file : " << filenames[file_no] << std::endl; - Persistence_intervals p( filenames[file_no] ); + Persistence_intervals p( filenames[file_no] , dimension ); std::pair min_max_ = p.min_max(); if ( min_max_.first < min_ )min_ = min_max_.first; if ( min_max_.second > max_ )max_ = min_max_.second; diff --git a/src/Gudhi_stat/utilities/persistence_intervals/compute_bottleneck_distance.cpp b/src/Gudhi_stat/utilities/persistence_intervals/compute_bottleneck_distance.cpp new file mode 100644 index 00000000..6f0ba635 --- /dev/null +++ b/src/Gudhi_stat/utilities/persistence_intervals/compute_bottleneck_distance.cpp @@ -0,0 +1,115 @@ +/* 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): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (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 . + */ + +#include +#include + + + +using namespace Gudhi; +using namespace Gudhi::Gudhi_stat; + +#include +#include + + +int main( int argc , char** argv ) +{ + std::cout << "This program compute the bottleneck distance of persistence diarams stored in a files. \n"; + std::cout << "The first parameter of the program is the dimension of persistence to be used to construct persistence landscapes. If your file contains "; + std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence pairs you want to use. If your input files consist only "; + std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; + std::cout << "The remaining parameters of this programs are names of files with persistence diagrams.\n"; + + if ( argc < 3 ) + { + std::cout << "Wrong number of parameters, the program will now terminate \n"; + return 1; + } + + int dim = atoi(argv[1]); + unsigned dimension = std::numeric_limits::max(); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + + + std::vector< const char* > filenames; + for ( int i = 2 ; i < argc ; ++i ) + { + filenames.push_back( argv[i] ); + } + + //reading the persistence intervals: + std::vector< Persistence_intervals_with_distances > persistence_intervals; + for ( size_t i = 0 ; i != filenames.size() ; ++i ) + { + Persistence_intervals_with_distances pers(filenames[i] , dimension ); + std::cerr << "perss : " << pers << std::endl; + getchar(); + persistence_intervals.push_back( pers ); + } + + //and now we will compute the scalar product of landscapes. + + //first we prepare an array: + std::vector< std::vector< double > > distance( filenames.size() ); + for ( size_t i = 0 ; i != filenames.size() ; ++i ) + { + std::vector< double > v( filenames.size() , 0 ); + distance[i] = v; + } + + //and now we can compute the distances: + for ( size_t i = 0 ; i != persistence_intervals.size() ; ++i ) + { + for ( size_t j = i+1 ; j != persistence_intervals.size() ; ++j ) + { + distance[i][j] = distance[j][i] = persistence_intervals[i].distance( persistence_intervals[j] ); + } + } + + //and now output the result to the screen and a file: + std::ofstream out; + out.open( "distance" ); + for ( size_t i = 0 ; i != distance.size() ; ++i ) + { + for ( size_t j = 0 ; j != distance.size() ; ++j ) + { + std::cout << distance[i][j] << " "; + out << distance[i][j] << " "; + } + std::cout << std::endl; + out << std::endl; + } + out.close(); + + return 0; +} + + + + + + + diff --git a/src/Gudhi_stat/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp b/src/Gudhi_stat/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp index eeda703a..0a7f7c2b 100644 --- a/src/Gudhi_stat/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp +++ b/src/Gudhi_stat/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp @@ -36,14 +36,19 @@ using namespace Gudhi::Gudhi_stat; int main( int argc , char** argv ) { std::cout << "This program compute the dominant intervals. A number of intervals to be displayed is a parameter of this program. \n"; - if ( argc != 3 ) + if ( argc != 4 ) { - std::cout << "To run this program, please provide the name of a file with persistence diagram and number of dominant intervals you would like to get \n"; + std::cout << "To run this program, please provide the name of a file with persistence diagram, dimension of intervals that should be taken into account (if your file contains only persistence pairs in a single dimension, set it up to -1) and number of dominant intervals you would like to get \n"; return 1; } - - Persistence_intervals p( argv[1] ); - std::vector< std::pair > dominant_intervals = p.dominant_intervals( atoi( argv[2] ) ); + int dim = atoi( argv[2] ); + unsigned dimension = std::numeric_limits::max(); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + Persistence_intervals p( argv[1] , dimension ); + std::vector< std::pair > dominant_intervals = p.dominant_intervals( atoi( argv[3] ) ); std::cout << "Here are the dominant intervals : " << std::endl; for ( size_t i = 0 ; i != dominant_intervals.size() ; ++i ) { diff --git a/src/Gudhi_stat/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp b/src/Gudhi_stat/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp index db9c3f98..11876a0d 100644 --- a/src/Gudhi_stat/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp +++ b/src/Gudhi_stat/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp @@ -39,10 +39,21 @@ int main( int argc , char** argv ) if ( argc != 3 ) { std::cout << "To run this program, please provide the name of a file with persistence diagram and number of dominant intervals you would like to get \n"; + std::cout << "The second parameter of a program is the dimension of the persistence that is to be used. If your file contains only birth-death pairs, you can skip this parameter\n"; return 1; } + unsigned dimension = std::numeric_limits::max(); + int dim = -1; + if ( argc > 2 ) + { + dim = atoi( argv[2] ); + } + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } - Persistence_intervals p( argv[1] ); + Persistence_intervals p( argv[1] , dimension ); std::vector< std::pair > dominant_intervals = p.dominant_intervals( atoi( argv[2] ) ); std::vector< size_t > histogram = p.histogram_of_lengths( 10 ); diff --git a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp new file mode 100644 index 00000000..09c6cc22 --- /dev/null +++ b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp @@ -0,0 +1,100 @@ +/* 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): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (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 . + */ + + + +#include +#include + +#include + + + +using namespace Gudhi; +using namespace Gudhi::Gudhi_stat; + + +int main( int argc , char** argv ) +{ + std::cout << "This program compute a plot of persistence Betti numbers. The input parameter is a file with persistence intervals. \n"; + std::cout << "The second optional parameter of a program is the dimension of the persistence that is to be used. If your file contains only birth-death pairs, you can skip this parameter\n"; + if ( argc < 2 ) + { + std::cout << "To run this program, please provide the name of a file with persistence diagram and number of dominant intervals you would like to get \n"; + return 1; + } + unsigned dimension = std::numeric_limits::max(); + int dim = -1; + if ( argc > 2 ) + { + dim = atoi( argv[2] ); + } + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + + + std::stringstream gnuplot_script; + gnuplot_script << argv[1] << "_Gnuplot_script"; + std::ofstream out; + out.open( gnuplot_script.str().c_str() ); + + Persistence_intervals p( argv[1] , dimension ); + std::vector< std::pair< double , size_t > > pbns = p.compute_persistent_betti_numbers(); + + //set up the ranges so that we see the image well. + double xRangeBegin = pbns[0].first; + double xRangeEnd = pbns[ pbns.size()-1 ].first; + double yRangeBegin = 0; + double yRangeEnd = 0; + for ( size_t i = 0 ; i != pbns.size() ; ++i ) + { + if ( pbns[i].second > yRangeEnd )yRangeEnd = pbns[i].second; + } + xRangeBegin -= (xRangeEnd -xRangeBegin)/100.0; + xRangeEnd += (xRangeEnd -xRangeBegin)/100.0; + yRangeEnd += yRangeEnd/100; + + + out << "set xrange [" << xRangeBegin << " : " << xRangeEnd << "]" << std::endl; + out << "set yrange [" << yRangeBegin << " : " << yRangeEnd << "]" << std::endl; + out << "plot '-' using 1:2 notitle with lp " << std::endl; + double previous_y = 0; + for ( size_t i = 0 ; i != pbns.size() ; ++i ) + { + out << pbns[i].first << " " << previous_y << std::endl; + out << pbns[i].first << " " << pbns[i].second << std::endl; + previous_y = pbns[i].second; + } + out << std::endl; + out.close(); + + //for ( size_t i = 0 ; i != pbns.size() ; ++i ) + //{ + // std::cout << pbns[i].first << " " << pbns[i].second << std::endl; + //} + + std::cout << "To vizualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; + + return 0; +} diff --git a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numebrs.cpp b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numebrs.cpp deleted file mode 100644 index cb89f6b9..00000000 --- a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numebrs.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* 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): Pawel Dlotko - * - * Copyright (C) 2015 INRIA (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 . - */ - - - -#include -#include - -#include - - - -using namespace Gudhi; -using namespace Gudhi::Gudhi_stat; - - -int main( int argc , char** argv ) -{ - std::cout << "This program compute a plot of persistence Betti numbers. The input parameter is a file with persistence intervals. \n"; - if ( argc != 2 ) - { - std::cout << "To run this program, please provide the name of a file with persistence diagram and number of dominant intervals you would like to get \n"; - return 1; - } - - - - std::stringstream gnuplot_script; - gnuplot_script << argv[1] << "_Gnuplot_script"; - std::ofstream out; - out.open( gnuplot_script.str().c_str() ); - - Persistence_intervals p( argv[1] ); - std::vector< std::pair< double , size_t > > pbns = p.compute_persistent_betti_numbers(); - - //set up the ranges so that we see the image well. - double xRangeBegin = pbns[0].first; - double xRangeEnd = pbns[ pbns.size()-1 ].first; - double yRangeBegin = 0; - double yRangeEnd = 0; - for ( size_t i = 0 ; i != pbns.size() ; ++i ) - { - if ( pbns[i].second > yRangeEnd )yRangeEnd = pbns[i].second; - } - xRangeBegin -= (xRangeEnd -xRangeBegin)/100.0; - xRangeEnd += (xRangeEnd -xRangeBegin)/100.0; - yRangeEnd += yRangeEnd/100; - - - out << "set xrange [" << xRangeBegin << " : " << xRangeEnd << "]" << std::endl; - out << "set yrange [" << yRangeBegin << " : " << yRangeEnd << "]" << std::endl; - out << "plot '-' using 1:2 notitle with lp " << std::endl; - double previous_y = 0; - for ( size_t i = 0 ; i != pbns.size() ; ++i ) - { - out << pbns[i].first << " " << previous_y << std::endl; - out << pbns[i].first << " " << pbns[i].second << std::endl; - previous_y = pbns[i].second; - } - out << std::endl; - out.close(); - - //for ( size_t i = 0 ; i != pbns.size() ; ++i ) - //{ - // std::cout << pbns[i].first << " " << pbns[i].second << std::endl; - //} - - std::cout << "To vizualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; - - return 0; -} diff --git a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp index bc466bd3..4315abb9 100644 --- a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp +++ b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp @@ -42,9 +42,23 @@ int main( int argc , char** argv ) if ( argc != 2 ) { std::cout << "To run this program, please provide the name of a file with persistence diagram \n"; + std::cout << "The second optional parameter of a program is the dimension of the persistence that is to be used. If your file contains only birth-death pairs, you can skip this parameter\n"; return 1; } - std::vector< std::pair< double , double > > intervals = read_gudhi_persistence_file_in_one_dimension( argv[1] , 2 ); + unsigned dimension = std::numeric_limits::max(); + int dim = -1; + if ( argc > 2 ) + { + dim = atoi( argv[2] ); + } + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + + + + std::vector< std::pair< double , double > > intervals = read_persistence_intervals_in_one_dimension_from_file( argv[1] , dimension ); Persistence_intervals b( intervals ); b.plot( argv[1] ); return 0; diff --git a/src/Gudhi_stat/utilities/persistence_landscapes/create_landscapes.cpp b/src/Gudhi_stat/utilities/persistence_landscapes/create_landscapes.cpp index 5485bf2a..f36e313a 100644 --- a/src/Gudhi_stat/utilities/persistence_landscapes/create_landscapes.cpp +++ b/src/Gudhi_stat/utilities/persistence_landscapes/create_landscapes.cpp @@ -32,9 +32,19 @@ using namespace Gudhi::Gudhi_stat; int main( int argc , char** argv ) { - std::cout << "This program creates persistence landscapes of diagrams provided as an input. Please call this program with the names of files with persistence diagrams \n"; + std::cout << "This program creates persistence landscapes of diagrams provided as an input. \n"; + std::cout << "The first parameter of the program is the dimension of persistence to be used to construct persistence landscapes. If your file contains "; + std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence pairs you want to use. If your input files consist only "; + std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; + std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n"; std::vector< const char* > filenames; - for ( int i = 1 ; i < argc ; ++i ) + int dim = atoi(argv[1]); + unsigned dimension = std::numeric_limits::max(); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + for ( int i = 2 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } @@ -42,8 +52,7 @@ int main( int argc , char** argv ) std::cout << "Creating persistence landscapes...\n"; for ( size_t i = 0 ; i != filenames.size() ; ++i ) { - //std::vector< std::pair< double , double > > pers = read_standard_file( filename ); - Persistence_landscape l( filenames[i] , 1 ); + Persistence_landscape l( filenames[i] , dimension ); std::stringstream ss; ss << filenames[i] << ".land"; l.print_to_file( ss.str().c_str() ); diff --git a/src/Gudhi_stat/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp b/src/Gudhi_stat/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp index 4f36f02d..eb534bf1 100644 --- a/src/Gudhi_stat/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp +++ b/src/Gudhi_stat/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp @@ -36,9 +36,12 @@ int main( int argc , char** argv ) std::cout << "This program creates persistence landscape on grid of diagrams provided as an input.\n"; std::cout << "The first parameter of a program is an integer, a size of a grid.\n"; std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed based on the data, set them both to -1 \n"; + std::cout << "The fourth parameter of the program is the dimension of persistence to be used to construct persistence landscape on a grid. If your file contains "; + std::cout << "the information about dimension of birth-death pairs, please provide here the dimension of intervals you want to use. If your input files consist only "; + std::cout << "of birth-death pairs, please set the fourth parameter to -1 \n"; std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; - if ( argc < 4 ) + if ( argc < 5 ) { std::cout << "Wrong parameter list, the program will now terminate \n"; return 1; @@ -47,9 +50,15 @@ int main( int argc , char** argv ) size_t size_of_grid = (size_t)atoi( argv[1] ); double min_ = atof( argv[2] ); double max_ = atof( argv[3] ); + int dim = atoi( argv[4] ); + unsigned dimension = std::numeric_limits::max(); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } std::vector< const char* > filenames; - for ( int i = 4 ; i < argc ; ++i ) + for ( int i = 5 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } @@ -61,12 +70,12 @@ int main( int argc , char** argv ) Persistence_landscape_on_grid l; if ( (min_ != -1) || (max_ != -1) ) { - l = Persistence_landscape_on_grid( filenames[i] , min_ , max_ , size_of_grid ); + l = Persistence_landscape_on_grid( filenames[i] , min_ , max_ , size_of_grid , dimension ); } else { //(min_ == -1) && (max_ == -1), in this case the program will find min_ and max_ based on the data. - l = Persistence_landscape_on_grid( filenames[i] , size_of_grid ); + l = Persistence_landscape_on_grid( filenames[i] , size_of_grid , dimension ); } std::stringstream ss; ss << filenames[i] << ".g_land"; 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 fc434ba8..40f5e81f 100644 --- a/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp +++ b/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp @@ -33,9 +33,19 @@ using namespace Gudhi::Gudhi_stat; int main( int argc , char** argv ) { - std::cout << "This program creates persistence vectors of diagrams provided as an input. Please call this program with the names of files with persistence diagrams \n"; + std::cout << "This program creates persistence vectors of diagrams provided as an input. The first parameter of this program is a dimension of persistence "; + std::cout << " that will be used in creation of the persistence vectors. If our input files contain persistence pairs of various dimension, as a second parameter of the "; + std::cout << " procedure please provide the dimension of persistence you want to use. If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1." << std::endl; + std::cout << "The remaining parameters are the names of files with persistence diagrams. \n"; + int dim = atoi( argv[1] ); + unsigned dimension = std::numeric_limits::max(); + if ( (dim != -1) && (dim >= 0) ) + { + dimension = (unsigned)dim; + } + std::vector< const char* > filenames; - for ( int i = 1 ; i < argc ; ++i ) + for ( int i = 2 ; i < argc ; ++i ) { filenames.push_back( argv[i] ); } @@ -44,7 +54,7 @@ int main( int argc , char** argv ) { std::cerr << "Creatign persistence vectors based on a file : " << filenames[i] << std::endl; //std::vector< std::pair< double , double > > persistence_pairs = read_gudhi_persistence_file_in_one_dimension( filenames[i] , size_t dimension = 0 ) - Vector_distances_in_diagram< Euclidean_distance > l( filenames[i] , -1 ); + Vector_distances_in_diagram< Euclidean_distance > l( filenames[i] , dimension ); std::stringstream ss; ss << filenames[i] << ".vect"; l.print_to_file( ss.str().c_str() ); -- cgit v1.2.3 From be976b50b0d036b1cf9efc58f936182647b7cd69 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 21 Apr 2017 16:06:28 +0000 Subject: Fix user version bug git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2374 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ff7a428dbe3a5c7c2b45037f66329f1061cf7f7b --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/CMakeLists.txt') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c94110a6..d0e5d5d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,7 +53,7 @@ add_subdirectory(example/Subsampling) add_subdirectory(example/Tangential_complex) add_subdirectory(example/Bottleneck_distance) add_subdirectory(example/Gudhi_stat) -add_subdirectory(example/Gudhi_stat/utilities) +add_subdirectory(utilities/Gudhi_stat) # data points generator add_subdirectory(data/points/generator) -- cgit v1.2.3 From e129379cf8a173b70ab123be668f4c67edf6f2a1 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Thu, 4 May 2017 11:56:16 +0000 Subject: Adding corrections to cmake files. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2396 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 56eaad66d3c21f84e4965c13f2596739825fc861 --- src/CMakeLists.txt | 6 +++++- src/Gudhi_stat/test/CMakeLists.txt | 11 ----------- 2 files changed, 5 insertions(+), 12 deletions(-) (limited to 'src/CMakeLists.txt') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d0e5d5d5..678303de 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,7 +53,11 @@ add_subdirectory(example/Subsampling) add_subdirectory(example/Tangential_complex) add_subdirectory(example/Bottleneck_distance) add_subdirectory(example/Gudhi_stat) -add_subdirectory(utilities/Gudhi_stat) +add_subdirectory(utilities/Gudhi_stat/persistence_heat_maps) +add_subdirectory(utilities/Gudhi_stat/persistence_intervals) +add_subdirectory(utilities/Gudhi_stat/persistence_landscapes) +add_subdirectory(utilities/Gudhi_stat/persistence_landscapes_on_grid) +add_subdirectory(utilities/Gudhi_stat/persistence_vectors) # data points generator add_subdirectory(data/points/generator) diff --git a/src/Gudhi_stat/test/CMakeLists.txt b/src/Gudhi_stat/test/CMakeLists.txt index ba457d5d..ab2b1cc3 100644 --- a/src/Gudhi_stat/test/CMakeLists.txt +++ b/src/Gudhi_stat/test/CMakeLists.txt @@ -86,17 +86,6 @@ add_test(NAME read_persistence_from_file_test # XML format for Jenkins xUnit plugin --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/read_persistence_from_file_UT.xml --log_level=test_suite --report_level=no) -file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) -add_executable ( additional_tests additional_tests.cpp ) -target_link_libraries(additional_tests ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) - -# Unitary tests -add_test(NAME additional_tests - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/additional_tests - file(COPY data DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/additional_tests/data") - # XML format for Jenkins xUnit plugin - --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/additional_tests_UT.xml --log_level=test_suite --report_level=no) - if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) -- cgit v1.2.3