summaryrefslogtreecommitdiff
path: root/src/Persistence_representations
diff options
context:
space:
mode:
authormcarrier <mcarrier@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-02-15 16:41:04 +0000
committermcarrier <mcarrier@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-02-15 16:41:04 +0000
commit69c683e663329d8410ca77c371f877bcc3bef906 (patch)
treefb18c914cf4056881b2b31875eb6b44e5ce23895 /src/Persistence_representations
parentbe131d6f74a9264e15a0b1c1e72fa8967c4518bd (diff)
parent265484997185f3bf900744406206a2d64ca0a20d (diff)
integrated kernel code in pers_representation branch
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/kernels@3249 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 58e77263a0da3674e4699cef832b6d357dcf12e2
Diffstat (limited to 'src/Persistence_representations')
-rw-r--r--src/Persistence_representations/doc/Persistence_representations_doc.h10
-rw-r--r--src/Persistence_representations/example/CMakeLists.txt17
-rw-r--r--src/Persistence_representations/example/persistence_vectors.cpp2
-rw-r--r--src/Persistence_representations/example/persistence_weighted_gaussian.cpp96
-rw-r--r--src/Persistence_representations/example/sliced_wasserstein.cpp55
-rw-r--r--src/Persistence_representations/include/gudhi/PSSK.h8
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_heat_maps.h21
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_intervals.h17
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h3
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_landscape.h130
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h12
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_vectors.h7
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h143
-rw-r--r--src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h285
-rw-r--r--src/Persistence_representations/include/gudhi/read_persistence_from_file.h125
-rw-r--r--src/Persistence_representations/test/CMakeLists.txt14
-rw-r--r--src/Persistence_representations/test/persistence_heat_maps_test.cpp72
-rw-r--r--src/Persistence_representations/test/persistence_intervals_test.cpp231
-rw-r--r--src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp19
-rw-r--r--src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp64
-rw-r--r--src/Persistence_representations/test/persistence_lanscapes_test.cpp170
-rw-r--r--src/Persistence_representations/test/read_persistence_from_file_test.cpp12
-rw-r--r--src/Persistence_representations/test/vector_representation_test.cpp8
-rw-r--r--src/Persistence_representations/utilities/CMakeLists.txt55
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt72
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/average_persistence_heat_maps.cpp16
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/compute_distance_of_persistence_heat_maps.cpp13
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/compute_scalar_product_of_persistence_heat_maps.cpp14
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_arctan_of_their_persistence.cpp35
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_distance_from_diagonal.cpp37
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/create_p_h_m_weighted_by_squared_diag_distance.cpp38
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/create_persistence_heat_maps.cpp34
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp34
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/plot_persistence_heat_map.cpp8
-rw-r--r--src/Persistence_representations/utilities/persistence_heat_maps/simple_diagram.txt.mps11
-rw-r--r--src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt44
-rw-r--r--src/Persistence_representations/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp22
-rw-r--r--src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp20
-rw-r--r--src/Persistence_representations/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp1
-rw-r--r--src/Persistence_representations/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp39
-rw-r--r--src/Persistence_representations/utilities/persistence_intervals/plot_persistence_Betti_numbers.cpp30
-rw-r--r--src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp13
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt40
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp15
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp14
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp15
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp24
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp16
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes/simple_diagram.txt.land13
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt39
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp16
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_distance_of_landscapes_on_grid.cpp13
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes_on_grid/compute_scalar_product_of_landscapes_on_grid.cpp15
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes_on_grid/create_landscapes_on_grid.cpp26
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes_on_grid/plot_landscapes_on_grid.cpp17
-rw-r--r--src/Persistence_representations/utilities/persistence_landscapes_on_grid/simple_diagram.txt.g_land104
-rw-r--r--src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt38
-rw-r--r--src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp16
-rw-r--r--src/Persistence_representations/utilities/persistence_vectors/compute_distance_of_persistence_vectors.cpp6
-rw-r--r--src/Persistence_representations/utilities/persistence_vectors/compute_scalar_product_of_persistence_vectors.cpp18
-rw-r--r--src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp26
-rw-r--r--src/Persistence_representations/utilities/persistence_vectors/plot_persistence_vectors.cpp3
-rw-r--r--src/Persistence_representations/utilities/persistence_vectors/simple_diagram.txt.vect1
63 files changed, 1399 insertions, 1133 deletions
diff --git a/src/Persistence_representations/doc/Persistence_representations_doc.h b/src/Persistence_representations/doc/Persistence_representations_doc.h
index c77e75e2..38bd3a21 100644
--- a/src/Persistence_representations/doc/Persistence_representations_doc.h
+++ b/src/Persistence_representations/doc/Persistence_representations_doc.h
@@ -67,7 +67,7 @@ namespace Persistence_representations {
\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.
+ \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
@@ -83,8 +83,8 @@ namespace Persistence_representations {
\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
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
@@ -139,7 +139,8 @@ namespace Persistence_representations {
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 as a last parameter of the constructor of persistence landscape (set by default to std::numeric_limits<size_t>::max()).
+ \li Compute just a number of initial nonzero landscapes. This option is available from C++ level as a last parameter of
+ the constructor of persistence landscape (set by default to std::numeric_limits<size_t>::max()).
@@ -249,7 +250,6 @@ namespace Persistence_representations {
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.
*/
/** @} */ // end defgroup Persistence_representations
diff --git a/src/Persistence_representations/example/CMakeLists.txt b/src/Persistence_representations/example/CMakeLists.txt
index 7788b603..54d719ac 100644
--- a/src/Persistence_representations/example/CMakeLists.txt
+++ b/src/Persistence_representations/example/CMakeLists.txt
@@ -1,34 +1,29 @@
cmake_minimum_required(VERSION 2.6)
project(Persistence_representations_example)
-file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/")
-
add_executable ( Persistence_representations_example_landscape_on_grid persistence_landscape_on_grid.cpp )
-target_link_libraries(Persistence_representations_example_landscape_on_grid ${Boost_SYSTEM_LIBRARY})
add_test(NAME Persistence_representations_example_landscape_on_grid
COMMAND $<TARGET_FILE:Persistence_representations_example_landscape_on_grid>)
+install(TARGETS Persistence_representations_example_landscape_on_grid DESTINATION bin)
add_executable ( Persistence_representations_example_landscape persistence_landscape.cpp )
-target_link_libraries(Persistence_representations_example_landscape ${Boost_SYSTEM_LIBRARY})
add_test(NAME Persistence_representations_example_landscape
COMMAND $<TARGET_FILE:Persistence_representations_example_landscape>)
+install(TARGETS Persistence_representations_example_landscape DESTINATION bin)
add_executable ( Persistence_representations_example_intervals persistence_intervals.cpp )
-target_link_libraries(Persistence_representations_example_intervals ${Boost_SYSTEM_LIBRARY})
add_test(NAME Persistence_representations_example_intervals
COMMAND $<TARGET_FILE:Persistence_representations_example_intervals>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
+ "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers")
+install(TARGETS Persistence_representations_example_intervals DESTINATION bin)
add_executable ( Persistence_representations_example_vectors persistence_vectors.cpp )
-target_link_libraries(Persistence_representations_example_vectors ${Boost_SYSTEM_LIBRARY})
add_test(NAME Persistence_representations_example_vectors
COMMAND $<TARGET_FILE:Persistence_representations_example_vectors>)
+install(TARGETS Persistence_representations_example_vectors DESTINATION bin)
add_executable ( Persistence_representations_example_heat_maps persistence_heat_maps.cpp )
-target_link_libraries(Persistence_representations_example_heat_maps ${Boost_SYSTEM_LIBRARY})
add_test(NAME Persistence_representations_example_heat_maps
COMMAND $<TARGET_FILE:Persistence_representations_example_heat_maps>)
-
-
-
+install(TARGETS Persistence_representations_example_heat_maps DESTINATION bin)
diff --git a/src/Persistence_representations/example/persistence_vectors.cpp b/src/Persistence_representations/example/persistence_vectors.cpp
index 59eca152..834ae644 100644
--- a/src/Persistence_representations/example/persistence_vectors.cpp
+++ b/src/Persistence_representations/example/persistence_vectors.cpp
@@ -30,7 +30,7 @@
#include <utility>
using Vector_distances_in_diagram =
- Gudhi::Persistence_representations::Vector_distances_in_diagram<Gudhi::Euclidean_distance>;
+ Gudhi::Persistence_representations::Vector_distances_in_diagram<Gudhi::Euclidean_distance>;
int main(int argc, char** argv) {
// create two simple vectors with birth--death pairs:
diff --git a/src/Persistence_representations/example/persistence_weighted_gaussian.cpp b/src/Persistence_representations/example/persistence_weighted_gaussian.cpp
new file mode 100644
index 00000000..e95b9445
--- /dev/null
+++ b/src/Persistence_representations/example/persistence_weighted_gaussian.cpp
@@ -0,0 +1,96 @@
+/* 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): Mathieu Carriere
+ *
+ * Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <gudhi/Persistence_weighted_gaussian.h>
+
+#include <iostream>
+#include <vector>
+#include <utility>
+
+using PD = std::vector<std::pair<double,double> >;
+using PWG = Gudhi::Persistence_representations::Persistence_weighted_gaussian;
+
+int main(int argc, char** argv) {
+
+ std::vector<std::pair<double, double> > persistence1;
+ std::vector<std::pair<double, double> > persistence2;
+
+ persistence1.push_back(std::make_pair(1, 2));
+ persistence1.push_back(std::make_pair(6, 8));
+ persistence1.push_back(std::make_pair(0, 4));
+ persistence1.push_back(std::make_pair(3, 8));
+
+ persistence2.push_back(std::make_pair(2, 9));
+ persistence2.push_back(std::make_pair(1, 6));
+ persistence2.push_back(std::make_pair(3, 5));
+ persistence2.push_back(std::make_pair(6, 10));
+
+ PWG PWG1(persistence1);
+ PWG PWG2(persistence2);
+ double sigma = 1;
+ double tau = 1;
+ int m = 1000;
+
+
+
+ // Linear PWG
+
+ std::cout << PWG1.compute_scalar_product (PWG2, sigma, PWG::arctan_weight, m) << std::endl;
+ std::cout << PWG1.compute_scalar_product (PWG2, sigma, PWG::arctan_weight, -1) << std::endl;
+
+ std::cout << PWG1.distance (PWG2, sigma, PWG::arctan_weight, m) << std::endl;
+ std::cout << PWG1.distance (PWG2, sigma, PWG::arctan_weight, -1) << std::endl;
+
+
+
+
+
+
+
+ // Gaussian PWG
+
+ std::cout << std::exp( -PWG1.distance (PWG2, sigma, PWG::arctan_weight, m, 2) ) / (2*tau*tau) << std::endl;
+ std::cout << std::exp( -PWG1.distance (PWG2, sigma, PWG::arctan_weight, -1, 2) ) / (2*tau*tau) << std::endl;
+
+
+
+
+
+
+
+ // PSS
+
+ PD pd1 = persistence1; int numpts = persistence1.size(); for(int i = 0; i < numpts; i++) pd1.emplace_back(persistence1[i].second,persistence1[i].first);
+ PD pd2 = persistence2; numpts = persistence2.size(); for(int i = 0; i < numpts; i++) pd2.emplace_back(persistence2[i].second,persistence2[i].first);
+
+ PWG pwg1(pd1);
+ PWG pwg2(pd2);
+
+ std::cout << pwg1.compute_scalar_product (pwg2, 2*std::sqrt(sigma), PWG::pss_weight, m) / (16*pi*sigma) << std::endl;
+ std::cout << pwg1.compute_scalar_product (pwg2, 2*std::sqrt(sigma), PWG::pss_weight, -1) / (16*pi*sigma) << std::endl;
+
+ std::cout << pwg1.distance (pwg2, 2*std::sqrt(sigma), PWG::pss_weight, m) / (16*pi*sigma) << std::endl;
+ std::cout << pwg1.distance (pwg2, 2*std::sqrt(sigma), PWG::pss_weight, -1) / (16*pi*sigma) << std::endl;
+
+
+ return 0;
+}
diff --git a/src/Persistence_representations/example/sliced_wasserstein.cpp b/src/Persistence_representations/example/sliced_wasserstein.cpp
new file mode 100644
index 00000000..673d8474
--- /dev/null
+++ b/src/Persistence_representations/example/sliced_wasserstein.cpp
@@ -0,0 +1,55 @@
+/* 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): Mathieu Carriere
+ *
+ * Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <gudhi/Sliced_Wasserstein.h>
+
+#include <iostream>
+#include <vector>
+#include <utility>
+
+using SW = Gudhi::Persistence_representations::Sliced_Wasserstein;
+
+int main(int argc, char** argv) {
+
+ std::vector<std::pair<double, double> > persistence1;
+ std::vector<std::pair<double, double> > persistence2;
+
+ persistence1.push_back(std::make_pair(1, 2));
+ persistence1.push_back(std::make_pair(6, 8));
+ persistence1.push_back(std::make_pair(0, 4));
+ persistence1.push_back(std::make_pair(3, 8));
+
+ persistence2.push_back(std::make_pair(2, 9));
+ persistence2.push_back(std::make_pair(1, 6));
+ persistence2.push_back(std::make_pair(3, 5));
+ persistence2.push_back(std::make_pair(6, 10));
+
+ SW SW1(persistence1);
+ SW SW2(persistence2);
+
+ std::cout << SW1.compute_sliced_wasserstein_distance(SW2,100) << std::endl;
+ std::cout << SW1.compute_sliced_wasserstein_distance(SW2,-1) << std::endl;
+ std::cout << SW1.compute_scalar_product(SW2,1,100) << std::endl;
+ std::cout << SW1.distance(SW2,1,100,1) << std::endl;
+
+ return 0;
+}
diff --git a/src/Persistence_representations/include/gudhi/PSSK.h b/src/Persistence_representations/include/gudhi/PSSK.h
index e2d4225e..630f5623 100644
--- a/src/Persistence_representations/include/gudhi/PSSK.h
+++ b/src/Persistence_representations/include/gudhi/PSSK.h
@@ -121,10 +121,10 @@ void PSSK::construct(const std::vector<std::pair<double, double> >& 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 = static_cast<int>((intervals_[pt_nr].first - this->min_) /
- (this->max_ - this->min_) * number_of_pixels);
- int y_grid = static_cast<int>((intervals_[pt_nr].second - this->min_) /
- (this->max_ - this->min_) * number_of_pixels);
+ int x_grid =
+ static_cast<int>((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels);
+ int y_grid =
+ static_cast<int>((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;
diff --git a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h
index 04dd78ad..a80c3c40 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h
@@ -582,10 +582,10 @@ void Persistence_heat_maps<Scalling_of_kernels>::construct(const std::vector<std
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 = static_cast<int>((intervals_[pt_nr].first - this->min_) /
- (this->max_ - this->min_) * number_of_pixels);
- int y_grid = static_cast<int>((intervals_[pt_nr].second - this->min_) /
- (this->max_ - this->min_) * number_of_pixels);
+ int x_grid =
+ static_cast<int>((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels);
+ int y_grid =
+ static_cast<int>((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;
@@ -743,10 +743,10 @@ void Persistence_heat_maps<Scalling_of_kernels>::compute_percentage_of_active(
template <typename Scalling_of_kernels>
void Persistence_heat_maps<Scalling_of_kernels>::plot(const char* filename) const {
std::ofstream out;
- std::stringstream ss;
- ss << filename << "_GnuplotScript";
+ std::stringstream gnuplot_script;
+ gnuplot_script << filename << "_GnuplotScript";
- out.open(ss.str().c_str());
+ out.open(gnuplot_script.str().c_str());
out << "plot '-' matrix with image" << std::endl;
for (size_t i = 0; i != this->heat_map.size(); ++i) {
for (size_t j = 0; j != this->heat_map[i].size(); ++j) {
@@ -755,8 +755,8 @@ void Persistence_heat_maps<Scalling_of_kernels>::plot(const char* filename) cons
out << std::endl;
}
out.close();
- std::cout << "Gnuplot script have been created. Open gnuplot and type load \'" << ss.str().c_str()
- << "\' to see the picture." << std::endl;
+ std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ << gnuplot_script.str().c_str() << "\'\"" << std::endl;
}
template <typename Scalling_of_kernels>
@@ -797,8 +797,7 @@ void Persistence_heat_maps<Scalling_of_kernels>::load_from_file(const char* file
std::string temp;
std::getline(in, temp);
-
- while (!in.eof()) {
+ while (in.good()) {
std::getline(in, temp);
std::stringstream lineSS;
lineSS << temp;
diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h
index 525d58a3..3d04d8b7 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h
@@ -167,10 +167,10 @@ class Persistence_intervals {
// this program create a gnuplot script file that allows to plot persistence diagram.
std::ofstream out;
- std::ostringstream nameSS;
- nameSS << filename << "_GnuplotScript";
- std::string nameStr = nameSS.str();
- out.open(nameStr);
+ std::stringstream gnuplot_script;
+ gnuplot_script << filename << "_GnuplotScript";
+
+ out.open(gnuplot_script.str().c_str());
std::pair<double, double> min_max_values = this->get_x_range();
if (min_x == max_x) {
@@ -195,8 +195,8 @@ class Persistence_intervals {
out.close();
- std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '"
- << nameStr << "' in gnuplot to visualize." << std::endl;
+ std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ << gnuplot_script.str().c_str() << "\'\"" << std::endl;
}
/**
@@ -402,9 +402,8 @@ std::vector<double> Persistence_intervals::characteristic_function_of_diagram(do
}
for (size_t pos = beginIt; pos != endIt; ++pos) {
- result[pos] +=
- ((x_max - x_min) / static_cast<double>(number_of_bins)) *
- (this->intervals[i].second - this->intervals[i].first);
+ result[pos] += ((x_max - x_min) / static_cast<double>(number_of_bins)) *
+ (this->intervals[i].second - this->intervals[i].first);
}
if (dbg) {
std::cerr << "Result at this stage \n";
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 d5ab04b4..79908883 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h
@@ -26,7 +26,6 @@
#include <gudhi/Persistence_intervals.h>
#include <gudhi/Bottleneck.h>
-
#include <limits>
namespace Gudhi {
@@ -47,7 +46,7 @@ class Persistence_intervals_with_distances : public Persistence_intervals {
* 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 tolerance = (std::numeric_limits<double>::min)()) const {
if (power >= std::numeric_limits<double>::max()) {
return Gudhi::persistence_diagram::bottleneck_distance(this->intervals, second.intervals, tolerance);
} else {
diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape.h b/src/Persistence_representations/include/gudhi/Persistence_landscape.h
index 5c300112..c5aa7867 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_landscape.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_landscape.h
@@ -79,14 +79,16 @@ class Persistence_landscape {
/**
* Constructor that takes as an input a vector of birth-death pairs.
**/
- Persistence_landscape(const std::vector<std::pair<double, double> >& p, size_t number_of_levels = std::numeric_limits<size_t>::max() );
+ Persistence_landscape(const std::vector<std::pair<double, double> >& p,
+ size_t number_of_levels = std::numeric_limits<size_t>::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.
**/
- Persistence_landscape(const char* filename, size_t dimension = std::numeric_limits<unsigned>::max() , size_t number_of_levels = std::numeric_limits<size_t>::max() );
+ Persistence_landscape(const char* filename, size_t dimension = std::numeric_limits<unsigned>::max(),
+ size_t number_of_levels = std::numeric_limits<size_t>::max());
/**
* This procedure loads a landscape from file. It erase all the data that was previously stored in this landscape.
@@ -285,7 +287,7 @@ class Persistence_landscape {
*distance, we need to take its absolute value. This is the purpose of this procedure.
**/
Persistence_landscape abs();
-
+
Persistence_landscape* new_abs();
/**
@@ -453,7 +455,8 @@ class Persistence_landscape {
size_t number_of_functions_for_vectorization;
size_t number_of_functions_for_projections_to_reals;
- void construct_persistence_landscape_from_barcode(const std::vector<std::pair<double, double> >& p , size_t number_of_levels = std::numeric_limits<size_t>::max());
+ void construct_persistence_landscape_from_barcode(const std::vector<std::pair<double, double> >& p,
+ size_t number_of_levels = std::numeric_limits<size_t>::max());
Persistence_landscape multiply_lanscape_by_real_number_not_overwrite(double x) const;
void multiply_lanscape_by_real_number_overwrite(double x);
friend double compute_maximal_distance_non_symmetric(const Persistence_landscape& pl1,
@@ -473,7 +476,7 @@ Persistence_landscape::Persistence_landscape(const char* filename, size_t dimens
} else {
barcode = read_persistence_intervals_in_one_dimension_from_file(filename);
}
- this->construct_persistence_landscape_from_barcode(barcode,number_of_levels);
+ this->construct_persistence_landscape_from_barcode(barcode, number_of_levels);
this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals();
}
@@ -506,14 +509,14 @@ bool Persistence_landscape::operator==(const Persistence_landscape& rhs) const {
return true;
}
-Persistence_landscape::Persistence_landscape(const std::vector<std::pair<double, double> >& p,size_t number_of_levels) {
- this->construct_persistence_landscape_from_barcode(p,number_of_levels);
+Persistence_landscape::Persistence_landscape(const std::vector<std::pair<double, double> >& p,
+ size_t number_of_levels) {
+ this->construct_persistence_landscape_from_barcode(p, number_of_levels);
this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals();
}
void Persistence_landscape::construct_persistence_landscape_from_barcode(
- const std::vector<std::pair<double, double> >& p, size_t number_of_levels)
- {
+ const std::vector<std::pair<double, double> >& p, size_t number_of_levels) {
bool dbg = false;
if (dbg) {
std::cerr << "Persistence_landscape::Persistence_landscape( const std::vector< std::pair< double , double > >& p )"
@@ -648,12 +651,11 @@ void Persistence_landscape::construct_persistence_landscape_from_barcode(
lambda_n.erase(std::unique(lambda_n.begin(), lambda_n.end()), lambda_n.end());
this->land.push_back(lambda_n);
-
+
++number_of_levels_in_the_landscape;
- if ( number_of_levels == number_of_levels_in_the_landscape )
- {
- break;
- }
+ if (number_of_levels == number_of_levels_in_the_landscape) {
+ break;
+ }
}
}
@@ -857,58 +859,47 @@ Persistence_landscape Persistence_landscape::abs() {
return result;
}
+Persistence_landscape* Persistence_landscape::new_abs() {
+ Persistence_landscape* result = new Persistence_landscape(*this);
+ for (size_t level = 0; level != this->land.size(); ++level) {
+ if (AbsDbg) {
+ std::cout << "level: " << level << std::endl;
+ }
+ std::vector<std::pair<double, double> > lambda_n;
+ lambda_n.push_back(std::make_pair(-std::numeric_limits<int>::max(), 0));
+ 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 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]);
-Persistence_landscape* Persistence_landscape::new_abs()
-{
- Persistence_landscape* result = new Persistence_landscape(*this);
- for (size_t level = 0; level != this->land.size(); ++level)
- {
- if (AbsDbg)
- {
- std::cout << "level: " << level << std::endl;
- }
- std::vector<std::pair<double, double> > lambda_n;
- lambda_n.push_back(std::make_pair(-std::numeric_limits<int>::max(), 0));
- 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 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]);
-
- lambda_n.push_back(std::make_pair(zero, 0));
- lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second)));
- if (AbsDbg)
- {
- std::cout << "Adding pair : (" << zero << ",0)" << std::endl;
- std::cout << "In the same step adding pair : (" << this->land[level][i].first << ","
- << fabs(this->land[level][i].second) << ") " << std::endl;
- std::cin.ignore();
- }
- }
- else
- {
- lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second)));
- if (AbsDbg)
- {
- std::cout << "Adding pair : (" << this->land[level][i].first << "," << fabs(this->land[level][i].second)
- << ") " << std::endl;
- std::cin.ignore();
- }
- }
- }
- result->land.push_back(lambda_n);
- }
- return result;
+ lambda_n.push_back(std::make_pair(zero, 0));
+ lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second)));
+ if (AbsDbg) {
+ std::cout << "Adding pair : (" << zero << ",0)" << std::endl;
+ std::cout << "In the same step adding pair : (" << this->land[level][i].first << ","
+ << fabs(this->land[level][i].second) << ") " << std::endl;
+ std::cin.ignore();
+ }
+ } else {
+ lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second)));
+ if (AbsDbg) {
+ std::cout << "Adding pair : (" << this->land[level][i].first << "," << fabs(this->land[level][i].second)
+ << ") " << std::endl;
+ std::cin.ignore();
+ }
+ }
+ }
+ result->land.push_back(lambda_n);
+ }
+ return result;
}
-
Persistence_landscape Persistence_landscape::multiply_lanscape_by_real_number_not_overwrite(double x) const {
std::vector<std::vector<std::pair<double, double> > > result(this->land.size());
for (size_t dim = 0; dim != this->land.size(); ++dim) {
@@ -954,7 +945,7 @@ void Persistence_landscape::load_landscape_from_file(const char* filename) {
std::vector<std::pair<double, double> > landscapeAtThisLevel;
bool isThisAFirsLine = true;
- while (!in.eof()) {
+ while (in.good()) {
getline(in, line);
if (!(line.length() == 0 || line[0] == '#')) {
std::stringstream lineSS;
@@ -1340,10 +1331,9 @@ void Persistence_landscape::plot(const char* filename, double xRangeBegin, doubl
// this program create a gnuplot script file that allows to plot persistence diagram.
std::ofstream out;
- std::ostringstream nameSS;
- nameSS << filename << "_GnuplotScript";
- std::string nameStr = nameSS.str();
- out.open(nameStr);
+ std::ostringstream gnuplot_script;
+ gnuplot_script << filename << "_GnuplotScript";
+ out.open(gnuplot_script.str().c_str());
if ((xRangeBegin != std::numeric_limits<double>::max()) || (xRangeEnd != std::numeric_limits<double>::max()) ||
(yRangeBegin != std::numeric_limits<double>::max()) || (yRangeEnd != std::numeric_limits<double>::max())) {
@@ -1376,8 +1366,8 @@ void Persistence_landscape::plot(const char* filename, double xRangeBegin, doubl
}
out << "EOF" << std::endl;
}
- std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '"
- << nameStr << "' in gnuplot to visualize." << std::endl;
+ std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ << gnuplot_script.str().c_str() << "\'\"" << std::endl;
}
} // namespace Persistence_representations
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 4ceb9bf6..84fd22ed 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid.h
@@ -1207,10 +1207,9 @@ void Persistence_landscape_on_grid::plot(const char* filename, double min_x, dou
// this program create a gnuplot script file that allows to plot persistence diagram.
std::ofstream out;
- std::ostringstream nameSS;
- nameSS << filename << "_GnuplotScript";
- std::string nameStr = nameSS.str();
- out.open(nameStr);
+ std::ostringstream gnuplot_script;
+ gnuplot_script << filename << "_GnuplotScript";
+ out.open(gnuplot_script.str().c_str());
if (min_x == max_x) {
std::pair<double, double> min_max = compute_minimum_maximum();
@@ -1241,7 +1240,6 @@ void Persistence_landscape_on_grid::plot(const char* filename, double min_x, dou
out << "plot ";
for (size_t lambda = from; lambda != to; ++lambda) {
- // out << " '-' using 1:2 title 'l" << lambda << "' with lp";
out << " '-' using 1:2 notitle with lp";
if (lambda + 1 != to) {
out << ", \\";
@@ -1261,8 +1259,8 @@ void Persistence_landscape_on_grid::plot(const char* filename, double min_x, dou
}
out << "EOF" << std::endl;
}
- std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '"
- << nameStr << "' in gnuplot to visualize." << std::endl;
+ std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ << gnuplot_script.str().c_str() << "\'\"" << std::endl;
}
template <typename T>
diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h
index 0fb49eee..63577e46 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h
@@ -201,7 +201,8 @@ class Vector_distances_in_diagram {
}
out << std::endl;
out.close();
- std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl;
+ std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ << gnuplot_script.str().c_str() << "\'\"" << std::endl;
}
/**
@@ -617,9 +618,7 @@ void Vector_distances_in_diagram<F>::load_from_file(const char* filename) {
}
double number;
- while (true) {
- in >> number;
- if (in.eof()) break;
+ while (in >> number) {
this->sorted_vector_of_distances.push_back(number);
}
in.close();
diff --git a/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h b/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h
new file mode 100644
index 00000000..2884885c
--- /dev/null
+++ b/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h
@@ -0,0 +1,143 @@
+/* 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): Mathieu Carriere
+ *
+ * Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PERSISTENCE_WEIGHTED_GAUSSIAN_H_
+#define PERSISTENCE_WEIGHTED_GAUSSIAN_H_
+
+#ifdef GUDHI_USE_TBB
+#include <tbb/parallel_for.h>
+#endif
+
+// gudhi include
+#include <gudhi/read_persistence_from_file.h>
+
+// standard include
+#include <cmath>
+#include <iostream>
+#include <vector>
+#include <limits>
+#include <fstream>
+#include <sstream>
+#include <algorithm>
+#include <string>
+#include <utility>
+#include <functional>
+#include <boost/math/constants/constants.hpp>
+
+double pi = boost::math::constants::pi<double>();
+using PD = std::vector<std::pair<double,double> >;
+
+namespace Gudhi {
+namespace Persistence_representations {
+
+class Persistence_weighted_gaussian{
+
+ protected:
+ PD diagram;
+
+ public:
+
+ Persistence_weighted_gaussian(PD _diagram){diagram = _diagram;}
+ PD get_diagram(){return this->diagram;}
+
+
+ // **********************************
+ // Utils.
+ // **********************************
+
+
+ static double pss_weight(std::pair<double,double> P){
+ if(P.second > P.first) return 1;
+ else return -1;
+ }
+
+ static double arctan_weight(std::pair<double,double> P){
+ return atan(P.second - P.first);
+ }
+
+ template<class Weight = std::function<double (std::pair<double,double>) > >
+ std::vector<std::pair<double,double> > Fourier_feat(PD D, std::vector<std::pair<double,double> > Z, Weight weight = arctan_weight){
+ int m = D.size(); std::vector<std::pair<double,double> > B; int M = Z.size();
+ for(int i = 0; i < M; i++){
+ double d1 = 0; double d2 = 0; double zx = Z[i].first; double zy = Z[i].second;
+ for(int j = 0; j < m; j++){
+ double x = D[j].first; double y = D[j].second;
+ d1 += weight(D[j])*cos(x*zx + y*zy);
+ d2 += weight(D[j])*sin(x*zx + y*zy);
+ }
+ B.emplace_back(d1,d2);
+ }
+ return B;
+ }
+
+ std::vector<std::pair<double,double> > random_Fourier(double sigma, int M = 1000){
+ std::normal_distribution<double> distrib(0,1); std::vector<std::pair<double,double> > Z; std::random_device rd;
+ for(int i = 0; i < M; i++){
+ std::mt19937 e1(rd()); std::mt19937 e2(rd());
+ double zx = distrib(e1); double zy = distrib(e2);
+ Z.emplace_back(zx/sigma,zy/sigma);
+ }
+ return Z;
+ }
+
+
+
+ // **********************************
+ // Scalar product + distance.
+ // **********************************
+
+
+ template<class Weight = std::function<double (std::pair<double,double>) > >
+ double compute_scalar_product(Persistence_weighted_gaussian second, double sigma, Weight weight = arctan_weight, int m = 1000){
+
+ PD diagram1 = this->diagram; PD diagram2 = second.diagram;
+
+ if(m == -1){
+ int num_pts1 = diagram1.size(); int num_pts2 = diagram2.size(); double k = 0;
+ for(int i = 0; i < num_pts1; i++)
+ for(int j = 0; j < num_pts2; j++)
+ k += weight(diagram1[i])*weight(diagram2[j])*exp(-((diagram1[i].first - diagram2[j].first) * (diagram1[i].first - diagram2[j].first) +
+ (diagram1[i].second - diagram2[j].second) * (diagram1[i].second - diagram2[j].second))
+ /(2*sigma*sigma));
+ return k;
+ }
+ else{
+ std::vector<std::pair<double,double> > z = random_Fourier(sigma, m);
+ std::vector<std::pair<double,double> > b1 = Fourier_feat(diagram1,z,weight);
+ std::vector<std::pair<double,double> > b2 = Fourier_feat(diagram2,z,weight);
+ double d = 0; for(int i = 0; i < m; i++) d += b1[i].first*b2[i].first + b1[i].second*b2[i].second;
+ return d/m;
+ }
+ }
+
+ template<class Weight = std::function<double (std::pair<double,double>) > >
+ double distance(Persistence_weighted_gaussian second, double sigma, Weight weight = arctan_weight, int m = 1000, double power = 1) {
+ return std::pow(this->compute_scalar_product(*this, sigma, weight, m) + second.compute_scalar_product(second, sigma, weight, m)-2*this->compute_scalar_product(second, sigma, weight, m), power/2.0);
+ }
+
+
+};
+
+} // namespace Persistence_weighted_gaussian
+} // namespace Gudhi
+
+#endif // PERSISTENCE_WEIGHTED_GAUSSIAN_H_
diff --git a/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h b/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h
new file mode 100644
index 00000000..4fa6151f
--- /dev/null
+++ b/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h
@@ -0,0 +1,285 @@
+/* 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): Mathieu Carriere
+ *
+ * Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SLICED_WASSERSTEIN_H_
+#define SLICED_WASSERSTEIN_H_
+
+#ifdef GUDHI_USE_TBB
+#include <tbb/parallel_for.h>
+#endif
+
+// gudhi include
+#include <gudhi/read_persistence_from_file.h>
+
+// standard include
+#include <cmath>
+#include <iostream>
+#include <vector>
+#include <limits>
+#include <fstream>
+#include <sstream>
+#include <algorithm>
+#include <string>
+#include <utility>
+#include <functional>
+#include <boost/math/constants/constants.hpp>
+
+double pi = boost::math::constants::pi<double>();
+using PD = std::vector<std::pair<double,double> >;
+
+namespace Gudhi {
+namespace Persistence_representations {
+
+class Sliced_Wasserstein {
+
+ protected:
+ PD diagram;
+
+ public:
+
+ Sliced_Wasserstein(PD _diagram){diagram = _diagram;}
+ PD get_diagram(){return this->diagram;}
+
+
+ // **********************************
+ // Utils.
+ // **********************************
+
+ // Compute the angle formed by two points of a PD
+ double compute_angle(PD diag, int i, int j){
+ std::pair<double,double> vect; double x1,y1, x2,y2;
+ x1 = diag[i].first; y1 = diag[i].second;
+ x2 = diag[j].first; y2 = diag[j].second;
+ if (y1 - y2 > 0){
+ vect.first = y1 - y2;
+ vect.second = x2 - x1;}
+ else{
+ if(y1 - y2 < 0){
+ vect.first = y2 - y1;
+ vect.second = x1 - x2;
+ }
+ else{
+ vect.first = 0;
+ vect.second = abs(x1 - x2);}
+ }
+ double norm = std::sqrt(vect.first*vect.first + vect.second*vect.second);
+ return asin(vect.second/norm);
+ }
+
+ // Compute the integral of |cos()| between alpha and beta, valid only if alpha is in [-pi,pi] and beta-alpha is in [0,pi]
+ double compute_int_cos(const double & alpha, const double & beta){
+ double res = 0;
+ if (alpha >= 0 && alpha <= pi){
+ if (cos(alpha) >= 0){
+ if(pi/2 <= beta){res = 2-sin(alpha)-sin(beta);}
+ else{res = sin(beta)-sin(alpha);}
+ }
+ else{
+ if(1.5*pi <= beta){res = 2+sin(alpha)+sin(beta);}
+ else{res = sin(alpha)-sin(beta);}
+ }
+ }
+ if (alpha >= -pi && alpha <= 0){
+ if (cos(alpha) <= 0){
+ if(-pi/2 <= beta){res = 2+sin(alpha)+sin(beta);}
+ else{res = sin(alpha)-sin(beta);}
+ }
+ else{
+ if(pi/2 <= beta){res = 2-sin(alpha)-sin(beta);}
+ else{res = sin(beta)-sin(alpha);}
+ }
+ }
+ return res;
+ }
+
+ double compute_int(const double & theta1, const double & theta2, const int & p, const int & q, const PD & PD1, const PD & PD2){
+ double norm = std::sqrt( (PD1[p].first-PD2[q].first)*(PD1[p].first-PD2[q].first) + (PD1[p].second-PD2[q].second)*(PD1[p].second-PD2[q].second) );
+ double angle1;
+ if (PD1[p].first > PD2[q].first)
+ angle1 = theta1 - asin( (PD1[p].second-PD2[q].second)/norm );
+ else
+ angle1 = theta1 - asin( (PD2[q].second-PD1[p].second)/norm );
+ double angle2 = angle1 + theta2 - theta1;
+ double integral = compute_int_cos(angle1,angle2);
+ return norm*integral;
+ }
+
+
+
+
+ // **********************************
+ // Scalar product + distance.
+ // **********************************
+
+ double compute_sliced_wasserstein_distance(Sliced_Wasserstein second, int approx) {
+
+ PD diagram1 = this->diagram; PD diagram2 = second.diagram; double sw = 0;
+
+ if(approx == -1){
+
+ // Add projections onto diagonal.
+ int n1, n2; n1 = diagram1.size(); n2 = diagram2.size(); double max_ordinate = std::numeric_limits<double>::lowest();
+ for (int i = 0; i < n2; i++){
+ max_ordinate = std::max(max_ordinate, diagram2[i].second);
+ diagram1.emplace_back( (diagram2[i].first+diagram2[i].second)/2, (diagram2[i].first+diagram2[i].second)/2 );
+ }
+ for (int i = 0; i < n1; i++){
+ max_ordinate = std::max(max_ordinate, diagram1[i].second);
+ diagram2.emplace_back( (diagram1[i].first+diagram1[i].second)/2, (diagram1[i].first+diagram1[i].second)/2 );
+ }
+ int num_pts_dgm = diagram1.size();
+
+ // Slightly perturb the points so that the PDs are in generic positions.
+ int mag = 0; while(max_ordinate > 10){mag++; max_ordinate/=10;}
+ double thresh = pow(10,-5+mag);
+ srand(time(NULL));
+ for (int i = 0; i < num_pts_dgm; i++){
+ diagram1[i].first += thresh*(1.0-2.0*rand()/RAND_MAX); diagram1[i].second += thresh*(1.0-2.0*rand()/RAND_MAX);
+ diagram2[i].first += thresh*(1.0-2.0*rand()/RAND_MAX); diagram2[i].second += thresh*(1.0-2.0*rand()/RAND_MAX);
+ }
+
+ // Compute all angles in both PDs.
+ std::vector<std::pair<double, std::pair<int,int> > > angles1, angles2;
+ for (int i = 0; i < num_pts_dgm; i++){
+ for (int j = i+1; j < num_pts_dgm; j++){
+ double theta1 = compute_angle(diagram1,i,j); double theta2 = compute_angle(diagram2,i,j);
+ angles1.emplace_back(theta1, std::pair<int,int>(i,j));
+ angles2.emplace_back(theta2, std::pair<int,int>(i,j));
+ }
+ }
+
+ // Sort angles.
+ std::sort(angles1.begin(), angles1.end(), [=](std::pair<double, std::pair<int,int> >& p1, const std::pair<double, std::pair<int,int> >& p2){return (p1.first < p2.first);});
+ std::sort(angles2.begin(), angles2.end(), [=](std::pair<double, std::pair<int,int> >& p1, const std::pair<double, std::pair<int,int> >& p2){return (p1.first < p2.first);});
+
+ // Initialize orders of the points of both PDs (given by ordinates when theta = -pi/2).
+ std::vector<int> orderp1, orderp2;
+ for (int i = 0; i < num_pts_dgm; i++){ orderp1.push_back(i); orderp2.push_back(i); }
+ std::sort( orderp1.begin(), orderp1.end(), [=](int i, int j){ if(diagram1[i].second != diagram1[j].second) return (diagram1[i].second < diagram1[j].second); else return (diagram1[i].first > diagram1[j].first); } );
+ std::sort( orderp2.begin(), orderp2.end(), [=](int i, int j){ if(diagram2[i].second != diagram2[j].second) return (diagram2[i].second < diagram2[j].second); else return (diagram2[i].first > diagram2[j].first); } );
+
+ // Find the inverses of the orders.
+ std::vector<int> order1(num_pts_dgm); std::vector<int> order2(num_pts_dgm);
+ for(int i = 0; i < num_pts_dgm; i++) for (int j = 0; j < num_pts_dgm; j++) if(orderp1[j] == i){ order1[i] = j; break; }
+ for(int i = 0; i < num_pts_dgm; i++) for (int j = 0; j < num_pts_dgm; j++) if(orderp2[j] == i){ order2[i] = j; break; }
+
+ // Record all inversions of points in the orders as theta varies along the positive half-disk.
+ std::vector<std::vector<std::pair<int,double> > > anglePerm1(num_pts_dgm);
+ std::vector<std::vector<std::pair<int,double> > > anglePerm2(num_pts_dgm);
+
+ int m1 = angles1.size();
+ for (int i = 0; i < m1; i++){
+ double theta = angles1[i].first; int p = angles1[i].second.first; int q = angles1[i].second.second;
+ anglePerm1[order1[p]].emplace_back(p,theta);
+ anglePerm1[order1[q]].emplace_back(q,theta);
+ int a = order1[p]; int b = order1[q]; order1[p] = b; order1[q] = a;
+ }
+
+ int m2 = angles2.size();
+ for (int i = 0; i < m2; i++){
+ double theta = angles2[i].first; int p = angles2[i].second.first; int q = angles2[i].second.second;
+ anglePerm2[order2[p]].emplace_back(p,theta);
+ anglePerm2[order2[q]].emplace_back(q,theta);
+ int a = order2[p]; int b = order2[q]; order2[p] = b; order2[q] = a;
+ }
+
+ for (int i = 0; i < num_pts_dgm; i++){
+ anglePerm1[order1[i]].emplace_back(i,pi/2);
+ anglePerm2[order2[i]].emplace_back(i,pi/2);
+ }
+
+ // Compute the SW distance with the list of inversions.
+ for (int i = 0; i < num_pts_dgm; i++){
+ std::vector<std::pair<int,double> > u,v; u = anglePerm1[i]; v = anglePerm2[i];
+ double theta1, theta2; theta1 = -pi/2;
+ unsigned int ku, kv; ku = 0; kv = 0; theta2 = std::min(u[ku].second,v[kv].second);
+ while(theta1 != pi/2){
+ if(diagram1[u[ku].first].first != diagram2[v[kv].first].first || diagram1[u[ku].first].second != diagram2[v[kv].first].second)
+ if(theta1 != theta2)
+ sw += compute_int(theta1, theta2, u[ku].first, v[kv].first, diagram1, diagram2);
+ theta1 = theta2;
+ if ( (theta2 == u[ku].second) && ku < u.size()-1 ) ku++;
+ if ( (theta2 == v[kv].second) && kv < v.size()-1 ) kv++;
+ theta2 = std::min(u[ku].second, v[kv].second);
+ }
+ }
+ }
+
+
+ else{
+ double step = pi/approx;
+
+ // Add projections onto diagonal.
+ int n1, n2; n1 = diagram1.size(); n2 = diagram2.size();
+ for (int i = 0; i < n2; i++)
+ diagram1.emplace_back( (diagram2[i].first + diagram2[i].second)/2, (diagram2[i].first + diagram2[i].second)/2 );
+ for (int i = 0; i < n1; i++)
+ diagram2.emplace_back( (diagram1[i].first + diagram1[i].second)/2, (diagram1[i].first + diagram1[i].second)/2 );
+ int n = diagram1.size();
+
+ // Sort and compare all projections.
+ #ifdef GUDHI_USE_TBB
+ tbb::parallel_for(0, approx, [&](int i){
+ std::vector<std::pair<int,double> > l1, l2;
+ for (int j = 0; j < n; j++){
+ l1.emplace_back( j, diagram1[j].first*cos(-pi/2+i*step) + diagram1[j].second*sin(-pi/2+i*step) );
+ l2.emplace_back( j, diagram2[j].first*cos(-pi/2+i*step) + diagram2[j].second*sin(-pi/2+i*step) );
+ }
+ std::sort(l1.begin(),l1.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;});
+ std::sort(l2.begin(),l2.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;});
+ double f = 0; for (int j = 0; j < n; j++) f += std::abs(l1[j].second - l2[j].second);
+ sw += f*step;
+ });
+ #else
+ for (int i = 0; i < approx; i++){
+ std::vector<std::pair<int,double> > l1, l2;
+ for (int j = 0; j < n; j++){
+ l1.emplace_back( j, diagram1[j].first*cos(-pi/2+i*step) + diagram1[j].second*sin(-pi/2+i*step) );
+ l2.emplace_back( j, diagram2[j].first*cos(-pi/2+i*step) + diagram2[j].second*sin(-pi/2+i*step) );
+ }
+ std::sort(l1.begin(),l1.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;});
+ std::sort(l2.begin(),l2.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;});
+ double f = 0; for (int j = 0; j < n; j++) f += std::abs(l1[j].second - l2[j].second);
+ sw += f*step;
+ }
+ #endif
+ }
+
+ return sw/pi;
+ }
+
+
+ double compute_scalar_product(Sliced_Wasserstein second, double sigma, int approx = 100) {
+ return std::exp(-compute_sliced_wasserstein_distance(second, approx)/(2*sigma*sigma));
+ }
+
+ double distance(Sliced_Wasserstein second, double sigma, int approx = 100, double power = 1) {
+ return std::pow(this->compute_scalar_product(*this, sigma, approx) + second.compute_scalar_product(second, sigma, approx)-2*this->compute_scalar_product(second, sigma, approx), power/2.0);
+ }
+
+
+};
+
+} // namespace Sliced_Wasserstein
+} // namespace Gudhi
+
+#endif // SLICED_WASSERSTEIN_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 770da15b..83b89d0e 100644
--- a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h
+++ b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h
@@ -23,6 +23,8 @@
#ifndef READ_PERSISTENCE_FROM_FILE_H_
#define READ_PERSISTENCE_FROM_FILE_H_
+#include <gudhi/reader_utils.h>
+
#include <iostream>
#include <fstream>
#include <sstream>
@@ -30,7 +32,7 @@
#include <algorithm>
#include <string>
#include <utility>
-#include <gudhi/reader_utils.h>
+#include <limits> // for std::numeric_limits<>
namespace Gudhi {
namespace Persistence_representations {
@@ -50,81 +52,66 @@ namespace Persistence_representations {
* The procedure returns vector of persistence pairs.
**/
std::vector<std::pair<double, double> > read_persistence_intervals_in_one_dimension_from_file(
- std::string const& filename, int dimension = -1, double what_to_substitute_for_infinite_bar = -1) {
+ std::string const& filename, int dimension = -1, double what_to_substitute_for_infinite_bar = -1) {
bool dbg = false;
std::string line;
- std::vector<std::pair<double, double> > barcode_initial = read_persistence_intervals_in_dimension(filename,(int)dimension);
+ std::vector<std::pair<double, double> > barcode_initial =
+ read_persistence_intervals_in_dimension(filename, (int)dimension);
std::vector<std::pair<double, double> > final_barcode;
- final_barcode.reserve( barcode_initial.size() );
-
- if ( dbg )
- {
- std::cerr << "Here are the intervals that we read from the file : \n";
- for ( size_t i = 0 ; i != barcode_initial.size() ; ++i )
- {
- std::cout << barcode_initial[i].first << " " << barcode_initial[i].second << std::endl;
- }
- getchar();
+ final_barcode.reserve(barcode_initial.size());
+
+ if (dbg) {
+ std::cerr << "Here are the intervals that we read from the file : \n";
+ for (size_t i = 0; i != barcode_initial.size(); ++i) {
+ std::cout << barcode_initial[i].first << " " << barcode_initial[i].second << std::endl;
+ }
+ getchar();
}
-
- for ( size_t i = 0 ; i != barcode_initial.size() ; ++i )
- {
- if ( dbg )
- {
- std::cout << "COnsidering interval : " << barcode_initial[i].first << " " << barcode_initial[i].second << std::endl;
- }
- // if ( barcode_initial[i].first == barcode_initial[i].second )
- //{
- // if ( dbg )std::cout << "It has zero length \n";
- // continue;//zero length intervals are not relevant, so we skip all of them.
- //}
-
- if ( barcode_initial[i].first > barcode_initial[i].second )//note that in this case barcode_initial[i].second != std::numeric_limits<double>::infinity()
- {
- if ( dbg )std::cout << "Swap and enter \n";
- //swap them to make sure that birth < death
- final_barcode.push_back( std::pair<double,double>( barcode_initial[i].second , barcode_initial[i].first ) );
- continue;
- }
- else
- {
- if ( barcode_initial[i].second != std::numeric_limits<double>::infinity() )
- {
- if ( dbg )std::cout << "Simply enters\n";
- //in this case, due to the previous conditions we know that barcode_initial[i].first < barcode_initial[i].second, so we put them as they are
- final_barcode.push_back( std::pair<double,double>( barcode_initial[i].first , barcode_initial[i].second ) );
- }
- }
-
- if ( (barcode_initial[i].second == std::numeric_limits<double>::infinity() ) && ( what_to_substitute_for_infinite_bar != -1 ) )
- {
- if ( barcode_initial[i].first < what_to_substitute_for_infinite_bar )//if only birth < death.
- {
- final_barcode.push_back( std::pair<double,double>( barcode_initial[i].first , what_to_substitute_for_infinite_bar ) );
- }
- }
- else
- {
- //if the variable what_to_substitute_for_infinite_bar is not set, then we ignore all the infinite bars.
- }
+
+ for (size_t i = 0; i != barcode_initial.size(); ++i) {
+ if (dbg) {
+ std::cout << "COnsidering interval : " << barcode_initial[i].first << " " << barcode_initial[i].second
+ << std::endl;
+ }
+
+ if (barcode_initial[i].first > barcode_initial[i].second) {
+ // note that in this case barcode_initial[i].second != std::numeric_limits<double>::infinity()
+ if (dbg) std::cout << "Swap and enter \n";
+ // swap them to make sure that birth < death
+ final_barcode.push_back(std::pair<double, double>(barcode_initial[i].second, barcode_initial[i].first));
+ continue;
+ } else {
+ if (barcode_initial[i].second != std::numeric_limits<double>::infinity()) {
+ if (dbg) std::cout << "Simply enters\n";
+ // in this case, due to the previous conditions we know that barcode_initial[i].first <
+ // barcode_initial[i].second, so we put them as they are
+ final_barcode.push_back(std::pair<double, double>(barcode_initial[i].first, barcode_initial[i].second));
+ }
+ }
+
+ if ((barcode_initial[i].second == std::numeric_limits<double>::infinity()) &&
+ (what_to_substitute_for_infinite_bar != -1)) {
+ if (barcode_initial[i].first < what_to_substitute_for_infinite_bar) // if only birth < death.
+ {
+ final_barcode.push_back(
+ std::pair<double, double>(barcode_initial[i].first, what_to_substitute_for_infinite_bar));
+ }
+ } else {
+ // if the variable what_to_substitute_for_infinite_bar is not set, then we ignore all the infinite bars.
+ }
}
-
-
- if ( dbg )
- {
- std::cerr << "Here are the final bars that we are sending further : \n";
- for ( size_t i = 0 ; i != final_barcode.size() ; ++i )
- {
- std::cout << final_barcode[i].first << " " << final_barcode[i].second << std::endl;
- }
- std::cerr << "final_barcode.size() : " << final_barcode.size() << std::endl;
- getchar();
+
+ if (dbg) {
+ std::cerr << "Here are the final bars that we are sending further : \n";
+ for (size_t i = 0; i != final_barcode.size(); ++i) {
+ std::cout << final_barcode[i].first << " " << final_barcode[i].second << std::endl;
+ }
+ std::cerr << "final_barcode.size() : " << final_barcode.size() << std::endl;
+ getchar();
}
-
-
-
- return final_barcode;
+
+ return final_barcode;
} // read_persistence_intervals_in_one_dimension_from_file
} // namespace Persistence_representations
diff --git a/src/Persistence_representations/test/CMakeLists.txt b/src/Persistence_representations/test/CMakeLists.txt
index 4483de07..335a71ef 100644
--- a/src/Persistence_representations/test/CMakeLists.txt
+++ b/src/Persistence_representations/test/CMakeLists.txt
@@ -6,38 +6,38 @@ include(GUDHI_test_coverage)
# copy data directory for tests purpose.
file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
add_executable ( Persistence_intervals_test_unit persistence_intervals_test.cpp )
-target_link_libraries(Persistence_intervals_test_unit ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Persistence_intervals_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
gudhi_add_coverage_test(Persistence_intervals_test_unit)
add_executable (Vector_representation_test_unit vector_representation_test.cpp )
-target_link_libraries(Vector_representation_test_unit ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Vector_representation_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
gudhi_add_coverage_test(Vector_representation_test_unit)
add_executable (Persistence_lanscapes_test_unit persistence_lanscapes_test.cpp )
-target_link_libraries(Persistence_lanscapes_test_unit ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Persistence_lanscapes_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
gudhi_add_coverage_test(Persistence_lanscapes_test_unit)
add_executable ( Persistence_lanscapes_on_grid_test_unit persistence_lanscapes_on_grid_test.cpp )
-target_link_libraries(Persistence_lanscapes_on_grid_test_unit ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Persistence_lanscapes_on_grid_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
gudhi_add_coverage_test(Persistence_lanscapes_on_grid_test_unit)
add_executable (Persistence_heat_maps_test_unit persistence_heat_maps_test.cpp )
-target_link_libraries(Persistence_heat_maps_test_unit ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Persistence_heat_maps_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
gudhi_add_coverage_test(Persistence_heat_maps_test_unit)
add_executable ( Read_persistence_from_file_test_unit read_persistence_from_file_test.cpp )
-target_link_libraries(Read_persistence_from_file_test_unit ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Read_persistence_from_file_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
gudhi_add_coverage_test(Read_persistence_from_file_test_unit)
if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1)
add_executable (Persistence_intervals_with_distances_test_unit persistence_intervals_with_distances_test.cpp )
- target_link_libraries(Persistence_intervals_with_distances_test_unit ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+ target_link_libraries(Persistence_intervals_with_distances_test_unit ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
if (TBB_FOUND)
target_link_libraries(Persistence_intervals_with_distances_test_unit ${TBB_LIBRARIES})
endif(TBB_FOUND)
diff --git a/src/Persistence_representations/test/persistence_heat_maps_test.cpp b/src/Persistence_representations/test/persistence_heat_maps_test.cpp
index 1f1502f5..e36108b7 100644
--- a/src/Persistence_representations/test/persistence_heat_maps_test.cpp
+++ b/src/Persistence_representations/test/persistence_heat_maps_test.cpp
@@ -25,12 +25,15 @@
#include <boost/test/unit_test.hpp>
#include <gudhi/reader_utils.h>
#include <gudhi/Persistence_heat_maps.h>
+#include <gudhi/Unitary_tests_utils.h>
#include <iostream>
using namespace Gudhi;
using namespace Gudhi::Persistence_representations;
+double epsilon = 0.0005;
+
BOOST_AUTO_TEST_CASE(check_construction_of_heat_maps) {
std::vector<std::vector<double> > filter = create_Gaussian_filter(100, 1);
Persistence_heat_maps<constant_scaling_function> p("data/file_with_diagram", filter, false, 1000, 0, 1);
@@ -139,28 +142,15 @@ BOOST_AUTO_TEST_CASE(check_distance_for_heat_maps) {
Persistence_heat_maps<constant_scaling_function> q("data/file_with_diagram_1", filter, false, 1000, 0, 1);
Persistence_heat_maps<constant_scaling_function> r("data/file_with_diagram_2", filter, false, 1000, 0, 1);
- // cerr << p.distance( p ) << endl;
- // cerr << p.distance( q ) << endl;
- // cerr << p.distance( r ) << endl;
- // cerr << q.distance( p ) << endl;
- // cerr << q.distance( q ) << endl;
- // cerr << q.distance( r ) << endl;
- // cerr << r.distance( p ) << endl;
- // cerr << r.distance( q ) << endl;
- // cerr << r.distance( r ) << endl;
- // 0 624.183 415.815
- // 624.183 0 528.06Z
- // 415.815 528.066 0
-
- BOOST_CHECK(fabs(p.distance(p) - 0) < 0.0005);
- BOOST_CHECK(fabs(p.distance(q) - 624.183) < 0.0005);
- BOOST_CHECK(fabs(p.distance(r) - 415.815) < 0.0005);
- BOOST_CHECK(fabs(q.distance(p) - 624.183) < 0.0005);
- BOOST_CHECK(fabs(q.distance(q) - 0) < 0.0005);
- BOOST_CHECK(fabs(q.distance(r) - 528.066) < 0.0005);
- BOOST_CHECK(fabs(r.distance(p) - 415.815) < 0.0005);
- BOOST_CHECK(fabs(r.distance(q) - 528.066) < 0.0005);
- BOOST_CHECK(fabs(r.distance(r) - 0) < 0.0005);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(p), 0., epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q), 624.183, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(r), 415.815, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.distance(p), 624.183, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.distance(q), 0., epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.distance(r), 528.066, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.distance(p), 415.815, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.distance(q), 528.066, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.distance(r), 0., epsilon);
}
BOOST_AUTO_TEST_CASE(check_projections_to_R_for_heat_maps) {
@@ -169,13 +159,9 @@ BOOST_AUTO_TEST_CASE(check_projections_to_R_for_heat_maps) {
Persistence_heat_maps<constant_scaling_function> q("data/file_with_diagram_1", filter, false, 1000, 0, 1);
Persistence_heat_maps<constant_scaling_function> r("data/file_with_diagram_2", filter, false, 1000, 0, 1);
- // cerr << p.project_to_R(0) << endl;
- // cerr << q.project_to_R(0) << endl;
- // cerr << r.project_to_R(0) << endl;
-
- BOOST_CHECK(fabs(p.project_to_R(0) - 44.3308) < 0.0005);
- BOOST_CHECK(fabs(q.project_to_R(0) - 650.568) < 0.0005);
- BOOST_CHECK(fabs(r.project_to_R(0) - 429.287) < 0.0005);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.project_to_R(0), 44.3308, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.project_to_R(0), 650.568, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.project_to_R(0), 429.287, epsilon);
}
BOOST_AUTO_TEST_CASE(check_scalar_products_for_heat_maps) {
@@ -184,25 +170,15 @@ BOOST_AUTO_TEST_CASE(check_scalar_products_for_heat_maps) {
Persistence_heat_maps<constant_scaling_function> q("data/file_with_diagram_1", filter, false, 1000, 0, 1);
Persistence_heat_maps<constant_scaling_function> r("data/file_with_diagram_2", filter, false, 1000, 0, 1);
- // cerr << p.compute_scalar_product( p ) << endl;
- // cerr << p.compute_scalar_product( q ) << endl;
- // cerr << p.compute_scalar_product( r ) << endl;
- // cerr << q.compute_scalar_product( p ) << endl;
- // cerr << q.compute_scalar_product( q ) << endl;
- // cerr << q.compute_scalar_product( r ) << endl;
- // cerr << r.compute_scalar_product( p ) << endl;
- // cerr << r.compute_scalar_product( q ) << endl;
- // cerr << r.compute_scalar_product( r ) << endl;
-
- BOOST_CHECK(fabs(p.compute_scalar_product(p) - 0.0345687) < 0.0005);
- BOOST_CHECK(fabs(p.compute_scalar_product(q) - 0.0509357) < 0.0005);
- BOOST_CHECK(fabs(p.compute_scalar_product(r) - 0.0375608) < 0.0005);
- BOOST_CHECK(fabs(q.compute_scalar_product(p) - 0.0509357) < 0.0005);
- BOOST_CHECK(fabs(q.compute_scalar_product(q) - 1.31293) < 0.0005);
- BOOST_CHECK(fabs(q.compute_scalar_product(r) - 0.536799) < 0.0005);
- BOOST_CHECK(fabs(r.compute_scalar_product(p) - 0.0375608) < 0.0005);
- BOOST_CHECK(fabs(r.compute_scalar_product(q) - 0.536799) < 0.0005);
- BOOST_CHECK(fabs(r.compute_scalar_product(r) - 0.672907) < 0.0005);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(p), 0.0345687, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(q), 0.0509357, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(r), 0.0375608, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.compute_scalar_product(p), 0.0509357, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.compute_scalar_product(q), 1.31293, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(q.compute_scalar_product(r), 0.536799, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.compute_scalar_product(p), 0.0375608, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.compute_scalar_product(q), 0.536799, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(r.compute_scalar_product(r), 0.672907, epsilon);
}
BOOST_AUTO_TEST_CASE(check_arythmetic_operations_for_heat_maps) {
diff --git a/src/Persistence_representations/test/persistence_intervals_test.cpp b/src/Persistence_representations/test/persistence_intervals_test.cpp
index 545330c4..f555e243 100644
--- a/src/Persistence_representations/test/persistence_intervals_test.cpp
+++ b/src/Persistence_representations/test/persistence_intervals_test.cpp
@@ -25,25 +25,20 @@
#include <boost/test/unit_test.hpp>
#include <gudhi/reader_utils.h>
#include "gudhi/Persistence_intervals.h"
+#include <gudhi/common_persistence_representations.h>
+#include <gudhi/Unitary_tests_utils.h>
#include <iostream>
using namespace Gudhi;
using namespace Gudhi::Persistence_representations;
-double epsilon = 0.0000005;
-
-// cout << "Left most end of the interval : " << min_max_.first << std::endl;
-// cout << "Right most end of the interval : " << min_max_.second << std::endl;
BOOST_AUTO_TEST_CASE(check_min_max_function) {
- std::cerr << "First test \n";
Persistence_intervals p("data/file_with_diagram");
std::pair<double, double> min_max_ = p.get_x_range();
- // cout << min_max_.first << " " << min_max_.second << std::endl;getchar();
-
- BOOST_CHECK(fabs(min_max_.first - 0.0290362) <= epsilon);
- BOOST_CHECK(fabs(min_max_.second - 0.994537) <= epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(min_max_.first, 0.0290362, Gudhi::Persistence_representations::epsi);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(min_max_.second, 0.994537, Gudhi::Persistence_representations::epsi);
}
BOOST_AUTO_TEST_CASE(check_length_of_dominant_intervals) {
@@ -61,7 +56,8 @@ BOOST_AUTO_TEST_CASE(check_length_of_dominant_intervals) {
dominant_intervals_length.push_back(0.700468);
dominant_intervals_length.push_back(0.622177);
for (size_t i = 0; i != dominant_ten_intervals_length.size(); ++i) {
- BOOST_CHECK(fabs(dominant_ten_intervals_length[i] - dominant_intervals_length[i]) <= epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(dominant_ten_intervals_length[i], dominant_intervals_length[i],
+ Gudhi::Persistence_representations::epsi);
}
}
BOOST_AUTO_TEST_CASE(check_dominant_intervals) {
@@ -81,8 +77,10 @@ BOOST_AUTO_TEST_CASE(check_dominant_intervals) {
templ.push_back(std::pair<double, double>(0.267421, 0.889597));
for (size_t i = 0; i != ten_dominant_intervals.size(); ++i) {
- BOOST_CHECK(fabs(ten_dominant_intervals[i].first - templ[i].first) <= epsilon);
- BOOST_CHECK(fabs(ten_dominant_intervals[i].second - templ[i].second) <= epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(ten_dominant_intervals[i].first, templ[i].first,
+ Gudhi::Persistence_representations::epsi);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(ten_dominant_intervals[i].second, templ[i].second,
+ Gudhi::Persistence_representations::epsi);
}
}
@@ -102,7 +100,7 @@ BOOST_AUTO_TEST_CASE(check_histogram_of_lengths) {
template_histogram.push_back(1);
template_histogram.push_back(1);
for (size_t i = 0; i != histogram.size(); ++i) {
- BOOST_CHECK(fabs(histogram[i] - template_histogram[i]) <= epsilon);
+ BOOST_CHECK(histogram[i] == template_histogram[i]);
}
}
@@ -123,7 +121,7 @@ BOOST_AUTO_TEST_CASE(check_cumulative_histograms_of_lengths) {
template_cumulative_histogram.push_back(45);
for (size_t i = 0; i != cumulative_histogram.size(); ++i) {
- BOOST_CHECK(fabs(cumulative_histogram[i] - template_cumulative_histogram[i]) <= epsilon);
+ BOOST_CHECK(cumulative_histogram[i] == template_cumulative_histogram[i]);
}
}
BOOST_AUTO_TEST_CASE(check_characteristic_function_of_diagram) {
@@ -143,15 +141,8 @@ BOOST_AUTO_TEST_CASE(check_characteristic_function_of_diagram) {
template_char_funct_diag.push_back(0.0676303);
for (size_t i = 0; i != char_funct_diag.size(); ++i) {
- // cout << char_funct_diag[i] << std::endl;
- if (fabs(char_funct_diag[i] - template_char_funct_diag[i]) >= 0.0001) {
- std::cout << "Boost test fail check_characteristic_function_of_diagram : " << std::endl;
- std::cerr << char_funct_diag[i] << " " << template_char_funct_diag[i] << std::endl;
- std::cerr << fabs(char_funct_diag[i] - template_char_funct_diag[i]) << std::endl;
- std::cerr << 0.0001 << std::endl;
- //getchar();
- }
- BOOST_CHECK(fabs(char_funct_diag[i] - template_char_funct_diag[i]) <= 0.0001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(char_funct_diag[i], template_char_funct_diag[i],
+ Gudhi::Persistence_representations::epsi);
}
}
@@ -174,110 +165,109 @@ BOOST_AUTO_TEST_CASE(check_cumulative_characteristic_function_of_diagram) {
template_char_funct_diag_cumul.push_back(9.48386);
for (size_t i = 0; i != cumul_char_funct_diag.size(); ++i) {
- // cout << cumul_char_funct_diag[i] << std::endl;
- BOOST_CHECK(fabs(cumul_char_funct_diag[i] - template_char_funct_diag_cumul[i]) <= 0.0001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(cumul_char_funct_diag[i], template_char_funct_diag_cumul[i],
+ Gudhi::Persistence_representations::epsi);
}
}
BOOST_AUTO_TEST_CASE(check_compute_persistent_betti_numbers) {
Persistence_intervals p("data/file_with_diagram");
- std::vector<std::pair<double, double> > pbns;
- pbns.push_back(std::pair<double, double>(0.0290362, 1));
- pbns.push_back(std::pair<double, double>(0.0307676, 2));
- pbns.push_back(std::pair<double, double>(0.0366312, 3));
- pbns.push_back(std::pair<double, double>(0.0544614, 4));
- pbns.push_back(std::pair<double, double>(0.0920033, 5));
- pbns.push_back(std::pair<double, double>(0.104599, 6));
- pbns.push_back(std::pair<double, double>(0.114718, 7));
- pbns.push_back(std::pair<double, double>(0.117379, 8));
- pbns.push_back(std::pair<double, double>(0.123493, 9));
- pbns.push_back(std::pair<double, double>(0.133638, 10));
- pbns.push_back(std::pair<double, double>(0.137798, 9));
- pbns.push_back(std::pair<double, double>(0.149798, 10));
- pbns.push_back(std::pair<double, double>(0.155421, 11));
- pbns.push_back(std::pair<double, double>(0.158443, 12));
- pbns.push_back(std::pair<double, double>(0.176956, 13));
- pbns.push_back(std::pair<double, double>(0.183234, 12));
- pbns.push_back(std::pair<double, double>(0.191069, 13));
- pbns.push_back(std::pair<double, double>(0.191333, 14));
- pbns.push_back(std::pair<double, double>(0.191836, 15));
- pbns.push_back(std::pair<double, double>(0.192675, 16));
- pbns.push_back(std::pair<double, double>(0.208564, 17));
- pbns.push_back(std::pair<double, double>(0.218425, 18));
- pbns.push_back(std::pair<double, double>(0.219902, 17));
- pbns.push_back(std::pair<double, double>(0.23233, 16));
- pbns.push_back(std::pair<double, double>(0.234558, 17));
- pbns.push_back(std::pair<double, double>(0.237166, 16));
- pbns.push_back(std::pair<double, double>(0.247352, 17));
- pbns.push_back(std::pair<double, double>(0.267421, 18));
- pbns.push_back(std::pair<double, double>(0.268093, 19));
- pbns.push_back(std::pair<double, double>(0.278734, 18));
- pbns.push_back(std::pair<double, double>(0.284722, 19));
- pbns.push_back(std::pair<double, double>(0.284998, 20));
- pbns.push_back(std::pair<double, double>(0.294069, 21));
- pbns.push_back(std::pair<double, double>(0.306293, 22));
- pbns.push_back(std::pair<double, double>(0.322361, 21));
- pbns.push_back(std::pair<double, double>(0.323152, 22));
- pbns.push_back(std::pair<double, double>(0.371021, 23));
- pbns.push_back(std::pair<double, double>(0.372395, 24));
- pbns.push_back(std::pair<double, double>(0.387744, 25));
- pbns.push_back(std::pair<double, double>(0.435537, 26));
- pbns.push_back(std::pair<double, double>(0.462911, 25));
- pbns.push_back(std::pair<double, double>(0.483569, 26));
- pbns.push_back(std::pair<double, double>(0.489209, 25));
- pbns.push_back(std::pair<double, double>(0.517115, 24));
- pbns.push_back(std::pair<double, double>(0.522197, 23));
- pbns.push_back(std::pair<double, double>(0.532665, 22));
- pbns.push_back(std::pair<double, double>(0.545262, 23));
- pbns.push_back(std::pair<double, double>(0.587227, 22));
- pbns.push_back(std::pair<double, double>(0.593036, 23));
- pbns.push_back(std::pair<double, double>(0.602647, 24));
- pbns.push_back(std::pair<double, double>(0.605044, 25));
- pbns.push_back(std::pair<double, double>(0.621962, 24));
- pbns.push_back(std::pair<double, double>(0.629449, 23));
- pbns.push_back(std::pair<double, double>(0.636719, 22));
- pbns.push_back(std::pair<double, double>(0.64957, 21));
- pbns.push_back(std::pair<double, double>(0.650781, 22));
- pbns.push_back(std::pair<double, double>(0.654951, 23));
- pbns.push_back(std::pair<double, double>(0.683489, 24));
- pbns.push_back(std::pair<double, double>(0.687172, 23));
- pbns.push_back(std::pair<double, double>(0.69703, 22));
- pbns.push_back(std::pair<double, double>(0.701174, 21));
- pbns.push_back(std::pair<double, double>(0.717623, 22));
- pbns.push_back(std::pair<double, double>(0.722023, 21));
- pbns.push_back(std::pair<double, double>(0.722298, 20));
- pbns.push_back(std::pair<double, double>(0.725347, 19));
- pbns.push_back(std::pair<double, double>(0.73071, 18));
- pbns.push_back(std::pair<double, double>(0.758355, 17));
- pbns.push_back(std::pair<double, double>(0.770913, 18));
- pbns.push_back(std::pair<double, double>(0.790833, 17));
- pbns.push_back(std::pair<double, double>(0.821211, 16));
- pbns.push_back(std::pair<double, double>(0.849305, 17));
- pbns.push_back(std::pair<double, double>(0.853669, 16));
- pbns.push_back(std::pair<double, double>(0.866659, 15));
- pbns.push_back(std::pair<double, double>(0.872896, 16));
- pbns.push_back(std::pair<double, double>(0.889597, 15));
- pbns.push_back(std::pair<double, double>(0.900231, 14));
- pbns.push_back(std::pair<double, double>(0.903847, 13));
- pbns.push_back(std::pair<double, double>(0.906299, 12));
- pbns.push_back(std::pair<double, double>(0.910852, 11));
- pbns.push_back(std::pair<double, double>(0.93453, 10));
- pbns.push_back(std::pair<double, double>(0.944757, 9));
- pbns.push_back(std::pair<double, double>(0.947812, 8));
- pbns.push_back(std::pair<double, double>(0.959154, 7));
- pbns.push_back(std::pair<double, double>(0.975654, 6));
- pbns.push_back(std::pair<double, double>(0.976719, 5));
- pbns.push_back(std::pair<double, double>(0.977343, 4));
- pbns.push_back(std::pair<double, double>(0.980129, 3));
- pbns.push_back(std::pair<double, double>(0.987842, 2));
- pbns.push_back(std::pair<double, double>(0.990127, 1));
- pbns.push_back(std::pair<double, double>(0.994537, 0));
+ std::vector<std::pair<double, size_t> > pbns;
+ pbns.push_back(std::pair<double, size_t>(0.0290362, 1));
+ pbns.push_back(std::pair<double, size_t>(0.0307676, 2));
+ pbns.push_back(std::pair<double, size_t>(0.0366312, 3));
+ pbns.push_back(std::pair<double, size_t>(0.0544614, 4));
+ pbns.push_back(std::pair<double, size_t>(0.0920033, 5));
+ pbns.push_back(std::pair<double, size_t>(0.104599, 6));
+ pbns.push_back(std::pair<double, size_t>(0.114718, 7));
+ pbns.push_back(std::pair<double, size_t>(0.117379, 8));
+ pbns.push_back(std::pair<double, size_t>(0.123493, 9));
+ pbns.push_back(std::pair<double, size_t>(0.133638, 10));
+ pbns.push_back(std::pair<double, size_t>(0.137798, 9));
+ pbns.push_back(std::pair<double, size_t>(0.149798, 10));
+ pbns.push_back(std::pair<double, size_t>(0.155421, 11));
+ pbns.push_back(std::pair<double, size_t>(0.158443, 12));
+ pbns.push_back(std::pair<double, size_t>(0.176956, 13));
+ pbns.push_back(std::pair<double, size_t>(0.183234, 12));
+ pbns.push_back(std::pair<double, size_t>(0.191069, 13));
+ pbns.push_back(std::pair<double, size_t>(0.191333, 14));
+ pbns.push_back(std::pair<double, size_t>(0.191836, 15));
+ pbns.push_back(std::pair<double, size_t>(0.192675, 16));
+ pbns.push_back(std::pair<double, size_t>(0.208564, 17));
+ pbns.push_back(std::pair<double, size_t>(0.218425, 18));
+ pbns.push_back(std::pair<double, size_t>(0.219902, 17));
+ pbns.push_back(std::pair<double, size_t>(0.23233, 16));
+ pbns.push_back(std::pair<double, size_t>(0.234558, 17));
+ pbns.push_back(std::pair<double, size_t>(0.237166, 16));
+ pbns.push_back(std::pair<double, size_t>(0.247352, 17));
+ pbns.push_back(std::pair<double, size_t>(0.267421, 18));
+ pbns.push_back(std::pair<double, size_t>(0.268093, 19));
+ pbns.push_back(std::pair<double, size_t>(0.278734, 18));
+ pbns.push_back(std::pair<double, size_t>(0.284722, 19));
+ pbns.push_back(std::pair<double, size_t>(0.284998, 20));
+ pbns.push_back(std::pair<double, size_t>(0.294069, 21));
+ pbns.push_back(std::pair<double, size_t>(0.306293, 22));
+ pbns.push_back(std::pair<double, size_t>(0.322361, 21));
+ pbns.push_back(std::pair<double, size_t>(0.323152, 22));
+ pbns.push_back(std::pair<double, size_t>(0.371021, 23));
+ pbns.push_back(std::pair<double, size_t>(0.372395, 24));
+ pbns.push_back(std::pair<double, size_t>(0.387744, 25));
+ pbns.push_back(std::pair<double, size_t>(0.435537, 26));
+ pbns.push_back(std::pair<double, size_t>(0.462911, 25));
+ pbns.push_back(std::pair<double, size_t>(0.483569, 26));
+ pbns.push_back(std::pair<double, size_t>(0.489209, 25));
+ pbns.push_back(std::pair<double, size_t>(0.517115, 24));
+ pbns.push_back(std::pair<double, size_t>(0.522197, 23));
+ pbns.push_back(std::pair<double, size_t>(0.532665, 22));
+ pbns.push_back(std::pair<double, size_t>(0.545262, 23));
+ pbns.push_back(std::pair<double, size_t>(0.587227, 22));
+ pbns.push_back(std::pair<double, size_t>(0.593036, 23));
+ pbns.push_back(std::pair<double, size_t>(0.602647, 24));
+ pbns.push_back(std::pair<double, size_t>(0.605044, 25));
+ pbns.push_back(std::pair<double, size_t>(0.621962, 24));
+ pbns.push_back(std::pair<double, size_t>(0.629449, 23));
+ pbns.push_back(std::pair<double, size_t>(0.636719, 22));
+ pbns.push_back(std::pair<double, size_t>(0.64957, 21));
+ pbns.push_back(std::pair<double, size_t>(0.650781, 22));
+ pbns.push_back(std::pair<double, size_t>(0.654951, 23));
+ pbns.push_back(std::pair<double, size_t>(0.683489, 24));
+ pbns.push_back(std::pair<double, size_t>(0.687172, 23));
+ pbns.push_back(std::pair<double, size_t>(0.69703, 22));
+ pbns.push_back(std::pair<double, size_t>(0.701174, 21));
+ pbns.push_back(std::pair<double, size_t>(0.717623, 22));
+ pbns.push_back(std::pair<double, size_t>(0.722023, 21));
+ pbns.push_back(std::pair<double, size_t>(0.722298, 20));
+ pbns.push_back(std::pair<double, size_t>(0.725347, 19));
+ pbns.push_back(std::pair<double, size_t>(0.73071, 18));
+ pbns.push_back(std::pair<double, size_t>(0.758355, 17));
+ pbns.push_back(std::pair<double, size_t>(0.770913, 18));
+ pbns.push_back(std::pair<double, size_t>(0.790833, 17));
+ pbns.push_back(std::pair<double, size_t>(0.821211, 16));
+ pbns.push_back(std::pair<double, size_t>(0.849305, 17));
+ pbns.push_back(std::pair<double, size_t>(0.853669, 16));
+ pbns.push_back(std::pair<double, size_t>(0.866659, 15));
+ pbns.push_back(std::pair<double, size_t>(0.872896, 16));
+ pbns.push_back(std::pair<double, size_t>(0.889597, 15));
+ pbns.push_back(std::pair<double, size_t>(0.900231, 14));
+ pbns.push_back(std::pair<double, size_t>(0.903847, 13));
+ pbns.push_back(std::pair<double, size_t>(0.906299, 12));
+ pbns.push_back(std::pair<double, size_t>(0.910852, 11));
+ pbns.push_back(std::pair<double, size_t>(0.93453, 10));
+ pbns.push_back(std::pair<double, size_t>(0.944757, 9));
+ pbns.push_back(std::pair<double, size_t>(0.947812, 8));
+ pbns.push_back(std::pair<double, size_t>(0.959154, 7));
+ pbns.push_back(std::pair<double, size_t>(0.975654, 6));
+ pbns.push_back(std::pair<double, size_t>(0.976719, 5));
+ pbns.push_back(std::pair<double, size_t>(0.977343, 4));
+ pbns.push_back(std::pair<double, size_t>(0.980129, 3));
+ pbns.push_back(std::pair<double, size_t>(0.987842, 2));
+ pbns.push_back(std::pair<double, size_t>(0.990127, 1));
+ pbns.push_back(std::pair<double, size_t>(0.994537, 0));
std::vector<std::pair<double, size_t> > pbns_new = p.compute_persistent_betti_numbers();
for (size_t i = 0; i != pbns.size(); ++i) {
- // cout << pbns_new[i].first << "," << pbns_new[i].second << std::endl;
- BOOST_CHECK(fabs(pbns[i].first - pbns_new[i].first) <= epsilon);
- BOOST_CHECK(fabs(pbns[i].second - pbns_new[i].second) <= epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(pbns[i].first, pbns_new[i].first, Gudhi::Persistence_representations::epsi);
+ BOOST_CHECK(pbns[i].second == pbns_new[i].second);
}
}
@@ -297,7 +287,6 @@ BOOST_AUTO_TEST_CASE(check_k_n_n) {
knn_template.push_back(0.786945);
for (size_t i = 0; i != knn.size(); ++i) {
- // cout << knn[i] << std::endl;
- BOOST_CHECK(fabs(knn[i] - knn_template[i]) <= 0.000005);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(knn[i], knn_template[i], Gudhi::Persistence_representations::epsi);
}
}
diff --git a/src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp b/src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp
index 7b70eee3..631e4d70 100644
--- a/src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp
+++ b/src/Persistence_representations/test/persistence_intervals_with_distances_test.cpp
@@ -24,8 +24,9 @@
#define BOOST_TEST_MODULE "Persistence_intervals_with_distances_test"
#include <boost/test/unit_test.hpp>
#include <gudhi/reader_utils.h>
-#include "gudhi/Persistence_intervals_with_distances.h"
-#include "gudhi/common_persistence_representations.h"
+#include <gudhi/Persistence_intervals_with_distances.h>
+#include <gudhi/common_persistence_representations.h>
+#include <gudhi/Unitary_tests_utils.h>
#include <iostream>
@@ -38,9 +39,7 @@ BOOST_AUTO_TEST_CASE(check_bottleneck_distances_computation) {
double dist = p.distance(q);
- // std::cout << "dist : " << dist << std::endl;
-
- BOOST_CHECK(almost_equal(dist, 0.389043));
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(dist, 0.389043, Gudhi::Persistence_representations::epsi);
}
BOOST_AUTO_TEST_CASE(check_default_parameters_in_distance) {
@@ -51,11 +50,7 @@ BOOST_AUTO_TEST_CASE(check_default_parameters_in_distance) {
double max_parameter_distance = p.distance(q, std::numeric_limits<double>::max());
double inf_parameter_distance = p.distance(q, std::numeric_limits<double>::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);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(default_parameter_distance, max_parameter_distance);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(inf_parameter_distance, max_parameter_distance);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(inf_parameter_distance, max_parameter_distance);
}
diff --git a/src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp b/src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp
index 6b1608fe..130ac8cc 100644
--- a/src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp
+++ b/src/Persistence_representations/test/persistence_lanscapes_on_grid_test.cpp
@@ -25,12 +25,15 @@
#include <boost/test/unit_test.hpp>
#include <gudhi/reader_utils.h>
#include <gudhi/Persistence_landscape_on_grid.h>
+#include <gudhi/Unitary_tests_utils.h>
#include <iostream>
using namespace Gudhi;
using namespace Gudhi::Persistence_representations;
+double epsilon = 0.0005;
+
BOOST_AUTO_TEST_CASE(check_construction_of_landscape) {
Persistence_landscape_on_grid l("data/file_with_diagram_1", 100, std::numeric_limits<unsigned short>::max());
l.print_to_file("landscape_from_file_with_diagram_1");
@@ -53,16 +56,14 @@ BOOST_AUTO_TEST_CASE(check_construction_of_landscape_using_only_ten_levels) {
std::vector<double> v2 = g.vectorize(level);
BOOST_CHECK(v1.size() == v2.size());
for (size_t i = 0; i != v1.size(); ++i) {
- BOOST_CHECK(v1[i] == v2[i]);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(v1[i], v2[i]);
}
}
}
BOOST_AUTO_TEST_CASE(check_computations_of_integrals) {
Persistence_landscape_on_grid p("data/file_with_diagram_1", 100, std::numeric_limits<unsigned short>::max());
- double integral = p.compute_integral_of_landscape();
- // cerr << "integral : " << integral << endl;getchar();
- BOOST_CHECK(fabs(integral - 27.343) <= 0.00005);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape(), 27.343, epsilon);
}
BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) {
@@ -92,9 +93,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly)
integrals_fir_different_levels.push_back(0.202633);
for (size_t level = 0; level != integrals_fir_different_levels.size(); ++level) {
- double integral = p.compute_integral_of_landscape(level);
- // cerr << integral << endl;
- BOOST_CHECK(fabs(integral - integrals_fir_different_levels[level]) <= 0.00005);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape(level), integrals_fir_different_levels[level],
+ epsilon);
}
}
@@ -109,9 +109,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_of_powers_of_landscape) {
integrals_fir_different_powers.push_back(0.23011);
for (size_t power = 0; power != 5; ++power) {
- double integral = p.compute_integral_of_landscape(power);
- // cerr << integral << endl;
- BOOST_CHECK(fabs(integral - integrals_fir_different_powers[power]) <= 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape(power), integrals_fir_different_powers[power],
+ epsilon);
}
}
@@ -145,8 +144,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_values_on_different_points) {
double x = 0.0012321;
double dx = 0.05212;
for (size_t i = 0; i != 10; ++i) {
- BOOST_CHECK(almost_equal(p.compute_value_at_a_given_point(0, x), results_level_0[i]));
- BOOST_CHECK(almost_equal(p.compute_value_at_a_given_point(10, x), results_level_10[i]));
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(0, x), results_level_0[i], epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(10, x), results_level_10[i], epsilon);
x += dx;
}
}
@@ -179,37 +178,27 @@ BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) {
Persistence_landscape_on_grid second("data/file_with_diagram_2", 0., 1., 100);
Persistence_landscape_on_grid sum = p + second;
- // cerr << p.compute_maximum() << endl;
- // cerr << p.compute_norm_of_landscape(1) << endl;
- // cerr << p.compute_norm_of_landscape(2) << endl;
- // cerr << p.compute_norm_of_landscape(3) << endl;
- // cerr << compute_distance_of_landscapes_on_grid(p,sum,1) << endl;
- // cerr << compute_distance_of_landscapes_on_grid(p,sum,2) << endl;
- // cerr << compute_distance_of_landscapes_on_grid(p,sum,std::numeric_limits<double>::max()) << endl;
-
- BOOST_CHECK(fabs(p.compute_maximum() - 0.46) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_norm_of_landscape(1) - 27.3373) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_norm_of_landscape(2) - 1.84143) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_norm_of_landscape(3) - 0.927067) <= 0.00001);
- BOOST_CHECK(fabs(compute_distance_of_landscapes_on_grid(p, sum, 1) - 16.8519) <= 0.00005);
- BOOST_CHECK(fabs(compute_distance_of_landscapes_on_grid(p, sum, 2) - 1.44542) <= 0.00001);
- BOOST_CHECK(fabs(compute_distance_of_landscapes_on_grid(p, sum, std::numeric_limits<double>::max()) - 0.45) <=
- 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_maximum(), 0.46, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(1), 27.3373, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(2), 1.84143, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(3), 0.927067, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes_on_grid(p, sum, 1), 16.8519, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes_on_grid(p, sum, 2), 1.44542, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes_on_grid(p, sum, std::numeric_limits<double>::max()),
+ 0.45, epsilon);
}
BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances) {
- std::vector<std::pair<double, double> > diag =
- read_persistence_intervals_in_dimension("data/file_with_diagram");
+ std::vector<std::pair<double, double> > diag = read_persistence_intervals_in_dimension("data/file_with_diagram");
Persistence_landscape_on_grid p(diag, 0., 1., 100);
- std::vector<std::pair<double, double> > diag1 =
- read_persistence_intervals_in_dimension("data/file_with_diagram_1");
+ std::vector<std::pair<double, double> > diag1 = read_persistence_intervals_in_dimension("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<double>::max());
double dist_infinity = p.distance(q, std::numeric_limits<double>::infinity());
- BOOST_CHECK(dist_numeric_limit_max == dist_infinity);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(dist_numeric_limit_max, dist_infinity);
}
BOOST_AUTO_TEST_CASE(check_computations_of_averages) {
@@ -226,16 +215,15 @@ BOOST_AUTO_TEST_CASE(check_computations_of_averages) {
BOOST_AUTO_TEST_CASE(check_computations_of_distances) {
Persistence_landscape_on_grid p("data/file_with_diagram", 0., 1., 10000);
Persistence_landscape_on_grid q("data/file_with_diagram_1", 0., 1., 10000);
- BOOST_CHECK(fabs(p.distance(q) - 25.5779) <= 0.00005);
- BOOST_CHECK(fabs(p.distance(q, 2) - 2.04891) <= 0.00001);
- BOOST_CHECK(fabs(p.distance(q, std::numeric_limits<double>::max()) - 0.359) <= 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q), 25.5779, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q, 2), 2.04891, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q, std::numeric_limits<double>::max()), 0.359, epsilon);
}
BOOST_AUTO_TEST_CASE(check_computations_of_scalar_product) {
Persistence_landscape_on_grid p("data/file_with_diagram", 0., 1., 10000);
Persistence_landscape_on_grid q("data/file_with_diagram_1", 0., 1., 10000);
- // std::cerr << p.compute_scalar_product( q ) << std::endl;
- BOOST_CHECK(almost_equal(p.compute_scalar_product(q), 0.754367));
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(q), 0.754367, epsilon);
}
// Below I am storing the code used to generate tests for that functionality.
diff --git a/src/Persistence_representations/test/persistence_lanscapes_test.cpp b/src/Persistence_representations/test/persistence_lanscapes_test.cpp
index 81adb6fa..e98ef894 100644
--- a/src/Persistence_representations/test/persistence_lanscapes_test.cpp
+++ b/src/Persistence_representations/test/persistence_lanscapes_test.cpp
@@ -25,6 +25,7 @@
#include <boost/test/unit_test.hpp>
#include <gudhi/reader_utils.h>
#include <gudhi/Persistence_landscape.h>
+#include <gudhi/Unitary_tests_utils.h>
#include <iostream>
#include <limits>
@@ -32,14 +33,14 @@
using namespace Gudhi;
using namespace Gudhi::Persistence_representations;
-double epsilon = 0.0000005;
+double epsilon = 0.0005;
-BOOST_AUTO_TEST_CASE(check_construction_of_landscape) {
+BOOST_AUTO_TEST_CASE(check_construction_of_landscape) {
std::vector<std::pair<double, double> > diag =
- read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
+ read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
Persistence_landscape p(diag);
- Persistence_landscape q;
- q.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram");
+ Persistence_landscape q;
+ q.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram");
BOOST_CHECK(p == q);
}
@@ -47,19 +48,15 @@ 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");
+ 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_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
Persistence_landscape p(diag);
- double integral = p.compute_integral_of_landscape();
- // cerr << integral << " " << 2.34992 << endl;
- BOOST_CHECK(fabs(integral - 2.34992) <= 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape(), 2.34992, epsilon);
}
BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) {
@@ -67,37 +64,37 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly)
read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
Persistence_landscape p(diag);
- std::vector<double> integrals_fir_different_levels;
- integrals_fir_different_levels.push_back(0.216432);
- integrals_fir_different_levels.push_back(0.204763);
- integrals_fir_different_levels.push_back(0.188793);
- integrals_fir_different_levels.push_back(0.178856);
- integrals_fir_different_levels.push_back(0.163142);
- integrals_fir_different_levels.push_back(0.155015);
- integrals_fir_different_levels.push_back(0.143046);
- integrals_fir_different_levels.push_back(0.133765);
- integrals_fir_different_levels.push_back(0.123531);
- integrals_fir_different_levels.push_back(0.117393);
- integrals_fir_different_levels.push_back(0.111269);
- integrals_fir_different_levels.push_back(0.104283);
- integrals_fir_different_levels.push_back(0.0941308);
- integrals_fir_different_levels.push_back(0.0811208);
- integrals_fir_different_levels.push_back(0.0679001);
- integrals_fir_different_levels.push_back(0.0580801);
- integrals_fir_different_levels.push_back(0.0489647);
- integrals_fir_different_levels.push_back(0.0407936);
- integrals_fir_different_levels.push_back(0.0342599);
- integrals_fir_different_levels.push_back(0.02896);
- integrals_fir_different_levels.push_back(0.0239881);
- integrals_fir_different_levels.push_back(0.0171792);
- integrals_fir_different_levels.push_back(0.0071511);
- integrals_fir_different_levels.push_back(0.00462067);
- integrals_fir_different_levels.push_back(0.00229033);
- integrals_fir_different_levels.push_back(0.000195296);
+ std::vector<double> integrals_for_different_levels;
+ integrals_for_different_levels.push_back(0.216432);
+ integrals_for_different_levels.push_back(0.204763);
+ integrals_for_different_levels.push_back(0.188793);
+ integrals_for_different_levels.push_back(0.178856);
+ integrals_for_different_levels.push_back(0.163142);
+ integrals_for_different_levels.push_back(0.155015);
+ integrals_for_different_levels.push_back(0.143046);
+ integrals_for_different_levels.push_back(0.133765);
+ integrals_for_different_levels.push_back(0.123531);
+ integrals_for_different_levels.push_back(0.117393);
+ integrals_for_different_levels.push_back(0.111269);
+ integrals_for_different_levels.push_back(0.104283);
+ integrals_for_different_levels.push_back(0.0941308);
+ integrals_for_different_levels.push_back(0.0811208);
+ integrals_for_different_levels.push_back(0.0679001);
+ integrals_for_different_levels.push_back(0.0580801);
+ integrals_for_different_levels.push_back(0.0489647);
+ integrals_for_different_levels.push_back(0.0407936);
+ integrals_for_different_levels.push_back(0.0342599);
+ integrals_for_different_levels.push_back(0.02896);
+ integrals_for_different_levels.push_back(0.0239881);
+ integrals_for_different_levels.push_back(0.0171792);
+ integrals_for_different_levels.push_back(0.0071511);
+ integrals_for_different_levels.push_back(0.00462067);
+ integrals_for_different_levels.push_back(0.00229033);
+ integrals_for_different_levels.push_back(0.000195296);
for (size_t level = 0; level != p.size(); ++level) {
- double integral = p.compute_integral_of_a_level_of_a_landscape(level);
- BOOST_CHECK(fabs(integral - integrals_fir_different_levels[level]) <= 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_a_level_of_a_landscape(level),
+ integrals_for_different_levels[level], epsilon);
}
}
@@ -106,16 +103,16 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_of_powers_of_landscape) {
read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
Persistence_landscape p(diag);
- std::vector<double> integrals_fir_different_powers;
- integrals_fir_different_powers.push_back(17.1692);
- integrals_fir_different_powers.push_back(2.34992);
- integrals_fir_different_powers.push_back(0.49857);
- integrals_fir_different_powers.push_back(0.126405);
- integrals_fir_different_powers.push_back(0.0355235);
+ std::vector<double> integrals_for_different_powers;
+ integrals_for_different_powers.push_back(17.1692);
+ integrals_for_different_powers.push_back(2.34992);
+ integrals_for_different_powers.push_back(0.49857);
+ integrals_for_different_powers.push_back(0.126405);
+ integrals_for_different_powers.push_back(0.0355235);
for (size_t power = 0; power != 5; ++power) {
- double integral = p.compute_integral_of_landscape((double)power);
- BOOST_CHECK(fabs(integral - integrals_fir_different_powers[power]) <= 0.00005);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_integral_of_landscape((double)power),
+ integrals_for_different_powers[power], epsilon);
}
}
@@ -124,18 +121,18 @@ BOOST_AUTO_TEST_CASE(check_computations_of_values_on_different_points) {
read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram");
Persistence_landscape p(diag);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(1, 0.0)) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(1, 0.1) - 0.0692324) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(1, 0.2) - 0.163369) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(1, 0.3) - 0.217115) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(2, 0.0)) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(2, 0.1) - 0.0633688) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(2, 0.2) - 0.122361) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(2, 0.3) - 0.195401) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(3, 0.0)) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(3, 0.1) - 0.0455386) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(3, 0.2) - 0.0954012) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_value_at_a_given_point(3, 0.3) - 0.185282) <= 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(1, 0.0), 0., epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(1, 0.1), 0.0692324, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(1, 0.2), 0.163369, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(1, 0.3), 0.217115, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(2, 0.0), 0., epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(2, 0.1), 0.0633688, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(2, 0.2), 0.122361, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(2, 0.3), 0.195401, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(3, 0.0), 0., epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(3, 0.1), 0.0455386, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(3, 0.2), 0.0954012, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_value_at_a_given_point(3, 0.3), 0.185282, epsilon);
}
BOOST_AUTO_TEST_CASE(check_computations_sum_differences_and_multiplications) {
@@ -171,13 +168,14 @@ BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) {
second.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram_1");
Persistence_landscape sum = p + second;
- BOOST_CHECK(fabs(p.compute_maximum() - 0.431313) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_norm_of_landscape(1) - 2.34992) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_norm_of_landscape(2) - 0.706095) <= 0.00001);
- BOOST_CHECK(fabs(p.compute_norm_of_landscape(3) - 0.501867) <= 0.00001);
- BOOST_CHECK(fabs(compute_distance_of_landscapes(p, sum, 1) - 27.9323) <= 0.00005);
- BOOST_CHECK(fabs(compute_distance_of_landscapes(p, sum, 2) - 2.35199) <= 0.00001);
- BOOST_CHECK(fabs(compute_distance_of_landscapes(p, sum, std::numeric_limits<double>::max()) - 0.464478) <= 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_maximum(), 0.431313, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(1), 2.34992, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(2), 0.706095, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_norm_of_landscape(3), 0.501867, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes(p, sum, 1), 27.9323, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes(p, sum, 2), 2.35199, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(compute_distance_of_landscapes(p, sum, std::numeric_limits<double>::max()), 0.464478,
+ epsilon);
}
BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances) {
@@ -192,7 +190,7 @@ BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances) {
double dist_numeric_limit_max = p.distance(q, std::numeric_limits<double>::max());
double dist_infinity = p.distance(q, std::numeric_limits<double>::infinity());
- BOOST_CHECK(dist_numeric_limit_max == dist_infinity);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(dist_numeric_limit_max, dist_infinity);
}
BOOST_AUTO_TEST_CASE(check_computations_of_averages) {
@@ -217,13 +215,9 @@ BOOST_AUTO_TEST_CASE(check_computations_of_distances) {
std::vector<std::pair<double, double> > diag2 =
read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1");
Persistence_landscape q(diag2);
- std::cout << "p.distance(q) = " << p.distance(q) << std::endl;
- BOOST_CHECK(fabs(p.distance(q) - 25.5824) <= 0.00005);
- std::cout << "p.distance(q, 2) = " << p.distance(q, 2) << std::endl;
- BOOST_CHECK(fabs(p.distance(q, 2) - 2.1264) <= 0.0001);
- std::cout << "p.distance(q, std::numeric_limits<double>::max()) = " <<
- p.distance(q, std::numeric_limits<double>::max()) << std::endl;
- BOOST_CHECK(fabs(p.distance(q, std::numeric_limits<double>::max()) - 0.359068) <= 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q), 25.5824, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q, 2), 2.1264, epsilon);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.distance(q, std::numeric_limits<double>::max()), 0.359068, epsilon);
}
BOOST_AUTO_TEST_CASE(check_computations_of_scalar_product) {
@@ -233,33 +227,9 @@ BOOST_AUTO_TEST_CASE(check_computations_of_scalar_product) {
std::vector<std::pair<double, double> > diag2 =
read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1");
Persistence_landscape q(diag2);
- BOOST_CHECK(fabs(p.compute_scalar_product(q) - 0.754498) <= 0.00001);
+ GUDHI_TEST_FLOAT_EQUALITY_CHECK(p.compute_scalar_product(q), 0.754498, epsilon);
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
// Below I am storing the code used to generate tests for that functionality.
/*
if ( argc != 2 )
diff --git a/src/Persistence_representations/test/read_persistence_from_file_test.cpp b/src/Persistence_representations/test/read_persistence_from_file_test.cpp
index 76d7cdb0..276b92ab 100644
--- a/src/Persistence_representations/test/read_persistence_from_file_test.cpp
+++ b/src/Persistence_representations/test/read_persistence_from_file_test.cpp
@@ -21,7 +21,7 @@
*/
#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE "Persistence_representations"
+#define BOOST_TEST_MODULE "read_persistence_from_file_test"
#include <boost/test/unit_test.hpp>
#include <gudhi/read_persistence_from_file.h>
@@ -30,8 +30,6 @@
using namespace Gudhi;
using namespace Gudhi::Persistence_representations;
-
-
BOOST_AUTO_TEST_CASE(test_read_file_with_four_elements_per_line) {
std::vector<std::pair<double, double> > what_we_should_get;
what_we_should_get.push_back(std::make_pair(0, 2));
@@ -39,7 +37,7 @@ BOOST_AUTO_TEST_CASE(test_read_file_with_four_elements_per_line) {
what_we_should_get.push_back(std::make_pair(10, 90));
what_we_should_get.push_back(std::make_pair(4, 4));
std::vector<std::pair<double, double> > what_we_get = read_persistence_intervals_in_one_dimension_from_file(
- "data/persistence_file_with_four_entries_per_line", 1, 1000);
+ "data/persistence_file_with_four_entries_per_line", 1, 1000);
// for ( size_t i = 0 ; i != what_we_get.size() ; ++i )
//{
@@ -76,7 +74,6 @@ BOOST_AUTO_TEST_CASE(test_read_file_with_three_elements_per_line) {
}
}
-
BOOST_AUTO_TEST_CASE(test_read_file_with_two_elements_per_line) {
std::vector<std::pair<double, double> > what_we_should_get;
what_we_should_get.push_back(std::make_pair(4, 10));
@@ -84,12 +81,11 @@ BOOST_AUTO_TEST_CASE(test_read_file_with_two_elements_per_line) {
what_we_should_get.push_back(std::make_pair(0, 1));
what_we_should_get.push_back(std::make_pair(1, 4));
- std::vector<std::pair<double, double> > what_we_get =
- read_persistence_intervals_in_one_dimension_from_file("data/persistence_file_with_two_entries_per_line", -1, 9999);
+ std::vector<std::pair<double, double> > what_we_get = read_persistence_intervals_in_one_dimension_from_file(
+ "data/persistence_file_with_two_entries_per_line", -1, 9999);
BOOST_CHECK(what_we_should_get.size() == what_we_get.size());
for (size_t i = 0; i != what_we_get.size(); ++i) {
BOOST_CHECK(what_we_should_get[i] == what_we_get[i]);
}
}
-
diff --git a/src/Persistence_representations/test/vector_representation_test.cpp b/src/Persistence_representations/test/vector_representation_test.cpp
index 3f3e2abe..c545dce7 100644
--- a/src/Persistence_representations/test/vector_representation_test.cpp
+++ b/src/Persistence_representations/test/vector_representation_test.cpp
@@ -26,7 +26,7 @@
#include <iostream>
#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE "Persistence_representations"
+#define BOOST_TEST_MODULE "vector_representation_test"
#include <boost/test/unit_test.hpp>
#include <gudhi/reader_utils.h>
#include <vector>
@@ -295,12 +295,10 @@ BOOST_AUTO_TEST_CASE(check_distance_computations) {
}
BOOST_AUTO_TEST_CASE(check_default_parameters_of_distances) {
- std::vector<std::pair<double, double> > diag =
- read_persistence_intervals_in_dimension("data/file_with_diagram");
+ std::vector<std::pair<double, double> > diag = read_persistence_intervals_in_dimension("data/file_with_diagram");
Vector_distances_in_diagram<Euclidean_distance> p(diag, 100);
- std::vector<std::pair<double, double> > diag1 =
- read_persistence_intervals_in_dimension("data/file_with_diagram_1");
+ std::vector<std::pair<double, double> > diag1 = read_persistence_intervals_in_dimension("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<double>::max());
diff --git a/src/Persistence_representations/utilities/CMakeLists.txt b/src/Persistence_representations/utilities/CMakeLists.txt
index 66524666..fc51b1d6 100644
--- a/src/Persistence_representations/utilities/CMakeLists.txt
+++ b/src/Persistence_representations/utilities/CMakeLists.txt
@@ -1,6 +1,59 @@
+# Copy files, otherwise result files are created in sources
+file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/")
+file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/")
+
+function(add_persistence_representation_creation_utility creation_utility)
+ add_executable ( ${creation_utility} ${creation_utility}.cpp )
+
+ # as the function is called in a subdirectory level, need to '../' to find persistence files
+ # ARGN will add all the other arguments (except creation_utility) sent to the CMake functions
+ add_test(NAME Persistence_representation_utilities_${creation_utility} COMMAND $<TARGET_FILE:${creation_utility}>
+ ${ARGN} "${CMAKE_CURRENT_BINARY_DIR}/../first.pers"
+ "${CMAKE_CURRENT_BINARY_DIR}/../second.pers")
+
+ install(TARGETS ${creation_utility} DESTINATION bin)
+endfunction(add_persistence_representation_creation_utility)
+
+function(add_persistence_representation_plot_utility plot_utility tool_extension)
+ add_executable ( ${plot_utility} ${plot_utility}.cpp )
+
+ # as the function is called in a subdirectory level, need to '../' to find persistence heat maps files
+ add_test(NAME Persistence_representation_utilities_${plot_utility}_first COMMAND $<TARGET_FILE:${plot_utility}>
+ "${CMAKE_CURRENT_BINARY_DIR}/../first.pers${tool_extension}")
+ #add_test(NAME Persistence_representation_utilities_${plot_utility}_second COMMAND $<TARGET_FILE:${plot_utility}>
+ # "${CMAKE_CURRENT_BINARY_DIR}/../second.pers${tool_extension}")
+ if(GNUPLOT_PATH)
+ add_test(NAME Persistence_representation_utilities_${plot_utility}_first_gnuplot COMMAND ${GNUPLOT_PATH}
+ "-e" "load '${CMAKE_CURRENT_BINARY_DIR}/../first.pers${tool_extension}_GnuplotScript'")
+ #add_test(NAME Persistence_representation_utilities_${plot_utility}_second_gnuplot COMMAND ${GNUPLOT_PATH}
+ # "-e" "load '${CMAKE_CURRENT_BINARY_DIR}/../second.pers${tool_extension}_GnuplotScript'")
+ endif()
+
+ install(TARGETS ${plot_utility} DESTINATION bin)
+endfunction(add_persistence_representation_plot_utility)
+
+function(add_persistence_representation_function_utility function_utility tool_extension)
+ add_executable ( ${function_utility} ${function_utility}.cpp )
+
+ # ARGV2 is an optional argument
+ if (${ARGV2})
+ # as the function is called in a subdirectory level, need to '../' to find persistence heat maps files
+ add_test(NAME Persistence_representation_utilities_${function_utility} COMMAND $<TARGET_FILE:${function_utility}>
+ "${ARGV2}"
+ "${CMAKE_CURRENT_BINARY_DIR}/../first.pers${tool_extension}"
+ "${CMAKE_CURRENT_BINARY_DIR}/../second.pers${tool_extension}")
+ else()
+ # as the function is called in a subdirectory level, need to '../' to find persistence heat maps files
+ add_test(NAME Persistence_representation_utilities_${function_utility} COMMAND $<TARGET_FILE:${function_utility}>
+ "${CMAKE_CURRENT_BINARY_DIR}/../first.pers${tool_extension}"
+ "${CMAKE_CURRENT_BINARY_DIR}/../second.pers${tool_extension}")
+ endif()
+
+ install(TARGETS ${function_utility} DESTINATION bin)
+endfunction(add_persistence_representation_function_utility)
+
add_subdirectory(persistence_heat_maps)
add_subdirectory(persistence_intervals)
add_subdirectory(persistence_landscapes)
add_subdirectory(persistence_landscapes_on_grid)
add_subdirectory(persistence_vectors)
-
diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt
index 0dd63852..386e9fa5 100644
--- a/src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt
+++ b/src/Persistence_representations/utilities/persistence_heat_maps/CMakeLists.txt
@@ -1,63 +1,15 @@
cmake_minimum_required(VERSION 2.6)
project(Persistence_representations_heat_maps_utilities)
-file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/")
-
-add_executable ( create_persistence_heat_maps create_persistence_heat_maps.cpp )
-target_link_libraries(create_persistence_heat_maps ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME create_persistence_heat_maps COMMAND $<TARGET_FILE:create_persistence_heat_maps>
- "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-
-add_executable ( create_pssk create_pssk.cpp )
-target_link_libraries(create_pssk ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME create_pssk COMMAND $<TARGET_FILE:create_pssk>
- "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( create_p_h_m_weighted_by_distance_from_diagonal create_p_h_m_weighted_by_distance_from_diagonal.cpp )
-target_link_libraries(create_p_h_m_weighted_by_distance_from_diagonal ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME create_p_h_m_weighted_by_distance_from_diagonal COMMAND $<TARGET_FILE:create_p_h_m_weighted_by_distance_from_diagonal>
- "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( create_p_h_m_weighted_by_squared_diag_distance create_p_h_m_weighted_by_squared_diag_distance.cpp )
-target_link_libraries(create_p_h_m_weighted_by_squared_diag_distance ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME create_p_h_m_weighted_by_squared_diag_distance COMMAND $<TARGET_FILE:create_p_h_m_weighted_by_squared_diag_distance>
- "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( create_p_h_m_weighted_by_arctan_of_their_persistence create_p_h_m_weighted_by_arctan_of_their_persistence.cpp )
-target_link_libraries(create_p_h_m_weighted_by_arctan_of_their_persistence ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME create_p_h_m_weighted_by_arctan_of_their_persistence COMMAND $<TARGET_FILE:create_p_h_m_weighted_by_arctan_of_their_persistence>
- "10" "-1" "-1" "4" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( average_persistence_heat_maps average_persistence_heat_maps.cpp )
-target_link_libraries(average_persistence_heat_maps ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME average_persistence_heat_maps COMMAND $<TARGET_FILE:average_persistence_heat_maps>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( plot_persistence_heat_map plot_persistence_heat_map.cpp )
-target_link_libraries(plot_persistence_heat_map ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME plot_persistence_heat_map COMMAND $<TARGET_FILE:plot_persistence_heat_map>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( compute_distance_of_persistence_heat_maps compute_distance_of_persistence_heat_maps.cpp )
-target_link_libraries(compute_distance_of_persistence_heat_maps ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME compute_distance_of_persistence_heat_maps COMMAND $<TARGET_FILE:compute_distance_of_persistence_heat_maps>
- "1"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( compute_scalar_product_of_persistence_heat_maps compute_scalar_product_of_persistence_heat_maps.cpp )
-target_link_libraries(compute_scalar_product_of_persistence_heat_maps ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME compute_scalar_product_of_persistence_heat_maps COMMAND $<TARGET_FILE:compute_scalar_product_of_persistence_heat_maps>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
+add_persistence_representation_creation_utility(create_pssk "10" "-1" "-1" "4" "-1")
+add_persistence_representation_creation_utility(create_p_h_m_weighted_by_arctan_of_their_persistence "10" "-1" "-1" "4" "-1")
+add_persistence_representation_creation_utility(create_p_h_m_weighted_by_distance_from_diagonal "10" "-1" "-1" "4" "-1")
+add_persistence_representation_creation_utility(create_p_h_m_weighted_by_squared_diag_distance "10" "-1" "-1" "4" "-1")
+# Need to set grid min and max for further average, distance and scalar_product
+add_persistence_representation_creation_utility(create_persistence_heat_maps "10" "0" "35" "10" "-1")
+
+add_persistence_representation_plot_utility(plot_persistence_heat_map ".mps")
+
+add_persistence_representation_function_utility(average_persistence_heat_maps ".mps")
+add_persistence_representation_function_utility(compute_distance_of_persistence_heat_maps ".mps" "1")
+add_persistence_representation_function_utility(compute_scalar_product_of_persistence_heat_maps ".mps")
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 4e81375a..6739e0b6 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
@@ -29,21 +29,20 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s
using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>;
int main(int argc, char** argv) {
- std::cout << "This program computes average persistence landscape of persistence landscapes created based on "
- "persistence diagrams provided as an input. Please call this program with the names of files with "
- "persistence diagrams \n";
- std::vector<const char*> filenames;
+ std::cout << "This program computes average of persistence heat maps stored in files (the files needs to be "
+ << "created beforehand).\n"
+ << "The parameters of this programs are names of files with persistence heat maps.\n";
- if (argc == 1) {
- std::cout << "No input files given, the program will now terminate \n";
+ if (argc < 3) {
+ std::cout << "Wrong number of parameters, the program will now terminate \n";
return 1;
}
+ std::vector<const char*> filenames;
for (int i = 1; i < argc; ++i) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence landscapes...\n";
std::vector<Persistence_heat_maps*> maps;
for (size_t i = 0; i != filenames.size(); ++i) {
Persistence_heat_maps* l = new Persistence_heat_maps;
@@ -53,13 +52,12 @@ int main(int argc, char** argv) {
Persistence_heat_maps av;
av.compute_average(maps);
-
av.print_to_file("average.mps");
for (size_t i = 0; i != filenames.size(); ++i) {
delete maps[i];
}
- std::cout << "Done \n";
+ std::cout << "Average can be found in 'average.mps' file\n";
return 0;
}
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 befb0837..ed8278a2 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
@@ -31,11 +31,11 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s
using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>;
int main(int argc, char** argv) {
- std::cout << "This program computes 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 program are names of files with persistence heat maps.\n";
+ std::cout << "This program computes distance of persistence heat maps stored in files (the files needs to be "
+ << "created beforehand).\n"
+ << "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"
+ << "The remaining parameters of this program are names of files with persistence heat maps.\n";
if (argc < 3) {
std::cout << "Wrong number of parameters, the program will now terminate \n";
@@ -78,7 +78,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("distance");
+ out.open("distance.mps");
for (size_t i = 0; i != distance.size(); ++i) {
for (size_t j = 0; j != distance.size(); ++j) {
std::cout << distance[i][j] << " ";
@@ -89,5 +89,6 @@ int main(int argc, char** argv) {
}
out.close();
+ std::cout << "Distance can be found in 'distance.mps' file\n";
return 0;
}
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 c684a336..63626853 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
@@ -30,9 +30,14 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s
using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>;
int main(int argc, char** argv) {
- std::cout << "This program computes scalar product of persistence landscapes stored in a file (the file needs to be "
- "created beforehand). \n";
- std::cout << "The parameters of this programs are names of files with persistence landscapes.\n";
+ std::cout << "This program computes scalar product of persistence heat maps stored in a file (the file needs to be "
+ << "created beforehand). \n"
+ << "The parameters of this programs are names of files with persistence heat maps.\n";
+
+ if (argc < 3) {
+ std::cout << "Wrong number of parameters, the program will now terminate \n";
+ return 1;
+ }
std::vector<const char*> filenames;
for (int i = 1; i < argc; ++i) {
@@ -64,7 +69,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("scalar_product");
+ out.open("scalar_product.mps");
for (size_t i = 0; i != scalar_product.size(); ++i) {
for (size_t j = 0; j != scalar_product.size(); ++j) {
std::cout << scalar_product[i][j] << " ";
@@ -75,5 +80,6 @@ int main(int argc, char** argv) {
}
out.close();
+ std::cout << "Distance can be found in 'scalar_product.mps' file\n";
return 0;
}
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 2bf185a3..b4a1daa5 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
@@ -29,25 +29,25 @@
using arc_tan_of_persistence_of_point = Gudhi::Persistence_representations::arc_tan_of_persistence_of_point;
using Persistence_heat_maps =
- Gudhi::Persistence_representations::Persistence_heat_maps<arc_tan_of_persistence_of_point>;
+ Gudhi::Persistence_representations::Persistence_heat_maps<arc_tan_of_persistence_of_point>;
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 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::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the "
- "persistence heat maps.";
- std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the "
- "procedure please provide the dimension of persistence you want to use.";
- std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1."
- << std::endl;
- std::cout << "The remaining parameters are the names of files with persistence diagrams. \n";
+ std::cout << "This program creates persistence heat map files (*.mps) of persistence diagrams files (*.pers) "
+ << "provided as an input.The Gaussian kernels are weighted by the arc tangential of their persistence.\n"
+ << "The first parameter of a program is an integer, a size of a grid.\n"
+ << "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"
+ << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number "
+ << "of pixels.\n"
+ << "The fifth parameter of this program is a dimension of persistence that will be used in creation of "
+ << "the persistence heat maps."
+ << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the "
+ << "procedure please provide the dimension of persistence you want to use."
+ << "If in your files there are only birth-death pairs of the same dimension, set the fifth parameter to "
+ << "-1.\n"
+ << "The remaining parameters are the names of files with persistence diagrams. \n";
- if (argc < 5) {
+ if (argc < 7) {
std::cout << "Wrong parameter list, the program will now terminate \n";
return 1;
}
@@ -68,9 +68,7 @@ int main(int argc, char** argv) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence heat maps...\n";
std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1);
-
for (size_t i = 0; i != filenames.size(); ++i) {
std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl;
Persistence_heat_maps l(filenames[i], filter, false, size_of_grid, min_, max_, dimension);
@@ -79,6 +77,5 @@ int main(int argc, char** argv) {
ss << filenames[i] << ".mps";
l.print_to_file(ss.str().c_str());
}
- std::cout << "Done \n";
return 0;
}
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 ec9477f1..c50f9ddb 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
@@ -28,26 +28,26 @@
#include <vector>
using distance_from_diagonal_scaling = Gudhi::Persistence_representations::distance_from_diagonal_scaling;
-using Persistence_heat_maps =
- Gudhi::Persistence_representations::Persistence_heat_maps<distance_from_diagonal_scaling>;
+using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<distance_from_diagonal_scaling>;
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::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the "
- "persistence heat maps.";
- std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the "
- "procedure please provide the dimension of persistence you want to use.";
- std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1."
- << std::endl;
- std::cout << "The remaining parameters are the names of files with persistence diagrams. \n";
+ std::cout << "This program creates persistence heat map files (*.mps) of persistence diagrams files (*.pers) "
+ << "provided as an input.The Gaussian kernels are weighted by the distance of a center from the "
+ << "diagonal.\n"
+ << "The first parameter of a program is an integer, a size of a grid.\n"
+ << "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"
+ << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number "
+ << "of pixels.\n"
+ << "The fifth parameter of this program is a dimension of persistence that will be used in creation of "
+ << "the persistence heat maps."
+ << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the "
+ << "procedure please provide the dimension of persistence you want to use."
+ << "If in your files there are only birth-death pairs of the same dimension, set the fifth parameter to "
+ << "-1.\n"
+ << "The remaining parameters are the names of files with persistence diagrams. \n";
- if (argc < 5) {
+ if (argc < 7) {
std::cout << "Wrong parameter list, the program will now terminate \n";
return 1;
}
@@ -68,9 +68,7 @@ int main(int argc, char** argv) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence heat maps...\n";
std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1);
-
for (size_t i = 0; i != filenames.size(); ++i) {
std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl;
Persistence_heat_maps l(filenames[i], filter, false, size_of_grid, min_, max_, dimension);
@@ -79,6 +77,5 @@ int main(int argc, char** argv) {
ss << filenames[i] << ".mps";
l.print_to_file(ss.str().c_str());
}
- std::cout << "Done \n";
return 0;
}
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 ffec8b3d..59ff3c24 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
@@ -28,27 +28,28 @@
#include <vector>
using squared_distance_from_diagonal_scaling =
- Gudhi::Persistence_representations::squared_distance_from_diagonal_scaling;
+ Gudhi::Persistence_representations::squared_distance_from_diagonal_scaling;
using Persistence_heat_maps =
- Gudhi::Persistence_representations::Persistence_heat_maps<squared_distance_from_diagonal_scaling>;
+ Gudhi::Persistence_representations::Persistence_heat_maps<squared_distance_from_diagonal_scaling>;
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::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the "
- "persistence heat maps.";
- std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the "
- "procedure please provide the dimension of persistence you want to use.";
- std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1."
- << std::endl;
- std::cout << "The remaining parameters are the names of files with persistence diagrams. \n";
+ std::cout << "This program creates persistence heat map files (*.mps) of persistence diagrams files (*.pers) "
+ << "provided as an input.The Gaussian kernels are weighted by the square of distance of a center from the "
+ << "diagonal.\n"
+ << "The first parameter of a program is an integer, a size of a grid.\n"
+ << "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"
+ << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number "
+ << "of pixels.\n"
+ << "The fifth parameter of this program is a dimension of persistence that will be used in creation of "
+ << "the persistence heat maps."
+ << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the "
+ << "procedure please provide the dimension of persistence you want to use."
+ << "If in your files there are only birth-death pairs of the same dimension, set the fifth parameter to "
+ << "-1.\n"
+ << "The remaining parameters are the names of files with persistence diagrams. \n";
- if (argc < 5) {
+ if (argc < 7) {
std::cout << "Wrong parameter list, the program will now terminate \n";
return 1;
}
@@ -69,9 +70,7 @@ int main(int argc, char** argv) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence heat maps...\n";
std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1);
-
for (size_t i = 0; i != filenames.size(); ++i) {
std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl;
Persistence_heat_maps l(filenames[i], filter, false, size_of_grid, min_, max_, dimension);
@@ -80,6 +79,5 @@ int main(int argc, char** argv) {
ss << filenames[i] << ".mps";
l.print_to_file(ss.str().c_str());
}
- std::cout << "Done \n";
return 0;
}
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 db2f0008..25cd1067 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
@@ -31,21 +31,22 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s
using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>;
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::cout << "This program creates persistence heat map files (*.mps) of persistence diagrams files (*.pers) "
+ << "provided as an input.\n"
+ << "The first parameter of a program is an integer, a size of a grid.\n"
+ << "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"
+ << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number "
+ << "of pixels.\n"
+ << "The fifth parameter of this program is a dimension of persistence that will be used in creation of "
+ << "the persistence heat maps."
+ << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the "
+ << "procedure please provide the dimension of persistence you want to use."
+ << "If in your files there are only birth-death pairs of the same dimension, set the fifth parameter to "
+ << "-1.\n"
+ << "The remaining parameters are the names of files with persistence diagrams. \n";
- std::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the "
- "persistence heat maps.";
- std::cout << "If your input file contains persistence pairs of various dimension, as a fifth parameter of the "
- "procedure please provide the dimension of persistence you want to use.";
- std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1."
- << std::endl;
- std::cout << "The remaining parameters are the names of files with persistence diagrams. \n";
- if (argc < 5) {
+ if (argc < 7) {
std::cout << "Wrong parameter list, the program will now terminate \n";
return 1;
}
@@ -64,17 +65,14 @@ int main(int argc, char** argv) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence heat maps...\n";
std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1);
-
for (size_t i = 0; i != filenames.size(); ++i) {
- std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl;
+ std::cout << "Creating a heat map based on file : " << filenames[i] << std::endl;
Persistence_heat_maps l(filenames[i], filter, false, size_of_grid, min_, max_, dimension);
std::stringstream ss;
ss << filenames[i] << ".mps";
l.print_to_file(ss.str().c_str());
}
- std::cout << "Done \n";
return 0;
}
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 6aefbb00..97ddb8f0 100644
--- a/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp
+++ b/src/Persistence_representations/utilities/persistence_heat_maps/create_pssk.cpp
@@ -30,21 +30,22 @@
using PSSK = Gudhi::Persistence_representations::PSSK;
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::cout << "The fifth parameter of this program is a dimension of persistence that will be used in creation of the "
- "persistence heat maps.";
- std::cout << "If our input files contain persistence pairs of various dimension, as a fifth parameter of the "
- "procedure please provide the dimension of persistence you want to use.";
- std::cout << "If in your file there are only birth-death pairs of the same dimension, set the first parameter to -1."
- << std::endl;
- std::cout << "The remaining parameters are the names of files with persistence diagrams. \n";
+ std::cout << "This program creates PSSK files (*.pssk) of persistence diagrams files (*.pers) "
+ << "provided as an input.\n"
+ << "The first parameter of a program is an integer, a size of a grid.\n"
+ << "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"
+ << "The fourth parameter is an integer, the standard deviation of a Gaussian kernel expressed in a number "
+ << "of pixels.\n"
+ << "The fifth parameter of this program is a dimension of persistence that will be used in creation of "
+ << "the PSSK."
+ << "If your input files contains persistence pairs of various dimension, as a fifth parameter of the "
+ << "procedure please provide the dimension of persistence you want to use."
+ << "If in your files there are only birth-death pairs of the same dimension, set the first parameter to "
+ << "-1.\n"
+ << "The remaining parameters are the names of files with persistence diagrams. \n";
- if (argc < 5) {
+ if (argc < 7) {
std::cout << "Wrong parameter list, the program will now terminate \n";
return 1;
}
@@ -65,17 +66,14 @@ int main(int argc, char** argv) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence heat maps...\n";
std::vector<std::vector<double> > filter = Gudhi::Persistence_representations::create_Gaussian_filter(stdiv, 1);
-
for (size_t i = 0; i != filenames.size(); ++i) {
- std::cout << "Creating a heat map based on a file : " << filenames[i] << std::endl;
+ std::cout << "Creating a PSSK based on a file : " << filenames[i] << std::endl;
PSSK l(filenames[i], filter, size_of_grid, min_, max_, dimension);
std::stringstream ss;
ss << filenames[i] << ".pssk";
l.print_to_file(ss.str().c_str());
}
- std::cout << "Done \n";
return 0;
}
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 a7c9f2d8..63711d83 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
@@ -29,8 +29,12 @@ using constant_scaling_function = Gudhi::Persistence_representations::constant_s
using Persistence_heat_maps = Gudhi::Persistence_representations::Persistence_heat_maps<constant_scaling_function>;
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 landscape file \n";
+ std::cout << "This program creates a gnuplot script from a persistence heat maps stored in a file (the file needs "
+ << "to be created beforehand). Please call the code with the name of a single heat maps file \n";
+ if (argc != 2) {
+ std::cout << "Wrong parameter list, the program will now terminate \n";
+ return 1;
+ }
Persistence_heat_maps l;
l.load_from_file(argv[1]);
l.plot(argv[1]);
diff --git a/src/Persistence_representations/utilities/persistence_heat_maps/simple_diagram.txt.mps b/src/Persistence_representations/utilities/persistence_heat_maps/simple_diagram.txt.mps
deleted file mode 100644
index b7643887..00000000
--- a/src/Persistence_representations/utilities/persistence_heat_maps/simple_diagram.txt.mps
+++ /dev/null
@@ -1,11 +0,0 @@
-0.93 8.0707
-0.0492104 0.03889 0.0190956 0.00603584 0.00131569 0.000120934 2.10152e-05 0 0 0
-0.0650745 0.0539306 0.0296488 0.011745 0.00357642 0.000695928 0.000120934 0 0 0
-0.0572665 0.0559446 0.0409942 0.0230905 0.00937173 0.00242903 0.000422102 0 0 0
-0.0409942 0.0559656 0.0573874 0.0408475 0.0192639 0.00628964 0.00178718 0.000422102 0.000120934 2.10152e-05
-0.0296488 0.0540515 0.0657704 0.0519133 0.0283092 0.0132056 0.00628964 0.00242903 0.000695928 0.000120934
-0.0190956 0.0393121 0.0516395 0.0465955 0.0359385 0.0283092 0.0192639 0.00937173 0.00357642 0.00131569
-0.00847814 0.0188418 0.0281882 0.0358964 0.0465955 0.0519133 0.0408475 0.0230905 0.011745 0.00603584
-0.00242903 0.00628964 0.0132056 0.0281882 0.0516395 0.0657704 0.0573874 0.0409942 0.0296488 0.0190956
-0.000422102 0.00178718 0.00628964 0.0188418 0.0393121 0.0540515 0.0559656 0.0559446 0.0539306 0.03889
-0 0.000422102 0.00242903 0.00847814 0.0190956 0.0296488 0.0409942 0.0572665 0.0650745 0.0492104
diff --git a/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt
index 105b7efb..875ff45e 100644
--- a/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt
+++ b/src/Persistence_representations/utilities/persistence_intervals/CMakeLists.txt
@@ -1,46 +1,38 @@
cmake_minimum_required(VERSION 2.6)
project(Persistence_representations_intervals_utilities)
-file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/")
-add_executable ( plot_persistence_intervals plot_persistence_intervals.cpp )
-target_link_libraries( plot_persistence_intervals ${Boost_SYSTEM_LIBRARY})
+add_executable ( plot_histogram_of_intervals_lengths plot_histogram_of_intervals_lengths.cpp )
-add_test(NAME plot_persistence_intervals COMMAND $<TARGET_FILE:plot_persistence_intervals>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
+add_test(NAME plot_histogram_of_intervals_lengths COMMAND $<TARGET_FILE:plot_histogram_of_intervals_lengths>
+ "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" "-1")
-add_executable ( compute_birth_death_range_in_persistence_diagram compute_birth_death_range_in_persistence_diagram.cpp )
-target_link_libraries( compute_birth_death_range_in_persistence_diagram ${Boost_SYSTEM_LIBRARY})
+install(TARGETS plot_histogram_of_intervals_lengths DESTINATION bin)
-add_test(NAME compute_birth_death_range_in_persistence_diagram COMMAND $<TARGET_FILE:compute_birth_death_range_in_persistence_diagram>
- "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
+add_persistence_representation_plot_utility(plot_persistence_intervals "")
+add_persistence_representation_plot_utility(plot_persistence_Betti_numbers "")
-add_executable ( compute_number_of_dominant_intervals compute_number_of_dominant_intervals.cpp )
-target_link_libraries( compute_number_of_dominant_intervals ${Boost_SYSTEM_LIBRARY})
+add_persistence_representation_creation_utility(compute_birth_death_range_in_persistence_diagram "-1")
-add_test(NAME compute_number_of_dominant_intervals COMMAND $<TARGET_FILE:compute_number_of_dominant_intervals>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" "-1" "2")
-add_executable ( plot_histogram_of_intervals_lengths plot_histogram_of_intervals_lengths.cpp )
-target_link_libraries( plot_histogram_of_intervals_lengths ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME plot_histogram_of_intervals_lengths COMMAND $<TARGET_FILE:plot_histogram_of_intervals_lengths>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt" "2")
+add_executable ( compute_number_of_dominant_intervals compute_number_of_dominant_intervals.cpp )
+add_test(NAME Persistence_representation_utilities_compute_number_of_dominant_intervals
+ COMMAND $<TARGET_FILE:compute_number_of_dominant_intervals>
+ "${CMAKE_CURRENT_BINARY_DIR}/../first.pers" "-1" "2")
-add_executable ( plot_persistence_Betti_numbers plot_persistence_Betti_numbers.cpp )
-target_link_libraries( plot_persistence_Betti_numbers ${Boost_SYSTEM_LIBRARY})
+install(TARGETS compute_number_of_dominant_intervals DESTINATION bin)
-add_test(NAME plot_persistence_Betti_numbers COMMAND $<TARGET_FILE:plot_persistence_Betti_numbers>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1)
add_executable ( compute_bottleneck_distance compute_bottleneck_distance.cpp )
- target_link_libraries( compute_bottleneck_distance ${Boost_SYSTEM_LIBRARY})
if (TBB_FOUND)
target_link_libraries(compute_bottleneck_distance ${TBB_LIBRARIES})
endif(TBB_FOUND)
+ add_test(NAME Persistence_representation_utilities_compute_bottleneck_distance
+ COMMAND $<TARGET_FILE:compute_bottleneck_distance>
+ "-1"
+ "${CMAKE_CURRENT_BINARY_DIR}/../first.pers"
+ "${CMAKE_CURRENT_BINARY_DIR}/../second.pers")
- add_test(NAME compute_bottleneck_distance COMMAND $<TARGET_FILE:compute_bottleneck_distance>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
+ install(TARGETS compute_bottleneck_distance DESTINATION bin)
endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1)
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 66fa31ca..9102da79 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
@@ -20,7 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gudhi/reader_utils.h>
#include <gudhi/Persistence_intervals.h>
#include <iostream>
@@ -31,16 +30,21 @@
using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals;
int main(int argc, char** argv) {
- std::cout << "This program compute the range of birth and death times of persistence pairs in diagrams provided as "
- "an input. \n";
- std::cout << "The first parameter of the program is the dimension of persistence to be used. If your file contains ";
- std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence "
- "pairs you want to use. If your input files consist only ";
- std::cout << "of birth-death pairs, please set this first parameter to -1 \n";
- std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n";
+ std::cout << "This program computes the range of birth and death times of persistence pairs in diagrams provided as "
+ << "an input.\n"
+ << "The first parameter is the dimension of persistence to be used to create persistence intervals. "
+ << "If your file contains 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 of birth-death pairs, please set this first parameter to -1.\n"
+ << "The remaining parameters of the program are the names of files with persistence diagrams.\n";
+
+ if (argc < 3) {
+ std::cout << "Wrong parameter list, the program will now terminate \n";
+ return 1;
+ }
- int dim = atoi(argv[1]);
unsigned dimension = std::numeric_limits<unsigned>::max();
+ int dim = atoi(argv[1]);
if (dim >= 0) {
dimension = (unsigned)dim;
}
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 0b1b526d..c8290845 100644
--- a/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp
+++ b/src/Persistence_representations/utilities/persistence_intervals/compute_bottleneck_distance.cpp
@@ -21,7 +21,6 @@
*/
#include <gudhi/Persistence_intervals_with_distances.h>
-#include <gudhi/read_persistence_from_file.h>
#include <iostream>
#include <sstream>
@@ -31,21 +30,21 @@
using Persistence_intervals_with_distances = Gudhi::Persistence_representations::Persistence_intervals_with_distances;
int main(int argc, char** argv) {
- 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";
- std::cout << "The remaining parameters of this programs are names of files with persistence diagrams.\n";
+ std::cout << "This program computes the bottleneck distance of persistence pairs in diagrams provided as "
+ << "an input.\n"
+ << "The first parameter is the dimension of persistence to be used to create persistence intervals. "
+ << "If your file contains 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 of birth-death pairs, please set this first parameter to -1.\n"
+ << "The remaining parameters of the program are the names of files with persistence diagrams.\n";
if (argc < 3) {
std::cout << "Wrong number of parameters, the program will now terminate \n";
return 1;
}
- int dim = atoi(argv[1]);
unsigned dimension = std::numeric_limits<unsigned>::max();
+ int dim = atoi(argv[1]);
if (dim >= 0) {
dimension = (unsigned)dim;
}
@@ -80,7 +79,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("distance");
+ out.open("distance.itv");
for (size_t i = 0; i != distance.size(); ++i) {
for (size_t j = 0; j != distance.size(); ++j) {
std::cout << distance[i][j] << " ";
@@ -91,5 +90,6 @@ int main(int argc, char** argv) {
}
out.close();
+ std::cout << "Distance can be found in 'distance.itv' file\n";
return 0;
}
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 1286ca57..b3d126f0 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
@@ -20,7 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gudhi/reader_utils.h>
#include <gudhi/Persistence_intervals.h>
#include <iostream>
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 d68f4584..ccb5b645 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
@@ -20,7 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gudhi/reader_utils.h>
#include <gudhi/Persistence_intervals.h>
#include <iostream>
@@ -31,30 +30,34 @@
using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals;
int main(int argc, char** argv) {
- std::cout << "This program compute a histogram of barcode's length. A number of bins in the histogram is a parameter "
- "of this program. \n";
- if (argc != 3) {
+ std::cout << "This program computes a histogram of barcode's length. A number of bins in the histogram is a "
+ << "parameter of this program. \n";
+ if ((argc != 3) && (argc != 4)) {
std::cout << "To run this program, please provide the name of a file with persistence diagram and number of "
- "dominant intervals you would like to get \n";
- std::cout << "The third parameter of a program is the dimension of the persistence that is to be used. If your "
- "file contains only birth-death pairs, you can skip this parameter\n";
+ << "dominant intervals you would like to get. Set a negative number dominant intervals value "
+ << "If your file contains only birth-death pairs.\n"
+ << "The third parameter is the dimension of the persistence that is to be used. If your "
+ << "file contains only birth-death pairs, you can skip this parameter\n";
return 1;
}
- unsigned dimension = std::numeric_limits<unsigned>::max();
- int dim = -1;
- if (argc > 2) {
- dim = atoi(argv[2]);
+
+ unsigned dominant_interval_number = std::numeric_limits<unsigned>::max();
+ int nbr = atoi(argv[2]);
+ if (nbr >= 0) {
+ dominant_interval_number = static_cast<unsigned>(nbr);
}
- if (dim >= 0) {
- dimension = (unsigned)dim;
+
+ int persistence_dimension = -1;
+ if (argc == 4) {
+ persistence_dimension = atoi(argv[3]);
}
- Persistence_intervals p(argv[1], dimension);
- std::vector<std::pair<double, double> > dominant_intervals = p.dominant_intervals(atoi(argv[2]));
+ Persistence_intervals p(argv[1], dominant_interval_number);
+ std::vector<std::pair<double, double> > dominant_intervals = p.dominant_intervals(persistence_dimension);
std::vector<size_t> histogram = p.histogram_of_lengths(10);
std::stringstream gnuplot_script;
- gnuplot_script << argv[1] << "_Gnuplot_script";
+ gnuplot_script << argv[1] << "_GnuplotScript";
std::ofstream out;
out.open(gnuplot_script.str().c_str());
@@ -66,7 +69,9 @@ int main(int argc, char** argv) {
out << histogram[i] << std::endl;
}
out << std::endl;
- std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl;
out.close();
+
+ std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ << gnuplot_script.str().c_str() << "\'\"" << std::endl;
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 da2b9319..b433c2b3 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
@@ -20,7 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gudhi/reader_utils.h>
#include <gudhi/Persistence_intervals.h>
#include <iostream>
@@ -31,29 +30,24 @@
using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals;
int main(int argc, char** argv) {
- std::cout << "This program compute a plot of persistence Betti numbers. The input parameter is a file with "
- "persistence intervals. \n";
- std::cout << "The second optional parameter of a program is the dimension of the persistence that is to be used. If "
- "your file contains only birth-death pairs, you can skip this parameter\n";
- if (argc < 2) {
- std::cout << "To run this program, please provide the name of a file with persistence diagram and number of "
- "dominant intervals you would like to get \n";
+ if ((argc != 3) && (argc != 2)) {
+ std::cout << "This program creates a gnuplot script of Betti numbers from a single persistence diagram file"
+ << "(*.pers).\n"
+ << "To run this program, please provide the name of a file with persistence diagram.\n"
+ << "The second optional parameter of a program is the dimension of the persistence that is to be used. "
+ << "If your file contains only birth-death pairs, you can skip this parameter.\n";
return 1;
}
+
unsigned dimension = std::numeric_limits<unsigned>::max();
int dim = -1;
- if (argc > 2) {
+ if (argc == 3) {
dim = atoi(argv[2]);
}
if (dim >= 0) {
dimension = (unsigned)dim;
}
- std::stringstream gnuplot_script;
- gnuplot_script << argv[1] << "_Gnuplot_script";
- std::ofstream out;
- out.open(gnuplot_script.str().c_str());
-
Persistence_intervals p(argv[1], dimension);
std::vector<std::pair<double, size_t> > pbns = p.compute_persistent_betti_numbers();
@@ -69,6 +63,11 @@ int main(int argc, char** argv) {
xRangeEnd += (xRangeEnd - xRangeBegin) / 100.0;
yRangeEnd += yRangeEnd / 100;
+ std::stringstream gnuplot_script;
+ gnuplot_script << argv[1] << "_GnuplotScript";
+ std::ofstream out;
+ out.open(gnuplot_script.str().c_str());
+
out << "set xrange [" << xRangeBegin << " : " << xRangeEnd << "]" << std::endl;
out << "set yrange [" << yRangeBegin << " : " << yRangeEnd << "]" << std::endl;
out << "plot '-' using 1:2 notitle with lp " << std::endl;
@@ -81,7 +80,8 @@ int main(int argc, char** argv) {
out << std::endl;
out.close();
- std::cout << "To visualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl;
+ std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ << gnuplot_script.str().c_str() << "\'\"" << std::endl;
return 0;
}
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 e7d29e84..33387802 100644
--- a/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp
+++ b/src/Persistence_representations/utilities/persistence_intervals/plot_persistence_intervals.cpp
@@ -20,9 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <gudhi/reader_utils.h>
#include <gudhi/Persistence_intervals.h>
-#include <gudhi/read_persistence_from_file.h>
#include <iostream>
#include <limits>
@@ -32,15 +30,16 @@
using Persistence_intervals = Gudhi::Persistence_representations::Persistence_intervals;
int main(int argc, char** argv) {
- if (argc < 2) {
- std::cout << "To run this program, please provide the name of a file with persistence diagram \n";
- std::cout << "The second optional parameter of a program is the dimension of the persistence that is to be used. "
- "If your file contains only birth-death pairs, you can skip this parameter\n";
+ if ((argc != 3) && (argc != 2)) {
+ std::cout << "This program creates a gnuplot script from a single persistence diagram file (*.pers).\n"
+ << "To run this program, please provide the name of a file with persistence diagram.\n"
+ << "The second optional parameter of a program is the dimension of the persistence that is to be used. "
+ << "If your file contains only birth-death pairs, you can skip this parameter.\n";
return 1;
}
unsigned dimension = std::numeric_limits<unsigned>::max();
int dim = -1;
- if (argc > 2) {
+ if (argc == 3) {
dim = atoi(argv[2]);
}
if (dim >= 0) {
diff --git a/src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt
index baf8de3c..d7087ed8 100644
--- a/src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt
+++ b/src/Persistence_representations/utilities/persistence_landscapes/CMakeLists.txt
@@ -1,38 +1,10 @@
cmake_minimum_required(VERSION 2.6)
-project(Persistence_representations_lanscapes_utilities)
+project(Persistence_representations_landscapes_utilities)
-file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/")
+add_persistence_representation_creation_utility(create_landscapes "-1")
-add_executable ( create_landscapes create_landscapes.cpp )
-target_link_libraries(create_landscapes ${Boost_SYSTEM_LIBRARY})
+add_persistence_representation_plot_utility(plot_landscapes ".land")
-# Will create simple_diagram.txt.land
-add_test(NAME create_landscapes COMMAND $<TARGET_FILE:create_landscapes>
- "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( average_landscapes average_landscapes.cpp )
-target_link_libraries(average_landscapes ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME average_landscapes COMMAND $<TARGET_FILE:average_landscapes>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( plot_landscapes plot_landscapes.cpp )
-target_link_libraries(plot_landscapes ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME plot_landscapes COMMAND $<TARGET_FILE:plot_landscapes>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( compute_distance_of_landscapes compute_distance_of_landscapes.cpp )
-target_link_libraries(compute_distance_of_landscapes ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME compute_distance_of_landscapes COMMAND $<TARGET_FILE:compute_distance_of_landscapes>
- "1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.land"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.land")
-
-add_executable ( compute_scalar_product_of_landscapes compute_scalar_product_of_landscapes.cpp )
-target_link_libraries(compute_scalar_product_of_landscapes ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME compute_scalar_product_of_landscapes COMMAND $<TARGET_FILE:compute_scalar_product_of_landscapes>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.land"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.land")
+add_persistence_representation_function_utility(average_landscapes ".land")
+add_persistence_representation_function_utility(compute_distance_of_landscapes ".land" "1")
+add_persistence_representation_function_utility(compute_scalar_product_of_landscapes ".land")
diff --git a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp
index 526130e9..1a59be8c 100644
--- a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp
+++ b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp
@@ -28,14 +28,13 @@
using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape;
int main(int argc, char** argv) {
- std::cout << "This program computes average persistence landscape of persistence landscapes created based on "
- "persistence diagrams provided as an input (you must create them first).\n";
- std::cout << "Please call this program with the names of files with persistence landscapes. The program will create "
- "a persistence landscape which will be their average \n";
+ std::cout << "This program computes average of persistence landscapes stored in files (the files needs to be "
+ << "created beforehand).\n"
+ << "The parameters of this programs are names of files with persistence landscapes.\n";
std::vector<const char*> filenames;
- if (argc == 1) {
- std::cout << "No input files given, the program will now terminate \n";
+ if (argc < 3) {
+ std::cout << "Wrong number of parameters, the program will now terminate \n";
return 1;
}
@@ -43,7 +42,6 @@ int main(int argc, char** argv) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence landscapes...\n";
std::vector<Persistence_landscape*> lands;
for (size_t i = 0; i != filenames.size(); ++i) {
Persistence_landscape* l = new Persistence_landscape;
@@ -60,7 +58,6 @@ int main(int argc, char** argv) {
delete lands[i];
}
- std::cout << "Done \n";
-
+ std::cout << "Average can be found in 'average.land' file\n";
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 b3881d6a..5062f521 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
@@ -30,11 +30,11 @@
using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape;
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 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.";
+ std::cout << "This program computes distance of persistence landscapes stored in files (the files needs to be "
+ << "created beforehand).\n"
+ << "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"
+ << "The remaining parameters of this program are names of files with persistence landscapes.\n";
if (argc < 3) {
std::cout << "Wrong number of parameters, the program will now terminate \n";
@@ -54,7 +54,6 @@ int main(int argc, char** argv) {
std::vector<Persistence_landscape> landscaspes;
landscaspes.reserve(filenames.size());
for (size_t file_no = 0; file_no != filenames.size(); ++file_no) {
- std::cout << "Loading persistence landscape from a file : " << filenames[file_no] << std::endl;
Persistence_landscape l;
l.load_landscape_from_file(filenames[file_no]);
landscaspes.push_back(l);
@@ -78,7 +77,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("distance");
+ out.open("distance.land");
for (size_t i = 0; i != distance.size(); ++i) {
for (size_t j = 0; j != distance.size(); ++j) {
std::cout << distance[i][j] << " ";
@@ -89,5 +88,6 @@ int main(int argc, char** argv) {
}
out.close();
+ std::cout << "Distance can be found in 'distance.land' file\n";
return 0;
}
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 8dad7b4d..5b5e9fa3 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
@@ -29,9 +29,14 @@
using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape;
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 "
- "created beforehand). \n";
- std::cout << "The parameters of this programs are names of files with persistence landscapes.\n";
+ std::cout << "This program computes scalar product of persistence landscapes stored in a file (the file needs to be "
+ << "created beforehand). \n"
+ << "The parameters of this programs are names of files with persistence landscapes.\n";
+
+ if (argc < 3) {
+ std::cout << "Wrong number of parameters, the program will now terminate \n";
+ return 1;
+ }
std::vector<const char*> filenames;
for (int i = 1; i < argc; ++i) {
@@ -40,7 +45,6 @@ int main(int argc, char** argv) {
std::vector<Persistence_landscape> landscaspes;
landscaspes.reserve(filenames.size());
for (size_t file_no = 0; file_no != filenames.size(); ++file_no) {
- std::cout << "Reading persistence landscape from a file : " << filenames[file_no] << std::endl;
Persistence_landscape l;
l.load_landscape_from_file(filenames[file_no]);
landscaspes.push_back(l);
@@ -64,7 +68,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("scalar_product");
+ out.open("scalar_product.land");
for (size_t i = 0; i != scalar_product.size(); ++i) {
for (size_t j = 0; j != scalar_product.size(); ++j) {
std::cout << scalar_product[i][j] << " ";
@@ -75,5 +79,6 @@ int main(int argc, char** argv) {
}
out.close();
+ std::cout << "Distance can be found in 'scalar_product.land' file\n";
return 0;
}
diff --git a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp
index 325081d1..6030e994 100644
--- a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp
+++ b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp
@@ -30,13 +30,20 @@
using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape;
int main(int argc, char** argv) {
- std::cout << "This program creates persistence landscapes of diagrams provided as an input. \n";
- std::cout << "The first parameter of the program is the dimension of persistence to be used to construct persistence "
- "landscapes. If your file contains ";
- std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence "
- "pairs you want to use. If your input files consist only ";
- std::cout << "of birth-death pairs, please set this first parameter to -1 \n";
- std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n";
+ std::cout << "This program creates persistence landscapes files (*.land) of persistence diagrams files (*.pers) "
+ << "provided as an input.\n"
+ << "The first parameter of this program is a dimension of persistence that will be used in creation of "
+ << "the persistence heat maps."
+ << "If your input files contains persistence pairs of various dimension, as a first parameter of the "
+ << "procedure please provide the dimension of persistence you want to use."
+ << "If in your files there are only birth-death pairs of the same dimension, set the first parameter to "
+ << "-1.\n"
+ << "The remaining parameters are the names of files with persistence diagrams. \n";
+
+ if (argc < 3) {
+ std::cout << "Wrong parameter list, the program will now terminate \n";
+ return 1;
+ }
std::vector<const char*> filenames;
int dim = atoi(argv[1]);
unsigned dimension = std::numeric_limits<unsigned>::max();
@@ -47,13 +54,12 @@ int main(int argc, char** argv) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence landscapes...\n";
for (size_t i = 0; i != filenames.size(); ++i) {
+ std::cout << "Creating a landscape based on file : " << filenames[i] << std::endl;
Persistence_landscape l(filenames[i], dimension);
std::stringstream ss;
ss << filenames[i] << ".land";
l.print_to_file(ss.str().c_str());
}
- std::cout << "Done \n";
return 0;
}
diff --git a/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp
index ebdb20a1..c797a7a8 100644
--- a/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp
+++ b/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp
@@ -28,16 +28,16 @@
using Persistence_landscape = Gudhi::Persistence_representations::Persistence_landscape;
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 landscape file \n";
+ std::cout << "This program creates a gnuplot script from a persistence landscape stored in a file (the file needs "
+ << "to be created beforehand). Please call the code with the name of a single landscape file.\n";
+ if (argc != 2) {
+ std::cout << "Wrong parameter list, the program will now terminate \n";
+ return 1;
+ }
+
Persistence_landscape l;
l.load_landscape_from_file(argv[1]);
-
- std::stringstream ss;
- ss << argv[1] << "_gnuplot_script";
- l.plot(ss.str().c_str());
-
- std::cout << "Done \n";
+ l.plot(argv[1]);
return 0;
}
diff --git a/src/Persistence_representations/utilities/persistence_landscapes/simple_diagram.txt.land b/src/Persistence_representations/utilities/persistence_landscapes/simple_diagram.txt.land
deleted file mode 100644
index b99d2f62..00000000
--- a/src/Persistence_representations/utilities/persistence_landscapes/simple_diagram.txt.land
+++ /dev/null
@@ -1,13 +0,0 @@
-#lambda_0
-1 0
-1.5 0.5
-2 0
-3 0
-3.5 0.5
-4 0
-5 0
-5.5 0.5
-6 0
-7 0
-7.5 0.5
-8 0
diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt
index 55a4fd50..c5ea4bbf 100644
--- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt
+++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/CMakeLists.txt
@@ -1,38 +1,11 @@
cmake_minimum_required(VERSION 2.6)
project(Persistence_representations_lanscapes_on_grid_utilities)
-file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/")
+# Need to set grid min and max for further average, distance and scalar_product
+add_persistence_representation_creation_utility(create_landscapes_on_grid "100" "0" "35" "-1")
-add_executable ( create_landscapes_on_grid create_landscapes_on_grid.cpp )
-target_link_libraries(create_landscapes_on_grid ${Boost_SYSTEM_LIBRARY})
+add_persistence_representation_plot_utility(plot_landscapes_on_grid ".g_land")
-# Will create simple_diagram.txt.land
-add_test(NAME create_landscapes_on_grid COMMAND $<TARGET_FILE:create_landscapes_on_grid>
- "100" "-1" "-1" "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( average_landscapes_on_grid average_landscapes_on_grid.cpp )
-target_link_libraries(average_landscapes_on_grid ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME average_landscapes_on_grid COMMAND $<TARGET_FILE:average_landscapes_on_grid>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land")
-
-add_executable ( plot_landscapes_on_grid plot_landscapes_on_grid.cpp )
-target_link_libraries(plot_landscapes_on_grid ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME plot_landscapes_on_grid COMMAND $<TARGET_FILE:plot_landscapes_on_grid>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land")
-
-add_executable ( compute_distance_of_landscapes_on_grid compute_distance_of_landscapes_on_grid.cpp )
-target_link_libraries(compute_distance_of_landscapes_on_grid ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME compute_distance_of_landscapes_on_grid COMMAND $<TARGET_FILE:compute_distance_of_landscapes_on_grid>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land")
-
-add_executable ( compute_scalar_product_of_landscapes_on_grid compute_scalar_product_of_landscapes_on_grid.cpp )
-target_link_libraries(compute_scalar_product_of_landscapes_on_grid ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME compute_scalar_product_of_landscapes_on_grid COMMAND $<TARGET_FILE:compute_scalar_product_of_landscapes_on_grid>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.g_land")
+add_persistence_representation_function_utility(average_landscapes_on_grid ".g_land")
+add_persistence_representation_function_utility(compute_distance_of_landscapes_on_grid ".g_land" "1")
+add_persistence_representation_function_utility(compute_scalar_product_of_landscapes_on_grid ".g_land")
diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp
index d50118a0..0b098d1a 100644
--- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp
+++ b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/average_landscapes_on_grid.cpp
@@ -28,21 +28,20 @@
using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid;
int main(int argc, char** argv) {
- std::cout << "This program computes average persistence landscape on grid of persistence landscapes on grid created "
- "based on persistence diagrams provided as an input. Please call this program with the names of files "
- "with persistence diagrams \n";
- std::vector<const char*> filenames;
+ std::cout << "This program computes average of persistence landscapes on grid stored in files (the files needs to "
+ << "be created beforehand).\n"
+ << "The parameters of this programs are names of files with persistence landscapes on grid.\n";
- if (argc == 1) {
- std::cout << "No input files given, the program will now terminate \n";
+ if (argc < 3) {
+ std::cout << "Wrong number of parameters, the program will now terminate \n";
return 1;
}
+ std::vector<const char*> filenames;
for (int i = 1; i < argc; ++i) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence landscapes...\n";
std::vector<Persistence_landscape_on_grid*> lands;
for (size_t i = 0; i != filenames.size(); ++i) {
Persistence_landscape_on_grid* l = new Persistence_landscape_on_grid;
@@ -59,7 +58,6 @@ int main(int argc, char** argv) {
delete lands[i];
}
- std::cout << "Done \n";
-
+ std::cout << "Average can be found in 'average.g_land' file\n";
return 0;
}
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 859c6991..fd0fcd15 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
@@ -30,11 +30,11 @@
using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid;
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 "
- "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";
+ std::cout << "This program computes distance of persistence landscapes on grid stored in files (the files needs to "
+ << "be created beforehand).\n"
+ << "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"
+ << "The remaining parameters of this program are names of files with persistence landscapes on grid.\n";
if (argc < 3) {
std::cout << "Wrong number of parameters, the program will now terminate \n";
@@ -77,7 +77,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("distance");
+ out.open("distance.g_land");
for (size_t i = 0; i != distance.size(); ++i) {
for (size_t j = 0; j != distance.size(); ++j) {
std::cout << distance[i][j] << " ";
@@ -88,5 +88,6 @@ int main(int argc, char** argv) {
}
out.close();
+ std::cout << "Distance can be found in 'distance.g_land' file\n";
return 0;
}
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 e95bf8ad..01de3dee 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
@@ -29,9 +29,15 @@
using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid;
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 "
- "to be created beforehand). \n";
- std::cout << "The parameters of this programs are names of files with persistence landscapes on grid.\n";
+ std::cout
+ << "This program computes scalar product of persistence landscapes on grid stored in a file (the file needs to "
+ << "be created beforehand). \n"
+ << "The parameters of this programs are names of files with persistence landscapes on grid.\n";
+
+ if (argc < 3) {
+ std::cout << "Wrong number of parameters, the program will now terminate \n";
+ return 1;
+ }
std::vector<const char*> filenames;
for (int i = 1; i < argc; ++i) {
@@ -63,7 +69,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("scalar_product");
+ out.open("scalar_product.g_land");
for (size_t i = 0; i != scalar_product.size(); ++i) {
for (size_t j = 0; j != scalar_product.size(); ++j) {
std::cout << scalar_product[i][j] << " ";
@@ -74,5 +80,6 @@ int main(int argc, char** argv) {
}
out.close();
+ std::cout << "Distance can be found in 'scalar_product.g_land' file\n";
return 0;
}
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 8d747c14..78e8ef57 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
@@ -30,18 +30,20 @@
using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid;
int main(int argc, char** argv) {
- std::cout << "This program creates persistence landscape on grid of diagrams provided as an input.\n";
- std::cout << "The first parameter of a program is an integer, a size of a grid.\n";
- std::cout << "The second and third parameters are min and max of the grid. If you want those numbers to be computed "
- "based on the data, set them both to -1 \n";
- std::cout << "The fourth parameter of the program is the dimension of persistence to be used to construct "
- "persistence landscape on a grid. If your file contains ";
- std::cout << "the information about dimension of birth-death pairs, please provide here the dimension of intervals "
- "you want to use. If your input files consist only ";
- std::cout << "of birth-death pairs, please set the fourth parameter to -1 \n";
- std::cout << "The remaining parameters are the names of files with persistence diagrams. \n";
+ std::cout << "This program creates persistence landscapes on grid files (*.g_land) of persistence diagrams files "
+ << "(*.pers) provided as an input.\n"
+ << "The first parameter of a program is an integer, a size of a grid.\n"
+ << "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"
+ << "The fourth parameter of this program is a dimension of persistence that will be used in creation of "
+ << "the persistence heat maps."
+ << "If your input files contains persistence pairs of various dimension, as a fourth parameter of the "
+ << "procedure please provide the dimension of persistence you want to use."
+ << "If in your files there are only birth-death pairs of the same dimension, set the fourth parameter to "
+ << "-1.\n"
+ << "The remaining parameters are the names of files with persistence diagrams. \n";
- if (argc < 5) {
+ if (argc < 6) {
std::cout << "Wrong parameter list, the program will now terminate \n";
return 1;
}
@@ -60,7 +62,6 @@ int main(int argc, char** argv) {
filenames.push_back(argv[i]);
}
- std::cout << "Creating persistence landscapes...\n";
for (size_t i = 0; i != filenames.size(); ++i) {
std::cout << "Creating persistence landscape on a grid based on a file : " << filenames[i] << std::endl;
Persistence_landscape_on_grid l;
@@ -74,6 +75,5 @@ int main(int argc, char** argv) {
ss << filenames[i] << ".g_land";
l.print_to_file(ss.str().c_str());
}
- std::cout << "Done \n";
return 0;
}
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 42822a01..dddb3615 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
@@ -28,20 +28,17 @@
using Persistence_landscape_on_grid = Gudhi::Persistence_representations::Persistence_landscape_on_grid;
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 landscape on grid file \n";
- if (argc == 1) {
- std::cout << "Wrong parameters of a program call, the program will now terminate \n";
+ std::cout << "This program creates a gnuplot script from a persistence landscape on grid stored in a file (the file "
+ << "needs to be created beforehand). Please call the code with the name of a single landscape on grid file"
+ << ".\n";
+ if (argc != 2) {
+ std::cout << "Wrong parameter list, the program will now terminate \n";
return 1;
}
+
Persistence_landscape_on_grid l;
l.load_landscape_from_file(argv[1]);
-
- std::stringstream ss;
- ss << argv[1] << "_gnuplot_script";
- l.plot(ss.str().c_str());
-
- std::cout << "Done \n";
+ l.plot(argv[1]);
return 0;
}
diff --git a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/simple_diagram.txt.g_land b/src/Persistence_representations/utilities/persistence_landscapes_on_grid/simple_diagram.txt.g_land
deleted file mode 100644
index dc53b932..00000000
--- a/src/Persistence_representations/utilities/persistence_landscapes_on_grid/simple_diagram.txt.g_land
+++ /dev/null
@@ -1,104 +0,0 @@
-1
-8
-101
-
-0.07
-0.14
-0.21
-0.28
-0.35
-0.42
-0.49
-0.42
-0.35
-0.28
-0.21
-0.14
-0.07
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-0.07
-0.14
-0.21
-0.28
-0.35
-0.42
-0.49
-0.42
-0.35
-0.28
-0.21
-0.14
-0.07
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-0.07
-0.14
-0.21
-0.28
-0.35
-0.42
-0.49
-0.42
-0.35
-0.28
-0.21
-0.14
-0.07
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-0.07
-0.14
-0.21
-0.28
-0.35
-0.42
-0.49
-0.42
-0.35
-0.28
-0.21
-0.14
-0.07
-
-
diff --git a/src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt b/src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt
index e3d1013b..a401c955 100644
--- a/src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt
+++ b/src/Persistence_representations/utilities/persistence_vectors/CMakeLists.txt
@@ -1,38 +1,10 @@
cmake_minimum_required(VERSION 2.6)
project(Persistence_vectors_utilities)
-file(COPY "${CMAKE_SOURCE_DIR}/data/persistence_diagram/simple_diagram.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/")
+add_persistence_representation_creation_utility(create_persistence_vectors "-1")
-add_executable ( create_persistence_vectors create_persistence_vectors.cpp )
-target_link_libraries(create_persistence_vectors ${Boost_SYSTEM_LIBRARY})
+add_persistence_representation_plot_utility(plot_persistence_vectors ".vect")
-# Will create simple_diagram.txt.vect
-add_test(NAME create_persistence_vectors COMMAND $<TARGET_FILE:create_persistence_vectors>
- "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt")
-
-add_executable ( average_persistence_vectors average_persistence_vectors.cpp )
-target_link_libraries(average_persistence_vectors ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME average_persistence_vectors COMMAND $<TARGET_FILE:average_persistence_vectors>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect")
-
-add_executable ( compute_distance_of_persistence_vectors compute_distance_of_persistence_vectors.cpp )
-target_link_libraries(compute_distance_of_persistence_vectors ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME compute_distance_of_persistence_vectors COMMAND $<TARGET_FILE:compute_distance_of_persistence_vectors>
- "-1" "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect")
-
-add_executable ( compute_scalar_product_of_persistence_vectors compute_scalar_product_of_persistence_vectors.cpp )
-target_link_libraries(compute_scalar_product_of_persistence_vectors ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME compute_scalar_product_of_persistence_vectors COMMAND $<TARGET_FILE:compute_scalar_product_of_persistence_vectors>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect"
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect")
-
-add_executable ( plot_persistence_vectors plot_persistence_vectors.cpp )
-target_link_libraries(plot_persistence_vectors ${Boost_SYSTEM_LIBRARY})
-
-add_test(NAME plot_persistence_vectors COMMAND $<TARGET_FILE:plot_persistence_vectors>
- "${CMAKE_CURRENT_BINARY_DIR}/simple_diagram.txt.vect")
+add_persistence_representation_function_utility(average_persistence_vectors ".vect")
+add_persistence_representation_function_utility(compute_distance_of_persistence_vectors ".vect" "1")
+add_persistence_representation_function_utility(compute_scalar_product_of_persistence_vectors ".vect")
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 366ee2bc..0144e76f 100644
--- a/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp
+++ b/src/Persistence_representations/utilities/persistence_vectors/average_persistence_vectors.cpp
@@ -26,25 +26,23 @@
#include <vector>
using Euclidean_distance = Gudhi::Euclidean_distance;
-using Vector_distances_in_diagram =
- Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
+using Vector_distances_in_diagram = Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
int main(int argc, char** argv) {
- std::cout << "This program computes average persistence vector of persistence vectors created based on persistence "
- "diagrams provided as an input. \n";
- std::cout << "Please call this program with the names of files with persistence diagrams \n";
- std::vector<const char*> filenames;
+ std::cout << "This program computes average of persistence vectors stored in files (the files needs to "
+ << "be created beforehand).\n"
+ << "The parameters of this programs are names of files with persistence vectors.\n";
- if (argc == 1) {
- std::cout << "No input files given, the program will now terminate \n";
+ if (argc < 3) {
+ std::cout << "Wrong number of parameters, the program will now terminate \n";
return 1;
}
+ std::vector<const char*> filenames;
for (int i = 1; i < argc; ++i) {
filenames.push_back(argv[i]);
}
- std::cout << "Reading persistence vectors...\n";
std::vector<Vector_distances_in_diagram*> lands;
for (size_t i = 0; i != filenames.size(); ++i) {
Vector_distances_in_diagram* l = new Vector_distances_in_diagram;
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 3aed297e..7e66d25e 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
@@ -28,8 +28,7 @@
#include <vector>
using Euclidean_distance = Gudhi::Euclidean_distance;
-using Vector_distances_in_diagram =
- Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
+using Vector_distances_in_diagram = Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
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 "
@@ -79,7 +78,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("distance");
+ out.open("distance.vect");
for (size_t i = 0; i != distance.size(); ++i) {
for (size_t j = 0; j != distance.size(); ++j) {
std::cout << distance[i][j] << " ";
@@ -90,5 +89,6 @@ int main(int argc, char** argv) {
}
out.close();
+ std::cout << "Distance can be found in 'distance.vect' file\n";
return 0;
}
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 d9ad4360..303c6e3e 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
@@ -28,13 +28,17 @@
#include <vector>
using Euclidean_distance = Gudhi::Euclidean_distance;
-using Vector_distances_in_diagram =
- Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
+using Vector_distances_in_diagram = Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
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 "
- "created beforehand). \n";
- std::cout << "The parameters of this programs are names of files with persistence vectors.\n";
+ std::cout << "This program computes scalar product of persistence vectors stored in a file (the file needs to "
+ << "be created beforehand). \n"
+ << "The parameters of this programs are names of files with persistence vectors.\n";
+
+ if (argc < 3) {
+ std::cout << "Wrong number of parameters, the program will now terminate \n";
+ return 1;
+ }
std::vector<const char*> filenames;
for (int i = 1; i < argc; ++i) {
@@ -66,7 +70,7 @@ int main(int argc, char** argv) {
// and now output the result to the screen and a file:
std::ofstream out;
- out.open("scalar_product");
+ out.open("scalar_product.vect");
for (size_t i = 0; i != scalar_product.size(); ++i) {
for (size_t j = 0; j != scalar_product.size(); ++j) {
std::cout << scalar_product[i][j] << " ";
@@ -76,5 +80,7 @@ int main(int argc, char** argv) {
out << std::endl;
}
out.close();
+
+ std::cout << "Distance can be found in 'scalar_product.vect' file\n";
return 0;
}
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 b618ca67..cc5e5393 100644
--- a/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp
+++ b/src/Persistence_representations/utilities/persistence_vectors/create_persistence_vectors.cpp
@@ -28,17 +28,24 @@
#include <vector>
using Euclidean_distance = Gudhi::Euclidean_distance;
-using Vector_distances_in_diagram =
- Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
+using Vector_distances_in_diagram = Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
int main(int argc, char** argv) {
- std::cout << "This program creates persistence vectors of diagrams provided as an input. The first parameter of this "
- "program is a dimension of persistence ";
- std::cout << " that will be used in creation of the persistence vectors. If our input files contain persistence "
- "pairs of various dimension, as a second parameter of the ";
- std::cout << " procedure please provide the dimension of persistence you want to use. If in your file there are only "
- "birth-death pairs of the same dimension, set the first parameter to -1."
- << std::endl;
+ std::cout << "This program creates persistence vectors files (*.vect) of persistence diagrams files (*.pers) "
+ << "provided as an input.\n"
+ << "The first parameter of this program is a dimension of persistence that will be used in creation of "
+ << "the persistence heat maps."
+ << "If your input files contains persistence pairs of various dimension, as a first parameter of the "
+ << "procedure please provide the dimension of persistence you want to use."
+ << "If in your files there are only birth-death pairs of the same dimension, set the first parameter to "
+ << "-1.\n"
+ << "The remaining parameters are the names of files with persistence diagrams. \n";
+
+ if (argc < 3) {
+ std::cout << "Wrong parameter list, the program will now terminate \n";
+ return 1;
+ }
+
std::cout << "The remaining parameters are the names of files with persistence diagrams. \n";
int dim = atoi(argv[1]);
unsigned dimension = std::numeric_limits<unsigned>::max();
@@ -58,6 +65,5 @@ int main(int argc, char** argv) {
ss << filenames[i] << ".vect";
l.print_to_file(ss.str().c_str());
}
- std::cout << "Done \n";
return 0;
}
diff --git a/src/Persistence_representations/utilities/persistence_vectors/plot_persistence_vectors.cpp b/src/Persistence_representations/utilities/persistence_vectors/plot_persistence_vectors.cpp
index e52b8f7d..aa33107d 100644
--- a/src/Persistence_representations/utilities/persistence_vectors/plot_persistence_vectors.cpp
+++ b/src/Persistence_representations/utilities/persistence_vectors/plot_persistence_vectors.cpp
@@ -26,8 +26,7 @@
#include <sstream>
using Euclidean_distance = Gudhi::Euclidean_distance;
-using Vector_distances_in_diagram =
- Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
+using Vector_distances_in_diagram = Gudhi::Persistence_representations::Vector_distances_in_diagram<Euclidean_distance>;
int main(int argc, char** argv) {
std::cout << "This program create a Gnuplot script to plot persistence vector. Please call this program with the "
diff --git a/src/Persistence_representations/utilities/persistence_vectors/simple_diagram.txt.vect b/src/Persistence_representations/utilities/persistence_vectors/simple_diagram.txt.vect
deleted file mode 100644
index 1d4eeaaf..00000000
--- a/src/Persistence_representations/utilities/persistence_vectors/simple_diagram.txt.vect
+++ /dev/null
@@ -1 +0,0 @@
-0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 0.707107 \ No newline at end of file