From 8252d6eb78c9fe355a2167ad68e9106fcaa8fcdb Mon Sep 17 00:00:00 2001 From: pdlotko Date: Thu, 6 Apr 2017 15:36:53 +0000 Subject: Answering MG3 comments. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2313 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3bae7a55d05831af55a5b1c3e0d2695383af325f --- src/common/include/gudhi/distance_functions.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index 22747637..7f33a804 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -35,7 +35,7 @@ * have the same dimension. */ class Euclidean_distance { public: - template< typename Point > + template< typename Point > auto operator()(const Point& p1, const Point& p2) const -> typename std::decay::type { auto it1 = p1.begin(); auto it2 = p2.begin(); @@ -46,6 +46,11 @@ class Euclidean_distance { } return std::sqrt(dist); } + template< typename T > + T operator() ( const std::pair< T,T >& f , const std::pair< T,T >& s ) + { + return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); + } }; #endif // DISTANCE_FUNCTIONS_H_ -- cgit v1.2.3 From ca2ad986b9925ab7006597f0f7045f7be47a42b2 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Fri, 7 Apr 2017 09:10:52 +0000 Subject: Answers to Marc's comments git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2317 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f941a6b20210282408d0ef95b84daa973add2513 --- biblio/bibliography.bib | 16 ++++++++-------- .../Persistence_landscape_on_grid.h | 8 +++++--- src/cmake/modules/GUDHI_user_version_target.txt | 2 +- src/common/doc/main_page.h | 17 +++++++++++++++++ src/cython/doc/img/average_landscape.png | Bin 0 -> 14917 bytes 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 src/cython/doc/img/average_landscape.png (limited to 'src/common') diff --git a/biblio/bibliography.bib b/biblio/bibliography.bib index dbd0cb42..37aa8198 100644 --- a/biblio/bibliography.bib +++ b/biblio/bibliography.bib @@ -988,14 +988,14 @@ language={English} } @ARTICLE{bubenik_dlotko_landscapes_2016, - author = {P. Bubenik, P. Dlotko}, + author = {P. Bubenik and P. Dlotko}, title = {A persistence landscapes toolbox for topological statistics.}, journal = {Journal of Symbolic Computation.}, year = {2016} } @ARTICLE{Fasy_Kim_Lecci_Maria_tda, - author = {B. Fasy, J. Kim, F. Lecci, C. Maria}, + author = {B. Fasy and J. Kim and F. Lecci and C. Maria}, title = {Introduction to the R package TDA.}, journal = {arXiv:1411.1830.}, year = {2016} @@ -1003,7 +1003,7 @@ language={English} @ARTICLE{Ferri_Frosini_comparision_sheme_1, - author = {P. Donatini, P. Frosini, A. Lovato}, + author = {P. Donatini and P. Frosini and A. Lovato}, title = {Size functions for signature recognition.}, journal = {Proceedings of SPIE, Vision Geometry VII, vol. 3454}, year = {1998} @@ -1011,14 +1011,14 @@ language={English} @ARTICLE{Ferri_Frosini_comparision_sheme_2, - author = {M. Ferri, P. Frosini, A. Lovato, C. Zambelli}, + author = {M. Ferri and P. Frosini and A. Lovato and C. Zambelli}, title = {Point selection: A new comparison scheme for size functions (With an application to monogram recognition).}, journal = {Proceedings Third Asian Conference on Computer Vision, Lecture Notes in Computer Science 1351.}, year = {1998} } @ARTICLE{Persistence_Images_2017, - author = {H. Adams, S. Chepushtanova, T. Emerson, E. Hanson, M. Kirby, F. Motta, R. Neville, C. Peterson, P. Shipman, L. Ziegelmeier}, + author = {H. Adams and S. Chepushtanova and T. Emerson and E. Hanson and M. Kirby and F. Motta and R. Neville and C. Peterson and P. Shipman and L. Ziegelmeier}, title = {Persistence Images: A Stable Vector Representation of Persistent Homology.}, journal = {Journal of Machine Learning Research}, year = {2017} @@ -1026,21 +1026,21 @@ language={English} @ARTICLE{Kusano_Fukumizu_Hiraoka_PWGK, - author = {G. Kusano, K. Fukumizu, Y. Hiraoka}, + author = {G. Kusano and K. Fukumizu and Y. Hiraoka}, title = {Persistence weighted Gaussian kernel for topological data analysis.}, journal = {ICML'16 Proceedings of the 33rd International Conference on International Conference on Machine Learning - Volume 48}, year = {2016} } @ARTICLE{Reininghaus_Huber_ALL_PSSK, - author = {J. Reininghaus, S. Huber, U. Bauer, R. Kwitt}, + author = {J. Reininghaus and S. Huber and U. Bauer and R. Kwitt}, title = {A Stable Multi-Scale Kernel for Topological Machine Learning.}, journal = {Proc. 2015 IEEE Conf. Comp. Vision & Pat. Rec. (CVPR '15)}, year = {2015} } @ARTICLE{Carriere_Oudot_Ovsjanikov_top_signatures_3d, - author = {M. Carrière, S. Oudot, M. Ovsjanikov}, + author = {M. Carrière and S. Oudot and M. Ovsjanikov}, title = {Stable Topological Signatures for Points on 3D Shapes.}, journal = {Proc. Sympos. on Geometry Processing}, year = {2015} 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 422699ef..b70ef1d9 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 @@ -313,8 +313,11 @@ public: //compute the value of the linear function parametrized by line on a point x: return line.first*x+line.second; } + + protected: + template < typename oper > friend Persistence_landscape_on_grid operation_on_pair_of_landscapes_on_grid( const Persistence_landscape_on_grid& land1 , const Persistence_landscape_on_grid& land2 ); - + public: /** *\private A function that compute sum of two landscapes. **/ @@ -1024,8 +1027,7 @@ protected: this->number_of_functions_for_projections_to_reals = this->values_of_landscapes.size(); } - void set_up_values_of_landscapes( const std::vector< std::pair< double , double > >& p , double grid_min_ , double grid_max_ , size_t number_of_points_ ); - template < typename oper > friend Persistence_landscape_on_grid operation_on_pair_of_landscapes_on_grid( const Persistence_landscape_on_grid& land1 , const Persistence_landscape_on_grid& land2 ); + void set_up_values_of_landscapes( const std::vector< std::pair< double , double > >& p , double grid_min_ , double grid_max_ , size_t number_of_points_ ); Persistence_landscape_on_grid multiply_lanscape_by_real_number_not_overwrite( double x )const; }; diff --git a/src/cmake/modules/GUDHI_user_version_target.txt b/src/cmake/modules/GUDHI_user_version_target.txt index b6a60dd1..a971f1d9 100644 --- a/src/cmake/modules/GUDHI_user_version_target.txt +++ b/src/cmake/modules/GUDHI_user_version_target.txt @@ -50,7 +50,7 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.11) copy_directory ${CMAKE_SOURCE_DIR}/src/GudhUI ${GUDHI_USER_VERSION_DIR}/GudhUI) set(GUDHI_MODULES "common;Alpha_complex;Bitmap_cubical_complex;Bottleneck_distance;Contraction;Gudhi_stat;Hasse_complex;Persistent_cohomology;Rips_complex;Simplex_tree;Skeleton_blocker;Spatial_searching;Subsampling;Tangential_complex;Witness_complex") - set(GUDHI_DIRECTORIES "doc;example;concept") + set(GUDHI_DIRECTORIES "doc;example;concept;utilities") set(GUDHI_INCLUDE_DIRECTORIES "include/gudhi;include/gudhi_patches") foreach(GUDHI_MODULE ${GUDHI_MODULES}) diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index e6f29fa8..55673f60 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -151,6 +151,23 @@ + + \subsection Gudhi_stat Gudhi statistical sublibrary + \image html "average_landscape.png" "Gudhi statistical sublibrary" + + + + + +
+ Author: Pawel Dlotko
+ Introduced in: GUDHI 2.0.0
+ Copyright: GPL v3
+
+ This is a statistical library for gudhi. It contain implementation of various representations of persistence diagrams; diagrams themselves, persistence landscapes (rigorous and grid version), + persistence heath maps, vectors and others. It implements basic functionalities which are neccessary to use persistence in statistics and machine learning. + User manual: \ref gudhi_stat - Reference manual: Gudhi::Gudhi_stat +
\section Toolbox Toolbox \subsection BottleneckDistanceToolbox Bottleneck distance diff --git a/src/cython/doc/img/average_landscape.png b/src/cython/doc/img/average_landscape.png new file mode 100644 index 00000000..ea59926b Binary files /dev/null and b/src/cython/doc/img/average_landscape.png differ -- cgit v1.2.3 From aecf253b150fcaf0a9e2a41686de7dfea91fa4d8 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Thu, 13 Apr 2017 12:42:19 +0000 Subject: Answer to Vincent's comments. At the moment I need to discuss how to correct the doc. At the moment make doxygen generate some errors. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2342 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4bb5c3b30bca852045fb414eacf59936975a3855 --- .../Persistence_landscape.h | 6 ++-- .../Persistence_landscape_on_grid.h | 6 ++-- src/Gudhi_stat/utilities/Landscape_bootstrap.cpp | 2 +- .../create_persistence_heat_maps.cpp | 2 +- ...aps_weighted_by_arctan_of_their_persistence.cpp | 2 +- ...eat_maps_weighted_by_distance_from_diagonal.cpp | 2 +- ..._weighted_by_squared_distance_from_diagonal.cpp | 2 +- .../persistence_heat_maps/create_pssk.cpp | 2 +- ...te_birth_death_range_in_persistence_diagram.cpp | 2 +- .../compute_bottleneck_distance.cpp | 2 +- .../compute_number_of_dominant_intervals.cpp | 2 +- .../plot_histogram_of_intervals_lengths.cpp | 2 +- .../plot_persistence_Betti_numbers.cpp | 2 +- .../plot_persistence_intervals.cpp | 2 +- .../persistence_landscapes/create_landscapes.cpp | 2 +- .../create_landscapes_on_grid.cpp | 2 +- .../create_persistence_vectors.cpp | 2 +- src/common/doc/main_page.h | 34 ++++++++++++---------- 18 files changed, 39 insertions(+), 37 deletions(-) (limited to 'src/common') 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 681f5d8d..925d784f 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape.h +++ b/src/Gudhi_stat/include/gudhi/persistence_representations/Persistence_landscape.h @@ -270,7 +270,7 @@ public: } /** - *\private Computations of a L^i norm of landscape, where i is the input parameter. + *\private Computations of a \f$L^i\f$ norm of landscape, where i is the input parameter. **/ double compute_norm_of_landscape( double i ) { @@ -291,14 +291,14 @@ public: double operator()(unsigned level,double x)const{return this->compute_value_at_a_given_point(level,x);} /** - *\private Computations of L^{\infty} distance between two landscapes. + *\private Computations of \f$L^{\infty}\f$ distance between two landscapes. **/ friend double compute_max_norm_distance_of_landscapes( const Persistence_landscape& first, const Persistence_landscape& second ); //friend double compute_max_norm_distance_of_landscapes( const Persistence_landscape& first, const Persistence_landscape& second , unsigned& nrOfLand , double&x , double& y1, double& y2 ); /** - *\private Computations of L^{p} distance between two landscapes. p is the parameter of the procedure. + *\private Computations of \f$L^{p}\f$ distance between two landscapes. p is the parameter of the procedure. **/ friend double compute_distance_of_landscapes( const Persistence_landscape& first, const Persistence_landscape& second , double p ); 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 1f4cb3ff..3103172d 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 @@ -595,7 +595,7 @@ public: } /** - * Computations of a L^i norm of landscape, where i is the input parameter. + * Computations of a \f$L^i\f$ norm of landscape, where i is the input parameter. **/ double compute_norm_of_landscape( double i )const { @@ -618,7 +618,7 @@ public: double operator()(unsigned level,double x)const{return this->compute_value_at_a_given_point(level,x);} /** - * Computations of L^{\infty} distance between two landscapes. + * Computations of \f$L^{\infty}\f$ distance between two landscapes. **/ friend double compute_max_norm_distance_of_landscapes( const Persistence_landscape_on_grid& first, const Persistence_landscape_on_grid& second ); //friend double compute_max_norm_distance_of_landscapes( const Persistence_landscape_on_grid& first, const Persistence_landscape_on_grid& second , unsigned& nrOfLand , double&x , double& y1, double& y2 ); @@ -765,7 +765,7 @@ public: /** - * Computations of L^{p} distance between two landscapes on a grid. p is the parameter of the procedure. + * Computations of \f$L^{p}\f$ distance between two landscapes on a grid. p is the parameter of the procedure. * FIXME: Note that, due to the grid representation, the method below may give non--accurate results in case when the landscape P and Q the difference of which we want to compute * are interxsecting. This is a consequence of a general way they are computed. In the future, an integral of absolute value of a difference of P and Q will be given as a separated * function to fix that inaccuracy. diff --git a/src/Gudhi_stat/utilities/Landscape_bootstrap.cpp b/src/Gudhi_stat/utilities/Landscape_bootstrap.cpp index d67bb820..9bd6c89e 100644 --- a/src/Gudhi_stat/utilities/Landscape_bootstrap.cpp +++ b/src/Gudhi_stat/utilities/Landscape_bootstrap.cpp @@ -38,7 +38,7 @@ using Persistence_landscape = Gudhi::Gudhi_stat::Persistence_landscape; typedef int Vertex_handle; -typedef double Filtration_value; +//typedef double Filtration_value; //if this variable is -1, then the infinite interals are ignored. If not, they infinite values are replaced with what_to_replace_infinite_intervals_with: 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 d9c7aded..e99b829a 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 @@ -57,7 +57,7 @@ int main( int argc , char** argv ) unsigned dimension = std::numeric_limits::max(); int dim = atoi( argv[5] ); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 7cb7eeb7..b98fc3f7 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 @@ -58,7 +58,7 @@ int main( int argc , char** argv ) unsigned dimension = std::numeric_limits::max(); int dim = atoi( argv[5] ); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 3242e106..ecef449a 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 @@ -57,7 +57,7 @@ int main( int argc , char** argv ) unsigned dimension = std::numeric_limits::max(); int dim = atoi( argv[5] ); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 27846a99..59966855 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 @@ -57,7 +57,7 @@ int main( int argc , char** argv ) unsigned dimension = std::numeric_limits::max(); int dim = atoi( argv[5] ); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 404a4be3..78989ccc 100644 --- a/src/Gudhi_stat/utilities/persistence_heat_maps/create_pssk.cpp +++ b/src/Gudhi_stat/utilities/persistence_heat_maps/create_pssk.cpp @@ -57,7 +57,7 @@ int main( int argc , char** argv ) unsigned dimension = std::numeric_limits::max(); int dim = atoi( argv[5] ); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 426a9b7b..a3e19400 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 @@ -45,7 +45,7 @@ int main( int argc , char** argv ) int dim = atoi( argv[1] ); unsigned dimension = std::numeric_limits::max(); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } diff --git a/src/Gudhi_stat/utilities/persistence_intervals/compute_bottleneck_distance.cpp b/src/Gudhi_stat/utilities/persistence_intervals/compute_bottleneck_distance.cpp index 6f0ba635..d8b533cf 100644 --- a/src/Gudhi_stat/utilities/persistence_intervals/compute_bottleneck_distance.cpp +++ b/src/Gudhi_stat/utilities/persistence_intervals/compute_bottleneck_distance.cpp @@ -48,7 +48,7 @@ int main( int argc , char** argv ) int dim = atoi(argv[1]); unsigned dimension = std::numeric_limits::max(); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 0a7f7c2b..281902fe 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 @@ -43,7 +43,7 @@ int main( int argc , char** argv ) } int dim = atoi( argv[2] ); unsigned dimension = std::numeric_limits::max(); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 11876a0d..acfb0eed 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 @@ -48,7 +48,7 @@ int main( int argc , char** argv ) { dim = atoi( argv[2] ); } - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 index 09c6cc22..21ba06f4 100644 --- a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp +++ b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp @@ -48,7 +48,7 @@ int main( int argc , char** argv ) { dim = atoi( argv[2] ); } - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 4315abb9..95c0cf1f 100644 --- a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp +++ b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp @@ -51,7 +51,7 @@ int main( int argc , char** argv ) { dim = atoi( argv[2] ); } - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } diff --git a/src/Gudhi_stat/utilities/persistence_landscapes/create_landscapes.cpp b/src/Gudhi_stat/utilities/persistence_landscapes/create_landscapes.cpp index f36e313a..040ccc95 100644 --- a/src/Gudhi_stat/utilities/persistence_landscapes/create_landscapes.cpp +++ b/src/Gudhi_stat/utilities/persistence_landscapes/create_landscapes.cpp @@ -40,7 +40,7 @@ int main( int argc , char** argv ) std::vector< const char* > filenames; int dim = atoi(argv[1]); unsigned dimension = std::numeric_limits::max(); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 eb534bf1..6dbb70c4 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 @@ -52,7 +52,7 @@ int main( int argc , char** argv ) double max_ = atof( argv[3] ); int dim = atoi( argv[4] ); unsigned dimension = std::numeric_limits::max(); - if ( (dim != -1) && (dim >= 0) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } 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 40f5e81f..7f0492c6 100644 --- a/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp +++ b/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp @@ -39,7 +39,7 @@ int main( int argc , char** argv ) 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) ) + if ( dim >= 0 ) { dimension = (unsigned)dim; } diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index 55673f60..f3816238 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -151,22 +151,6 @@ - - \subsection Gudhi_stat Gudhi statistical sublibrary - \image html "average_landscape.png" "Gudhi statistical sublibrary" - - - - -
- Author: Pawel Dlotko
- Introduced in: GUDHI 2.0.0
- Copyright: GPL v3
-
- This is a statistical library for gudhi. It contain implementation of various representations of persistence diagrams; diagrams themselves, persistence landscapes (rigorous and grid version), - persistence heath maps, vectors and others. It implements basic functionalities which are neccessary to use persistence in statistics and machine learning. - User manual: \ref gudhi_stat - Reference manual: Gudhi::Gudhi_stat -
\section Toolbox Toolbox @@ -227,9 +211,27 @@ \cite DBLP:journals/corr/abs-1208-5018 and the Compressed Annotation Matrix implementation of \cite DBLP:conf/esa/BoissonnatDM13 .
User manual: \ref persistent_cohomology - Reference manual: Gudhi::persistent_cohomology::Persistent_cohomology + + + + \subsection Gudhi_stat_sublibrary Gudhi statistical sublibrary + \image html "average_landscape.png" "Gudhi statistical sublibrary" + + + +
+ Author: Pawel Dlotko
+ Introduced in: GUDHI 2.0.0
+ Copyright: GPL v3
+
+ This is a statistical library for gudhi. It contain implementation of various representations of persistence diagrams; diagrams themselves, persistence landscapes (rigorous and grid version), + persistence heath maps, vectors and others. It implements basic functionalities which are neccessary to use persistence in statistics and machine learning. + User manual: \ref Gudhi_stat +
+ */ /*! \page installation GUDHI installation -- cgit v1.2.3 From 0654bfbab17fe16edf90445f0a351454b460028f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 30 May 2017 15:20:29 +0000 Subject: Fix spell checker errors git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2475 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 94422e6f356532b2db4dc5a55cbb851210b3c36d --- CMakeLists.txt | 16 +- src/CMakeLists.txt | 12 +- src/Doxyfile | 4 +- .../concept/Real_valued_topological_data.h | 21 ++- .../concept/Topological_data_with_averages.h | 11 +- .../concept/Topological_data_with_distances.h | 22 ++- .../concept/Topological_data_with_scalar_product.h | 15 +- .../concept/Vectorized_topological_data.h | 15 +- .../doc/Persistence_representations_doc.h | 52 +++--- .../example/persistence_heat_maps.cpp | 4 +- .../example/persistence_intervals.cpp | 4 +- .../example/persistence_landscape.cpp | 4 +- .../example/persistence_landscape_on_grid.cpp | 2 +- .../include/gudhi/PSSK.h | 15 +- .../include/gudhi/Persistence_heat_maps.h | 85 +++++---- .../include/gudhi/Persistence_intervals.h | 106 +++--------- .../gudhi/Persistence_intervals_with_distances.h | 12 +- .../include/gudhi/Persistence_landscape.h | 116 +++++-------- .../include/gudhi/Persistence_landscape_on_grid.h | 192 ++++++--------------- .../include/gudhi/Persistence_vectors.h | 105 ++++------- .../gudhi/common_persistence_representations.h | 28 ++- .../include/gudhi/read_persistence_from_file.h | 104 ++--------- .../compute_distance_of_persistence_heat_maps.cpp | 9 +- ...h_m_weighted_by_arctan_of_their_persistence.cpp | 4 +- ...te_p_h_m_weighted_by_distance_from_diagonal.cpp | 4 +- ...ate_p_h_m_weighted_by_squared_diag_distance.cpp | 2 +- .../create_persistence_heat_maps.cpp | 2 +- .../persistence_heat_maps/create_pssk.cpp | 2 +- .../plot_persistence_heat_map.cpp | 2 +- .../compute_bottleneck_distance.cpp | 2 +- .../plot_histogram_of_intervals_lengths.cpp | 2 +- .../plot_persistence_Betti_numbers.cpp | 7 +- .../compute_distance_of_landscapes.cpp | 2 +- .../persistence_landscapes/plot_landscapes.cpp | 2 +- .../compute_distance_of_landscapes_on_grid.cpp | 6 +- .../plot_landscapes_on_grid.cpp | 2 +- .../compute_distance_of_persistence_vectors.cpp | 3 +- .../create_persistence_vectors.cpp | 3 +- src/cmake/modules/GUDHI_user_version_target.txt | 2 +- src/common/doc/main_page.h | 13 +- src/common/include/gudhi/distance_functions.h | 5 + 41 files changed, 384 insertions(+), 635 deletions(-) (limited to 'src/common') diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c772506..30306885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ include_directories(src/Spatial_searching/include/) include_directories(src/Subsampling/include/) include_directories(src/Tangential_complex/include/) include_directories(src/Witness_complex/include/) -include_directories(src/Gudhi_stat/include/) +include_directories(src/Persistence_representations/include/) add_subdirectory(src/common/example) add_subdirectory(src/common/test) @@ -82,13 +82,13 @@ add_subdirectory(src/Bottleneck_distance/test) add_subdirectory(src/Bottleneck_distance/benchmark) add_subdirectory(src/Rips_complex/example) add_subdirectory(src/Rips_complex/test) -add_subdirectory(src/Gudhi_stat/test) -add_subdirectory(src/Gudhi_stat/example) -add_subdirectory(src/Gudhi_stat/utilities/persistence_heat_maps) -add_subdirectory(src/Gudhi_stat/utilities/persistence_intervals) -add_subdirectory(src/Gudhi_stat/utilities/persistence_landscapes) -add_subdirectory(src/Gudhi_stat/utilities/persistence_landscapes_on_grid) -add_subdirectory(src/Gudhi_stat/utilities/persistence_vectors) +add_subdirectory(src/Persistence_representations/test) +add_subdirectory(src/Persistence_representations/example) +add_subdirectory(src/Persistence_representations/utilities/persistence_heat_maps) +add_subdirectory(src/Persistence_representations/utilities/persistence_intervals) +add_subdirectory(src/Persistence_representations/utilities/persistence_landscapes) +add_subdirectory(src/Persistence_representations/utilities/persistence_landscapes_on_grid) +add_subdirectory(src/Persistence_representations/utilities/persistence_vectors) # data points generator add_subdirectory(data/points/generator) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe4eb677..06e479be 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,12 +52,12 @@ add_subdirectory(example/Spatial_searching) add_subdirectory(example/Subsampling) add_subdirectory(example/Tangential_complex) add_subdirectory(example/Bottleneck_distance) -add_subdirectory(example/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) +add_subdirectory(example/Persistence_representations) +add_subdirectory(utilities/Persistence_representations/persistence_heat_maps) +add_subdirectory(utilities/Persistence_representations/persistence_intervals) +add_subdirectory(utilities/Persistence_representations/persistence_landscapes) +add_subdirectory(utilities/Persistence_representations/persistence_landscapes_on_grid) +add_subdirectory(utilities/Persistence_representations/persistence_vectors) # data points generator add_subdirectory(data/points/generator) diff --git a/src/Doxyfile b/src/Doxyfile index f4df4e84..eb0b3e9e 100644 --- a/src/Doxyfile +++ b/src/Doxyfile @@ -852,7 +852,7 @@ IMAGE_PATH = doc/Skeleton_blocker/ \ doc/Spatial_searching/ \ doc/Tangential_complex/ \ doc/Bottleneck_distance/ \ - doc/Gudhi_stat/ + doc/Persistence_representations/ # 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 @@ -2116,7 +2116,7 @@ COLLABORATION_GRAPH = NO # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. -GROUP_GRAPHS = YES +GROUP_GRAPHS = NO # If the UML_LOOK tag is set to YES doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling diff --git a/src/Persistence_representations/concept/Real_valued_topological_data.h b/src/Persistence_representations/concept/Real_valued_topological_data.h index 4d4ee8d3..5a15c769 100644 --- a/src/Persistence_representations/concept/Real_valued_topological_data.h +++ b/src/Persistence_representations/concept/Real_valued_topological_data.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -20,6 +20,14 @@ * along with this program. If not, see . */ +#ifndef CONCEPT_REAL_VALUED_TOPOLOGICAL_DATA_H_ +#define CONCEPT_REAL_VALUED_TOPOLOGICAL_DATA_H_ + +namespace Gudhi { + +namespace Persistence_representations { + + /** \brief The concept Real_valued_topological_data describes the requirements * for a type to implement a container that allows computations of its projections to R. */ @@ -27,12 +35,19 @@ class Real_valued_topological_data { public: /** - * Typically there are various ways data can be projected to R. This function give us the number of functions for vectorization provided by a given class. + * Typically there are various ways data can be projected to R. This function gives us the number of functions for + * vectorization provided by a given class. **/ size_t number_of_projections_to_R(); /** - * This is a function to compute the projection from this container to reals. The parameter of a function have to be between 0 and the value returned by number_of_projections_to_R(). + * This is a function to compute the projection from this container to reals. The parameter of a function have to + * be between 0 and the value returned by number_of_projections_to_R(). **/ double project_to_R( size_t number_of_projection ); }; +} // namespace Persistence_representations + +} // namespace Gudhi + +#endif // CONCEPT_REAL_VALUED_TOPOLOGICAL_DATA_H_ diff --git a/src/Persistence_representations/concept/Topological_data_with_averages.h b/src/Persistence_representations/concept/Topological_data_with_averages.h index aeeb94f0..0501c306 100644 --- a/src/Persistence_representations/concept/Topological_data_with_averages.h +++ b/src/Persistence_representations/concept/Topological_data_with_averages.h @@ -5,7 +5,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -21,7 +21,12 @@ * along with this program. If not, see . */ +#ifndef CONCEPT_TOPOLOGICAL_DATA_WITH_AVERAGES_H_ +#define CONCEPT_TOPOLOGICAL_DATA_WITH_AVERAGES_H_ +namespace Gudhi { + +namespace Persistence_representations { /** \brief The concept Topological_data_with_averages describes the requirements * for a type to implement a container that allows computations of averages. @@ -33,4 +38,8 @@ public: void compute_average( const std::vector< Topological_data_with_averages* >& to_average ); }; +} // namespace Persistence_representations + +} // namespace Gudhi +#endif // CONCEPT_TOPOLOGICAL_DATA_WITH_AVERAGES_H_ diff --git a/src/Persistence_representations/concept/Topological_data_with_distances.h b/src/Persistence_representations/concept/Topological_data_with_distances.h index 1318b9d1..2e6de729 100644 --- a/src/Persistence_representations/concept/Topological_data_with_distances.h +++ b/src/Persistence_representations/concept/Topological_data_with_distances.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -20,11 +20,22 @@ * along with this program. If not, see . */ +#ifndef CONCEPT_TOPOLOGICAL_DATA_WITH_DISTANCES_H_ +#define CONCEPT_TOPOLOGICAL_DATA_WITH_DISTANCES_H_ + +namespace Gudhi { + +namespace Persistence_representations { + + /** \brief The concept Topological_data_with_distances describes the requirements - * for a type to implement a container that allows computations of distance to another contained of that type. + * for a type to implement a container that allows computations of distance to another contained of that type. + * \details * The second parameter of the distance function allow to declare power of a distance. The exact meaning of that * number will be different for different distances. A few examples are given below: - * In case of p-Wasserstein distance, the power is equal to p. power = std::limit::max() for bottleneck distance. + * In case of p-Wasserstein distance, the power is equal to p. power = std::limit::max() for bottleneck + * distance. + * * In case of L^p landscape distance, the power is equal to p. s */ class Topological_data_with_distances @@ -33,3 +44,8 @@ public: double distance( const Topological_data_with_distances& second , double power = 1); }; +} // namespace Persistence_representations + +} // namespace Gudhi + +#endif // CONCEPT_TOPOLOGICAL_DATA_WITH_DISTANCES_H_ diff --git a/src/Persistence_representations/concept/Topological_data_with_scalar_product.h b/src/Persistence_representations/concept/Topological_data_with_scalar_product.h index f32271c7..203a1d91 100644 --- a/src/Persistence_representations/concept/Topological_data_with_scalar_product.h +++ b/src/Persistence_representations/concept/Topological_data_with_scalar_product.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -20,6 +20,13 @@ * along with this program. If not, see . */ +#ifndef CONCEPT_TOPOLOGICAL_DATA_WITH_SCALAR_PRODUCT_H_ +#define CONCEPT_TOPOLOGICAL_DATA_WITH_SCALAR_PRODUCT_H_ + +namespace Gudhi { + +namespace Persistence_representations { + /** \brief The concept Topological_data_with_scalar_product describes the requirements * for a type to implement a container that allows computations of scalar products. @@ -29,3 +36,9 @@ class Topological_data_with_scalar_product public: double compute_scalar_product( const Topological_data_with_scalar_product& second ); }; + +} // namespace Persistence_representations + +} // namespace Gudhi + +#endif // CONCEPT_TOPOLOGICAL_DATA_WITH_SCALAR_PRODUCT_H_ diff --git a/src/Persistence_representations/concept/Vectorized_topological_data.h b/src/Persistence_representations/concept/Vectorized_topological_data.h index 2dd966fd..8d4105a2 100644 --- a/src/Persistence_representations/concept/Vectorized_topological_data.h +++ b/src/Persistence_representations/concept/Vectorized_topological_data.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -20,6 +20,12 @@ * along with this program. If not, see . */ +#ifndef CONCEPT_VECTORIZED_TOPOLOGICAL_DATA_H_ +#define CONCEPT_VECTORIZED_TOPOLOGICAL_DATA_H_ + +namespace Gudhi { + +namespace Persistence_representations { /** \brief The concept Vectorized_topological_data describes the requirements * for a type to implement a container that allows vectorization. @@ -28,7 +34,7 @@ class Vectorized_topological_data { public: /** - * There are various ways data can be verctorized. This function give us the number of functions for vectorization provided by a given class. + * There are various ways data can be vectorized. This function give us the number of functions for vectorization provided by a given class. **/ size_t number_of_vectorize_functions(); /** @@ -37,3 +43,8 @@ public: std::vector vectorize( int number_of_function ); }; +} // namespace Persistence_representations + +} // namespace Gudhi + +#endif // CONCEPT_VECTORIZED_TOPOLOGICAL_DATA_H_ diff --git a/src/Persistence_representations/doc/Persistence_representations_doc.h b/src/Persistence_representations/doc/Persistence_representations_doc.h index 215616a0..bc11d2c4 100644 --- a/src/Persistence_representations/doc/Persistence_representations_doc.h +++ b/src/Persistence_representations/doc/Persistence_representations_doc.h @@ -28,12 +28,12 @@ namespace Gudhi { namespace Persistence_representations { -/** \defgroup Persistence_representations Persistence_representations +/** \defgroup Persistence_representations Persistence representations * * \author Pawel Dlotko * * @{ - *\section idea Idea + *\section Persistence_representations_idea Idea *In order to perform most of the statistical tests and machine learning algorithms on a data one need to be able to perform only a very limited number of operations on them. Let us fix a representation of * data of a type A. To perform most of the statistical and machine learning operations one need to be able to compute average of objects of type A (so that the averaged object is also of a type A), to @@ -71,24 +71,24 @@ namespace Persistence_representations { *\li Persistence diagrams / barcodes (allow computation of distances, vectorizations and real value characteristics). * * - *Note that at the while functionalities like averaging, distances and scalar products are fixed, there is no canonical way of vectorizing and computing real valued characteristics of objects. Therefore the + * Note that at the while functionalities like averaging, distances and scalar products are fixed, there is no canonical way of vectorizing and computing real valued characteristics of objects. Therefore the * vectorizations and computation of real value characteristics procedures are quite likely to evolve in the furthering versions of the library. * - *The main aim of this implementation is to be able to implement various statistical methods, both on the level of C++ and on the level of python. The methods will operate on the functionalities offered + * The main aim of this implementation is to be able to implement various statistical methods, both on the level of C++ and on the level of python. The methods will operate on the functionalities offered * by concepts. That means that the statistical and ML methods will be able to operate on any representation that implement the required concept (including the ones that are not in the library at the moment). * That gives provides a framework, that is very easy to extend, for topological statistics. * - *Below we are discussing the representations which are currently implemented in Persistence\_representations package: + * Below we are discussing the representations which are currently implemented in Persistence\_representations package: * - *\section sec_persistence_landscapes Persistence Landscapes - * Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape - *Persistence landscapes were originally proposed by Bubenik in \cite bubenik_landscapes_2015. Efficient algorithms to compute them rigorously were proposed by Bubenik and Dlotko in \cite bubenik_dlotko_landscapes_2016. The idea of + * \section sec_persistence_landscapes Persistence Landscapes + * Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape
+ * Persistence landscapes were originally proposed by Bubenik in \cite bubenik_landscapes_2015. Efficient algorithms to compute them rigorously were proposed by Bubenik and Dlotko in \cite bubenik_dlotko_landscapes_2016. The idea of * persistence landscapes is shortly summarized in below. * - *To begin with, suppose we are given a point \f$(b,d) \in \mathbb{R}^2\f$ in a - *persistence diagram. With this point, we associate a piecewise - *linear function \f$f_{(b,d)} : \mathbb{R} \rightarrow [0,\infty)\f$, which is - *defined as + * To begin with, suppose we are given a point \f$(b,d) \in \mathbb{R}^2\f$ in a + * persistence diagram. With this point, we associate a piecewise + * linear function \f$f_{(b,d)} : \mathbb{R} \rightarrow [0,\infty)\f$, which is + * defined as * * \f[f_{(b,d)}(x) = * \left\{ \begin{array}{ccl} @@ -100,16 +100,16 @@ namespace Persistence_representations { * \end{array} \right. *\f] * - *A persistence landscape of the birth-death - *pairs \f$(b_i , d_i)\f$, where \f$i = 1,\ldots,m\f$, which constitute the given - *persistence diagram is the sequence of functions \f$\lambda_k : \mathbb{R} \rightarrow [0,\infty)\f$ for \f$k \in \mathbb{N}\f$, where \f$\lambda_k(x)\f$ - *denotes the \f$k^{\rm th}\f$ largest value of the numbers \f$f_{(b_i,d_i)}(x)\f$, - *for \f$i = 1, \ldots, m\f$, and we define \f$\lambda_k(x) = 0\f$ if \f$k > m\f$. - *Equivalently, this sequence of functions can be combined into a single - *function \f$L : \mathbb{N} \times \mathbb{R} \to [0,\infty)\f$ of two - *variables, if we define \f$L(k,t) = \lambda_k(t)\f$. + * A persistence landscape of the birth-death + * pairs \f$(b_i , d_i)\f$, where \f$i = 1,\ldots,m\f$, which constitute the given + * persistence diagram is the sequence of functions \f$\lambda_k : \mathbb{R} \rightarrow [0,\infty)\f$ for \f$k \in \mathbb{N}\f$, where \f$\lambda_k(x)\f$ + * denotes the \f$k^{\rm th}\f$ largest value of the numbers \f$f_{(b_i,d_i)}(x)\f$, + * for \f$i = 1, \ldots, m\f$, and we define \f$\lambda_k(x) = 0\f$ if \f$k > m\f$. + * Equivalently, this sequence of functions can be combined into a single + * function \f$L : \mathbb{N} \times \mathbb{R} \to [0,\infty)\f$ of two + * variables, if we define \f$L(k,t) = \lambda_k(t)\f$. * - *The detailed description of algorithms used to compute persistence landscapes can be found in \cite bubenik_dlotko_landscapes_2016. + * The detailed description of algorithms used to compute persistence landscapes can be found in \cite bubenik_dlotko_landscapes_2016. * Note that this implementation provides exact representation of landscapes. That have many advantages, but also a few drawbacks. For instance, as discussed * in \cite bubenik_dlotko_landscapes_2016, the exact representation of landscape may be of quadratic size with respect to the input persistence diagram. It may therefore happen * that, for very large diagrams, using this representation may be memory--prohibitive. In such a case, there are two possible ways to proceed: @@ -120,13 +120,13 @@ namespace Persistence_representations { * * *\section sec_landscapes_on_grid Persistence Landscapes on a grid - * Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape_on_grid - *This is an alternative, not--exact, representation of persistence landscapes defined in the Section \ref sec_persistence_landscapes. Unlike in the Section \ref sec_persistence_landscapes we build a + * Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape_on_grid
+ * This is an alternative, not--exact, representation of persistence landscapes defined in the Section \ref sec_persistence_landscapes. Unlike in the Section \ref sec_persistence_landscapes we build a * representation of persistence landscape by sampling its values on a finite, equally distributed grid of points. * Since, the persistence landscapes that originate from persistence diagrams have slope \f$1\f$ or \f$-1\f$, we have an estimate of a region between the grid points where the landscape cab be located. * That allows to estimate an error make when performing various operations on landscape. Note that for average landscapes the slope is in range \f$[-1,1]\f$ and similar estimate can be used. * - *Due to a lack of rigorous description of the algorithms to deal with this non--rigorous representaion of persistence landscapes in the literature, we are providing a short discussion of them in below. + * Due to a lack of rigorous description of the algorithms to deal with this non--rigorous representation of persistence landscapes in the literature, we are providing a short discussion of them in below. * *Let us assume that we want to compute persistence landscape on a interval \f$[x,y]\f$. Let us assume that we want to use \f$N\f$ grid points for that purpose. * Then we will sample the persistence landscape on points \f$x_1 = x , x_2 = x + \frac{y-x}{N}, \ldots , x_{N} = y\f$. Persistence landscapes are represented as a vector of @@ -153,7 +153,7 @@ namespace Persistence_representations { *Note that the same representation is used in TDA R-package \cite Fasy_Kim_Lecci_Maria_tda. * *\section sec_persistence_heat_maps Persistence heat maps - * Reference manual: \ref Gudhi::Persistence_representations::Persistence heat maps + * Reference manual: \ref Gudhi::Persistence_representations::Persistence_heat_maps
*This is a general class of discrete structures which are based on idea of placing a kernel in the points of persistence diagrams. *This idea appeared in work by many authors over the last 15 years. As far as we know this idea was firstly described in the work of Bologna group in \cite Ferri_Frosini_comparision_sheme_1 and \cite Ferri_Frosini_comparision_sheme_2. *Later it has been described by Colorado State University group in \cite Persistence_Images_2017. The presented paper in the first time provide a discussion of stability of the representation. @@ -177,7 +177,7 @@ namespace Persistence_representations { * * *\section sec_persistence_vectors Persistence vectors - * Reference manual: \ref Gudhi::Persistence_representations::Persistence vectors + * Reference manual: \ref Gudhi::Persistence_representations::Vector_distances_in_diagram
*This is a representation of persistent homology in a form of a vector which was designed for an application in 3d graphic in \cite Carriere_Oudot_Ovsjanikov_top_signatures_3d. Below we provide a short description of this representation. * *Given a persistence diagram \f$D = \{ (b_i,d_i) \}\f$, for every pair of birth--death points \f$(b_1,d_1)\f$ and \f$(b_2,d_2)\f$ we compute the following three distances: diff --git a/src/Persistence_representations/example/persistence_heat_maps.cpp b/src/Persistence_representations/example/persistence_heat_maps.cpp index da87486d..c75e2731 100644 --- a/src/Persistence_representations/example/persistence_heat_maps.cpp +++ b/src/Persistence_representations/example/persistence_heat_maps.cpp @@ -55,7 +55,7 @@ int main( int argc , char** argv ) persistence2.push_back( std::make_pair(3,5) ); persistence2.push_back( std::make_pair(6,10) ); - //over here we define a function we sill put on a top on every birth--death pair in the persistence interval. It can be anything. Over here we will use standarg Gaussian + //over here we define a function we sill put on a top on every birth--death pair in the persistence interval. It can be anything. Over here we will use standard Gaussian std::vector< std::vector > filter = create_Gaussian_filter(5,1); //creating two heat maps. @@ -72,7 +72,7 @@ int main( int argc , char** argv ) Persistence_heat_maps median; median.compute_median( vector_of_maps ); - //to compute L^1 disance between hm1 and hm2: + //to compute L^1 distance between hm1 and hm2: std::cout << "The L^1 distance is : " << hm1.distance( hm2 , 1 ) << std::endl; //to average of hm1 and hm2: diff --git a/src/Persistence_representations/example/persistence_intervals.cpp b/src/Persistence_representations/example/persistence_intervals.cpp index ed5b4e34..947c9627 100644 --- a/src/Persistence_representations/example/persistence_intervals.cpp +++ b/src/Persistence_representations/example/persistence_intervals.cpp @@ -47,7 +47,7 @@ int main( int argc , char** argv ) std::vector dominant_ten_intervals_length = p.length_of_dominant_intervals(10); - std::cout << "Lendth of ten dominant intervals : " < cumulative_histogram = p.cumulative_histogram_of_lengths( 10 ); - std::cout<< "Cumuative histogram : " <. */ -#pragma once -#ifndef PSSK_H -#define PSSK_H +#ifndef PSSK_H_ +#define PSSK_H_ //gudhi include #include @@ -138,7 +137,7 @@ void PSSK::construct( const std::vector< std::pair >& intervals_ std::cerr << "y_grid : " << y_grid << std::endl; } - //x_grid and y_grid gives a center of the kernel. We want to have its lower left cordner. To get this, we need to shift x_grid and y_grid by a grid diameter. + //x_grid and y_grid gives a center of the kernel. We want to have its lower left corner. To get this, we need to shift x_grid and y_grid by a grid diameter. x_grid -= filter.size()/2; y_grid -= filter.size()/2; //note that the numbers x_grid and y_grid may be negative. @@ -174,8 +173,8 @@ void PSSK::construct( const std::vector< std::pair >& intervals_ } }//construct +} //namespace Persistence_representations +} //namespace Gudhi -#endif -}//namespace Gudhi_stat -}//namespace Gudhi +#endif // PSSK_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h index 59e58e41..a20702ff 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h +++ b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef Persistence_heat_maps_H -#define Persistence_heat_maps_H +#ifndef PERSISTENCE_HEAT_MAPS_H_ +#define PERSISTENCE_HEAT_MAPS_H_ //standard include #include @@ -69,7 +69,7 @@ std::vector< std::vector > create_Gaussian_filter( size_t pixel_radius , if ( dbg ) { - std::cerr << "Kernel initalize \n"; + std::cerr << "Kernel initialize \n"; std::cerr << "pixel_radius : " << pixel_radius << std::endl; std::cerr << "kernel.size() : " << kernel.size() << std::endl; getchar(); @@ -114,7 +114,7 @@ std::vector< std::vector > create_Gaussian_filter( size_t pixel_radius , /* -* There are various options to scale the poits depending on their location. One can for instance: +* There are various options to scale the points depending on their location. One can for instance: * (1) do nothing (scale all of them with the weight 1), as in the function constant_function * (2) Scale them by the distance to the diagonal. This is implemented in function * (3) Scale them with the square of their distance to diagonal. This is implemented in function @@ -123,8 +123,8 @@ std::vector< std::vector > create_Gaussian_filter( size_t pixel_radius , /** - * This is one of a scaling functions used to weight poits depending on their persistence and/or location in the diagram. - * This particular functiona is a finction which always assign value 1 to a point in the diagram. + * This is one of a scaling functions used to weight points depending on their persistence and/or location in the diagram. + * This particular functionality is a function which always assign value 1 to a point in the diagram. **/ class constant_scaling_function { @@ -137,7 +137,7 @@ public: /** - * This is one of a scaling functions used to weight poits depending on their persistence and/or location in the diagram. + * This is one of a scaling functions used to weight points depending on their persistence and/or location in the diagram. * The scaling given by this function to a point (b,d) is Euclidean distance of (b,d) from diagonal. **/ class distance_from_diagonal_scaling @@ -151,7 +151,7 @@ public: }; /** - * This is one of a scaling functions used to weight poits depending on their persistence and/or location in the diagram. + * This is one of a scaling functions used to weight points depending on their persistence and/or location in the diagram. * The scaling given by this function to a point (b,d) is a square of Euclidean distance of (b,d) from diagonal. **/ class squared_distance_from_diagonal_scaling @@ -164,7 +164,7 @@ public: }; /** - * This is one of a scaling functions used to weight poits depending on their persistence and/or location in the diagram. + * This is one of a scaling functions used to weight points depending on their persistence and/or location in the diagram. * The scaling given by this function to a point (b,d) is an arctan of a persistence of a point (i.e. arctan( b-d ). **/ class arc_tan_of_persistence_of_point @@ -177,7 +177,7 @@ public: }; /** - * This is one of a scaling functions used to weight poits depending on their persistence and/or location in the diagram. + * This is one of a scaling functions used to weight points depending on their persistence and/or location in the diagram. * This scaling function do not only depend on a point (p,d) in the diagram, but it depends on the whole diagram. * The longest persistence pair get a scaling 1. Any other pair get a scaling belong to [0,1], which is proportional * to the persistence of that pair. @@ -196,14 +196,19 @@ private: /** - * This class implements the following concepts: Vectorized_topological_data, Topological_data_with_distances, Real_valued_topological_data, Topological_data_with_averages, Topological_data_with_scalar_product -**/ + * \class Persistence_heat_maps Persistence_heat_maps.h gudhi/Persistence_heat_maps.h + * \brief A class implementing persistence heat maps. + * + * \ingroup Persistence_representations +**/ + +// This class implements the following concepts: Vectorized_topological_data, Topological_data_with_distances, Real_valued_topological_data, Topological_data_with_averages, Topological_data_with_scalar_product template class Persistence_heat_maps { public: /** - * The default constructor. A scaling function from the diagonal is set up to a constant function. The image is not erased below the diagonal. The gaussian have diameter 5. + * The default constructor. A scaling function from the diagonal is set up to a constant function. The image is not erased below the diagonal. The Gaussian have diameter 5. **/ Persistence_heat_maps() { @@ -217,7 +222,7 @@ public: /** * Construction that takes at the input the following parameters: * (1) A vector of pairs of doubles (representing persistence intervals). 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), + * (2) a Gaussian filter generated by create_Gaussian_filter filter (the default value of this variable 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, @@ -226,12 +231,12 @@ public: Persistence_heat_maps( const std::vector< std::pair< double,double > > & interval , 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() ); /** - * Construction that takes at the input a name of a file with persistence intervals, a filter (radius 5 by default), a scaling function (constant by default), a boolean value which determines if the area of image below diagonal should, or should not be erased (should by default). The next parameter is the number of pixels in each direction (set to 1000 by default). and min and max values of images (both set to std::numeric_limits::max() by defaulet. If this is the case, the program will pick the right values based on the data). + * Construction that takes at the input a name of a file with persistence intervals, a filter (radius 5 by default), a scaling function (constant by default), a boolean value which determines if the area of image below diagonal should, or should not be erased (should by default). The next parameter is the number of pixels in each direction (set to 1000 by default) and min and max values of images (both set to std::numeric_limits::max() by default. If this is the case, the program will pick the right values based on the data). **/ /** * 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_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), + * (1) A name of a file with persistence intervals. The file should be readable by the function read_persistence_intervals_in_one_dimension_from_file. All other parameters are optional. They are: + * (2) a Gaussian filter generated by create_Gaussian_filter filter (the default value of this variable 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, @@ -259,14 +264,14 @@ public: //put to file subroutine /** - * The function outputs the perssitence image to a text file. The format as follow: + * The function outputs the persistence image to a text file. The format as follow: * In the first line, the values min and max of the image are stored * In the next lines, we have the persistence images in a form of a bitmap image. **/ void print_to_file( const char* filename )const; /** - * A function that load a heat map from file to the current object (and arase qhatever was stored in the current object before). + * A function that load a heat map from file to the current object (and erase whatever was stored in the current object before). **/ void load_from_file( const char* filename ); @@ -347,7 +352,7 @@ public: /** - * A function to generate a gnuplot script to vizualize the persistent image. + * A function to generate a gnuplot script to visualize the persistent image. **/ void plot( const char* filename )const; @@ -474,7 +479,7 @@ public: //Implementations of functions for various concepts. /** - * This function produce a vector of doubles based on a persisence heat map. It is required in a concept Vectorized_topological_data + * This function produce a vector of doubles based on a persistence heat map. It is required in a concept Vectorized_topological_data */ std::vector vectorize( int number_of_function )const; /** @@ -486,9 +491,9 @@ public: } /** - * This function is required by the Real_valued_topological_data concept. It returns various projections od the persistence heat map to a real line. - * At the moment this function is not tested, since it is quite likelly to be changed in the future. Given this, when using it, keep in mind that it - * will be most likelly changed in the next versions. + * This function is required by the Real_valued_topological_data concept. It returns various projections on the persistence heat map to a real line. + * At the moment this function is not tested, since it is quite likely to be changed in the future. Given this, when using it, keep in mind that it + * will be most likely changed in the next versions. **/ double project_to_R( int number_of_function )const; /** @@ -515,7 +520,7 @@ public: /** * A function to compute scalar product of persistence heat maps. - * The parameter of this functionis a const reference to an object of a class Persistence_heat_maps. + * The parameter of this function is a const reference to an object of a class Persistence_heat_maps. * This function is required in Topological_data_with_scalar_product concept. **/ double compute_scalar_product( const Persistence_heat_maps& second_ )const; @@ -559,7 +564,6 @@ protected: } //data - //double (*scalling_function_with_respect_to_distance_from_diagonal)( const std::pair< double , double >& point_in_diagram ); Scalling_of_kernels f; bool erase_below_diagonal; double min_; @@ -583,7 +587,7 @@ void Persistence_heat_maps::construct( const std::vector< s if ( min_ == max_ ) { - if (dbg)std::cerr << "min and max parameters will be etermined based on intervals \n"; + if (dbg)std::cerr << "min and max parameters will be determined based on intervals \n"; //in this case, we want the program to set up the min_ and max_ values by itself. min_ = std::numeric_limits::max(); max_ = -std::numeric_limits::max(); @@ -636,7 +640,7 @@ void Persistence_heat_maps::construct( const std::vector< s std::cerr << "y_grid : " << y_grid << std::endl; } - //x_grid and y_grid gives a center of the kernel. We want to have its lower left cordner. To get this, we need to shift x_grid and y_grid by a grid diameter. + //x_grid and y_grid gives a center of the kernel. We want to have its lower left corner. To get this, we need to shift x_grid and y_grid by a grid diameter. x_grid -= filter.size()/2; y_grid -= filter.size()/2; //note that the numbers x_grid and y_grid may be negative. @@ -711,11 +715,6 @@ Persistence_heat_maps::Persistence_heat_maps( const char* f { intervals_ = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); } - //std::cerr << "intervals_.size() : " << intervals_.size() << std::endl; - //for ( size_t i = 0 ; i != intervals_.size() ; ++i ) - //{ - // std::cerr << intervals_[i].first << " " << intervals_[i].second << std::endl; - //} this->construct( intervals_ , filter, erase_below_diagonal , number_of_pixels , min_ , max_ ); this->set_up_parameters_for_basic_classes(); } @@ -956,11 +955,11 @@ double Persistence_heat_maps::distance( const Persistence_h //first we need to check if (*this) and second are defined on the same domain and have the same dimensions: if ( !this->check_if_the_same(second) ) { - std::cerr << "The persistence images are of noncompatible sizes. We cannot therefore compute distance between them. The program will now terminate"; - throw "The persistence images are of noncompatible sizes. We cannot therefore compute distance between them. The program will now terminate"; + std::cerr << "The persistence images are of non compatible sizes. We cannot therefore compute distance between them. The program will now terminate"; + throw "The persistence images are of non compatible sizes. We cannot therefore compute distance between them. The program will now terminate"; } - //if we are here, we know that the two persistence iomages are defined on the same domain, so we can start computing their distances: + //if we are here, we know that the two persistence images are defined on the same domain, so we can start computing their distances: double distance = 0; if ( power < std::numeric_limits::max() ) @@ -1016,11 +1015,11 @@ double Persistence_heat_maps::compute_scalar_product( const //first we need to check if (*this) and second are defined on the same domain and have the same dimensions: if ( !this->check_if_the_same(second) ) { - std::cerr << "The persistence images are of noncompatible sizes. We cannot therefore compute distance between them. The program will now terminate"; - throw "The persistence images are of noncompatible sizes. We cannot therefore compute distance between them. The program will now terminate"; + std::cerr << "The persistence images are of non compatible sizes. We cannot therefore compute distance between them. The program will now terminate"; + throw "The persistence images are of non compatible sizes. We cannot therefore compute distance between them. The program will now terminate"; } - //if we are here, we know that the two persistence iomages are defined on the same domain, so we can start computing their scalar product: + //if we are here, we know that the two persistence images are defined on the same domain, so we can start computing their scalar product: double scalar_prod = 0; for ( size_t i = 0 ; i != this->heat_map.size() ; ++i ) { @@ -1035,8 +1034,8 @@ double Persistence_heat_maps::compute_scalar_product( const -}//namespace Gudhi_stat -}//namespace Gudhi +} // namespace Persistence_representations +} // namespace Gudhi -#endif +#endif // PERSISTENCE_HEAT_MAPS_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h index 792c0a28..40c24670 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef Persistence_intervals_H_ -#define Persistence_intervals_H_ +#ifndef PERSISTENCE_INTERVALS_H_ +#define PERSISTENCE_INTERVALS_H_ //gudhi include #include @@ -48,14 +48,14 @@ class Persistence_intervals { 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) + * 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 double (or convertible 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. + * * The second parameter of a constructor is a dimension of intervals to be read from a file. If your file contains only birth-death pairs, use the default value. **/ 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 + * 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 elements of pairs * are smaller or equal the second elements of pairs. **/ Persistence_intervals( const std::vector< std::pair< double,double > >& intervals ); @@ -102,15 +102,15 @@ public: std::vector< std::pair > dominant_intervals( size_t where_to_cut = 100 )const; /** - * 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). + * Procedure to compute a histogram of interval'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 > histogram_of_lengths( size_t number_of_bins = 10 )const; /** - * Based on a histogram of intervals lengts computed by the function histogram_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. + * Based on a histogram of intervals lengths computed by the function histogram_of_lengths H the procedure below computes the cumulative histogram. The i-th position of the resulting histogram + * is the sum of values of H for the positions from 0 to i. **/ std::vector< size_t > cumulative_histogram_of_lengths( size_t number_of_bins = 10 )const; @@ -127,13 +127,13 @@ public: std::vector< double > cumulative_characteristic_function_of_diagram( double x_min , double x_max , size_t number_of_bins = 10 )const; /** - * 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. + * Compute the function 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()const; /** - *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 + *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 parameter 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 )const; @@ -188,12 +188,9 @@ public: std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '" << nameStr << "' in gnuplot to visualize." << std::endl; } - - - /** - * Retun numbr of points in the diagram. + * Return number of points in the diagram. **/ size_t size()const{return this->intervals.size();} @@ -207,25 +204,12 @@ public: } - - - - - - - - - - - - - //Implementations of functions for various concepts. /** - * 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 + * This is a simple function projecting the persistence intervals to a real number. The function we use here is a sum of squared lengths of intervals. It can be naturally interpreted as * sum of step function, where the step hight it equal to the length of the interval. - * At the moment this function is not tested, since it is quite likelly to be changed in the future. Given this, when using it, keep in mind that it - * will be most likelly changed in the next versions. + * At the moment this function is not tested, since it is quite likely to be changed in the future. Given this, when using it, keep in mind that it + * will be most likely changed in the next versions. **/ double project_to_R( int number_of_function )const; /** @@ -237,14 +221,14 @@ public: } /** - * Return a familly of vectors obtained from the persistence diagram. The i-th vector consist of the lenfth of i dominant persistence intervals. + * Return a family of vectors obtained from the persistence diagram. The i-th vector consist of the length of i dominant persistence intervals. **/ std::vector vectorize( int number_of_function )const { return this->length_of_dominant_intervals( number_of_function ); } /** - * This function return the number of functions that allows vectorization of a persisence diagram. It is required in a concept Vectorized_topological_data. + * This function return the number of functions that allows vectorization of a persistence diagram. It is required in a concept Vectorized_topological_data. **/ size_t number_of_vectorize_functions()const { @@ -252,19 +236,7 @@ public: } //end of implementation of functions needed for concepts. - //end of implementation of functions needed for concepts. - - - - - - - - - - - - + //For visualization use output from vectorize and build histograms. std::vector< std::pair< double,double > > output_for_visualization() @@ -289,37 +261,6 @@ protected: Persistence_intervals::Persistence_intervals( const char* filename , unsigned dimension ) { - //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 ) - // { - // std::cerr << "Adding interval [ " << first << " , " << second << " ]\n"; - // getchar(); - // } - //} - //in.close(); if ( dimension == std::numeric_limits::max() ) { this->intervals = read_persistence_intervals_in_one_dimension_from_file( filename ); @@ -490,7 +431,6 @@ std::vector< double > Persistence_intervals::characteristic_function_of_diagram( { 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 ) { std::cerr << "Result at this stage \n"; @@ -499,7 +439,6 @@ std::vector< double > Persistence_intervals::characteristic_function_of_diagram( std::cerr << result[aa] << " "; } std::cerr << std::endl; - //getchar(); } } return result; @@ -599,8 +538,7 @@ std::vector< double > Persistence_intervals::k_n_n( size_t k , size_t where_to_c { 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: + //also add a distance from this guy to diagonal: 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; @@ -694,7 +632,7 @@ double Persistence_intervals::project_to_R( int number_of_function )const } -}//namespace gudhi stat -}//namespace gudhi +} // namespace Persistence_representations +} // namespace gudhi -#endif +#endif // PERSISTENCE_INTERVALS_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h index 7ef711e9..0da58399 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef Persistence_intervals_WITH_DISTANCES_H_ -#define Persistence_intervals_WITH_DISTANCES_H_ +#ifndef PERSISTENCE_INTERVALS_WITH_DISTANCES_H_ +#define PERSISTENCE_INTERVALS_WITH_DISTANCES_H_ #include @@ -59,7 +59,7 @@ public: }; -}//namespace gudhi stat -}//namespace gudhi +} // namespace Persistence_representations +} // namespace gudhi -#endif +#endif // PERSISTENCE_INTERVALS_WITH_DISTANCES_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape.h b/src/Persistence_representations/include/gudhi/Persistence_landscape.h index 9a177b60..642bba84 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -21,8 +21,8 @@ */ -#ifndef Persistence_landscapes_H -#define Persistence_landscapes_H +#ifndef PERSISTENCE_LANDSCAPE_H_ +#define PERSISTENCE_LANDSCAPE_H_ //standard include #include @@ -48,7 +48,7 @@ namespace Persistence_representations -//predeclaration +// pre declaration class Persistence_landscape; template < typename operation > Persistence_landscape operation_on_pair_of_landscapes( const Persistence_landscape& land1 , const Persistence_landscape& land2 ); @@ -56,12 +56,25 @@ Persistence_landscape operation_on_pair_of_landscapes( const Persistence_landsca /** - * A clas implementing persistence landascpes data structures. For theroretical desciritpion, please consult a paper ''Statistical topological data analysis using persistence landscapes'' by Peter Bubenik. - * For details of algorithms, please consult ''A persistence landscapes toolbox for topological statistics'' by Peter Bubenik and Pawel Dlotko. - * Persistence landscapes allow vertorization, computations of distances, computations of projections to Real, computations of averages and scalar products. Therefore they implement suitable interfaces. - * It implements the following concepts: Vectorized_topological_data, Topological_data_with_distances, Real_valued_topological_data, Topological_data_with_averages, Topological_data_with_scalar_product - * Note that at the moment, due to roundoff errors during the construction of persistence landscapes, elements which are different by 0.000005 are considered the same. If the scale in your persistence diagrams - * is comparable to this value, please rescale them before use this code. + * \class Persistence_landscape Persistence_landscape.h gudhi/Persistence_landscape.h + * \brief A class implementing persistence landscapes data structures. + * + * \ingroup Persistence_representations + * + * \details + * For theoretical description, please consult Statistical topological data analysis using persistence + * landscapes\cite bubenik_landscapes_2015 , and for details of algorithms, + * A persistence landscapes toolbox for topological statistics\cite bubenik_dlotko_landscapes_2016. + * + * Persistence landscapes allow vectorization, computations of distances, computations of projections to Real, + * computations of averages and scalar products. Therefore they implement suitable interfaces. + * It implements the following concepts: Vectorized_topological_data, Topological_data_with_distances, + * Real_valued_topological_data, Topological_data_with_averages, Topological_data_with_scalar_product + * + * Note that at the moment, due to rounding errors during the construction of persistence landscapes, elements which + * are different by 0.000005 are considered the same. If the scale in your persistence diagrams is comparable to this + * value, please rescale them before use this code. + * **/ class Persistence_landscape { @@ -169,7 +182,7 @@ public: } /** - * An operator * that allows multipilication of a landscape by a real number. + * An operator * that allows multiplication of a landscape by a real number. **/ friend Persistence_landscape operator*( const Persistence_landscape& first , double con ) { @@ -177,7 +190,7 @@ public: } /** - * An operator * that allows multipilication of a landscape by a real number (order of parameters swapped). + * An operator * that allows multiplication of a landscape by a real number (order of parameters swapped). **/ friend Persistence_landscape operator*( double con , const Persistence_landscape& first ) { @@ -297,7 +310,6 @@ public: *\private Computations of \f$L^{\infty}\f$ distance between two landscapes. **/ friend double compute_max_norm_distance_of_landscapes( const Persistence_landscape& first, const Persistence_landscape& second ); - //friend double compute_max_norm_distance_of_landscapes( const Persistence_landscape& first, const Persistence_landscape& second , unsigned& nrOfLand , double&x , double& y1, double& y2 ); /** @@ -308,7 +320,7 @@ public: /** - * Function to compute absolute value of a PL function. The representation of persistence landscapes allow to store general PL-function. When computing distance betwen two landscapes, we compute difference between + * Function to compute absolute value of a PL function. The representation of persistence landscapes allow to store general PL-function. When computing distance between two landscapes, we compute difference between * them. In this case, a general PL-function with negative value can appear as a result. Then in order to compute distance, we need to take its absolute value. This is the purpose of this procedure. **/ Persistence_landscape abs(); @@ -319,7 +331,7 @@ public: size_t size()const{return this->land.size(); } /** - * Computate maximal value of lambda-level landscape. + * Compute maximal value of lambda-level landscape. **/ double find_max( unsigned lambda )const; @@ -328,27 +340,13 @@ public: **/ friend double compute_inner_product( const Persistence_landscape& l1 , const Persistence_landscape& l2 ); - - - - - - - - - - - - - - //Implementations of functions for various concepts. /** * The number of projections to R is defined to the number of nonzero landscape functions. I-th projection is an integral of i-th landscape function over whole R. * This function is required by the Real_valued_topological_data concept. - * At the moment this function is not tested, since it is quite likelly to be changed in the future. Given this, when using it, keep in mind that it - * will be most likelly changed in the next versions. + * At the moment this function is not tested, since it is quite likely to be changed in the future. Given this, when using it, keep in mind that it + * will be most likely changed in the next versions. **/ double project_to_R( int number_of_function )const { @@ -382,7 +380,7 @@ public: return v; } /** - * This function return the number of functions that allows vectorization of persistence laandscape. It is required in a concept Vectorized_topological_data. + * This function return the number of functions that allows vectorization of persistence landscape. It is required in a concept Vectorized_topological_data. **/ size_t number_of_vectorize_functions()const { @@ -404,8 +402,8 @@ public: { nextLevelMerge[i] = to_average[i]; } - bool is_this_first_level = true;//in the loop, we will create dynamically a unmber of intermediate complexes. We have to clean that up, but we cannot erase the initial andscapes we have - //to average. In this case, we simply check if the nextLevelMerge are the input landscapes or the ones created in that loop by usig this extra variable. + bool is_this_first_level = true;//in the loop, we will create dynamically a number of intermediate complexes. We have to clean that up, but we cannot erase the initial landscapes we have + //to average. In this case, we simply check if the nextLevelMerge are the input landscapes or the ones created in that loop by using this extra variable. while ( nextLevelMerge.size() != 1 ) { @@ -446,7 +444,7 @@ public: /** * A function to compute distance between persistence landscape. - * The parameter of this functionis a Persistence_landscape. + * The parameter of this function is a Persistence_landscape. * This function is required in Topological_data_with_distances concept. * For max norm distance, set power to std::numeric_limits::max() **/ @@ -465,7 +463,7 @@ public: /** * A function to compute scalar product of persistence landscapes. - * The parameter of this functionis a Persistence_landscape. + * The parameter of this function is a Persistence_landscape. * This function is required in Topological_data_with_scalar_product concept. **/ double compute_scalar_product( const Persistence_landscape& second )const @@ -473,25 +471,6 @@ public: return compute_inner_product( (*this) , second ); } //end of implementation of functions needed for concepts. - - - // - // This procedure returns x-range of a given level persistence landscape. If a default value is used, the x-range - //of 0th level landscape is given (and this range contains the ranges of all other landscapes). - // - //std::pair< double , double > get_x_range( size_t level = 0 )const - //{ - // std::pair< double , double > result; - // if ( level < this->land.size() ) - // { - // result = std::make_pair( this->land[level][1].first , this->land[level][ this->land[level].size() - 2 ].first ); - // } - // else - // { - // result = std::make_pair( 0,0 ); - // } - // return result; - //} /** * This procedure returns y-range of a given level persistence landscape. If a default value is used, the y-range @@ -582,7 +561,6 @@ bool Persistence_landscape::operator == ( const Persistence_landscape& rhs )con { if ( !( almost_equal(this->land[level][i].first , rhs.land[level][i].first) && almost_equal(this->land[level][i].second , rhs.land[level][i].second) ) ) { - //std::cerr<< this->land[level][i].first << " , " << rhs.land[level][i].first << " and " << this->land[level][i].second << " , " << rhs.land[level][i].second << std::endl; if (operatorEqualDbg)std::cerr << "this->land[level][i] : " << this->land[level][i].first << " " << this->land[level][i].second << "\n"; if (operatorEqualDbg)std::cerr << "rhs.land[level][i] : " << rhs.land[level][i].first << " " << rhs.land[level][i].second << "\n"; if (operatorEqualDbg)std::cerr << "3\n"; @@ -768,7 +746,7 @@ double Persistence_landscape::compute_integral_of_landscape()const { for ( size_t nr = 2 ; nr != this->land[i].size()-1 ; ++nr ) { - //it suffices to compute every planar integral and then sum them ap for each lambda_n + //it suffices to compute every planar integral and then sum them up for each lambda_n result += 0.5*( this->land[i][nr].first - this->land[i][nr-1].first )*(this->land[i][nr].second + this->land[i][nr-1].second); } } @@ -780,7 +758,7 @@ double Persistence_landscape::compute_integral_of_a_level_of_a_landscape( size_t double result = 0; if ( level >= this->land.size() ) { - //this landscape function is constantly equal 0, so is the intergral. + //this landscape function is constantly equal 0, so is the integral. return result; } //also negative landscapes are assumed to be zero. @@ -788,7 +766,7 @@ double Persistence_landscape::compute_integral_of_a_level_of_a_landscape( size_t for ( size_t nr = 2 ; nr != this->land[ level ].size()-1 ; ++nr ) { - //it suffices to compute every planar integral and then sum them ap for each lambda_n + //it suffices to compute every planar integral and then sum them up for each lambda_n result += 0.5*( this->land[ level ][nr].first - this->land[ level ][nr-1].first )*(this->land[ level ][nr].second + this->land[ level ][nr-1].second); } @@ -826,7 +804,6 @@ double Persistence_landscape::compute_integral_of_landscape( double p )const std::cout << "result : " << result << std::endl; } } - //if (compute_integral_of_landscapeDbg) std::cin.ignore(); } return result; } @@ -953,7 +930,7 @@ Persistence_landscape Persistence_landscape::abs() for ( size_t i = 1 ; i != this->land[level].size() ; ++i ) { if ( AbsDbg ){std::cout << "this->land[" << level << "][" << i << "] : " << this->land[level][i].first << " " << this->land[level][i].second << std::endl;} - //if a line segment between this->land[level][i-1] and this->land[level][i] crosses the x-axis, then we have to add one landscape point t oresult + //if a line segment between this->land[level][i-1] and this->land[level][i] crosses the x-axis, then we have to add one landscape point t o result if ( (this->land[level][i-1].second)*(this->land[level][i].second) < 0 ) { double zero = find_zero_of_a_line_segment_between_those_two_points( this->land[level][i-1] , this->land[level][i] ); @@ -1025,7 +1002,7 @@ void Persistence_landscape::load_landscape_from_file( const char* filename ) this->land.clear(); - //this constructor reads persistence landscape form a file. This file have to be created by this software beforehead + //this constructor reads persistence landscape form a file. This file have to be created by this software before head std::ifstream in; in.open( filename ); if ( !in.good() ) @@ -1049,7 +1026,7 @@ void Persistence_landscape::load_landscape_from_file( const char* filename ) lineSS >> beginn; lineSS >> endd; landscapeAtThisLevel.push_back( std::make_pair( beginn , endd ) ); - if (dbg){std::cerr << "Reading a pont : " << beginn << " , " << endd << std::endl;} + if (dbg){std::cerr << "Reading a point : " << beginn << " , " << endd << std::endl;} } else { @@ -1117,7 +1094,6 @@ Persistence_landscape operation_on_pair_of_landscapes ( const Persistence_landsc std::cerr << "land2.land[" << i << "].size() : " << land2.land[i].size() << std::endl; std::cout << "land1.land[i][p].first : " << land1.land[i][p].first << "\n"; std::cout << "land2.land[i][q].first : " << land2.land[i][q].first << "\n"; - //getchar(); } if ( land1.land[i][p].first < land2.land[i][q].first ) @@ -1126,7 +1102,6 @@ Persistence_landscape operation_on_pair_of_landscapes ( const Persistence_landsc { std::cout << "first \n"; std::cout << " function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) : "<< function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) << "\n"; - //std::cout << "oper( " << land1.land[i][p].second <<"," << function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) << " : " << oper( land1.land[i][p].second , function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) ) << "\n"; } lambda_n.push_back( std::make_pair( @@ -1242,7 +1217,7 @@ double compute_maximal_distance_non_symmetric( const Persistence_landscape& pl1, } int p2Count = 0; - for ( size_t i = 1 ; i != pl1.land[level].size()-1 ; ++i ) //w tym przypadku nie rozwarzam punktow w nieskocznosci + for ( size_t i = 1 ; i != pl1.land[level].size()-1 ; ++i ) // In this case, I consider points at the infinity { while ( true ) { @@ -1488,11 +1463,8 @@ void Persistence_landscape::plot( const char* filename, double xRangeBegin , do std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '" << nameStr << "' in gnuplot to visualize." << std::endl; } +} // namespace Persistence_representations +} // namespace gudhi - -}//namespace gudhi stat -}//namespace gudhi - - -#endif +#endif // PERSISTENCE_LANDSCAPE_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h index 5703163a..d663b543 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -21,8 +21,8 @@ * along with this program. If not, see . **/ -#ifndef Persistence_landscape_on_grid_H_ -#define Persistence_landscape_on_grid_H_ +#ifndef PERSISTENCE_LANDSCAPE_ON_GRID_H_ +#define PERSISTENCE_LANDSCAPE_ON_GRID_H_ //standard include @@ -50,16 +50,25 @@ namespace Gudhi namespace Persistence_representations { -//predeclaration +// pre declaration class Persistence_landscape_on_grid; template < typename operation > Persistence_landscape_on_grid operation_on_pair_of_landscapes_on_grid( const Persistence_landscape_on_grid& land1 , const Persistence_landscape_on_grid& land2 ); /** - * A clas implementing persistence landascpes by approximating them on a collection of grid points. * Persistence landscapes on grid allow vertorization, computations of distances, computations - * of projections to Real, computations of averages and scalar products. Therefore they implement suitable interfaces. - * It implements the following concepts: Vectorized_topological_data, Topological_data_with_distances, Real_valued_topological_data, Topological_data_with_averages, Topological_data_with_scalar_product - * Note that at the moment, due to roundoff errors during the construction of persistence landscapes on a grid, elements which are different by 0.000005 are considered the same. If the scale in your persistence diagrams + * \class Persistence_landscape_on_grid Persistence_landscape_on_grid.h gudhi/Persistence_landscape_on_grid.h + * \brief A class implementing persistence landscapes by approximating them on a collection of grid points. + * + * \ingroup Persistence_representations + * + * \details + * Persistence landscapes on grid allows vectorization, computations of distances, computations of projections to Real, + * computations of averages and scalar products. Therefore they implement suitable interfaces. + * It implements the following concepts: Vectorized_topological_data, Topological_data_with_distances, + * Real_valued_topological_data, Topological_data_with_averages, Topological_data_with_scalar_product + * + * Note that at the moment, due to rounding errors during the construction of persistence landscapes on a grid, + * elements which are different by 0.000005 are considered the same. If the scale in your persistence diagrams * is comparable to this value, please rescale them before use this code. **/ @@ -89,14 +98,14 @@ 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. The additional parameters of this procedure are: ranges of grid, resoltion of a grid + * 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, resolution 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 , 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 + * 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, resolution 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_ , unsigned short dimension_ = std::numeric_limits::max() ); @@ -104,16 +113,16 @@ 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. 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. + * 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 resolution of a grid and the number of landscape + * functions to be created. The remaining parameters are calculated based on data. **/ 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 last parameter is the dimension + * 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 resolution 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. + * The remaining parameters are calculated based on data. **/ Persistence_landscape_on_grid(const char* filename , size_t number_of_points , unsigned short dimension = std::numeric_limits::max() ); @@ -258,7 +267,7 @@ public: if ( dbg ) { std::cerr << "Increasing result by : " << value_to_add << std::endl; - std::cerr << "restult : " << result << std::endl; + std::cerr << "result : " << result << std::endl; getchar(); } previous_x = current_x; @@ -311,9 +320,9 @@ public: std::cerr << "This is a procedure compute_value_at_a_given_point \n"; std::cerr << "level : " << level << std::endl; std::cerr << "x : " << x << std::endl; - std::cerr << "psoition : " << position << std::endl; + std::cerr << "position : " << position << std::endl; } - //check if we are not exacly in the grid point: + //check if we are not exactly in the grid point: if ( almost_equal( position*dx+ this->grid_min , x) ) { if ( this->values_of_landscapes[position].size() < level ) @@ -389,7 +398,7 @@ public: } /** - * An operator * that allows multipilication of a landscape by a real number. + * An operator * that allows multiplication of a landscape by a real number. **/ friend Persistence_landscape_on_grid operator*( const Persistence_landscape_on_grid& first , double con ) { @@ -397,7 +406,7 @@ public: } /** - * An operator * that allows multipilication of a landscape by a real number (order of parameters swapped). + * An operator * that allows multiplication of a landscape by a real number (order of parameters swapped). **/ friend Persistence_landscape_on_grid operator*( double con , const Persistence_landscape_on_grid& first ) { @@ -413,7 +422,7 @@ public: } /** - * Operator +=. The second parameter is persistnece landwscape. + * Operator +=. The second parameter is persistence landscape. **/ Persistence_landscape_on_grid operator += ( const Persistence_landscape_on_grid& rhs ) { @@ -422,7 +431,7 @@ public: } /** - * Operator -=. The second parameter is persistnece landwscape. + * Operator -=. The second parameter is persistence landscape. **/ Persistence_landscape_on_grid operator -= ( const Persistence_landscape_on_grid& rhs ) { @@ -458,7 +467,7 @@ public: bool dbg = true; if ( this->values_of_landscapes.size() != rhs.values_of_landscapes.size() ) { - if (dbg) std::cerr << "values_of_landscapes of incompatable sizes\n"; + if (dbg) std::cerr << "values_of_landscapes of incompatible sizes\n"; return false; } if ( !almost_equal( this->grid_min , rhs.grid_min ) ) @@ -546,28 +555,6 @@ public: std::pair< double , double > get_x_range( size_t level = 0 )const { return std::make_pair( this->grid_min , this->grid_max ); - //std::pair< double , double > result; - //if ( level < this->land.size() ) - //{ - // double dx = (this->grid_max - this->grid_min)/(double)this->values_of_landscapes.size(); - // size_t first_nonzero = 0; - // while ( (first_nonzero != this->values_of_landscapes.size()) && (this->values_of_landscapes[level][first_nonzero] == 0) )++first_nonzero; - // - // if ( first_nonzero == 0 ) - // { - // return std::make_pair( 0,0 );//this landscape is empty. - // } - // - // size_t last_nonzero = 0; - // while ( (last_nonzero != 0) && (this->values_of_landscapes[level][last_nonzero] == 0) )--last_nonzero; - // - // result = std::make_pair( this->grid_min +first_nonzero*dx , this->grid_max - last_nonzero*dx ); - //} - //else - //{ - // result = std::make_pair( 0,0 ); - //} - //return result; } /** @@ -577,16 +564,6 @@ public: std::pair< double , double > get_y_range( size_t level = 0 )const { return this->compute_minimum_maximum(); - //std::pair< double , double > result; - //if ( level < this->land.size() ) - //{ - // result = this->compute_minimum_maximum() - //} - //else - //{ - // result = std::make_pair( 0,0 ); - //} - //return result; } /** @@ -629,13 +606,11 @@ public: * Computations of \f$L^{\infty}\f$ distance between two landscapes. **/ friend double compute_max_norm_distance_of_landscapes( const Persistence_landscape_on_grid& first, const Persistence_landscape_on_grid& second ); - //friend double compute_max_norm_distance_of_landscapes( const Persistence_landscape_on_grid& first, const Persistence_landscape_on_grid& second , unsigned& nrOfLand , double&x , double& y1, double& y2 ); - /** - * Function to compute absolute value of a PL function. The representation of persistence landscapes allow to store general PL-function. When computing distance betwen two landscapes, we compute difference between + * Function to compute absolute value of a PL function. The representation of persistence landscapes allow to store general PL-function. When computing distance between two landscapes, we compute difference between * them. In this case, a general PL-function with negative value can appear as a result. Then in order to compute distance, we need to take its absolute value. This is the purpose of this procedure. **/ void abs() @@ -655,7 +630,7 @@ public: size_t size()const{return this->number_of_nonzero_levels(); } /** - * Computate maximal value of lambda-level landscape. + * Compute maximal value of lambda-level landscape. **/ double find_max( unsigned lambda )const { @@ -742,14 +717,14 @@ public: } //now, to compute the inner product in this interval we need to compute the integral of (ax+b)(cx+d) = acx^2 + (ad+bc)x + bd in the interval from previous_x to current_x: - //The integal is ac/3*x^3 + (ac+bd)/2*x^2 + bd*x + //The integral is ac/3*x^3 + (ac+bd)/2*x^2 + bd*x double added_value = (a*c/3*current_x*current_x*current_x + (a*d+b*c)/2*current_x*current_x + b*d*current_x)- (a*c/3*previous_x*previous_x*previous_x + (a*d+b*c)/2*previous_x*previous_x + b*d*previous_x); if ( dbg ) { - std::cerr << "Value of the integral on the left end ie : " << previous_x << " is : " << a*c/3*previous_x*previous_x*previous_x + (a*d+b*c)/2*previous_x*previous_x + b*d*previous_x << std::endl; + std::cerr << "Value of the integral on the left end i.e. : " << previous_x << " is : " << a*c/3*previous_x*previous_x*previous_x + (a*d+b*c)/2*previous_x*previous_x + b*d*previous_x << std::endl; std::cerr << "Value of the integral on the right end i.e. : " << current_x << " is " << a*c/3*current_x*current_x*current_x + (a*d+b*c)/2*current_x*current_x + b*d*current_x << std::endl; } @@ -775,7 +750,7 @@ public: /** * Computations of \f$L^{p}\f$ distance between two landscapes on a grid. p is the parameter of the procedure. * FIXME: Note that, due to the grid representation, the method below may give non--accurate results in case when the landscape P and Q the difference of which we want to compute - * are interxsecting. This is a consequence of a general way they are computed. In the future, an integral of absolute value of a difference of P and Q will be given as a separated + * are intersecting. This is a consequence of a general way they are computed. In the future, an integral of absolute value of a difference of P and Q will be given as a separated * function to fix that inaccuracy. **/ friend double compute_distance_of_landscapes_on_grid( const Persistence_landscape_on_grid& first, const Persistence_landscape_on_grid& second , double p ) @@ -819,7 +794,7 @@ public: else { result = lan.compute_integral_of_landscape(); - if (dbg){std::cerr << "integral, wihtout power : " << result << std::endl;getchar();} + if (dbg){std::cerr << "integral, without power : " << result << std::endl;getchar();} } //(\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) return pow( result , 1/(double)p ); @@ -830,45 +805,14 @@ public: return lan.compute_maximum(); } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //Functions that are needed for that class to implement the concept. /** * The number of projections to R is defined to the number of nonzero landscape functions. I-th projection is an integral of i-th landscape function over whole R. * This function is required by the Real_valued_topological_data concept. - * At the moment this function is not tested, since it is quite likelly to be changed in the future. Given this, when using it, keep in mind that it - * will be most likelly changed in the next versions. + * At the moment this function is not tested, since it is quite likely to be changed in the future. Given this, when using it, keep in mind that it + * will be most likely changed in the next versions. **/ double project_to_R( int number_of_function )const { @@ -884,8 +828,6 @@ public: } - - /** * This function produce a vector of doubles based on a landscape. It is required in a concept Vectorized_topological_data */ @@ -909,16 +851,13 @@ public: } /** - * This function return the number of functions that allows vectorization of persistence laandscape. It is required in a concept Vectorized_topological_data. + * This function return the number of functions that allows vectorization of persistence landscape. It is required in a concept Vectorized_topological_data. **/ size_t number_of_vectorize_functions()const { return number_of_functions_for_vectorization; } - - - /** * A function to compute averaged persistence landscape on a grid, based on vector of persistence landscapes on grid. @@ -932,7 +871,7 @@ public: this->values_of_landscapes .clear(); this->grid_min = this->grid_max = 0; - //if there is nothing to averate, then the average is a zero landscape. + //if there is nothing to average, then the average is a zero landscape. if ( to_average.size() == 0 )return; //now we need to check if the grids in all objects of to_average are the same: @@ -968,7 +907,7 @@ public: std::cerr << "We are considering the point : " << grid_point << " of the grid. In this point, there are at most : " << maximal_size_of_vector << " nonzero landscape functions \n"; } - //and compute an arythmetic average: + //and compute an arithmetic average: for ( size_t land_no = 0 ; land_no != to_average.size() ; ++land_no ) { //summing: @@ -989,7 +928,7 @@ public: /** * A function to compute distance between persistence landscape on a grid. - * The parameter of this functionis a Persistence_landscape_on_grid. + * The parameter of this function is a Persistence_landscape_on_grid. * This function is required in Topological_data_with_distances concept. * For max norm distance, set power to std::numeric_limits::max() **/ @@ -1007,7 +946,7 @@ public: /** * A function to compute scalar product of persistence landscape on a grid. - * The parameter of this functionis a Persistence_landscape_on_grid. + * The parameter of this function is a Persistence_landscape_on_grid. * This function is required in Topological_data_with_scalar_product concept. **/ double compute_scalar_product( const Persistence_landscape_on_grid& second ) @@ -1016,28 +955,9 @@ public: } //end of implementation of functions needed for concepts. - - - - - - - - - - - - - - - - - - - /** - * A function that returns values of landsapes. It can be used for vizualization + * A function that returns values of landscapes. It can be used for visualization **/ std::vector< std::vector< double > > output_for_visualization()const { @@ -1046,7 +966,7 @@ public: /** * function used to create a gnuplot script for visualization of landscapes. Over here we need to specify which landscapes do we want to plot. - * In addition, the user may specify the range (min and max) where landscape is plot. The fefault values for min and max are std::numeric_limits::max(). If the procedure detect those + * In addition, the user may specify the range (min and max) where landscape is plot. The default values for min and max are std::numeric_limits::max(). If the procedure detect those * values, it will determine the range so that the whole landscape is supported there. If at least one min or max value is different from std::numeric_limits::max(), then the values * provided by the user will be used. **/ @@ -1123,7 +1043,7 @@ void Persistence_landscape_on_grid::set_up_values_of_landscapes( const std::vect if ( grid_max_ <= grid_min_ ) { - throw "Wrong parameters of grid_min and grid_max given to the procedure. THe grid have negative, or zero size. The program will now terminate.\n"; + throw "Wrong parameters of grid_min and grid_max given to the procedure. The grid have negative, or zero size. The program will now terminate.\n"; } double dx = ( grid_max_ - grid_min_ )/(double)(number_of_points_); @@ -1174,7 +1094,7 @@ void Persistence_landscape_on_grid::set_up_values_of_landscapes( const std::vect if ( this->values_of_landscapes[i].size() == number_of_levels-1 ) { //this->values_of_landscapes[i].size() == number_of_levels - //in this case we need to create the heep. + //in this case we need to create the heap. std::make_heap (this->values_of_landscapes[i].begin(),this->values_of_landscapes[i].end()); } } @@ -1212,7 +1132,7 @@ void Persistence_landscape_on_grid::set_up_values_of_landscapes( const std::vect if ( this->values_of_landscapes[i].size() == number_of_levels-1 ) { //this->values_of_landscapes[i].size() == number_of_levels - //in this case we need to create the heep. + //in this case we need to create the heap. std::make_heap (this->values_of_landscapes[i].begin(),this->values_of_landscapes[i].end()); } } @@ -1225,7 +1145,7 @@ void Persistence_landscape_on_grid::set_up_values_of_landscapes( const std::vect if ( dbg ) { - std::cerr << "AAdding landscape value (going down) for a point : " << i << " equal : " << landscape_value << std::endl; + std::cerr << "Adding landscape value (going down) for a point : " << i << " equal : " << landscape_value << std::endl; } } landscape_value -= dx; @@ -1235,11 +1155,10 @@ void Persistence_landscape_on_grid::set_up_values_of_landscapes( const std::vect if ( number_of_levels != std::numeric_limits< unsigned >::max() ) { //in this case, vectors are used as heaps. And, since we want to have the smallest element at the top of - //each heap, we store mminus distances. To get if right at the end, we need to multiply each value + //each heap, we store minus distances. To get if right at the end, we need to multiply each value //in the heap by -1 to get real vector of distances. for ( size_t pt = 0 ; pt != this->values_of_landscapes.size() ; ++pt ) { - //std::cerr << this->values_of_landscapes[pt].size() <values_of_landscapes[pt].size() ; ++j ) { this->values_of_landscapes[pt][j] *= -1; @@ -1362,7 +1281,6 @@ void Persistence_landscape_on_grid::load_landscape_from_file( const char* filena //read a line of a file and convert it to a vector. std::vector< double > vv; std::getline(in, line); - //std::cerr << "Reading line : " << line << std::endl;getchar(); std::istringstream stream(line); while (stream >> number) { @@ -1485,7 +1403,7 @@ Persistence_landscape_on_grid operation_on_pair_of_landscapes_on_grid ( const Pe result.grid_min = land1.grid_min; result.grid_max = land1.grid_max; - //now we perorm the operations: + //now we perform the operations: for ( size_t grid_point = 0 ; grid_point != land1.values_of_landscapes.size() ; ++grid_point ) { result.values_of_landscapes[grid_point] = std::vector< double >( std::max( land1.values_of_landscapes[grid_point].size() , land2.values_of_landscapes[grid_point].size() ) ); @@ -1555,9 +1473,7 @@ double compute_max_norm_distance_of_landscapes( const Persistence_landscape_on_g return result; } - - -}//namespace Gudhi_stat +}//namespace Persistence_representations }//namespace Gudhi -#endif +#endif // PERSISTENCE_LANDSCAPE_ON_GRID_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h index 7fde3413..616ec50f 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h +++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -21,8 +21,8 @@ */ -#ifndef Vector_distances_in_diagram_H -#define Vector_distances_in_diagram_H +#ifndef PERSISTENCE_VECTORS_H_ +#define PERSISTENCE_VECTORS_H_ #include #include @@ -42,32 +42,6 @@ namespace Gudhi namespace Persistence_representations { -/* -template -struct Euclidean_distance -{ - double operator() ( const std::pair< T,T >& f , const std::pair& s ) - { - return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); - } - double operator() ( const std::vector< T >& f , const std::vector < T >& s ) - { - if ( f.size() != s.size() ) - { - std::cerr << "Not compatible points dimensions in the procedure to compute Euclidean distance. The program will now terminate. \n"; - std::cout << f.size() << " , " << s.size() << std::endl; - throw "Not compatible points dimensions in the procedure to compute Euclidean distance. The program will now terminate. \n"; - } - double result = 0; - for ( size_t i = 0 ; i != f.size() ; ++i ) - { - result += ( f[i]-s[i] )*( f[i]-s[i] ); - } - return sqrt( result ); - } -}; -* */ - template struct Maximum_distance { @@ -79,16 +53,21 @@ struct Maximum_distance - /** -* This is an implementation of idea presented in the paper 'Stable Topological Signatures for Points on 3D Shapes' by -* M. Carriere, S. Y. Oudot and M. Ovsjanikov published in Computer Graphics Forum (proc. SGP 2015). -* The parameter of the class is the class that computes distance used to construct the vectors. The typical function is -* either Eucludean of maximum (Manhattan) distance. -* This class implements the following concepts: Vectorized_topological_data, Topological_data_with_distances, Real_valued_topological_data, Topological_data_with_averages, Topological_data_with_scalar_product -* -**/ - + * \class Vector_distances_in_diagram Vector_distances_in_diagram.h gudhi/Vector_distances_in_diagram.h + * \brief A class implementing persistence vectors. + * + * \ingroup Persistence_representations + * + * \details + * This is an implementation of idea presented in the paper Stable Topological Signatures for Points on 3D + * Shapes \cite Carriere_Oudot_Ovsjanikov_top_signatures_3d .
+ * The parameter of the class is the class that computes distance used to construct the vectors. The typical function + * is either Euclidean of maximum (Manhattan) distance. + * + * This class implements the following concepts: Vectorized_topological_data, Topological_data_with_distances, + * Real_valued_topological_data, Topological_data_with_averages, Topological_data_with_scalar_product + **/ template class Vector_distances_in_diagram { @@ -99,12 +78,12 @@ public: Vector_distances_in_diagram(){}; /** - * The constructor that takes as an input a multiset of persistence intervals (given as vector of birth-death pairs). The second parameter is the desiered length of the output vectors. + * The constructor that takes as an input a multiset of persistence intervals (given as vector of birth-death pairs). The second parameter is the desired length of the output vectors. **/ Vector_distances_in_diagram( const std::vector< std::pair< double , double > >& intervals , size_t where_to_cut ); /** - * The constructor taking as an input a file with birth-death pairs. The second parameter is the desiered length of the output vectors. + * The constructor taking as an input a file with birth-death pairs. The second parameter is the desired length of the output vectors. **/ Vector_distances_in_diagram( const char* filename , size_t where_to_cut , unsigned dimension = std::numeric_limits::max() ); @@ -155,7 +134,7 @@ public: void load_from_file( const char* filename ); /** - * Comparision operators: + * Comparison operators: **/ bool operator == ( const Vector_distances_in_diagram& second )const { @@ -172,14 +151,11 @@ public: return !( *this == second ); } - - - - //Implementations of functions for various concepts. + //Implementations of functions for various concepts. /** * Compute projection to real numbers of persistence vector. This function is required by the Real_valued_topological_data concept - * At the moment this function is not tested, since it is quite likelly to be changed in the future. Given this, when using it, keep in mind that it - * will be most likelly changed in the next versions. + * At the moment this function is not tested, since it is quite likely to be changed in the future. Given this, when using it, keep in mind that it + * will be most likely changed in the next versions. **/ double project_to_R( int number_of_function )const; /** @@ -195,7 +171,7 @@ public: **/ std::vector vectorize( int number_of_function )const; /** - * This function return the number of functions that allows vectorization of a persisence vector. It is required in a concept Vectorized_topological_data. + * This function return the number of functions that allows vectorization of a persistence vector. It is required in a concept Vectorized_topological_data. **/ size_t number_of_vectorize_functions()const { @@ -220,22 +196,6 @@ public: //end of implementation of functions needed for concepts. - - - - - - - - - - - - - - - - /** * For visualization use output from vectorize and build histograms. **/ @@ -246,7 +206,7 @@ public: /** - * Create a gnuplot script to vizualize the data structure. + * Create a gnuplot script to visualize the data structure. **/ void plot( const char* filename )const { @@ -264,7 +224,7 @@ public: } out <sorted_vector_of_distances[0] , 0); } - //arythmetic operations: + //arithmetic operations: template < typename Operation_type > friend Vector_distances_in_diagram operation_on_pair_of_vectors( const Vector_distances_in_diagram& first , const Vector_distances_in_diagram& second , Operation_type opertion ) { @@ -511,7 +471,6 @@ void Vector_distances_in_diagram::compute_sorted_vector_of_distances_via_heap double value = f( 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) ) ); if ( -value < heap.front() ) { - //std::cerr << "Replacing : " << heap.front() << " with : " << -value <::distance( const Vector_distances_in_diagr } else { - //nax morm + // max norm if ( result < fabs( this->sorted_vector_of_distances[i] - second_.sorted_vector_of_distances[i] ) )result = fabs( this->sorted_vector_of_distances[i] - second_.sorted_vector_of_distances[i] ); } if ( dbg ) @@ -767,12 +726,8 @@ double Vector_distances_in_diagram::compute_scalar_product( const Vector_dist return result; } - - - - -}//namespace Gudhi_stat +}//namespace Persistence_representations }//namespace Gudhi -#endif // Vector_distances_in_diagram_H +#endif // PERSISTENCE_VECTORS_H_ diff --git a/src/Persistence_representations/include/gudhi/common_persistence_representations.h b/src/Persistence_representations/include/gudhi/common_persistence_representations.h index f223079a..f571ca4f 100644 --- a/src/Persistence_representations/include/gudhi/common_persistence_representations.h +++ b/src/Persistence_representations/include/gudhi/common_persistence_representations.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -20,15 +20,15 @@ * along with this program. If not, see . */ -#ifndef common_gudhi_stat_H -#define common_gudhi_stat_H +#ifndef COMMON_PERSISTENCE_REPRESENTATIONS_H_ +#define COMMON_PERSISTENCE_REPRESENTATIONS_H_ namespace Gudhi { namespace Persistence_representations { - //this file contain an implementation of some common procedures used in Gudhi_stat. + //this file contain an implementation of some common procedures used in Persistence_representations. //double epsi = std::numeric_limits::epsilon(); double epsi = 0.000005; @@ -38,8 +38,8 @@ double epsi = 0.000005; /** - * A procedure used to compare doubles. Typically gien two doubles A and B, comparing A == B is not good idea. In this case, we use the procedure almostEqual with the epsi defined at - * the top of the file. Setting up the epsi give the user a tolerance on what should be consider equal. + * A procedure used to compare doubles. Typically given two doubles A and B, comparing A == B is not good idea. In this case, we use the procedure almostEqual with the epsi defined at + * the top of the file. Setting up the epsi gives the user a tolerance on what should be consider equal. **/ inline bool almost_equal( double a , double b ) { @@ -78,7 +78,7 @@ std::pair compute_parameters_of_a_line( std::pair //landscapes /** - * This procedure given two points which lies on the opposide sides of x axis, compute x for which the line connecting those two points crosses x axis. + * This procedure given two points which lies on the opposite sides of x axis, compute x for which the line connecting those two points crosses x axis. **/ double find_zero_of_a_line_segment_between_those_two_points ( std::pair p1, std::pair p2 ) { @@ -86,7 +86,7 @@ double find_zero_of_a_line_segment_between_those_two_points ( std::pair 0 ) { std::ostringstream errMessage; - errMessage <<"In function find_zero_of_a_line_segment_between_those_two_points the agguments are: (" << p1.first << "," << p1.second << ") and (" << p2.first << "," << p2.second << "). There is no zero in line between those two points. Program terminated."; + errMessage <<"In function find_zero_of_a_line_segment_between_those_two_points the arguments are: (" << p1.first << "," << p1.second << ") and (" << p2.first << "," << p2.second << "). There is no zero in line between those two points. Program terminated."; std::string errMessageStr = errMessage.str(); const char* err = errMessageStr.c_str(); throw(err); @@ -94,8 +94,6 @@ double find_zero_of_a_line_segment_between_those_two_points ( std::pair f, std::pair s ) @@ -135,7 +133,7 @@ bool compare_points_sorting( std::pair f, std::pair p1, std::pair p2 , double x ) { @@ -148,7 +146,7 @@ double function_value ( std::pair p1, std::pair p2 -}//namespace Gudhi_stat -}//namespace Gudhi +} // namespace Persistence_representations +} // namespace Gudhi -#endif +#endif // COMMON_PERSISTENCE_REPRESENTATIONS_H_ diff --git a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h index 058c77a4..a4884314 100644 --- a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h +++ b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h @@ -4,7 +4,7 @@ * * Author(s): Pawel Dlotko * - * Copyright (C) 2015 INRIA (France) + * Copyright (C) 2017 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 @@ -21,8 +21,8 @@ */ -#ifndef Read_Persitence_From_File_H -#define Read_Persitence_From_File_H +#ifndef READ_PERSISTENCE_FROM_FILE_H_ +#define READ_PERSISTENCE_FROM_FILE_H_ #include #include @@ -36,86 +36,6 @@ namespace Gudhi { namespace Persistence_representations { - - - -/** - * This procedure reads names of files which are stored in a file. -**/ -std::vector< std::string > readFileNames( const char* filenameWithFilenames ) -{ - bool dbg = false; - - std::ifstream in(filenameWithFilenames); - if ( !in.good() ) - { - std::cerr << "The file : " << filenameWithFilenames << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read do not exist. The program will now terminate \n"; - } - - std::vector< std::string > result; - std::string line; - while (!in.eof()) - { - getline(in,line); - line.erase( std::remove_if( line.begin(), line.end(), ::isspace) , line.end() ); - - if (dbg){std::cerr << "line : " << line << std::endl;} - - if ( (line.length() == 0) || (line[0] == '#') ) - { - //in this case we have a file name. First we should remove all the white spaces. - if ( dbg ){std::cerr << "This is a line with comment, it will be ignored n";} - } - else - { - result.push_back( line ); - if (dbg){std::cerr << "Line after removing white spaces : " << line << std::endl;} - } - } - in.close(); - - return result; -}//readFileNames - - - -std::vector< std::vector< double > > read_numbers_from_file_line_by_line( const char* filename ) -{ - bool dbg = false; - std::ifstream in(filename); - if ( !in.good() ) - { - std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; - } - - std::vector< std::vector< double > > result; - double number; - - - std::string line; - while ( in.good() ) - { - std::getline(in,line); - std::stringstream ss(line); - - if ( dbg )std::cerr << "\n Reading line : " << line << std::endl; - - std::vector< double > this_line; - while ( ss.good() ) - { - ss >> number; - this_line.push_back( number ); - if ( dbg )std::cerr << number << " "; - } - if ( this_line.size() && in.good() ) result.push_back( this_line ); - } - in.close(); - - return result; -}//read_numbers_from_file_line_by_line - /** * Universal procedure to read files with persistence. It ignores the lines starting from # (treat them as comments). @@ -123,7 +43,7 @@ std::vector< std::vector< double > > read_numbers_from_file_line_by_line( const * that each other line in the file, which is not a comment, have the same number of numerical entries (2, 3 or 4). * If there are two numerical entries per line, then the function assume that they are birth/death coordinates. * If there are three numerical entries per line, then the function assume that they are: dimension and birth/death coordinates. - * If there are four numerical entries per line, then the function assume that they are: thc characteristic of a filed over which + * If there are four numerical entries per line, then the function assume that they are: the characteristic of a filed over which * persistence was computed, dimension and birth/death coordinates. * The 'inf' string can appear only as a last element of a line. * The procedure returns vector of persistence pairs. @@ -162,7 +82,7 @@ std::vector > read_persistence_intervals_in_one_dimensi if ( line_copy.find("inf") != std::string::npos ) { size_t np = line_copy.find("inf"); - //replace symbols 'inf' in line_copy with whilespaces: + //replace symbols 'inf' in line_copy with white spaces: line_copy[np] = ' '; line_copy[np+1] = ' '; line_copy[np+2] = ' '; @@ -194,7 +114,7 @@ std::vector > read_persistence_intervals_in_one_dimensi { std::cerr << "This line: " << line << " contains infinite interval. \n"; } - //first we substitute inf by whitespaces: + //first we substitute inf by white spaces: size_t np = line.find("inf"); line[np] = ' '; line[np+1] = ' '; @@ -288,13 +208,9 @@ std::vector > read_persistence_intervals_in_one_dimensi if ( dbg )std::cerr << "End of reading \n"; return barcode; -}//read_persistence_intervals_in_one_dimension_from_file +} // read_persistence_intervals_in_one_dimension_from_file -}//namespace Gudhi_stat -}//namespace Gudhi +} // namespace Persistence_representations +} // namespace Gudhi - - - -#endif - +#endif // READ_PERSISTENCE_FROM_FILE_H_ diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp index d3e6f322..27a7836f 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp @@ -34,8 +34,8 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { - std::cout << "This program compute dsitance of persistence heat maps stored in a file (the file needs to be created beforehand). \n"; - std::cout << "The first parameter of a program is an interger p. The program compute L^p distance of the two heat maps. For L^infty distance choose p = -1. \n"; + std::cout << "This program compute distance of persistence heat maps stored in a file (the file needs to be created beforehand). \n"; + std::cout << "The first parameter of a program is an integer p. The program compute L^p distance of the two heat maps. For L^infty distance choose p = -1. \n"; std::cout << "The remaining parameters of this programs are names of files with persistence heat maps.\n"; if ( argc < 3 ) @@ -76,7 +76,7 @@ int main( int argc , char** argv ) distance[i] = v; } - //and now we can compute the distnaces: + //and now we can compute the distances: for ( size_t i = 0 ; i != filenames.size() ; ++i ) { for ( size_t j = i ; j != filenames.size() ; ++j ) @@ -106,6 +106,3 @@ int main( int argc , char** argv ) - - - diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp index aa887c9c..f755e9a6 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp @@ -36,10 +36,10 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { - std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are weighted by the arcus tangens of their persistence.\n"; + std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are weighted by the arc tangential of their persistence.\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::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; diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp index aa13d786..732b3768 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp @@ -38,7 +38,7 @@ int main( int argc , char** argv ) std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are weighted by the distance of a center from the diagonal.\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::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; @@ -62,8 +62,6 @@ int main( int argc , char** argv ) dimension = (unsigned)dim; } - //std::cout << "Parameters of the program : size_of_grid : " << size_of_grid << ", min_ : " << min_ << ", max_ : " << max_ << ", stdiv: " << stdiv << ", dim : " << dim << std::endl; - std::vector< const char* > filenames; for ( int i = 6 ; i != argc ; ++i ) { diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp index 46258329..58406d08 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp @@ -38,7 +38,7 @@ int main( int argc , char** argv ) std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are weighted by the square of distance of a center from the diagonal.\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::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; diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp index cac81495..90b50b0b 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp @@ -39,7 +39,7 @@ int main( int argc , char** argv ) std::cout << "This program creates persistence heat map 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::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."; diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp index 6aab42f7..6a07bf19 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp @@ -37,7 +37,7 @@ int main( int argc , char** argv ) std::cout << "This program creates PSSK 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::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; diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp index 5a4776ff..7aedfbb1 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp @@ -34,7 +34,7 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { - std::cout << "This program plot persistence landscape stored in a file (the file needs to be created beforehand). Please call the code with the name of a landsape file \n"; + std::cout << "This program plot persistence landscape stored in a file (the file needs to be created beforehand). Please call the code with the name of a landscape file \n"; Persistence_heat_maps l; l.load_from_file( argv[1] ); l.plot( argv[1] ); diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp index 19e49bbb..fe4e709f 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp @@ -34,7 +34,7 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { - std::cout << "This program compute the bottleneck distance of persistence diarams stored in a files. \n"; + std::cout << "This program compute the bottleneck distance of persistence diagrams 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"; diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp index b2cbac70..6e2598fa 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp @@ -71,7 +71,7 @@ int main( int argc , char** argv ) out << histogram[i] << std::endl; } out << std::endl; - std::cout << "To vizualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; + std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; out.close(); return 0; } diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp index e20f85c0..5b36e0ce 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp @@ -89,12 +89,7 @@ int main( int argc , char** argv ) 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; + std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp index 85954cb2..ef969ed0 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp @@ -34,7 +34,7 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { std::cout << "This program compute distance of persistence landscapes stored in a file (the file needs to be created beforehand). \n"; - std::cout << "The first parameter of a program is an interger p. The program compute L^p distance of the given landscapes. For L^infty distance choose p = -1. \n"; + std::cout << "The first parameter of a program is an integer p. The program compute L^p distance of the given landscapes. For L^infty distance choose p = -1. \n"; std::cout << "The remaining parameters of this programs are names of files with persistence landscapes."; if ( argc < 3 ) diff --git a/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp index b79a689d..670f0364 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp @@ -33,7 +33,7 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { - std::cout << "This program plot persistence landscape stored in a file (the file needs to be created beforehand). Please call the code with the name of a landsape file \n"; + std::cout << "This program plot persistence landscape stored in a file (the file needs to be created beforehand). Please call the code with the name of a landscape file \n"; Persistence_landscape l; l.load_landscape_from_file( argv[1] ); diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp index 4ecbd548..3065b52c 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp @@ -33,8 +33,8 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { - std::cout << "This program compute dsitance of persistence landscapes on grid stored in a file (the file needs to be created beforehand). \n"; - std::cout << "The first parameter of a program is an interger p. The program compute L^p distance of the the landscapes on grid. For L^infty distance choose p = -1. \n"; + std::cout << "This program compute distance of persistence landscapes on grid stored in a file (the file needs to be created beforehand). \n"; + std::cout << "The first parameter of a program is an integer p. The program compute L^p distance of the landscapes on grid. For L^infty distance choose p = -1. \n"; std::cout << "The remaining parameters of this programs are names of files with persistence landscapes on grid.\n"; if ( argc < 3 ) @@ -106,5 +106,3 @@ int main( int argc , char** argv ) - - diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp index 700b2f1f..b4fa3046 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp @@ -33,7 +33,7 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { - std::cout << "This program plot persistence landscape on grid stored in a file (the file needs to be created beforehand). Please call the code with the name of a landsape on grid file \n"; + std::cout << "This program plot persistence landscape on grid stored in a file (the file needs to be created beforehand). Please call the code with the name of a landscape on grid file \n"; if ( argc == 1 ) { std::cout << "Wrong parameters of a program call, the program will now terminate \n"; diff --git a/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp index 39e24cd7..5c0d3328 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp @@ -34,7 +34,7 @@ using namespace Gudhi::Persistence_representations; int main( int argc , char** argv ) { std::cout << "This program compute distance of persistence vectors stored in a file (the file needs to be created beforehand). \n"; - std::cout << "The first parameter of a program is an interger p. The program compute l^p distance of the vectors. For l^infty distance choose p = -1. \n"; + std::cout << "The first parameter of a program is an integer p. The program compute l^p distance of the vectors. For l^infty distance choose p = -1. \n"; std::cout << "The remaining parameters of this programs are names of files with persistence vectors.\n"; if ( argc < 3 ) @@ -60,7 +60,6 @@ int main( int argc , char** argv ) vectors.reserve( filenames.size() ); for ( size_t file_no = 0 ; file_no != filenames.size() ; ++file_no ) { - //cerr << filenames[file_no] << endl; Vector_distances_in_diagram< Euclidean_distance > l; l.load_from_file( filenames[file_no] ); vectors.push_back( l ); diff --git a/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp index 634bcb13..d7a22e58 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp @@ -52,8 +52,7 @@ int main( int argc , char** argv ) for ( size_t i = 0 ; i != filenames.size() ; ++i ) { - 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 ) + std::cerr << "Creating persistence vectors based on a file : " << filenames[i] << std::endl; Vector_distances_in_diagram< Euclidean_distance > l( filenames[i] , dimension ); std::stringstream ss; ss << filenames[i] << ".vect"; diff --git a/src/cmake/modules/GUDHI_user_version_target.txt b/src/cmake/modules/GUDHI_user_version_target.txt index 8b7cf0e2..3172f6b1 100644 --- a/src/cmake/modules/GUDHI_user_version_target.txt +++ b/src/cmake/modules/GUDHI_user_version_target.txt @@ -47,7 +47,7 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.11) add_custom_command(TARGET user_version PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/GudhUI ${GUDHI_USER_VERSION_DIR}/GudhUI) - set(GUDHI_MODULES "common;Alpha_complex;Bitmap_cubical_complex;Bottleneck_distance;Contraction;Gudhi_stat;Hasse_complex;Persistent_cohomology;Rips_complex;Simplex_tree;Skeleton_blocker;Spatial_searching;Subsampling;Tangential_complex;Witness_complex") + set(GUDHI_MODULES "common;Alpha_complex;Bitmap_cubical_complex;Bottleneck_distance;Contraction;Hasse_complex;Persistence_representations;Persistent_cohomology;Rips_complex;Simplex_tree;Skeleton_blocker;Spatial_searching;Subsampling;Tangential_complex;Witness_complex") set(GUDHI_DIRECTORIES "doc;example;concept;utilities") set(GUDHI_INCLUDE_DIRECTORIES "include/gudhi;include/gudhi_patches") diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index d1cb691c..6986a6b5 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -212,19 +212,20 @@ - \subsection Gudhi_stat_sublibrary Gudhi statistical sublibrary - \image html "average_landscape.png" "Gudhi statistical sublibrary" + \subsection PersistenceRepresentationsToolbox Persistence representations + \image html "average_landscape.png" "Persistence representations" diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index f6e2ab5a..f683136b 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -48,6 +48,11 @@ class Euclidean_distance { } return std::sqrt(dist); } + template< typename T > + T operator() ( const std::pair< T,T >& f , const std::pair< T,T >& s ) + { + return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); + } }; } // namespace Gudhi -- cgit v1.2.3 From 2bcb3d7cb47ce71803f2464cc822346ed2e1b039 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 30 May 2017 15:43:48 +0000 Subject: Fix doc typo git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2476 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: eee441e3902a0995a8356d76007664fe559f3036 --- src/Persistence_representations/include/gudhi/Persistence_vectors.h | 2 +- src/common/doc/main_page.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src/common') diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h index 616ec50f..7cfb8e0b 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h +++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h @@ -54,7 +54,7 @@ struct Maximum_distance /** - * \class Vector_distances_in_diagram Vector_distances_in_diagram.h gudhi/Vector_distances_in_diagram.h + * \class Vector_distances_in_diagram Persistence_vectors.h gudhi/Persistence_vectors.h * \brief A class implementing persistence vectors. * * \ingroup Persistence_representations diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index 6986a6b5..ec968558 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -222,11 +222,10 @@ Copyright: GPL v3
Author: Pawel Dlotko
- Introduced in: GUDHI 2.0.0
+ Introduced in: GUDHI 2.1.0
Copyright: GPL v3
- This is a statistical library for gudhi. It contain implementation of various representations of persistence diagrams; diagrams themselves, persistence landscapes (rigorous and grid version), - persistence heath maps, vectors and others. It implements basic functionalities which are neccessary to use persistence in statistics and machine learning. - User manual: \ref Gudhi_stat + It contain implementation of various representations of persistence diagrams; diagrams themselves, persistence + landscapes (rigorous and grid version), persistence heath maps, vectors and others. It implements basic + functionalities which are neccessary to use persistence in statistics and machine learning.
+ User manual: \ref Persistence_representations
- It contain implementation of various representations of persistence diagrams; diagrams themselves, persistence + It contains implementation of various representations of persistence diagrams; diagrams themselves, persistence landscapes (rigorous and grid version), persistence heath maps, vectors and others. It implements basic functionalities which are neccessary to use persistence in statistics and machine learning.
User manual: \ref Persistence_representations -
-- cgit v1.2.3 From 3a76dcb9f49671b01ae200a13569f47fca57dac0 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 31 May 2017 06:20:04 +0000 Subject: Fix cpplint and cppcheck git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2480 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9ad6fc7b096fff02a8696515c074ddd92980a8e2 --- .../example/persistence_heat_maps.cpp | 1 + .../example/persistence_intervals.cpp | 2 + .../example/persistence_landscape.cpp | 6 ++- .../example/persistence_landscape_on_grid.cpp | 6 ++- .../example/persistence_vectors.cpp | 6 ++- .../include/gudhi/PSSK.h | 9 +++-- .../include/gudhi/Persistence_heat_maps.h | 33 ++++++++-------- .../include/gudhi/Persistence_intervals.h | 7 ++-- .../gudhi/Persistence_intervals_with_distances.h | 4 +- .../include/gudhi/Persistence_landscape.h | 37 +++++++++--------- .../include/gudhi/Persistence_landscape_on_grid.h | 44 +++++++++++----------- .../include/gudhi/Persistence_vectors.h | 18 +++++---- .../gudhi/common_persistence_representations.h | 3 ++ .../include/gudhi/read_persistence_from_file.h | 8 ++-- .../average_persistence_heat_maps.cpp | 1 + .../compute_distance_of_persistence_heat_maps.cpp | 2 + ...ute_scalar_product_of_persistence_heat_maps.cpp | 1 + ...h_m_weighted_by_arctan_of_their_persistence.cpp | 2 + ...te_p_h_m_weighted_by_distance_from_diagonal.cpp | 2 + ...ate_p_h_m_weighted_by_squared_diag_distance.cpp | 2 + .../create_persistence_heat_maps.cpp | 2 + .../persistence_heat_maps/create_pssk.cpp | 2 + ...te_birth_death_range_in_persistence_diagram.cpp | 1 + .../compute_bottleneck_distance.cpp | 2 + .../compute_number_of_dominant_intervals.cpp | 3 ++ .../plot_histogram_of_intervals_lengths.cpp | 3 ++ .../plot_persistence_Betti_numbers.cpp | 3 ++ .../plot_persistence_intervals.cpp | 3 ++ .../persistence_landscapes/average_landscapes.cpp | 1 + .../compute_distance_of_landscapes.cpp | 1 + .../compute_scalar_product_of_landscapes.cpp | 1 + .../compute_distance_of_landscapes_on_grid.cpp | 2 + ...ompute_scalar_product_of_landscapes_on_grid.cpp | 1 + .../create_landscapes_on_grid.cpp | 4 +- .../average_persistence_vectors.cpp | 1 + .../compute_distance_of_persistence_vectors.cpp | 2 + ...mpute_scalar_product_of_persistence_vectors.cpp | 2 + .../create_persistence_vectors.cpp | 2 + src/common/include/gudhi/distance_functions.h | 4 +- 39 files changed, 151 insertions(+), 83 deletions(-) (limited to 'src/common') diff --git a/src/Persistence_representations/example/persistence_heat_maps.cpp b/src/Persistence_representations/example/persistence_heat_maps.cpp index 5e3be880..a9ac5df5 100644 --- a/src/Persistence_representations/example/persistence_heat_maps.cpp +++ b/src/Persistence_representations/example/persistence_heat_maps.cpp @@ -25,6 +25,7 @@ #include #include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/example/persistence_intervals.cpp b/src/Persistence_representations/example/persistence_intervals.cpp index 1accfb0c..29cd66f3 100644 --- a/src/Persistence_representations/example/persistence_intervals.cpp +++ b/src/Persistence_representations/example/persistence_intervals.cpp @@ -24,6 +24,8 @@ #include #include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/example/persistence_landscape.cpp b/src/Persistence_representations/example/persistence_landscape.cpp index 4225f83a..1bcc524a 100644 --- a/src/Persistence_representations/example/persistence_landscape.cpp +++ b/src/Persistence_representations/example/persistence_landscape.cpp @@ -22,11 +22,13 @@ #include +#include +#include +#include + using namespace Gudhi; using namespace Gudhi::Persistence_representations; -#include - int main(int argc, char** argv) { // create two simple vectors with birth--death pairs: diff --git a/src/Persistence_representations/example/persistence_landscape_on_grid.cpp b/src/Persistence_representations/example/persistence_landscape_on_grid.cpp index 821fb5b7..0cede07e 100644 --- a/src/Persistence_representations/example/persistence_landscape_on_grid.cpp +++ b/src/Persistence_representations/example/persistence_landscape_on_grid.cpp @@ -22,11 +22,13 @@ #include +#include +#include +#include + using namespace Gudhi; using namespace Gudhi::Persistence_representations; -#include - int main(int argc, char** argv) { // create two simple vectors with birth--death pairs: diff --git a/src/Persistence_representations/example/persistence_vectors.cpp b/src/Persistence_representations/example/persistence_vectors.cpp index bc2f3fe7..c6581039 100644 --- a/src/Persistence_representations/example/persistence_vectors.cpp +++ b/src/Persistence_representations/example/persistence_vectors.cpp @@ -21,12 +21,14 @@ */ #include -#include - #include + +#include #include #include #include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/include/gudhi/PSSK.h b/src/Persistence_representations/include/gudhi/PSSK.h index 59e73af4..53628737 100644 --- a/src/Persistence_representations/include/gudhi/PSSK.h +++ b/src/Persistence_representations/include/gudhi/PSSK.h @@ -26,6 +26,10 @@ // gudhi include #include +#include +#include +#include + namespace Gudhi { namespace Persistence_representations { @@ -117,8 +121,8 @@ void PSSK::construct(const std::vector >& intervals_, for (size_t pt_nr = 0; pt_nr != intervals_.size(); ++pt_nr) { // compute the value of intervals_[pt_nr] in the grid: - int x_grid = (int)((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels); - int y_grid = (int)((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int x_grid = static_cast((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int y_grid = static_cast((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); if (dbg) { std::cerr << "point : " << intervals_[pt_nr].first << " , " << intervals_[pt_nr].second << std::endl; @@ -134,7 +138,6 @@ void PSSK::construct(const std::vector >& intervals_, if (dbg) { std::cerr << "After shift : \n"; - ; std::cerr << "x_grid : " << x_grid << std::endl; std::cerr << "y_grid : " << y_grid << std::endl; std::cerr << "filter.size() : " << filter.size() << std::endl; diff --git a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h index 549c19e7..5ef5129d 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h +++ b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h @@ -23,18 +23,20 @@ #ifndef PERSISTENCE_HEAT_MAPS_H_ #define PERSISTENCE_HEAT_MAPS_H_ +// gudhi include +#include +#include + // standard include #include #include #include #include #include -#include #include - -// gudhi include -#include -#include +#include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -68,8 +70,8 @@ std::vector > create_Gaussian_filter(size_t pixel_radius, do getchar(); } - for (int x = -pixel_radius; x <= (int)pixel_radius; x++) { - for (int y = -pixel_radius; y <= (int)pixel_radius; y++) { + for (int x = -pixel_radius; x <= static_cast(pixel_radius); x++) { + for (int y = -pixel_radius; y <= static_cast(pixel_radius); y++) { double real_x = 2 * sigma * x / pixel_radius; double real_y = 2 * sigma * y / pixel_radius; r = sqrt(real_x * real_x + real_y * real_y); @@ -123,7 +125,7 @@ class constant_scaling_function { class distance_from_diagonal_scaling { public: double operator()(const std::pair& point_in_diagram) { - //(point_in_diagram.first+point_in_diagram.second)/2.0 + // (point_in_diagram.first+point_in_diagram.second)/2.0 return sqrt(pow((point_in_diagram.first - (point_in_diagram.first + point_in_diagram.second) / 2.0), 2) + pow((point_in_diagram.second - (point_in_diagram.first + point_in_diagram.second) / 2.0), 2)); } @@ -194,7 +196,7 @@ class Persistence_heat_maps { this->erase_below_diagonal = false; this->min_ = this->max_ = 0; this->set_up_parameters_for_basic_classes(); - }; + } /** * Construction that takes at the input the following parameters: @@ -580,8 +582,8 @@ void Persistence_heat_maps::construct(const std::vectormin_) / (this->max_ - this->min_) * number_of_pixels); - int y_grid = (int)((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int x_grid = static_cast((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int y_grid = static_cast((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); if (dbg) { std::cerr << "point : " << intervals_[pt_nr].first << " , " << intervals_[pt_nr].second << std::endl; @@ -597,7 +599,6 @@ void Persistence_heat_maps::construct(const std::vector::compute_mean(const std::vector< for (size_t map_no = 0; map_no != maps.size(); ++map_no) { mean += maps[map_no]->heat_map[i][j]; } - heat_maps[i][j] = mean / (double)maps.size(); + heat_maps[i][j] = mean / static_cast(maps.size()); } } this->heat_map = heat_maps; @@ -782,7 +783,7 @@ void Persistence_heat_maps::load_from_file(const char* file // checking if the file exist / if it was open. if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } // now we read the file one by one. @@ -848,7 +849,7 @@ double Persistence_heat_maps::distance(const Persistence_he if (!this->check_if_the_same(second)) { std::cerr << "The persistence images are of non compatible sizes. We cannot therefore compute distance between " "them. The program will now terminate"; - throw "The persistence images are of non compatible sizes. We cannot therefore compute distance between them. The program will now terminate"; + throw "The persistence images are of non compatible sizes. The program will now terminate"; } // if we are here, we know that the two persistence images are defined on the same domain, so we can start computing @@ -897,7 +898,7 @@ double Persistence_heat_maps::compute_scalar_product(const if (!this->check_if_the_same(second)) { std::cerr << "The persistence images are of non compatible sizes. We cannot therefore compute distance between " "them. The program will now terminate"; - throw "The persistence images are of non compatible sizes. We cannot therefore compute distance between them. The program will now terminate"; + throw "The persistence images are of non compatible sizes. The program will now terminate"; } // if we are here, we know that the two persistence images are defined on the same domain, so we can start computing diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h index 939ae274..9e614efd 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h @@ -32,9 +32,10 @@ #include #include #include -#include #include #include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -402,7 +403,7 @@ std::vector Persistence_intervals::characteristic_function_of_diagram(do 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); + ((x_max - x_min) / static_cast(number_of_bins)) * (this->intervals[i].second - this->intervals[i].first); } if (dbg) { std::cerr << "Result at this stage \n"; @@ -564,6 +565,6 @@ double Persistence_intervals::project_to_R(int number_of_function) const { } } // namespace Persistence_representations -} // namespace gudhi +} // namespace Gudhi #endif // PERSISTENCE_INTERVALS_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h index 0f3920cd..e476d28a 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h @@ -26,6 +26,8 @@ #include #include +#include + namespace Gudhi { namespace Persistence_representations { @@ -56,6 +58,6 @@ class Persistence_intervals_with_distances : public Persistence_intervals { }; } // namespace Persistence_representations -} // namespace gudhi +} // namespace Gudhi #endif // PERSISTENCE_INTERVALS_WITH_DISTANCES_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape.h b/src/Persistence_representations/include/gudhi/Persistence_landscape.h index be7c9e31..c86e68d3 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape.h @@ -23,6 +23,10 @@ #ifndef PERSISTENCE_LANDSCAPE_H_ #define PERSISTENCE_LANDSCAPE_H_ +// gudhi include +#include +#include + // standard include #include #include @@ -31,10 +35,9 @@ #include #include #include - -// gudhi include -#include -#include +#include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -323,7 +326,7 @@ class Persistence_landscape { * Vectorized_topological_data */ std::vector vectorize(int number_of_function) const { - // TODO, think of something smarter over here + // TODO(PD) think of something smarter over here std::vector v; if ((size_t)number_of_function > this->land.size()) { return v; @@ -393,7 +396,7 @@ class Persistence_landscape { nextLevelMerge.swap(nextNextLevelMerge); } (*this) = (*nextLevelMerge[0]); - (*this) *= 1 / ((double)to_average.size()); + (*this) *= 1 / static_cast(to_average.size()); } /** @@ -882,7 +885,7 @@ void Persistence_landscape::load_landscape_from_file(const char* filename) { in.open(filename); if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } std::string line; @@ -971,7 +974,7 @@ Persistence_landscape operation_on_pair_of_landscapes(const Persistence_landscap } lambda_n.push_back( std::make_pair(land1.land[i][p].first, - oper((double)land1.land[i][p].second, + oper(static_cast(land1.land[i][p].second), function_value(land2.land[i][q - 1], land2.land[i][q], land1.land[i][p].first)))); ++p; continue; @@ -1085,8 +1088,8 @@ double compute_maximal_distance_non_symmetric(const Persistence_landscape& pl1, } int p2Count = 0; - for (size_t i = 1; i != pl1.land[level].size() - 1; ++i) // In this case, I consider points at the infinity - { + // In this case, I consider points at the infinity + for (size_t i = 1; i != pl1.land[level].size() - 1; ++i) { while (true) { if ((pl1.land[level][i].first >= pl2.land[level][p2Count].first) && (pl1.land[level][i].first <= pl2.land[level][p2Count + 1].first)) @@ -1142,17 +1145,17 @@ double compute_distance_of_landscapes(const Persistence_landscape& first, const } if (p < std::numeric_limits::max()) { - //\int_{- \infty}^{+\infty}| first-second |^p + // \int_{- \infty}^{+\infty}| first-second |^p double result; if (p != 1) { if (dbg) std::cerr << "Power != 1, compute integral to the power p\n"; - result = lan.compute_integral_of_landscape((double)p); + result = lan.compute_integral_of_landscape(p); } else { if (dbg) std::cerr << "Power = 1, compute integral \n"; result = lan.compute_integral_of_landscape(); } - //(\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) - return pow(result, 1 / (double)p); + // (\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) + return pow(result, 1.0 / p); } else { // p == infty if (dbg) std::cerr << "Power = infty, compute maximum \n"; @@ -1232,9 +1235,9 @@ double compute_inner_product(const Persistence_landscape& l1, const Persistence_ } // we have two intervals in which functions are constant: - //[l1.land[level][l1It].first , l1.land[level][l1It+1].first] + // [l1.land[level][l1It].first , l1.land[level][l1It+1].first] // and - //[l2.land[level][l2It].first , l2.land[level][l2It+1].first] + // [l2.land[level][l2It].first , l2.land[level][l2It+1].first] // We also have an interval [x1,x2]. Since the intervals in the landscapes cover the whole R, then it is clear // that x2 // is either l1.land[level][l1It+1].first of l2.land[level][l2It+1].first or both. Lets test it. @@ -1316,6 +1319,6 @@ void Persistence_landscape::plot(const char* filename, double xRangeBegin, doubl } } // namespace Persistence_representations -} // namespace gudhi +} // namespace Gudhi #endif // PERSISTENCE_LANDSCAPE_H_ diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h index bea98f74..6eec26d6 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h @@ -24,6 +24,10 @@ #ifndef PERSISTENCE_LANDSCAPE_ON_GRID_H_ #define PERSISTENCE_LANDSCAPE_ON_GRID_H_ +// gudhi include +#include +#include + // standard include #include #include @@ -32,14 +36,9 @@ #include #include #include -#include -#include #include - -// gudhi include - -#include -#include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -165,7 +164,7 @@ class Persistence_landscape_on_grid { double compute_integral_of_landscape(size_t level) const { bool dbg = false; double result = 0; - double dx = (this->grid_max - this->grid_min) / (double)(this->values_of_landscapes.size() - 1); + double dx = (this->grid_max - this->grid_min) / static_cast(this->values_of_landscapes.size() - 1); if (dbg) { std::cerr << "this->grid_max : " << this->grid_max << std::endl; @@ -220,7 +219,7 @@ class Persistence_landscape_on_grid { bool dbg = false; double result = 0; - double dx = (this->grid_max - this->grid_min) / (double)(this->values_of_landscapes.size() - 1); + double dx = (this->grid_max - this->grid_min) / static_cast(this->values_of_landscapes.size() - 1); double previous_x = this->grid_min; double previous_y = 0; if (this->values_of_landscapes[0].size() > level) previous_y = this->values_of_landscapes[0][level]; @@ -279,7 +278,7 @@ class Persistence_landscape_on_grid { * Shall those points be joined with lines, we will obtain the i-th landscape function. **/ friend std::ostream& operator<<(std::ostream& out, const Persistence_landscape_on_grid& land) { - double dx = (land.grid_max - land.grid_min) / (double)(land.values_of_landscapes.size() - 1); + double dx = (land.grid_max - land.grid_min) / static_cast(land.values_of_landscapes.size() - 1); double x = land.grid_min; for (size_t i = 0; i != land.values_of_landscapes.size(); ++i) { out << x << " : "; @@ -306,7 +305,7 @@ class Persistence_landscape_on_grid { if ((x < this->grid_min) || (x > this->grid_max)) return 0; // find a position of a vector closest to x: - double dx = (this->grid_max - this->grid_min) / (double)(this->values_of_landscapes.size() - 1); + double dx = (this->grid_max - this->grid_min) / static_cast(this->values_of_landscapes.size() - 1); size_t position = size_t((x - this->grid_min) / dx); if (dbg) { @@ -338,7 +337,6 @@ class Persistence_landscape_on_grid { std::make_pair(position * dx + this->grid_min, this->values_of_landscapes[position][level]), std::make_pair((position + 1) * dx + this->grid_min, 0)); } else { - //(this->values_of_landscapes[position+1].size() > level) line = compute_parameters_of_a_line( std::make_pair(position * dx + this->grid_min, 0), std::make_pair((position + 1) * dx + this->grid_min, this->values_of_landscapes[position + 1][level])); @@ -623,7 +621,7 @@ class Persistence_landscape_on_grid { throw "Landscapes are not defined on the same grid, the program will now terminate"; double result = 0; - double dx = (l1.grid_max - l1.grid_min) / (double)(l1.values_of_landscapes.size() - 1); + double dx = (l1.grid_max - l1.grid_min) / static_cast(l1.values_of_landscapes.size() - 1); double previous_x = l1.grid_min - dx; double previous_y_l1 = 0; @@ -737,14 +735,14 @@ class Persistence_landscape_on_grid { } if (p < std::numeric_limits::max()) { - //\int_{- \infty}^{+\infty}| first-second |^p + // \int_{- \infty}^{+\infty}| first-second |^p double result; if (p != 1) { if (dbg) { std::cerr << "p : " << p << std::endl; getchar(); } - result = lan.compute_integral_of_landscape((double)p); + result = lan.compute_integral_of_landscape(p); if (dbg) { std::cerr << "integral : " << result << std::endl; getchar(); @@ -756,8 +754,8 @@ class Persistence_landscape_on_grid { getchar(); } } - //(\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) - return pow(result, 1 / (double)p); + // (\int_{- \infty}^{+\infty}| first-second |^p)^(1/p) + return pow(result, 1.0 / p); } else { // p == infty return lan.compute_maximum(); @@ -789,7 +787,7 @@ class Persistence_landscape_on_grid { * Vectorized_topological_data */ std::vector vectorize(int number_of_function) const { - // TODO, think of something smarter over here + // TODO(PD) think of something smarter over here if ((number_of_function < 0) || ((size_t)number_of_function >= this->values_of_landscapes.size())) { throw "Wrong number of function\n"; } @@ -864,7 +862,7 @@ class Persistence_landscape_on_grid { } // normalizing: for (size_t i = 0; i != this->values_of_landscapes[grid_point].size(); ++i) { - this->values_of_landscapes[grid_point][i] /= (double)to_average.size(); + this->values_of_landscapes[grid_point][i] /= static_cast(to_average.size()); } } } // compute_average @@ -979,10 +977,10 @@ void Persistence_landscape_on_grid::set_up_values_of_landscapes(const std::vecto this->grid_max = grid_max_; if (grid_max_ <= grid_min_) { - throw "Wrong parameters of grid_min and grid_max given to the procedure. The grid have negative, or zero size. The program will now terminate.\n"; + throw "Wrong parameters of grid_min and grid_max given to the procedure. The program will now terminate.\n"; } - double dx = (grid_max_ - grid_min_) / (double)(number_of_points_); + double dx = (grid_max_ - grid_min_) / static_cast(number_of_points_); // for every interval in the diagram: for (size_t int_no = 0; int_no != p.size(); ++int_no) { size_t grid_interval_begin = (p[int_no].first - grid_min_) / dx; @@ -1161,7 +1159,7 @@ void Persistence_landscape_on_grid::load_landscape_from_file(const char* filenam // check if the file exist. if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } size_t number_of_points_in_the_grid = 0; @@ -1223,7 +1221,7 @@ void Persistence_landscape_on_grid::plot(const char* filename, double min_x, dou } size_t number_of_nonzero_levels = this->number_of_nonzero_levels(); - double dx = (this->grid_max - this->grid_min) / ((double)this->values_of_landscapes.size() - 1); + double dx = (this->grid_max - this->grid_min) / static_cast(this->values_of_landscapes.size() - 1); size_t from = 0; if (from_ != std::numeric_limits::max()) { diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h index 282c107d..ad4d3c57 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h +++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h @@ -23,17 +23,19 @@ #ifndef PERSISTENCE_VECTORS_H_ #define PERSISTENCE_VECTORS_H_ +// gudhi include +#include +#include +#include + #include #include #include #include #include #include - -// gudhi include -#include -#include -#include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -66,7 +68,7 @@ class Vector_distances_in_diagram { /** * The default constructor. **/ - Vector_distances_in_diagram(){}; + Vector_distances_in_diagram(){} /** * The constructor that takes as an input a multiset of persistence intervals (given as vector of birth-death @@ -517,7 +519,7 @@ void Vector_distances_in_diagram::compute_average(const std::vector(to_average.size()); } this->sorted_vector_of_distances = av; this->where_to_cut = av.size(); @@ -611,7 +613,7 @@ void Vector_distances_in_diagram::load_from_file(const char* filename) { // check if the file exist. if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } double number; diff --git a/src/Persistence_representations/include/gudhi/common_persistence_representations.h b/src/Persistence_representations/include/gudhi/common_persistence_representations.h index 8f56ad3e..61a3274d 100644 --- a/src/Persistence_representations/include/gudhi/common_persistence_representations.h +++ b/src/Persistence_representations/include/gudhi/common_persistence_representations.h @@ -23,6 +23,9 @@ #ifndef COMMON_PERSISTENCE_REPRESENTATIONS_H_ #define COMMON_PERSISTENCE_REPRESENTATIONS_H_ +#include +#include + namespace Gudhi { namespace Persistence_representations { // this file contain an implementation of some common procedures used in Persistence_representations. diff --git a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h index a5c2b286..ad3d4e83 100644 --- a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h +++ b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h @@ -28,6 +28,8 @@ #include #include #include +#include +#include namespace Gudhi { namespace Persistence_representations { @@ -54,7 +56,7 @@ std::vector > read_persistence_intervals_in_one_dimens // checking if the file exist: if (!in.good()) { std::cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; - throw "The file from which you are trying to read the persistence landscape do not exist. The program will now terminate \n"; + throw "The persistence landscape file do not exist. The program will now terminate \n"; } std::string line; @@ -85,7 +87,7 @@ std::vector > read_persistence_intervals_in_one_dimens while (ss >> number) { this_line.push_back(number); } - number_of_entries_per_line += (int)this_line.size(); + number_of_entries_per_line += static_cast(this_line.size()); if (dbg) { std::cerr << "number_of_entries_per_line : " << number_of_entries_per_line << ". This number was obtained by analyzing this line : " << line << std::endl; @@ -93,7 +95,7 @@ std::vector > read_persistence_intervals_in_one_dimens if ((number_of_entries_per_line < 2) || (number_of_entries_per_line > 4)) { std::cerr << "The input file you have provided have wrong number of numerical entries per line. The program " "will now terminate. \n"; - throw "The input file you have provided have wrong number of numerical entries per line. The program will now terminate. \n"; + throw "Wrong number of numerical entries per line in the input file. The program will now terminate. \n"; } } // In case there is an 'inf' string in this line, we are dealing with this situation in below. diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp index b0ea3a35..b4e2be89 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp @@ -26,6 +26,7 @@ using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include +#include int main(int argc, char** argv) { std::cout << "This program computes average persistence landscape of persistence landscapes created based on " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp index f87530d4..56b2d336 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute distance of persistence heat maps stored in a file (the file needs to be created " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp index f801d056..ec9482f0 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp @@ -27,6 +27,7 @@ using namespace Gudhi::Persistence_representations; #include #include +#include int main(int argc, char** argv) { std::cout << "This program compute scalar product of persistence landscapes stored in a file (the file needs to be " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp index a127996f..68c75059 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp index 371d94a6..a56393a3 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp index e2b9abb1..44115329 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence heat map of diagrams provided as an input. The Gaussian kernels are " diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp index 03f1641a..ebc82f82 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence heat map of diagrams provided as an input.\n"; diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp b/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp index 004fa90e..7b24bb7c 100644 --- a/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp +++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates PSSK of diagrams provided as an input.\n"; diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp index 058677d9..72c56e92 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp index f1ccda9f..6a872b7a 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp @@ -28,6 +28,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute the bottleneck distance of persistence diagrams stored in a files. \n"; diff --git a/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp b/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp index 1f7011e1..5fbbef14 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp @@ -24,6 +24,9 @@ #include #include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp index 6bdb0081..b8f96b60 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp @@ -24,6 +24,9 @@ #include #include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp index 206745c1..521621b2 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp @@ -24,6 +24,9 @@ #include #include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp index 971f039e..e76906e9 100644 --- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp +++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::Persistence_representations; diff --git a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp index 1927551d..f885a7a7 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp @@ -26,6 +26,7 @@ using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include +#include int main(int argc, char** argv) { std::cout << "This program computes average persistence landscape of persistence landscapes created based on " diff --git a/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp index a4027fa7..7028b98b 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp @@ -27,6 +27,7 @@ using namespace Gudhi::Persistence_representations; #include #include +#include int main(int argc, char** argv) { std::cout << "This program compute distance of persistence landscapes stored in a file (the file needs to be created " diff --git a/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp index 95d5a998..76a9d433 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp @@ -27,6 +27,7 @@ using namespace Gudhi::Persistence_representations; #include #include +#include int main(int argc, char** argv) { std::cout << "This program compute scalar product of persistence landscapes stored in a file (the file needs to be " diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp index 1ba34762..4694e897 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute distance of persistence landscapes on grid stored in a file (the file needs to be " diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp index 4ec9a740..75c33cb1 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp @@ -27,6 +27,7 @@ using namespace Gudhi::Persistence_representations; #include #include +#include int main(int argc, char** argv) { std::cout << "This program compute scalar product of persistence landscapes on grid stored in a file (the file needs " diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp index 65addbe5..490a1c25 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence landscape on grid of diagrams provided as an input.\n"; @@ -66,7 +68,7 @@ int main(int argc, char** argv) { if ((min_ != -1) || (max_ != -1)) { 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. + // (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, dimension); } std::stringstream ss; diff --git a/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp index 2bfc4a6d..585f2f61 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp @@ -26,6 +26,7 @@ using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include +#include int main(int argc, char** argv) { std::cout << "This program computes average persistence vector of persistence vectors created based on persistence " diff --git a/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp index a2e27612..79906262 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute distance of persistence vectors stored in a file (the file needs to be created " diff --git a/src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp index 95f2d2ae..a5916ed8 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program compute scalar product of persistence vectors stored in a file (the file needs to be " diff --git a/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp index 2996f49b..0941308f 100644 --- a/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp +++ b/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence vectors of diagrams provided as an input. The first parameter of this " diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index f683136b..e52fc611 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -26,6 +26,7 @@ #include // for std::sqrt #include // for std::decay #include // for std::begin, std::end +#include namespace Gudhi { @@ -49,8 +50,7 @@ class Euclidean_distance { return std::sqrt(dist); } template< typename T > - T operator() ( const std::pair< T,T >& f , const std::pair< T,T >& s ) - { + T operator() ( const std::pair< T, T >& f , const std::pair< T, T >& s ) { return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); } }; -- cgit v1.2.3 From 3736caa9ed742f985d743b9c959442d331110050 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 31 May 2017 06:46:24 +0000 Subject: Fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2481 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3e39324360996e408351421a2185c2cd9e6ee1ae --- .../doc/Persistence_representations_doc.h | 321 ++++++++++----------- .../include/gudhi/Persistence_vectors.h | 2 +- .../persistence_landscapes/create_landscapes.cpp | 2 + src/common/include/gudhi/distance_functions.h | 4 +- 4 files changed, 165 insertions(+), 164 deletions(-) (limited to 'src/common') diff --git a/src/Persistence_representations/doc/Persistence_representations_doc.h b/src/Persistence_representations/doc/Persistence_representations_doc.h index 7884574d..49a1cdd0 100644 --- a/src/Persistence_representations/doc/Persistence_representations_doc.h +++ b/src/Persistence_representations/doc/Persistence_representations_doc.h @@ -34,223 +34,222 @@ namespace Persistence_representations { * @{ *\section Persistence_representations_idea Idea - *In order to perform most of the statistical tests and machine learning algorithms on a data one need to be able to + In order to perform most of the statistical tests and machine learning algorithms on a data one need to be able to perform only a very limited number of operations on them. Let us fix a representation of - * data of a type A. To perform most of the statistical and machine learning operations one need to be able to compute + data of a type A. To perform most of the statistical and machine learning operations one need to be able to compute average of objects of type A (so that the averaged object is also of a type A), to - * compute distance between objects of a type A, to vectorize object of a type A and to compute scalar product of a pair + compute distance between objects of a type A, to vectorize object of a type A and to compute scalar product of a pair objects of a type A. - * - *To put this statement into a context, let us assume we have two collections \f$ c_1,\ldots,c_n\f$ and + + To put this statement into a context, let us assume we have two collections \f$ c_1,\ldots,c_n\f$ and \f$d_1,...,d_n\f$ of objects of a type A. We want to verify if the average of those two collections - * are different by performing a permutation test. - *First of all, we compute averages of those two collections: C average of \f$ c_1,\ldots,c_n \f$ and D average of + are different by performing a permutation test. + First of all, we compute averages of those two collections: C average of \f$ c_1,\ldots,c_n \f$ and D average of \f$d_1,\ldots,d_n\f$. Note that both C and D are of a type A. Then we compute \f$d(C,D)\f$, - * a distance between C and D. - *Later we put the two collections into one bin: - *\f[B = \{ c_1,...,c_n,d_1,...,d_n \}\f] - *Then we shuffle B, and we divide the shuffled version of B into two classes: \f$B_1\f$ and \f$B_2\f$ (in this case, of + a distance between C and D. + Later we put the two collections into one bin: + \f[B = \{ c_1,...,c_n,d_1,...,d_n \}\f] + Then we shuffle B, and we divide the shuffled version of B into two classes: \f$B_1\f$ and \f$B_2\f$ (in this case, of the same cardinality). Then we compute averages \f$\hat{B_1}\f$ and \f$\hat{B_2}\f$ - * of elements in \f$B_1\f$ and \f$B_2\f$. Note that again, \f$\hat{B_1}\f$ and \f$\hat{B_2}\f$ are of a type A. - *Then we compute their distance \f$d(\hat{B_1},\hat{B_2})\f$. The procedure of shuffling and dividing the set \f$B\f$ + of elements in \f$B_1\f$ and \f$B_2\f$. Note that again, \f$\hat{B_1}\f$ and \f$\hat{B_2}\f$ are of a type A. + Then we compute their distance \f$d(\hat{B_1},\hat{B_2})\f$. The procedure of shuffling and dividing the set \f$B\f$ is repeated \f$N\f$ times (where \f$N\f$ is reasonably large number). - *Then the p-value of a statement that the averages of \f$c_1,...,c_n\f$ and \f$d_1,...,d_n\f$ is approximated by the + Then the p-value of a statement that the averages of \f$c_1,...,c_n\f$ and \f$d_1,...,d_n\f$ is approximated by the number of times \f$d(\hat{B_1},\hat{B_2}) > d(C,D)\f$ divided by \f$N\f$. - * - *The permutation test reminded above can be performed for any type A which can be averaged, and which allows for + + The permutation test reminded above can be performed for any type A which can be averaged, and which allows for computations of distances. - * - *The Persistence\_representations contains a collection of various representations of persistent homology that + + The Persistence\_representations contains a collection of various representations of persistent homology that implements various concepts described below: - * - *\li Concept of a representation of persistence that allows averaging (so that the average object is of the same type). - *\li Concept of representation of persistence that allows computations of distances. - *\li Concept of representation of persistence that allows computations of scalar products. - *\li Concept of representation of persistence that allows vectorization. - *\li Concept of representation of persistence that allows computations of real--valued characteristics of objects. - * - * - *At the moment an implementation of the following representations of persistence are available (further details of + + \li Concept of a representation of persistence that allows averaging (so that the average object is of the same type). + \li Concept of representation of persistence that allows computations of distances. + \li Concept of representation of persistence that allows computations of scalar products. + \li Concept of representation of persistence that allows vectorization. + \li Concept of representation of persistence that allows computations of real--valued characteristics of objects. + + + At the moment an implementation of the following representations of persistence are available (further details of those representations will be discussed later): - * - *\li Exact persistence landscapes (allow averaging, computation of distances, scalar products, vectorizations and real + + \li Exact persistence landscapes (allow averaging, computation of distances, scalar products, vectorizations and real value characteristics). - *\li Persistence landscapes on a grid (allow averaging, computation of distances scalar products, vectorizations and + \li Persistence landscapes on a grid (allow averaging, computation of distances scalar products, vectorizations and real value characteristics). - *\li Persistence heat maps – various representations where one put some weighted or not Gaussian kernel for each point + \li Persistence heat maps – various representations where one put some weighted or not Gaussian kernel for each point of diagram (allow averaging, computation of distances, scalar products, - * vectorizations and real value characteristics). - *\li Persistence vectors (allow averaging, computation of distances, scalar products, vectorizations and real value + vectorizations and real value characteristics). + \li Persistence vectors (allow averaging, computation of distances, scalar products, vectorizations and real value characteristics). - *\li Persistence diagrams / barcodes (allow computation of distances, vectorizations and real value characteristics). - * - * - * Note that at the while functionalities like averaging, distances and scalar products are fixed, there is no canonical + \li Persistence diagrams / barcodes (allow computation of distances, vectorizations and real value characteristics). + + + Note that at the while functionalities like averaging, distances and scalar products are fixed, there is no canonical way of vectorizing and computing real valued characteristics of objects. Therefore the - * vectorizations and computation of real value characteristics procedures are quite likely to evolve in the furthering + vectorizations and computation of real value characteristics procedures are quite likely to evolve in the furthering versions of the library. - * - * The main aim of this implementation is to be able to implement various statistical methods, both on the level of C++ + + The main aim of this implementation is to be able to implement various statistical methods, both on the level of C++ and on the level of python. The methods will operate on the functionalities offered - * by concepts. That means that the statistical and ML methods will be able to operate on any representation that + by concepts. That means that the statistical and ML methods will be able to operate on any representation that implement the required concept (including the ones that are not in the library at the moment). - * That gives provides a framework, that is very easy to extend, for topological statistics. - * - * Below we are discussing the representations which are currently implemented in Persistence\_representations package: - * - * \section sec_persistence_landscapes Persistence Landscapes - * Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape
- * Persistence landscapes were originally proposed by Bubenik in \cite bubenik_landscapes_2015. Efficient algorithms to + That gives provides a framework, that is very easy to extend, for topological statistics. + + Below we are discussing the representations which are currently implemented in Persistence\_representations package: + + \section sec_persistence_landscapes Persistence Landscapes + Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape
+ Persistence landscapes were originally proposed by Bubenik in \cite bubenik_landscapes_2015. Efficient algorithms to compute them rigorously were proposed by Bubenik and Dlotko in \cite bubenik_dlotko_landscapes_2016. The idea of - * persistence landscapes is shortly summarized in below. - * - * To begin with, suppose we are given a point \f$(b,d) \in \mathbb{R}^2\f$ in a - * persistence diagram. With this point, we associate a piecewise - * linear function \f$f_{(b,d)} : \mathbb{R} \rightarrow [0,\infty)\f$, which is - * defined as - * - * \f[f_{(b,d)}(x) = - * \left\{ \begin{array}{ccl} - * 0 & \mbox{ if } & x \not\in (b, d) \; , \\ - * x - b & \mbox{ if } & x \in \left( b, \frac{b+d}{2} - * \right] \; , \\ - * d - x & \mbox{ if } & x \in \left(\frac{b+d}{2}, - * d \right) \; . - * \end{array} \right. - *\f] - * - * A persistence landscape of the birth-death - * pairs \f$(b_i , d_i)\f$, where \f$i = 1,\ldots,m\f$, which constitute the given - * persistence diagram is the sequence of functions \f$\lambda_k : \mathbb{R} \rightarrow [0,\infty)\f$ for \f$k \in + persistence landscapes is shortly summarized in below. + + To begin with, suppose we are given a point \f$(b,d) \in \mathbb{R}^2\f$ in a + persistence diagram. With this point, we associate a piecewise + linear function \f$f_{(b,d)} : \mathbb{R} \rightarrow [0,\infty)\f$, which is + defined as + + \f[f_{(b,d)}(x) = + \left\{ \begin{array}{ccl} + 0 & \mbox{ if } & x \not\in (b, d) \; , \\ + x - b & \mbox{ if } & x \in \left( b, \frac{b+d}{2} + \right] \; , \\ + d - x & \mbox{ if } & x \in \left(\frac{b+d}{2}, + d \right) \; . + \end{array} \right. + \f] + + A persistence landscape of the birth-death + pairs \f$(b_i , d_i)\f$, where \f$i = 1,\ldots,m\f$, which constitute the given + persistence diagram is the sequence of functions \f$\lambda_k : \mathbb{R} \rightarrow [0,\infty)\f$ for \f$k \in \mathbb{N}\f$, where \f$\lambda_k(x)\f$ - * denotes the \f$k^{\rm th}\f$ largest value of the numbers \f$f_{(b_i,d_i)}(x)\f$, - * for \f$i = 1, \ldots, m\f$, and we define \f$\lambda_k(x) = 0\f$ if \f$k > m\f$. - * Equivalently, this sequence of functions can be combined into a single - * function \f$L : \mathbb{N} \times \mathbb{R} \to [0,\infty)\f$ of two - * variables, if we define \f$L(k,t) = \lambda_k(t)\f$. - * - * The detailed description of algorithms used to compute persistence landscapes can be found in \cite - bubenik_dlotko_landscapes_2016. - * Note that this implementation provides exact representation of landscapes. That have many advantages, but also a few + denotes the \f$k^{\rm th}\f$ largest value of the numbers \f$f_{(b_i,d_i)}(x)\f$, + for \f$i = 1, \ldots, m\f$, and we define \f$\lambda_k(x) = 0\f$ if \f$k > m\f$. + Equivalently, this sequence of functions can be combined into a single + function \f$L : \mathbb{N} \times \mathbb{R} \to [0,\infty)\f$ of two + variables, if we define \f$L(k,t) = \lambda_k(t)\f$. + + The detailed description of algorithms used to compute persistence landscapes can be found in + \cite bubenik_dlotko_landscapes_2016. + Note that this implementation provides exact representation of landscapes. That have many advantages, but also a few drawbacks. For instance, as discussed - * in \cite bubenik_dlotko_landscapes_2016, the exact representation of landscape may be of quadratic size with respect + in \cite bubenik_dlotko_landscapes_2016, the exact representation of landscape may be of quadratic size with respect to the input persistence diagram. It may therefore happen - * that, for very large diagrams, using this representation may be memory--prohibitive. In such a case, there are two + that, for very large diagrams, using this representation may be memory--prohibitive. In such a case, there are two possible ways to proceed: - * - *\li Use non exact representation on a grid described in the Section \ref sec_landscapes_on_grid. - *\li Compute just a number of initial nonzero landscapes. This option is available from C++ level. - * - * - * - *\section sec_landscapes_on_grid Persistence Landscapes on a grid - * Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape_on_grid
- * This is an alternative, not--exact, representation of persistence landscapes defined in the Section \ref + + \li Use non exact representation on a grid described in the Section \ref sec_landscapes_on_grid. + \li Compute just a number of initial nonzero landscapes. This option is available from C++ level. + + + + \section sec_landscapes_on_grid Persistence Landscapes on a grid + Reference manual: \ref Gudhi::Persistence_representations::Persistence_landscape_on_grid
+ This is an alternative, not--exact, representation of persistence landscapes defined in the Section \ref sec_persistence_landscapes. Unlike in the Section \ref sec_persistence_landscapes we build a - * representation of persistence landscape by sampling its values on a finite, equally distributed grid of points. - * Since, the persistence landscapes that originate from persistence diagrams have slope \f$1\f$ or \f$-1\f$, we have an + representation of persistence landscape by sampling its values on a finite, equally distributed grid of points. + Since, the persistence landscapes that originate from persistence diagrams have slope \f$1\f$ or \f$-1\f$, we have an estimate of a region between the grid points where the landscape cab be located. - * That allows to estimate an error make when performing various operations on landscape. Note that for average + That allows to estimate an error make when performing various operations on landscape. Note that for average landscapes the slope is in range \f$[-1,1]\f$ and similar estimate can be used. - * - * Due to a lack of rigorous description of the algorithms to deal with this non--rigorous representation of persistence + + Due to a lack of rigorous description of the algorithms to deal with this non--rigorous representation of persistence landscapes in the literature, we are providing a short discussion of them in below. - * - *Let us assume that we want to compute persistence landscape on a interval \f$[x,y]\f$. Let us assume that we want to + + Let us assume that we want to compute persistence landscape on a interval \f$[x,y]\f$. Let us assume that we want to use \f$N\f$ grid points for that purpose. - * Then we will sample the persistence landscape on points \f$x_1 = x , x_2 = x + \frac{y-x}{N}, \ldots , x_{N} = y\f$. + Then we will sample the persistence landscape on points \f$x_1 = x , x_2 = x + \frac{y-x}{N}, \ldots , x_{N} = y\f$. Persistence landscapes are represented as a vector of - * vectors of real numbers. Assume that i-th vector consist of \f$n_i\f$ numbers sorted from larger to smaller. They + vectors of real numbers. Assume that i-th vector consist of \f$n_i\f$ numbers sorted from larger to smaller. They represent the values of the functions \f$\lambda_1,\ldots,\lambda_{n_i}\f$ ,\f$\lambda_{n_i+1}\f$ and the functions with larger indices are then zero functions) on the i-th point of a grid, i.e. \f$x + i \frac{y-x}{N}\f$. - * - *When averaging two persistence landscapes represented by a grid we need to make sure that they are defined in a + + When averaging two persistence landscapes represented by a grid we need to make sure that they are defined in a compatible grids. I.e. the intervals \f$[x,y]\f$ on which they are defined are - * the same, and the numbers of grid points \f$N\f$ are the same in both cases. If this is the case, we simply compute + the same, and the numbers of grid points \f$N\f$ are the same in both cases. If this is the case, we simply compute point-wise averages of the entries of corresponding - * vectors (In this whole section we assume that if one vector of numbers is shorter than another, we extend the shorter + vectors (In this whole section we assume that if one vector of numbers is shorter than another, we extend the shorter one with zeros so that they have the same length.) - * - *Computations of distances between two persistence landscapes on a grid is not much different than in the rigorous + + Computations of distances between two persistence landscapes on a grid is not much different than in the rigorous case. In this case, we sum up the distances between the same levels of - * corresponding landscapes. For fixed level, we approximate the landscapes between the corresponding constitutive + corresponding landscapes. For fixed level, we approximate the landscapes between the corresponding constitutive points of landscapes by linear functions, and compute the \f$L^p\f$ distance between them. - * - *Similarly as in case of distance, when computing the scalar product of two persistence landscapes on a grid, we sum up + + Similarly as in case of distance, when computing the scalar product of two persistence landscapes on a grid, we sum up the scalar products of corresponding levels of landscapes. For each level, - * we assume that the persistence landscape on a grid between two grid points is approximated by linear function. + we assume that the persistence landscape on a grid between two grid points is approximated by linear function. Therefore to compute scalar product of two corresponding levels of landscapes, - * we sum up the integrals of products of line segments for every pair of constitutive grid points. - * - *Note that for this representation we need to specify a few parameters: - * - *\li Begin and end point of a grid -- the interval \f$[x,y]\f$ (real numbers). - *\li Number of points in a grid (positive integer \f$N\f$). - * - * - *Note that the same representation is used in TDA R-package \cite Fasy_Kim_Lecci_Maria_tda. - * - *\section sec_persistence_heat_maps Persistence heat maps - * Reference manual: \ref Gudhi::Persistence_representations::Persistence_heat_maps
- *This is a general class of discrete structures which are based on idea of placing a kernel in the points of + we sum up the integrals of products of line segments for every pair of constitutive grid points. + + Note that for this representation we need to specify a few parameters: + + \li Begin and end point of a grid -- the interval \f$[x,y]\f$ (real numbers). + \li Number of points in a grid (positive integer \f$N\f$). + + + Note that the same representation is used in TDA R-package \cite Fasy_Kim_Lecci_Maria_tda. + + \section sec_persistence_heat_maps Persistence heat maps + Reference manual: \ref Gudhi::Persistence_representations::Persistence_heat_maps
+ This is a general class of discrete structures which are based on idea of placing a kernel in the points of persistence diagrams. - *This idea appeared in work by many authors over the last 15 years. As far as we know this idea was firstly described + This idea appeared in work by many authors over the last 15 years. As far as we know this idea was firstly described in the work of Bologna group in \cite Ferri_Frosini_comparision_sheme_1 and \cite Ferri_Frosini_comparision_sheme_2. - *Later it has been described by Colorado State University group in \cite Persistence_Images_2017. The presented paper + Later it has been described by Colorado State University group in \cite Persistence_Images_2017. The presented paper in the first time provide a discussion of stability of the representation. - *Also, the same ideas are used in construction of two recent kernels used for machine learning: \cite - Kusano_Fukumizu_Hiraoka_PWGK and \cite Reininghaus_Huber_ALL_PSSK. Both the kernel's construction uses interesting - ideas to - *ensure stability of the representation with respect to Wasserstein metric. In the kernel presented in \cite - Kusano_Fukumizu_Hiraoka_PWGK, a scaling function is used to multiply the Gaussian kernel in the - *way that the points close to diagonal got low weight and consequently do not have a big influence on the resulting + Also, the same ideas are used in construction of two recent kernels used for machine learning: + \cite Kusano_Fukumizu_Hiraoka_PWGK and \cite Reininghaus_Huber_ALL_PSSK. Both the kernel's construction uses + interesting ideas to ensure stability of the representation with respect to Wasserstein metric. In the kernel + presented in \cite Kusano_Fukumizu_Hiraoka_PWGK, a scaling function is used to multiply the Gaussian kernel in the + way that the points close to diagonal got low weight and consequently do not have a big influence on the resulting distribution. In \cite Reininghaus_Huber_ALL_PSSK for every point \f$(b,d)\f$ two Gaussian kernels - *are added: first, with a weight 1 in a point \f$(b,d)\f$, and the second, with the weight -1 for a point \f$(b,d)\f$. + are added: first, with a weight 1 in a point \f$(b,d)\f$, and the second, with the weight -1 for a point \f$(b,d)\f$. In both cases, the representations are stable with respect to 1-Wasserstein distance. - * - *In Persistence\_representations package we currently implement a discretization of the distributions described above. + + In Persistence\_representations package we currently implement a discretization of the distributions described above. The base of this implementation is 2-dimensional array of pixels. Each pixel have assigned a real value which - * is a sum of values of distributions induced by each point of the persistence diagram. At the moment we compute the + is a sum of values of distributions induced by each point of the persistence diagram. At the moment we compute the sum of values on a center of a pixels. It can be easily extended to any other function - * (like for instance sum of integrals of the intermediate distribution on a pixel). - * - *The parameters that determine the structure are the following: - * - *\li A positive integer k determining the size of the kernel we used (we always assume that the kernels are square). - *\li A filter: in practice a square matrix of a size \f$2k+1 \times 2k+1\f$. By default, this is a discretization of + (like for instance sum of integrals of the intermediate distribution on a pixel). + + The parameters that determine the structure are the following: + + \li A positive integer k determining the size of the kernel we used (we always assume that the kernels are square). + \li A filter: in practice a square matrix of a size \f$2k+1 \times 2k+1\f$. By default, this is a discretization of N(0,1) kernel. - *\li The box \f$[x_0,x_1]\times [y_0,y_1]\f$ bounding the domain of the persistence image. - *\li Scaling function. Each Gaussian kernel at point \f$(p,q)\f$ gets multiplied by the value of this function at the + \li The box \f$[x_0,x_1]\times [y_0,y_1]\f$ bounding the domain of the persistence image. + \li Scaling function. Each Gaussian kernel at point \f$(p,q)\f$ gets multiplied by the value of this function at the point \f$(p,q)\f$. - *\li A boolean value determining if the space below diagonal should be erased or not. To be precise: when points close + \li A boolean value determining if the space below diagonal should be erased or not. To be precise: when points close to diagonal are given then sometimes the kernel have support that reaches the region - *below the diagonal. If the value of this parameter is true, then the values below diagonal can be erased. - * - * - *\section sec_persistence_vectors Persistence vectors - * Reference manual: \ref Gudhi::Persistence_representations::Vector_distances_in_diagram
- *This is a representation of persistent homology in a form of a vector which was designed for an application in 3d + below the diagonal. If the value of this parameter is true, then the values below diagonal can be erased. + + + \section sec_persistence_vectors Persistence vectors + Reference manual: \ref Gudhi::Persistence_representations::Vector_distances_in_diagram
+ This is a representation of persistent homology in a form of a vector which was designed for an application in 3d graphic in \cite Carriere_Oudot_Ovsjanikov_top_signatures_3d. Below we provide a short description of this representation. - * - *Given a persistence diagram \f$D = \{ (b_i,d_i) \}\f$, for every pair of birth--death points \f$(b_1,d_1)\f$ and + + Given a persistence diagram \f$D = \{ (b_i,d_i) \}\f$, for every pair of birth--death points \f$(b_1,d_1)\f$ and \f$(b_2,d_2)\f$ we compute the following three distances: - * - *\li \f$d( (b_1,d_1) , (b_2,d_2) )\f$. - *\li \f$d( (b_1,d_1) , (\frac{b_1,d_1}{2},\frac{b_1,d_1}{2}) )\f$. - *\li \f$d( (b_2,d_2) , (\frac{b_2,d_2}{2},\frac{b_2,d_2}{2}) )\f$. - * - *We pick the smallest of those and add it to a vector. The obtained vector of numbers is then sorted in decreasing + + \li \f$d( (b_1,d_1) , (b_2,d_2) )\f$. + \li \f$d( (b_1,d_1) , (\frac{b_1,d_1}{2},\frac{b_1,d_1}{2}) )\f$. + \li \f$d( (b_2,d_2) , (\frac{b_2,d_2}{2},\frac{b_2,d_2}{2}) )\f$. + + We pick the smallest of those and add it to a vector. The obtained vector of numbers is then sorted in decreasing order. This way we obtain a persistence vector representing the diagram. - * - *Given two persistence vectors, the computation of distances, averages and scalar products is straightforward. Average + + Given two persistence vectors, the computation of distances, averages and scalar products is straightforward. Average is simply a coordinate-wise average of a collection of vectors. In this section we - * assume that the vectors are extended by zeros if they are of a different size. To compute distances we compute + assume that the vectors are extended by zeros if they are of a different size. To compute distances we compute absolute value of differences between coordinates. A scalar product is a sum of products of - * values at the corresponding positions of two vectors. - * - * \copyright GNU General Public License v3. + values at the corresponding positions of two vectors. + + \copyright GNU General Public License v3. */ /** @} */ // end defgroup Persistence_representations diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h index ad4d3c57..0fb49eee 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h +++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h @@ -68,7 +68,7 @@ class Vector_distances_in_diagram { /** * The default constructor. **/ - Vector_distances_in_diagram(){} + Vector_distances_in_diagram() {} /** * The constructor that takes as an input a multiset of persistence intervals (given as vector of birth-death diff --git a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp index 1692c7ac..a6b33225 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp @@ -27,6 +27,8 @@ using namespace Gudhi::Persistence_representations; #include #include +#include +#include int main(int argc, char** argv) { std::cout << "This program creates persistence landscapes of diagrams provided as an input. \n"; diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index e52fc611..c556155e 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -50,8 +50,8 @@ class Euclidean_distance { return std::sqrt(dist); } template< typename T > - T operator() ( const std::pair< T, T >& f , const std::pair< T, T >& s ) { - return sqrt( (f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second) ); + T operator() (const std::pair< T, T >& f, const std::pair< T, T >& s) { + return sqrt((f.first-s.first)*(f.first-s.first) + (f.second-s.second)*(f.second-s.second)); } }; -- cgit v1.2.3 From f583b644e6bb34e6289c17fa33e34f52897a6329 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 13 Jun 2017 15:27:43 +0000 Subject: Merge read_persistence_from_file into persistence_representation_integration git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2539 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2bfc0f855b4814946c5cad892d6314d147db1caf --- src/Bottleneck_distance/example/CMakeLists.txt | 4 ++ .../example/bottleneck_read_file_example.cpp | 36 ++-------- src/common/doc/file_formats.h | 54 +++++++++++++++ src/common/include/gudhi/reader_utils.h | 76 +++++++++++++++++++++- 4 files changed, 139 insertions(+), 31 deletions(-) create mode 100644 src/common/doc/file_formats.h (limited to 'src/common') diff --git a/src/Bottleneck_distance/example/CMakeLists.txt b/src/Bottleneck_distance/example/CMakeLists.txt index 0534a2c4..508e57bf 100644 --- a/src/Bottleneck_distance/example/CMakeLists.txt +++ b/src/Bottleneck_distance/example/CMakeLists.txt @@ -19,6 +19,10 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.15" "-m" "0.12" "-d" "3" "-p" "3") + add_test(NAME Bottleneck_read_file_example + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers") + install(TARGETS bottleneck_read_file_example DESTINATION bin) install(TARGETS bottleneck_basic_example DESTINATION bin) install(TARGETS alpha_rips_persistence_bottleneck_distance DESTINATION bin) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index bde05825..238d99ad 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -20,9 +20,8 @@ * along with this program. If not, see . */ -#define CGAL_HAS_THREADS - #include +#include #include #include #include // for pair @@ -30,43 +29,22 @@ #include #include -std::vector< std::pair > read_diagram_from_file(const char* filename) { - std::ifstream in; - in.open(filename); - std::vector< std::pair > result; - if (!in.is_open()) { - std::cerr << "File : " << filename << " do not exist. The program will now terminate \n"; - throw "File do not exist \n"; - } - - std::string line; - while (!in.eof()) { - getline(in, line); - if (line.length() != 0) { - std::stringstream lineSS; - lineSS << line; - double beginn, endd; - lineSS >> beginn; - lineSS >> endd; - result.push_back(std::make_pair(beginn, endd)); - } - } - in.close(); - return result; -} // read_diagram_from_file - int main(int argc, char** argv) { if (argc < 3) { std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file " << "should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << " distance (set by default to zero). The program will now terminate \n"; + return -1; } - std::vector< std::pair< double, double > > diag1 = read_diagram_from_file(argv[1]); - std::vector< std::pair< double, double > > diag2 = read_diagram_from_file(argv[2]); + std::vector> diag1 = read_persistence_intervals_in_dimension(argv[1]); + std::vector> diag2 = read_persistence_intervals_in_dimension(argv[2]); + double tolerance = 0.; if (argc == 4) { tolerance = atof(argv[3]); } double b = Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, tolerance); std::cout << "The distance between the diagrams is : " << b << ". The tolerance is : " << tolerance << std::endl; + + return 0; } diff --git a/src/common/doc/file_formats.h b/src/common/doc/file_formats.h new file mode 100644 index 00000000..c145b271 --- /dev/null +++ b/src/common/doc/file_formats.h @@ -0,0 +1,54 @@ +/* This file is part of the Gudhi Library. The Gudhi library +* (Geometric Understanding in Higher Dimensions) is a generic C++ +* library for computational topology. +* +* Author(s): Clément Jamin +* +* Copyright (C) 2017 INRIA +* +* 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 DOC_COMMON_FILE_FORMAT_H_ +#define DOC_COMMON_FILE_FORMAT_H_ + +namespace Gudhi { + +/*! \page fileformats File formats + + \tableofcontents + + \section FileFormatsPers Persistence Diagram + + Such a file, whose extension is usually `.pers`, contains a list of persistence intervals.
+ Lines starting with `#` are ignored (comments).
+ Other lines might contain 2, 3 or 4 values (the number of values on each line must be the same for all lines): + \code{.unparsed} + [[field] dimension] birth death + \endcode + + Here is a simple sample file: + \code{.unparsed} + # Beautiful persistence diagram + 2 2.7 3.7 + 2 9.6 14. + 3 34.2 34.974 + 4 3. inf + \endcode + + Other sample files can be found in the `data/persistence_diagram` folder. +*/ +} // namespace Gudhi + +#endif // DOC_COMMON_FILE_FORMAT_H_ diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 97a87edd..35af09bd 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -2,7 +2,7 @@ * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * - * Author(s): Clement Maria, Pawel Dlotko + * Author(s): Clement Maria, Pawel Dlotko, Clement Jamin * * Copyright (C) 2014 INRIA * @@ -24,6 +24,8 @@ #define READER_UTILS_H_ #include +#include +#include #include @@ -92,7 +94,10 @@ template< typename Graph_t, typename Filtration_value, typename Vertex_handle > Graph_t read_graph(std::string file_name) { std::ifstream in_(file_name.c_str(), std::ios::in); if (!in_.is_open()) { - std::cerr << "Unable to open file " << file_name << std::endl; + std::string error_str("read_graph - Unable to open file "); + error_str.append(file_name); + std::cerr << error_str << std::endl; + throw std::invalid_argument(error_str); } typedef std::pair< Vertex_handle, Vertex_handle > Edge_t; @@ -295,4 +300,71 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from return result; } // read_lower_triangular_matrix_from_csv_file +/** +Reads a file containing persistence intervals. +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death +The output iterator `out` is used this way: `*out++ = std::make_tuple(dim, birth, death);` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +**/ +template +void read_persistence_intervals_and_dimension(std::string const& filename, OutputIterator out) { + + std::ifstream in(filename); + if (!in.is_open()) { + std::string error_str("read_persistence_intervals_and_dimension - Unable to open file "); + error_str.append(filename); + std::cerr << error_str << std::endl; + throw std::invalid_argument(error_str); + } + + while (!in.eof()) { + std::string line; + getline(in, line); + if (line.length() != 0 && line[0] != '#') { + double numbers[4]; + int n = sscanf(line.c_str(), "%lf %lf %lf %lf", &numbers[0], &numbers[1], &numbers[2], &numbers[3]); + if (n >= 2) { + //int field = (n == 4 ? static_cast(numbers[0]) : -1); + int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); + GUDHI_CHECK(numbers[n - 2] <= numbers[n - 1], "Error: birth > death."); + *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]); + } + } + } +} // read_persistence_diagram_from_file + +/** +Reads a file containing persistence intervals. +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death +The return value is an `std::map>>` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +**/ +std::map>> read_persistence_intervals_grouped_by_dimension(std::string const& filename) { + + std::map>> ret; + read_persistence_intervals_and_dimension( + filename, + boost::make_function_output_iterator([&ret](auto t) { ret[get<0>(t)].push_back(std::make_pair(get<1>(t), get<2>(t))); })); + return ret; +} // read_persistence_diagram_from_file + + +/** +Reads a file containing persistence intervals. +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death +If `only_this_dim` = -1, dimension is ignored and all lines are returned. +If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim` +(or where dimension is not specified) are returned. +The return value is an `std::vector>` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +**/ +std::vector> read_persistence_intervals_in_dimension(std::string const& filename, int only_this_dim = -1) { + + std::vector> ret; + read_persistence_intervals_and_dimension( + filename, + boost::make_function_output_iterator([&ret](auto t) { ret.emplace_back(get<1>(t), get<2>(t)); })); + return ret; +} // read_persistence_diagram_from_file + #endif // READER_UTILS_H_ -- cgit v1.2.3