GUDHI / gudhi-devel

The GUDHI library is a generic open source C++ library, with a Python interface, for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.
https://gudhi.inria.fr/
MIT License
259 stars 66 forks source link

Square root filtration values for alpha and delaunay-cech complex #1138

Open VincentRouvreau opened 2 months ago

VincentRouvreau commented 2 months ago

Fix #80 and #771

mglisse commented 1 month ago
  • are weights with sqrt=True well-defined (e.g., via $x\mapsto \mathrm{sgn}(x)\sqrt{|x|}$) ?

If the weights make some (squared) values negative, I don't think theory provides anything meaningful for the sqrt, no. There are a number of applications where the weights can only increase filtration values, so they remain non-negative. Adding the same constant to all weights (without sqrt, so possibly negative) preserves a lot of things (the triangulation, the order between filtration values), that's one way to avoid negative values, but it obviously does not preserve filtration values, so it would be confusing. I didn't check if the code replaces only the negative ones with NaN, or if this propagates to random nonsense.

  • do you think it would be reasonable to put the sqrt to True ? (I'm in favor of it, to make it consistent with other complexes).

I am rather strongly against changing the behavior of old code, that's really not a nice thing to do to users. However

VincentRouvreau commented 1 week ago

Some benchmark to compare std::sqrt inside functions (as done on this PR) and when std::sqrt is performed after construction with for_each_simplex. (cf. src/Alpha_complex/benchmark/Alpha_complex_1d_benchmark.cpp)

master - without sqrt

$ for seed in 40 41 42 43 44; do ./Alpha_complex_1d_benchmark 5000000 $seed; done
... create simplex tree from alpha complex: 7.906s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.398s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 7.837s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.369s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 7.906s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.37s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 7.876s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.38s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 7.887s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.373s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.

sqrt inside functions - cf. branch alpha_sqrt

$ for seed in 40 41 42 43 44; do ./Alpha_complex_1d_benchmark 5000000 $seed; done
... create simplex tree from alpha complex: 7.975s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.43s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 8.021s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.431s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 7.866s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.401s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 7.927s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.395s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 7.87s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.394s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.

for_each_simplex(sqrt) - cf. branch alpha_for_each_sqrt

$ for seed in 40 41 42 43 44; do ./Alpha_complex_1d_benchmark 5000000 $seed; done
... create simplex tree from alpha complex: 8.494s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.499s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 8.099s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.496s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 8.345s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.529s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 8.157s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.468s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... create simplex tree from alpha complex: 8.15s
Alpha complex is of dimension 1 - 9999999 simplices - 5000000 vertices.
... simplex tree assign MEB: 2.391s
Delaunay-Cech complex is of dimension 1 - 9999999 simplices - 5000000 vertices.