summaryrefslogtreecommitdiff
path: root/src/Bottleneck_distance/include/gudhi/Bottleneck.h
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-01-04 08:39:18 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-01-04 08:39:18 +0000
commit64dd2a2b0eec1374ed23ca079f86b312125d03f7 (patch)
treef22c13edb5f6d2980c0af4ec21a6a9b8910990de /src/Bottleneck_distance/include/gudhi/Bottleneck.h
parent67c34d7b506efe6445a24380b3ad0743e09ef334 (diff)
Move bottleneck_chrono in benchmark
Add test in cmake for basic example Move CGAL gudhi patches for bottleneck in dedicated directory Fix cpplint syntax issue git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bottleneck_integration@1920 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 24671facf791de93dc6fd94bb39ca7362bb22959
Diffstat (limited to 'src/Bottleneck_distance/include/gudhi/Bottleneck.h')
-rw-r--r--src/Bottleneck_distance/include/gudhi/Bottleneck.h93
1 files changed, 48 insertions, 45 deletions
diff --git a/src/Bottleneck_distance/include/gudhi/Bottleneck.h b/src/Bottleneck_distance/include/gudhi/Bottleneck.h
index 42a0d444..2b7e4767 100644
--- a/src/Bottleneck_distance/include/gudhi/Bottleneck.h
+++ b/src/Bottleneck_distance/include/gudhi/Bottleneck.h
@@ -4,7 +4,7 @@
*
* Author: Francois Godi
*
- * Copyright (C) 2015 INRIA (France)
+ * Copyright (C) 2015 INRIA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,62 +31,65 @@ namespace Gudhi {
namespace persistence_diagram {
double bottleneck_distance_approx(Persistence_graph& g, double e) {
- double b_lower_bound = 0.;
- double b_upper_bound = g.diameter_bound();
- const double alpha = std::pow(g.size(), 1./5.);
- Graph_matching m(g);
- Graph_matching biggest_unperfect(g);
- while (b_upper_bound - b_lower_bound > 2*e) {
- double step = b_lower_bound + (b_upper_bound - b_lower_bound)/alpha;
- if(step <= b_lower_bound || step >= b_upper_bound) //Avoid precision problem
- break;
- m.set_r(step);
- while (m.multi_augment()); //compute a maximum matching (in the graph corresponding to the current r)
- if (m.perfect()) {
- m = biggest_unperfect;
- b_upper_bound = step;
- } else {
- biggest_unperfect = m;
- b_lower_bound = step;
- }
+ double b_lower_bound = 0.;
+ double b_upper_bound = g.diameter_bound();
+ const double alpha = std::pow(g.size(), 1. / 5.);
+ Graph_matching m(g);
+ Graph_matching biggest_unperfect(g);
+ while (b_upper_bound - b_lower_bound > 2 * e) {
+ double step = b_lower_bound + (b_upper_bound - b_lower_bound) / alpha;
+ if (step <= b_lower_bound || step >= b_upper_bound) // Avoid precision problem
+ break;
+ m.set_r(step);
+ while (m.multi_augment()); // compute a maximum matching (in the graph corresponding to the current r)
+ if (m.perfect()) {
+ m = biggest_unperfect;
+ b_upper_bound = step;
+ } else {
+ biggest_unperfect = m;
+ b_lower_bound = step;
}
- return (b_lower_bound + b_upper_bound)/2.;
+ }
+ return (b_lower_bound + b_upper_bound) / 2.;
}
double bottleneck_distance_exact(Persistence_graph& g) {
- std::vector<double> sd = g.sorted_distances();
- long lower_bound_i = 0;
- long upper_bound_i = sd.size()-1;
- const double alpha = std::pow(g.size(), 1./5.);
- Graph_matching m(g);
- Graph_matching biggest_unperfect(g);
- while (lower_bound_i != upper_bound_i) {
- long step = lower_bound_i + static_cast<long>((upper_bound_i - lower_bound_i - 1)/alpha);
- m.set_r(sd.at(step));
- while (m.multi_augment()); //compute a maximum matching (in the graph corresponding to the current r)
- if (m.perfect()) {
- m = biggest_unperfect;
- upper_bound_i = step;
- } else {
- biggest_unperfect = m;
- lower_bound_i = step + 1;
- }
+ std::vector<double> sd = g.sorted_distances();
+ long lower_bound_i = 0;
+ long upper_bound_i = sd.size() - 1;
+ const double alpha = std::pow(g.size(), 1. / 5.);
+ Graph_matching m(g);
+ Graph_matching biggest_unperfect(g);
+ while (lower_bound_i != upper_bound_i) {
+ long step = lower_bound_i + static_cast<long> ((upper_bound_i - lower_bound_i - 1) / alpha);
+ m.set_r(sd.at(step));
+ while (m.multi_augment()); // compute a maximum matching (in the graph corresponding to the current r)
+ if (m.perfect()) {
+ m = biggest_unperfect;
+ upper_bound_i = step;
+ } else {
+ biggest_unperfect = m;
+ lower_bound_i = step + 1;
}
- return sd.at(lower_bound_i);
+ }
+ return sd.at(lower_bound_i);
}
/** \brief Function to use in order to compute the Bottleneck distance between two persistence diagrams (see concepts).
- * If the last parameter e is not 0, you get an additive e-approximation, which is a lot faster to compute whatever is e.
- * Thus, by default, e is a very small positive double, actually the smallest double possible such that the floating-point inaccuracies don't lead to a failure of the algorithm.
+ * If the last parameter e is not 0, you get an additive e-approximation, which is a lot faster to compute whatever is
+ * e.
+ * Thus, by default, e is a very small positive double, actually the smallest double possible such that the
+ * floating-point inaccuracies don't lead to a failure of the algorithm.
*
* \ingroup bottleneck_distance
*/
template<typename Persistence_diagram1, typename Persistence_diagram2>
-double bottleneck_distance(const Persistence_diagram1 &diag1, const Persistence_diagram2 &diag2, double e=std::numeric_limits<double>::min()) {
- Persistence_graph g(diag1, diag2, e);
- if(g.bottleneck_alive() == std::numeric_limits<double>::infinity())
- return std::numeric_limits<double>::infinity();
- return std::max(g.bottleneck_alive(), e == 0. ? bottleneck_distance_exact(g) : bottleneck_distance_approx(g, e));
+double bottleneck_distance(const Persistence_diagram1 &diag1, const Persistence_diagram2 &diag2,
+ double e = std::numeric_limits<double>::min()) {
+ Persistence_graph g(diag1, diag2, e);
+ if (g.bottleneck_alive() == std::numeric_limits<double>::infinity())
+ return std::numeric_limits<double>::infinity();
+ return std::max(g.bottleneck_alive(), e == 0. ? bottleneck_distance_exact(g) : bottleneck_distance_approx(g, e));
}
} // namespace persistence_diagram