From 897783d59fbe6ac6bca89a18ab893fa76cf990c9 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Fri, 28 Apr 2017 06:48:29 +0000 Subject: Answers to Vincent's comments. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@2383 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 67e837dc1620294b3538c6f4a0515be5bde53fa9 --- .../include/gudhi/Persistence_heat_maps.h | 2 + .../include/gudhi/Persistence_intervals.h | 2 + .../gudhi/Persistence_intervals_with_distances.h | 4 +- .../include/gudhi/Persistence_landscape.h | 23 +++---- .../include/gudhi/Persistence_landscape_on_grid.h | 4 +- src/Gudhi_stat/include/gudhi/persistence_vectors.h | 2 + src/Gudhi_stat/test/CMakeLists.txt | 28 +++++++++ ...tence_file_with_four_entries_per_line_landscape | 8 +++ src/Gudhi_stat/test/persistence_heat_maps_test.cpp | 20 ++++++- src/Gudhi_stat/test/persistence_intervals_test.cpp | 2 +- .../persistence_intervals_with_distances_test.cpp | 70 ++++++++++++++++++++++ .../test/persistence_lanscapes_on_grid_test.cpp | 20 +++++-- src/Gudhi_stat/test/persistence_lanscapes_test.cpp | 28 ++++++++- .../test/read_persistence_from_file_test.cpp | 2 +- src/Gudhi_stat/test/vector_representation_test.cpp | 16 ++++- 15 files changed, 203 insertions(+), 28 deletions(-) create mode 100644 src/Gudhi_stat/test/data/persistence_file_with_four_entries_per_line_landscape create mode 100644 src/Gudhi_stat/test/persistence_intervals_with_distances_test.cpp diff --git a/src/Gudhi_stat/include/gudhi/Persistence_heat_maps.h b/src/Gudhi_stat/include/gudhi/Persistence_heat_maps.h index 78cbed20..59e58e41 100644 --- a/src/Gudhi_stat/include/gudhi/Persistence_heat_maps.h +++ b/src/Gudhi_stat/include/gudhi/Persistence_heat_maps.h @@ -487,6 +487,8 @@ 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. **/ double project_to_R( int number_of_function )const; /** diff --git a/src/Gudhi_stat/include/gudhi/Persistence_intervals.h b/src/Gudhi_stat/include/gudhi/Persistence_intervals.h index 95e6ae91..539d38e5 100644 --- a/src/Gudhi_stat/include/gudhi/Persistence_intervals.h +++ b/src/Gudhi_stat/include/gudhi/Persistence_intervals.h @@ -223,6 +223,8 @@ public: /** * This is a simple function projectig the persistence intervals to a real number. The function we use here is a sum of squared lendgths of intervals. It can be naturally interpreted as * sum of step function, where the step hight it equal to the length of the interval. + * 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. **/ double project_to_R( int number_of_function )const; /** diff --git a/src/Gudhi_stat/include/gudhi/Persistence_intervals_with_distances.h b/src/Gudhi_stat/include/gudhi/Persistence_intervals_with_distances.h index 60343dc1..7ef711e9 100644 --- a/src/Gudhi_stat/include/gudhi/Persistence_intervals_with_distances.h +++ b/src/Gudhi_stat/include/gudhi/Persistence_intervals_with_distances.h @@ -24,7 +24,7 @@ #define Persistence_intervals_WITH_DISTANCES_H_ -#include +#include #include namespace Gudhi @@ -44,7 +44,7 @@ public: * exception will be thrown. * The last parameter, tolerance, it is an additiv error of the approimation, set by default to zero. **/ - double distance( const Persistence_intervals_with_distances& second , double power = std::numeric_limits< double >::max() , double tolerance = 0) const + double distance( const Persistence_intervals_with_distances& second , double power = std::numeric_limits< double >::max() , double tolerance = 0) const { if ( power >= std::numeric_limits< double >::max() ) { diff --git a/src/Gudhi_stat/include/gudhi/Persistence_landscape.h b/src/Gudhi_stat/include/gudhi/Persistence_landscape.h index 9150e507..9a177b60 100644 --- a/src/Gudhi_stat/include/gudhi/Persistence_landscape.h +++ b/src/Gudhi_stat/include/gudhi/Persistence_landscape.h @@ -347,6 +347,8 @@ public: /** * 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. **/ double project_to_R( int number_of_function )const { @@ -543,24 +545,17 @@ protected: - Persistence_landscape::Persistence_landscape(const char* filename , size_t dimension) -{ - bool dbg = false; - - if ( dbg ) +{ + std::vector< std::pair< double , double > > barcode; + if ( dimension < std::numeric_limits::max() ) { - std::cerr << "Using constructor : Persistence_landscape(char* filename)" << std::endl; - } - std::vector< std::pair< double , double > > barcode; - if ( dimension == std::numeric_limits::max() ) - { - barcode = read_persistence_intervals_in_one_dimension_from_file( filename ); - } + barcode = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); + } else { - barcode = read_persistence_intervals_in_one_dimension_from_file( filename , dimension ); - } + barcode = read_persistence_intervals_in_one_dimension_from_file( filename ); + } this->construct_persistence_landscape_from_barcode( barcode ); this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); } diff --git a/src/Gudhi_stat/include/gudhi/Persistence_landscape_on_grid.h b/src/Gudhi_stat/include/gudhi/Persistence_landscape_on_grid.h index de5c74ac..ed9c14ea 100644 --- a/src/Gudhi_stat/include/gudhi/Persistence_landscape_on_grid.h +++ b/src/Gudhi_stat/include/gudhi/Persistence_landscape_on_grid.h @@ -865,7 +865,9 @@ public: /** * 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. + * 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. **/ double project_to_R( int number_of_function )const { diff --git a/src/Gudhi_stat/include/gudhi/persistence_vectors.h b/src/Gudhi_stat/include/gudhi/persistence_vectors.h index 9ed32fc1..d623dd0d 100644 --- a/src/Gudhi_stat/include/gudhi/persistence_vectors.h +++ b/src/Gudhi_stat/include/gudhi/persistence_vectors.h @@ -177,6 +177,8 @@ public: //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. **/ double project_to_R( int number_of_function )const; /** diff --git a/src/Gudhi_stat/test/CMakeLists.txt b/src/Gudhi_stat/test/CMakeLists.txt index 35231e83..62335c77 100644 --- a/src/Gudhi_stat/test/CMakeLists.txt +++ b/src/Gudhi_stat/test/CMakeLists.txt @@ -85,3 +85,31 @@ add_test(NAME read_persistence_from_file_test file(COPY data DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/read_persistence_from_file_test/data") # XML format for Jenkins xUnit plugin --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/read_persistence_from_file_UT.xml --log_level=test_suite --report_level=no) + +file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) +add_executable ( additional_tests additional_tests.cpp ) +target_link_libraries(additional_tests ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + +# Unitary tests +add_test(NAME additional_tests + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/additional_tests + file(COPY data DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/additional_tests/data") + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/additional_tests_UT.xml --log_level=test_suite --report_level=no) + + + +if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) +file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) +add_executable ( persistence_intervals_with_distances_test persistence_intervals_with_distances_test.cpp ) +target_link_libraries(persistence_intervals_with_distances_test ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +if (TBB_FOUND) +target_link_libraries(persistence_intervals_with_distances_test ${TBB_LIBRARIES}) +endif(TBB_FOUND) +# Unitary tests +add_test(NAME persistence_intervals_with_distances_test + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/persistence_intervals_with_distances_test + file(COPY data DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/persistence_intervals_with_distances_test/data") + # XML format for Jenkins xUnit plugin + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/persistence_intervals_with_distances_test_UT.xml --log_level=test_suite --report_level=no) +endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) diff --git a/src/Gudhi_stat/test/data/persistence_file_with_four_entries_per_line_landscape b/src/Gudhi_stat/test/data/persistence_file_with_four_entries_per_line_landscape new file mode 100644 index 00000000..33fae63e --- /dev/null +++ b/src/Gudhi_stat/test/data/persistence_file_with_four_entries_per_line_landscape @@ -0,0 +1,8 @@ +#lambda_0 +0 0 +1 1 +2 0 +4 0 +10 0 +50 40 +90 0 diff --git a/src/Gudhi_stat/test/persistence_heat_maps_test.cpp b/src/Gudhi_stat/test/persistence_heat_maps_test.cpp index c7b36688..b997382e 100644 --- a/src/Gudhi_stat/test/persistence_heat_maps_test.cpp +++ b/src/Gudhi_stat/test/persistence_heat_maps_test.cpp @@ -23,7 +23,7 @@ #define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "gudhi_stat" +#define BOOST_TEST_MODULE "Persistence_representations" #include #include #include @@ -254,8 +254,24 @@ BOOST_AUTO_TEST_CASE(check_arythmetic_operations_for_heat_maps) Persistence_heat_maps multiply_by_scalar_template; multiply_by_scalar_template.load_from_file( "data/heat_map_multiply_by_scalar" ); - BOOST_CHECK( sum == sum_template ); + BOOST_CHECK( sum == sum_template ); +} + +BOOST_AUTO_TEST_CASE(check_distance_of_heat_maps_infinite_power_parameters) +{ + std::vector< std::vector > filter = create_Gaussian_filter(100,1); + Persistence_heat_maps p( "data/file_with_diagram" , filter , false , 1000 , 0 , 1 ); + + std::vector< std::vector > filter_2 = create_Gaussian_filter(150,1); + Persistence_heat_maps q( "data/file_with_diagram" , filter_2 , true , 1000 , 0 , 1 ); + double distance_max_double_parameter = p.distance( q , std::numeric_limits::max() ); + double distance_inf_double_parameter = p.distance( q , std::numeric_limits::infinity() ); + + //std::cerr << "distance_max_double_parameter: " << distance_max_double_parameter << std::endl; + //std::cerr << "distance_inf_double_parameter: " << distance_inf_double_parameter << std::endl; + + BOOST_CHECK( distance_max_double_parameter == distance_inf_double_parameter ); } diff --git a/src/Gudhi_stat/test/persistence_intervals_test.cpp b/src/Gudhi_stat/test/persistence_intervals_test.cpp index dae270ed..8bad499a 100644 --- a/src/Gudhi_stat/test/persistence_intervals_test.cpp +++ b/src/Gudhi_stat/test/persistence_intervals_test.cpp @@ -23,7 +23,7 @@ #define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "gudhi_stat" +#define BOOST_TEST_MODULE "Persistence_representations" #include #include #include "gudhi/Persistence_intervals.h" diff --git a/src/Gudhi_stat/test/persistence_intervals_with_distances_test.cpp b/src/Gudhi_stat/test/persistence_intervals_with_distances_test.cpp new file mode 100644 index 00000000..703b5011 --- /dev/null +++ b/src/Gudhi_stat/test/persistence_intervals_with_distances_test.cpp @@ -0,0 +1,70 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "Persistence_representations" +#include +#include +#include "gudhi/Persistence_intervals_with_distances.h" +#include "gudhi/common_persistence_representations.h" + +#include + + + +using namespace Gudhi; +using namespace Gudhi::Persistence_representations; + + +BOOST_AUTO_TEST_CASE(check_bottleneck_distances_computation) +{ + Persistence_intervals_with_distances p( "data/file_with_diagram" ); + Persistence_intervals_with_distances q( "data/file_with_diagram_1" ); + + double dist = p.distance( q ); + + //std::cout << "dist : " << dist << std::endl; + + BOOST_CHECK( almost_equal(dist,0.389043) ); +} + + +BOOST_AUTO_TEST_CASE(check_default_parameters_in_distance) +{ + Persistence_intervals_with_distances p( "data/file_with_diagram" ); + Persistence_intervals_with_distances q( "data/file_with_diagram_1" ); + + double default_parameter_distance = p.distance( q ); + double max_parameter_distance = p.distance( q , std::numeric_limits< double >::max() ); + double inf_parameter_distance = p.distance( q , std::numeric_limits::infinity() ); + + //std::cout << "default_parameter_distance : " << default_parameter_distance << std::endl; + //std::cout << "max_parameter_distance : " << max_parameter_distance << std::endl; + //std::cout << "inf_parameter_distance : " << inf_parameter_distance << std::endl; + + BOOST_CHECK( default_parameter_distance == max_parameter_distance ); + BOOST_CHECK( inf_parameter_distance == max_parameter_distance ); + BOOST_CHECK( inf_parameter_distance == max_parameter_distance ); +} + + + diff --git a/src/Gudhi_stat/test/persistence_lanscapes_on_grid_test.cpp b/src/Gudhi_stat/test/persistence_lanscapes_on_grid_test.cpp index e935cb97..971993ed 100644 --- a/src/Gudhi_stat/test/persistence_lanscapes_on_grid_test.cpp +++ b/src/Gudhi_stat/test/persistence_lanscapes_on_grid_test.cpp @@ -23,7 +23,7 @@ #define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "gudhi_stat" +#define BOOST_TEST_MODULE "Persistence_representations" #include #include #include @@ -36,10 +36,6 @@ using namespace Gudhi; using namespace Gudhi::Persistence_representations; -double epsilon = 0.0000005; - - - BOOST_AUTO_TEST_CASE(check_construction_of_landscape) @@ -231,6 +227,20 @@ BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) BOOST_CHECK( fabs(compute_distance_of_landscapes_on_grid(p,sum,std::numeric_limits::max()) - 0.45 ) <= 0.00001 ); } +BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances ) +{ + std::vector< std::pair< double , double > > diag = read_standard_persistence_file( "data/file_with_diagram" ); + Persistence_landscape_on_grid p( diag , 0. , 1. , 100 ); + + std::vector< std::pair< double , double > > diag1 = read_standard_persistence_file( "data/file_with_diagram_1" ); + Persistence_landscape_on_grid q( diag1 , 0. , 1. , 100 ); + + double dist_numeric_limit_max = p.distance( q,std::numeric_limits::max() ); + double dist_infinity = p.distance( q,std::numeric_limits::infinity() ); + + BOOST_CHECK( dist_numeric_limit_max == dist_infinity ); +} + diff --git a/src/Gudhi_stat/test/persistence_lanscapes_test.cpp b/src/Gudhi_stat/test/persistence_lanscapes_test.cpp index 684c50ff..e401e075 100644 --- a/src/Gudhi_stat/test/persistence_lanscapes_test.cpp +++ b/src/Gudhi_stat/test/persistence_lanscapes_test.cpp @@ -23,12 +23,13 @@ #define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "gudhi_stat" +#define BOOST_TEST_MODULE "Persistence_representations" #include #include #include #include +#include @@ -51,6 +52,16 @@ BOOST_AUTO_TEST_CASE(check_construction_of_landscape) } +BOOST_AUTO_TEST_CASE(check_construction_of_landscape_form_gudhi_style_file) +{ + Persistence_landscape p( "data/persistence_file_with_four_entries_per_line" , 1 ); + //p.print_to_file("persistence_file_with_four_entries_per_line_landscape"); + Persistence_landscape q; + q.load_landscape_from_file( "data/persistence_file_with_four_entries_per_line_landscape" ); + BOOST_CHECK( p == q ); +} + + BOOST_AUTO_TEST_CASE(check_computations_of_integrals) { std::vector< std::pair< double , double > > diag = read_standard_persistence_file( "data/file_with_diagram" ); @@ -190,6 +201,21 @@ BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) BOOST_CHECK( fabs(compute_distance_of_landscapes( p , sum , std::numeric_limits::max() ) - 0.464478 ) <= 0.00001 ); } + +BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances ) +{ + std::vector< std::pair< double , double > > diag = read_standard_persistence_file( "data/file_with_diagram" ); + Persistence_landscape p( diag ); + + std::vector< std::pair< double , double > > diag1 = read_standard_persistence_file( "data/file_with_diagram_1" ); + Persistence_landscape q( diag1 ); + + double dist_numeric_limit_max = p.distance( q,std::numeric_limits::max() ); + double dist_infinity = p.distance( q,std::numeric_limits::infinity() ); + + BOOST_CHECK( dist_numeric_limit_max == dist_infinity ); +} + BOOST_AUTO_TEST_CASE(check_computations_of_averages) { std::vector< std::pair< double , double > > diag = read_standard_persistence_file( "data/file_with_diagram" ); diff --git a/src/Gudhi_stat/test/read_persistence_from_file_test.cpp b/src/Gudhi_stat/test/read_persistence_from_file_test.cpp index d4dc7f89..69493efb 100644 --- a/src/Gudhi_stat/test/read_persistence_from_file_test.cpp +++ b/src/Gudhi_stat/test/read_persistence_from_file_test.cpp @@ -23,7 +23,7 @@ #define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "gudhi_stat" +#define BOOST_TEST_MODULE "Persistence_representations" #include #include #include diff --git a/src/Gudhi_stat/test/vector_representation_test.cpp b/src/Gudhi_stat/test/vector_representation_test.cpp index 2c1ef1f8..3ef3427c 100644 --- a/src/Gudhi_stat/test/vector_representation_test.cpp +++ b/src/Gudhi_stat/test/vector_representation_test.cpp @@ -26,7 +26,7 @@ #include #define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "gudhi_stat" +#define BOOST_TEST_MODULE "Persistence_representations" #include #include #include @@ -317,6 +317,20 @@ BOOST_AUTO_TEST_CASE(check_distance_computations) BOOST_CHECK( almost_equal ( p_prime.distance( p_bis , 1 ) , 1.86428 ) ); } +BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances ) +{ + std::vector< std::pair< double , double > > diag = read_standard_persistence_file( "data/file_with_diagram" ); + Vector_distances_in_diagram< Euclidean_distance > p( diag , 100 ); + + std::vector< std::pair< double , double > > diag1 = read_standard_persistence_file( "data/file_with_diagram_1" ); + Vector_distances_in_diagram< Euclidean_distance > q( diag1 , 100 ); + + double dist_numeric_limit_max = p.distance( q,std::numeric_limits::max() ); + double dist_infinity = p.distance( q,std::numeric_limits::infinity() ); + + BOOST_CHECK( dist_numeric_limit_max == dist_infinity ); +} + BOOST_AUTO_TEST_CASE(check_compute_average) -- cgit v1.2.3