From 860fa7d916cb591cb0b016b046077d5333570731 Mon Sep 17 00:00:00 2001 From: mcarrier Date: Fri, 30 Mar 2018 18:09:57 +0000 Subject: git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/kernels@3323 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 550a4c3f9050b542203ab53ea7ef5ae1c8032f38 --- src/cython/cython/kernels.pyx | 4 ++++ src/cython/include/Kernels_interface.h | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'src/cython') 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 +#include #include #include @@ -44,20 +45,20 @@ namespace persistence_diagram { double pwg(const std::vector>& diag1, const std::vector>& 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>& diag1, const std::vector>& diag2, double sigma, int N) { - + double pi = boost::math::constants::pi(); std::vector> pd1 = diag1; int numpts = diag1.size(); for(int i = 0; i < numpts; i++) pd1.emplace_back(diag1[i].second,diag1[i].first); std::vector> 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>& diag1, const std::vector>& 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(); + 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> 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> 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; -- cgit v1.2.3