diff options
Diffstat (limited to 'src')
4 files changed, 20 insertions, 12 deletions
diff --git a/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h b/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h index f824225a..d5c8e6d7 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h +++ b/src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h @@ -39,7 +39,6 @@ #include <functional> #include <boost/math/constants/constants.hpp> -double pi = boost::math::constants::pi<double>(); using PD = std::vector<std::pair<double,double> >; using Weight = std::function<double (std::pair<double,double>) >; @@ -88,6 +87,8 @@ class Persistence_weighted_gaussian{ int approx; public: + + double pi = boost::math::constants::pi<double>(); /** \brief Persistence Weighted Gaussian Kernel constructor. * \ingroup Persistence_weighted_gaussian diff --git a/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h b/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h index bfb77384..fc3cd142 100644 --- a/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h +++ b/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h @@ -39,7 +39,6 @@ #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 { @@ -77,13 +76,14 @@ class Sliced_Wasserstein { double sigma; std::vector<std::vector<double> > projections, projections_diagonal; - public: + double pi = boost::math::constants::pi<double>(); + void build_rep(){ if(approx > 0){ - + double step = pi/this->approx; int n = diagram.size(); diff --git a/src/cython/cython/kernels.pyx b/src/cython/cython/kernels.pyx index 4fc21f03..466917b1 100644 --- a/src/cython/cython/kernels.pyx +++ b/src/cython/cython/kernels.pyx @@ -32,6 +32,10 @@ __license__ = "GPL v3" cdef extern from "Kernels_interface.h" namespace "Gudhi::persistence_diagram": double sw (vector[pair[double, double]], vector[pair[double, double]], double, int) vector[vector[double]] sw_matrix (vector[vector[pair[double, double]]], vector[vector[pair[double, double]]], double, int) + double pss (vector[pair[double, double]], vector[pair[double, double]], double, int) + vector[vector[double]] pss_matrix (vector[vector[pair[double, double]]], vector[vector[pair[double, double]]], double, int) + double pwg (vector[pair[double, double]], vector[pair[double, double]], double, int) + vector[vector[double]] pwg_matrix (vector[vector[pair[double, double]]], vector[vector[pair[double, double]]], double, int) def sliced_wasserstein(diagram_1, diagram_2, sigma = 1, N = 100): """ diff --git a/src/cython/include/Kernels_interface.h b/src/cython/include/Kernels_interface.h index 17bb5d8b..33cd6e35 100644 --- a/src/cython/include/Kernels_interface.h +++ b/src/cython/include/Kernels_interface.h @@ -24,6 +24,7 @@ #define INCLUDE_KERNELS_INTERFACE_H_ #include <gudhi/Sliced_Wasserstein.h> +#include <gudhi/Persistence_weighted_gaussian.h> #include <iostream> #include <vector> @@ -44,20 +45,20 @@ namespace persistence_diagram { double pwg(const std::vector<std::pair<double, double>>& diag1, const std::vector<std::pair<double, double>>& diag2, double sigma, int N) { - Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg1(diag1, sigma, N, Gudhi::Persistence_representations::arctan_weight); - Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg2(diag2, sigma, N, Gudhi::Persistence_representations::arctan_weight); + Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg1(diag1, sigma, N, Gudhi::Persistence_representations::Persistence_weighted_gaussian::arctan_weight); + Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg2(diag2, sigma, N, Gudhi::Persistence_representations::Persistence_weighted_gaussian::arctan_weight); return pwg1.compute_scalar_product(pwg2); } double pss(const std::vector<std::pair<double, double>>& diag1, const std::vector<std::pair<double, double>>& diag2, double sigma, int N) { - + double pi = boost::math::constants::pi<double>(); std::vector<std::pair<double, double>> pd1 = diag1; int numpts = diag1.size(); for(int i = 0; i < numpts; i++) pd1.emplace_back(diag1[i].second,diag1[i].first); std::vector<std::pair<double, double>> pd2 = diag2; numpts = diag2.size(); for(int i = 0; i < numpts; i++) pd2.emplace_back(diag2[i].second,diag2[i].first); - Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg1(pd1, 2*std::sqrt(sigma), N, Gudhi::Persistence_representations::pss_weight); - Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg2(pd2, 2*std::sqrt(sigma), N, Gudhi::Persistence_representations::pss_weight); + Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg1(pd1, 2*std::sqrt(sigma), N, Gudhi::Persistence_representations::Persistence_weighted_gaussian::pss_weight); + Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg2(pd2, 2*std::sqrt(sigma), N, Gudhi::Persistence_representations::Persistence_weighted_gaussian::pss_weight); return pwg1.compute_scalar_product (pwg2) / (16*pi*sigma); } @@ -65,9 +66,9 @@ namespace persistence_diagram { double pss_sym(const std::vector<std::pair<double, double>>& diag1, const std::vector<std::pair<double, double>>& diag2, double sigma, int N) { - - Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg1(pd1, 2*std::sqrt(sigma), N, Gudhi::Persistence_representations::pss_weight); - Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg2(pd2, 2*std::sqrt(sigma), N, Gudhi::Persistence_representations::pss_weight); + double pi = boost::math::constants::pi<double>(); + Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg1(diag1, 2*std::sqrt(sigma), N, Gudhi::Persistence_representations::Persistence_weighted_gaussian::pss_weight); + Gudhi::Persistence_representations::Persistence_weighted_gaussian pwg2(diag2, 2*std::sqrt(sigma), N, Gudhi::Persistence_representations::Persistence_weighted_gaussian::pss_weight); return pwg1.compute_scalar_product (pwg2) / (16*pi*sigma); } @@ -108,11 +109,13 @@ namespace persistence_diagram { std::vector<std::pair<double, double>> pd1 = s1[i]; int numpts = s1[i].size(); for(int j = 0; j < numpts; j++) pd1.emplace_back(s1[i][j].second,s1[i][j].first); ss1.push_back(pd1); + } for(int i = 0; i < num_diag_2; i++){ std::vector<std::pair<double, double>> pd2 = s2[i]; int numpts = s2[i].size(); for(int j = 0; j < numpts; j++) pd2.emplace_back(s2[i][j].second,s2[i][j].first); ss2.push_back(pd2); + } for(int i = 0; i < num_diag_1; i++){ std::cout << 100.0*i/num_diag_1 << " %" << std::endl; |