summaryrefslogtreecommitdiff
path: root/src/Bottleneck_distance/include/gudhi
diff options
context:
space:
mode:
authorfgodi <fgodi@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-11-28 15:25:17 +0000
committerfgodi <fgodi@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-11-28 15:25:17 +0000
commit7449716dca77dd81759d024ae1e9dbfcfeb202e7 (patch)
tree732c2dfbb4a2a1d8cfd1646c422aa44d778c72fc /src/Bottleneck_distance/include/gudhi
parentb0c33669d948f25c413a67991f8ae03e854892a8 (diff)
compute and compute_exactly merged
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bottleneck_integration@1792 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7c4e66f5449759f7d99319ca14989b2d74e96e20
Diffstat (limited to 'src/Bottleneck_distance/include/gudhi')
-rw-r--r--src/Bottleneck_distance/include/gudhi/Bottleneck.h62
-rw-r--r--src/Bottleneck_distance/include/gudhi/Neighbors_finder.h4
2 files changed, 9 insertions, 57 deletions
diff --git a/src/Bottleneck_distance/include/gudhi/Bottleneck.h b/src/Bottleneck_distance/include/gudhi/Bottleneck.h
index 52de30be..59df655e 100644
--- a/src/Bottleneck_distance/include/gudhi/Bottleneck.h
+++ b/src/Bottleneck_distance/include/gudhi/Bottleneck.h
@@ -29,32 +29,6 @@ namespace Gudhi {
namespace bottleneck_distance {
-template<typename Persistence_diagram1, typename Persistence_diagram2>
-double compute_exactly(const Persistence_diagram1 &diag1, const Persistence_diagram2 &diag2) {
- Persistence_graph g(diag1, diag2, 0.);
- std::vector<double> sd(g.sorted_distances());
- int idmin = 0;
- int idmax = sd.size() - 1;
- // alpha can change the complexity
- double alpha = pow(sd.size(), 0.25);
- Graph_matching m(g);
- Graph_matching biggest_unperfect(g);
- while (idmin != idmax) {
- int step = static_cast<int>((idmax - idmin) / alpha);
- m.set_r(sd.at(idmin + step));
- while (m.multi_augment());
- //The above while compute a maximum matching (according to the r setted before)
- if (m.perfect()) {
- idmax = idmin + step;
- m = biggest_unperfect;
- } else {
- biggest_unperfect = m;
- idmin = idmin + step + 1;
- }
- }
- return sd.at(idmin);
-}
-
/** \brief Function to use in order to compute the Bottleneck distance between two persistence diagrams.
* If the last parameter e is not 0 (default value if not explicited), you get an additive e-approximation.
*
@@ -62,19 +36,19 @@ double compute_exactly(const Persistence_diagram1 &diag1, const Persistence_diag
*/
template<typename Persistence_diagram1, typename Persistence_diagram2>
double compute(const Persistence_diagram1 &diag1, const Persistence_diagram2 &diag2, double e=0.) {
- if(e == 0.)
- return compute_exactly(diag1, diag2);
Persistence_graph g(diag1, diag2, e);
- int in = g.diameter_bound()/e + 1;
+ std::vector<double> sd;
+ if(e == 0.)
+ sd = g.sorted_distances();
int idmin = 0;
- int idmax = in;
+ int idmax = e==0. ? sd.size() - 1 : g.diameter_bound()/e + 1;
// alpha can change the complexity
- double alpha = pow(in, 0.10);
+ double alpha = pow(idmax, 0.25);
Graph_matching m(g);
Graph_matching biggest_unperfect(g);
while (idmin != idmax) {
int step = static_cast<int>((idmax - idmin) / alpha);
- m.set_r(e*(idmin + step));
+ m.set_r(e == 0. ? sd.at(idmin + step) : e*(idmin + step));
while (m.multi_augment());
//The above while compute a maximum matching (according to the r setted before)
if (m.perfect()) {
@@ -85,7 +59,7 @@ double compute(const Persistence_diagram1 &diag1, const Persistence_diagram2 &di
idmin = idmin + step + 1;
}
}
- return e*(idmin);
+ return e == 0. ? sd.at(idmin) : e*(idmin);
}
@@ -95,25 +69,3 @@ double compute(const Persistence_diagram1 &diag1, const Persistence_diagram2 &di
} // namespace Gudhi
#endif // BOTTLENECK_H_
-
-/* Dichotomic version
-template<typename Persistence_diagram1, typename Persistence_diagram2>
-double compute(const Persistence_diagram1 &diag1, const Persistence_diagram2 &diag2, double e) {
- if(e< std::numeric_limits<double>::min())
- return compute_exactly(diag1, diag2);
- G::initialize(diag1, diag2, e);
- double d = 0.;
- double f = G::diameter();
- while (f-d > e){
- Graph_matching m;
- m.set_r((d+f)/2.);
- while (m.multi_augment());
- //The above while compute a maximum matching (according to the r setted before)
- if (m.perfect())
- f = (d+f)/2.;
- else
- d= (d+f)/2.;
- }
- return d;
-} */
-
diff --git a/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h b/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h
index f28e21a2..90ddabef 100644
--- a/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h
+++ b/src/Bottleneck_distance/include/gudhi/Neighbors_finder.h
@@ -122,8 +122,8 @@ inline int Neighbors_finder::pull_near(int u_point_index) {
else{
//Is the query point near to a V point in the plane ?
Internal_point u_point = g.get_u_point(u_point_index);
- std::vector<double> w = {1., 1.};
- K_neighbor_search search(kd_t, u_point, 0., true, Distance(0, 2, w));
+ std::array<double, 2> w = { {1., 1.} };
+ K_neighbor_search search(kd_t, u_point, 0., true, Distance(0, 2, w.begin(), w.end()));
auto it = search.begin();
if(it==search.end() || g.distance(u_point_index, it->first.point_index) > r)
return null_point_index();