Skip to content

Commit e01d30b

Browse files
committed
important numeric fixes
1 parent 9493a83 commit e01d30b

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ All simplifications are vertex-restricted!
9898
- signature: `fred.Cluster_Assignment`
9999
- methods:
100100
- `len(fred.Cluster_Assignment)`: number of centers
101-
-`fred.Cluster_Assignment.count(i)`: number of curves assigned to center `i`
101+
- `fred.Cluster_Assignment.count(i)`: number of curves assigned to center `i`
102102
- `fred.Cluster_Assignment.get(i,j)`: get index of `j`th curve assigned to center `i`
103103

104104
### Dimension Reduction via Gaussian Random Projection

include/point.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class Point : public Coordinates {
165165
const Vector u = line_end-line_start, v = *this - line_start;
166166
const parameter_t ulen_sqr = u.length_sqr(), vlen_sqr = v.length_sqr();
167167

168-
if (ulen_sqr == 0) {
169-
if (vlen_sqr <= distance_sqr) return Interval(0, 1);
168+
if (near_eq(ulen_sqr, parameter_t(0))) {
169+
if (vlen_sqr <= distance_sqr) return Interval(parameter_t(0), parameter_t(1));
170170
else return Interval();
171171
}
172172

include/types.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1111
#pragma once
1212

1313
#include <vector>
14+
#include <cmath>
15+
#include <limits>
1416

1517
typedef double distance_t;
1618
typedef double coordinate_t;
@@ -29,3 +31,9 @@ using Vector = Point;
2931
using Intervals = std::vector<Interval>;
3032
using Coordinates = std::vector<coordinate_t>;
3133

34+
template<typename T>
35+
inline bool near_eq(T x, T y) {
36+
return std::abs(x - y) <= std::min(std::abs(x), std::abs(y)) * std::numeric_limits<T>::epsilon();
37+
}
38+
39+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def build_extension(self, ext):
7474

7575
setup(
7676
name='Fred-Frechet',
77-
version='1.9.3',
77+
version='1.9.4',
7878
author='Dennis Rohde',
7979
author_email='[email protected]',
8080
description='A fast, scalable and light-weight C++ Fréchet distance library, exposed to python and focused on (k,l)-clustering of polygonal curves.',

src/frechet.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ Distance _distance(const Curve &curve1, const Curve &curve2, distance_t ub, dist
8080
//Binary search over the feasible distances
8181
while (ub - lb > p_error) {
8282
++number_searches;
83-
split = (ub + lb)/2;
83+
split = (ub + lb)/distance_t(2);
84+
if (split == lb or split == ub) break;
8485
auto isLessThan = _less_than_or_equal(split, curve1, curve2, reachable1, reachable2, free_intervals1, free_intervals2);
8586
if (isLessThan) {
8687
ub = split;
@@ -93,7 +94,7 @@ Distance _distance(const Curve &curve1, const Curve &curve2, distance_t ub, dist
9394
}
9495

9596
const auto end = std::chrono::high_resolution_clock::now();
96-
result.value = (ub + lb)/2.;
97+
result.value = lb;
9798
result.time_searches = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
9899
result.number_searches = number_searches;
99100
return result;

src/fred_python_wrapper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ Curve approximate_minimum_error_simplification(const Curve &curve, const curve_s
5050

5151
PYBIND11_MODULE(backend, m) {
5252

53-
m.def("set_maximum_number_threads", set_number_threads);
54-
5553
py::class_<Config::Config>(m, "Config")
5654
.def(py::init<>())
5755
.def_property("continuous_frechet_error", [&](Config::Config&) { return fc::error; }, [&](Config::Config&, const bool error) { fc::error = error; })

src/simplification.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ Curve Simplification::approximate_minimum_error_simplification(const Curve &curv
8888
}
8989

9090
if (Config::verbose) std::cout << "ASIMPL: binary search using upper bound" << std::endl;
91-
while (max_distance - min_distance > min_distance * Frechet::Continuous::error / 100) {
92-
mid_distance = (min_distance + max_distance) / 2.;
93-
91+
const distance_t epsilon = std::max(min_distance * Frechet::Continuous::error / 100, std::numeric_limits<distance_t>::epsilon());
92+
while (max_distance - min_distance > epsilon) {
93+
mid_distance = (min_distance + max_distance) / distance_t(2);
94+
if (mid_distance == max_distance or mid_distance == min_distance) break;
9495
new_simplification = Simplification::approximate_minimum_link_simplification(curve, mid_distance);
9596

9697
if (new_simplification.complexity() > ell) min_distance = mid_distance;

0 commit comments

Comments
 (0)