summaryrefslogtreecommitdiff
path: root/src/Persistence_representations
diff options
context:
space:
mode:
authormcarrier <mcarrier@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-04-12 15:22:45 +0000
committermcarrier <mcarrier@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-04-12 15:22:45 +0000
commit905be209a0e62121c125c37e01f4d2eae5aa606d (patch)
treede48475b4c0e45936f6cc2b655851f0cbc552fbc /src/Persistence_representations
parent860fa7d916cb591cb0b016b046077d5333570731 (diff)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/kernels@3378 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 7cd9f2ae7c9da5d525bdb76a00ffac1359a47da7
Diffstat (limited to 'src/Persistence_representations')
-rw-r--r--src/Persistence_representations/example/persistence_weighted_gaussian.cpp4
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_weighted_gaussian.h12
-rw-r--r--src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h23
-rw-r--r--src/Persistence_representations/include/gudhi/common_persistence_representations.h2
4 files changed, 23 insertions, 18 deletions
diff --git a/src/Persistence_representations/example/persistence_weighted_gaussian.cpp b/src/Persistence_representations/example/persistence_weighted_gaussian.cpp
index d447f165..dea5dab6 100644
--- a/src/Persistence_representations/example/persistence_weighted_gaussian.cpp
+++ b/src/Persistence_representations/example/persistence_weighted_gaussian.cpp
@@ -91,8 +91,8 @@ int main(int argc, char** argv) {
PWG pwgex1(pd1, 2*std::sqrt(sigma), -1, PWG::pss_weight);
PWG pwgex2(pd2, 2*std::sqrt(sigma), -1, PWG::pss_weight);
- std::cout << "Approx PSS kernel: " << pwg1.compute_scalar_product (pwg2) / (16*pi*sigma) << std::endl;
- std::cout << "Exact PSS kernel: " << pwgex1.compute_scalar_product (pwgex2) / (16*pi*sigma) << std::endl;
+ std::cout << "Approx PSS kernel: " << pwg1.compute_scalar_product (pwg2) / (16*Gudhi::Persistence_representations::pi*sigma) << std::endl;
+ std::cout << "Exact PSS kernel: " << pwgex1.compute_scalar_product (pwgex2) / (16*Gudhi::Persistence_representations::pi*sigma) << std::endl;
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;