diff options
Diffstat (limited to 'src/Persistence_representations/include/gudhi')
3 files changed, 21 insertions, 16 deletions
diff --git a/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h b/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h index d5c8e6d7..b30e0273 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h +++ b/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h @@ -25,6 +25,7 @@ // gudhi include #include <gudhi/read_persistence_from_file.h> +#include <gudhi/common_persistence_representations.h> // standard include #include <cmath> @@ -37,7 +38,6 @@ #include <string> #include <utility> #include <functional> -#include <boost/math/constants/constants.hpp> using PD = std::vector<std::pair<double,double> >; using Weight = std::function<double (std::pair<double,double>) >; @@ -87,8 +87,6 @@ class Persistence_weighted_gaussian{ int approx; public: - - double pi = boost::math::constants::pi<double>(); /** \brief Persistence Weighted Gaussian Kernel constructor. * \ingroup Persistence_weighted_gaussian @@ -101,10 +99,10 @@ class Persistence_weighted_gaussian{ */ Persistence_weighted_gaussian(PD _diagram, double _sigma = 1.0, int _approx = 1000, Weight _weight = arctan_weight){diagram = _diagram; sigma = _sigma; approx = _approx; weight = _weight;} - PD get_diagram(){return this->diagram;} - double get_sigma(){return this->sigma;} - int get_approx(){return this->approx;} - Weight get_weight(){return this->weight;} + PD get_diagram() const {return this->diagram;} + double get_sigma() const {return this->sigma;} + int get_approx() const {return this->approx;} + Weight get_weight() const {return this->weight;} // ********************************** diff --git a/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h b/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h index fc3cd142..6a9a607e 100644 --- a/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h +++ b/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h @@ -25,6 +25,8 @@ // gudhi include #include <gudhi/read_persistence_from_file.h> +#include <gudhi/common_persistence_representations.h> +#include <gudhi/Debug_utils.h> // standard include #include <cmath> @@ -37,7 +39,6 @@ #include <string> #include <utility> #include <functional> -#include <boost/math/constants/constants.hpp> using PD = std::vector<std::pair<double,double> >; @@ -68,6 +69,7 @@ namespace Persistence_representations { * It implements the following concepts: Topological_data_with_distances, Topological_data_with_scalar_product. * **/ + class Sliced_Wasserstein { protected: @@ -78,8 +80,6 @@ class Sliced_Wasserstein { public: - double pi = boost::math::constants::pi<double>(); - void build_rep(){ if(approx > 0){ @@ -117,9 +117,9 @@ class Sliced_Wasserstein { */ Sliced_Wasserstein(PD _diagram, double _sigma = 1.0, int _approx = 100){diagram = _diagram; approx = _approx; sigma = _sigma; build_rep();} - PD get_diagram(){return this->diagram;} - int get_approx(){return this->approx;} - double get_sigma(){return this->sigma;} + PD get_diagram() const {return this->diagram;} + int get_approx() const {return this->approx;} + double get_sigma() const {return this->sigma;} @@ -197,11 +197,15 @@ class Sliced_Wasserstein { /** \brief Evaluation of the Sliced Wasserstein Distance between a pair of diagrams. * \ingroup Sliced_Wasserstein * - * @param[in] second other instance of class Sliced_Wasserstein. Warning: approx parameter needs to be the same for both instances!!! + * @param[in] second other instance of class Sliced_Wasserstein. + * For warning in red: + * @warning approx parameter needs to be the same for both instances. * */ double compute_sliced_wasserstein_distance(Sliced_Wasserstein second) { + GUDHI_CHECK(this->approx != second.approx, std::invalid_argument("Error: different approx values for representations")); + PD diagram1 = this->diagram; PD diagram2 = second.diagram; double sw = 0; if(this->approx == -1){ @@ -321,6 +325,7 @@ class Sliced_Wasserstein { * */ double compute_scalar_product(Sliced_Wasserstein second){ + GUDHI_CHECK(this->sigma != second.sigma, std::invalid_argument("Error: different sigma values for representations")); return std::exp(-compute_sliced_wasserstein_distance(second)/(2*this->sigma*this->sigma)); } @@ -331,8 +336,8 @@ class Sliced_Wasserstein { * */ double distance(Sliced_Wasserstein second) { - if(this->sigma != second.sigma || this->approx != second.approx){std::cout << "Error: different representations!" << std::endl; return 0;} - else return std::pow(this->compute_scalar_product(*this) + second.compute_scalar_product(second)-2*this->compute_scalar_product(second), 0.5); + GUDHI_CHECK(this->sigma != second.sigma, std::invalid_argument("Error: different sigma values for representations")); + return std::pow(this->compute_scalar_product(*this) + second.compute_scalar_product(second)-2*this->compute_scalar_product(second), 0.5); } diff --git a/src/Persistence_representations/include/gudhi/common_persistence_representations.h b/src/Persistence_representations/include/gudhi/common_persistence_representations.h index 44e125a7..90f2626d 100644 --- a/src/Persistence_representations/include/gudhi/common_persistence_representations.h +++ b/src/Persistence_representations/include/gudhi/common_persistence_representations.h @@ -26,11 +26,13 @@ #include <utility> #include <string> #include <cmath> +#include <boost/math/constants/constants.hpp> namespace Gudhi { namespace Persistence_representations { // this file contain an implementation of some common procedures used in Persistence_representations. +static constexpr double pi = boost::math::constants::pi<double>(); // double epsi = std::numeric_limits<double>::epsilon(); double epsi = 0.000005; |