summaryrefslogtreecommitdiff
path: root/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h
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/include/gudhi/Sliced_Wasserstein.h
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/include/gudhi/Sliced_Wasserstein.h')
-rw-r--r--src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h23
1 files changed, 14 insertions, 9 deletions
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);
}