summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-05-23 09:52:24 +0200
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-05-23 09:52:24 +0200
commit50b460f867b5801ce3459d60fb86b02051eb4a7d (patch)
tree502afa1479cb6d243f3d978ed1d3147c14f96f9f /src
parent28a6889dc9865c75acc3d3be4edce01b3942e56f (diff)
Delaunay complex and tests all possibilities
Diffstat (limited to 'src')
-rw-r--r--src/python/gudhi/alpha_complex.pyx22
-rw-r--r--src/python/include/Alpha_complex_interface.h5
-rwxr-xr-xsrc/python/test/test_alpha_complex.py75
3 files changed, 82 insertions, 20 deletions
diff --git a/src/python/gudhi/alpha_complex.pyx b/src/python/gudhi/alpha_complex.pyx
index e2d3db9c..700fa738 100644
--- a/src/python/gudhi/alpha_complex.pyx
+++ b/src/python/gudhi/alpha_complex.pyx
@@ -31,7 +31,7 @@ cdef extern from "Alpha_complex_interface.h" namespace "Gudhi":
# bool from_file is a workaround for cython to find the correct signature
Alpha_complex_exact_interface(string off_file, bool from_file) nogil except +
vector[double] get_point(int vertex) nogil except +
- void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square) nogil except +
+ void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square, bool exact_version, bool default_filtration_value) nogil except +
cdef extern from "Alpha_complex_interface.h" namespace "Gudhi":
cdef cppclass Alpha_complex_inexact_interface "Gudhi::alpha_complex::Alpha_complex_interface<Gudhi::alpha_complex::Inexact_kernel>":
@@ -39,7 +39,7 @@ cdef extern from "Alpha_complex_interface.h" namespace "Gudhi":
# bool from_file is a workaround for cython to find the correct signature
Alpha_complex_inexact_interface(string off_file, bool from_file) nogil except +
vector[double] get_point(int vertex) nogil except +
- void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square) nogil except +
+ void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square, bool exact_version, bool default_filtration_value) nogil except +
# AlphaComplex python interface
cdef class AlphaComplex:
@@ -138,23 +138,27 @@ cdef class AlphaComplex:
else:
return self.exact_ptr.get_point(vertex)
- def create_simplex_tree(self, max_alpha_square = float('inf')):
+ def create_simplex_tree(self, max_alpha_square = float('inf'), default_filtration_value = False):
"""
- :param max_alpha_square: The maximum alpha square threshold the
- simplices shall not exceed. Default is set to infinity, and
- there is very little point using anything else since it does
- not save time.
+ :param max_alpha_square: The maximum alpha square threshold the simplices shall not exceed. Default is set to
+ infinity, and there is very little point using anything else since it does not save time.
:type max_alpha_square: float
+ :param default_filtration_value: Set this value to `True` if filtration values are not needed to be computed
+ (will be set to `NaN`). Default value is `False` (which means compute the filtration values).
+ :type default_filtration_value: bool
:returns: A simplex tree created from the Delaunay Triangulation.
:rtype: SimplexTree
"""
stree = SimplexTree()
cdef double mas = max_alpha_square
cdef intptr_t stree_int_ptr=stree.thisptr
+ cdef bool compute_filtration = default_filtration_value == True
if self.fast:
with nogil:
- self.inexact_ptr.create_simplex_tree(<Simplex_tree_interface_full_featured*>stree_int_ptr, mas)
+ self.inexact_ptr.create_simplex_tree(<Simplex_tree_interface_full_featured*>stree_int_ptr,
+ mas, False, compute_filtration)
else:
with nogil:
- self.exact_ptr.create_simplex_tree(<Simplex_tree_interface_full_featured*>stree_int_ptr, mas)
+ self.exact_ptr.create_simplex_tree(<Simplex_tree_interface_full_featured*>stree_int_ptr,
+ mas, self.exact, compute_filtration)
return stree
diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h
index 5fb694cd..3dd01345 100644
--- a/src/python/include/Alpha_complex_interface.h
+++ b/src/python/include/Alpha_complex_interface.h
@@ -56,8 +56,9 @@ class Alpha_complex_interface {
return vd;
}
- void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square) {
- alpha_complex_->create_complex(*simplex_tree, max_alpha_square);
+ void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
+ bool exact_version, bool default_filtration_value) {
+ alpha_complex_->create_complex(*simplex_tree, max_alpha_square, exact_version, default_filtration_value);
}
private:
diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py
index 77121302..913397dd 100755
--- a/src/python/test/test_alpha_complex.py
+++ b/src/python/test/test_alpha_complex.py
@@ -24,14 +24,18 @@ __copyright__ = "Copyright (C) 2016 Inria"
__license__ = "MIT"
-def test_empty_alpha():
- alpha_complex = AlphaComplex(points=[[0, 0]])
+def _empty_alpha(complexity):
+ alpha_complex = AlphaComplex(points=[[0, 0]], complexity = complexity)
assert alpha_complex.__is_defined() == True
+def test_empty_alpha():
+ _empty_alpha('fast')
+ _empty_alpha('safe')
+ _empty_alpha('exact')
-def test_infinite_alpha():
+def _infinite_alpha(complexity):
point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
- alpha_complex = AlphaComplex(points=point_list)
+ alpha_complex = AlphaComplex(points=point_list, complexity = complexity)
assert alpha_complex.__is_defined() == True
simplex_tree = alpha_complex.create_simplex_tree()
@@ -79,10 +83,14 @@ def test_infinite_alpha():
else:
assert False
+def test_infinite_alpha():
+ _infinite_alpha('fast')
+ _infinite_alpha('safe')
+ _infinite_alpha('exact')
-def test_filtered_alpha():
+def _filtered_alpha(complexity):
point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
- filtered_alpha = AlphaComplex(points=point_list)
+ filtered_alpha = AlphaComplex(points=point_list, complexity = complexity)
simplex_tree = filtered_alpha.create_simplex_tree(max_alpha_square=0.25)
@@ -119,7 +127,12 @@ def test_filtered_alpha():
assert simplex_tree.get_star([0]) == [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)]
assert simplex_tree.get_cofaces([0], 1) == [([0, 1], 0.25), ([0, 2], 0.25)]
-def test_safe_alpha_persistence_comparison():
+def test_filtered_alpha():
+ _filtered_alpha('fast')
+ _filtered_alpha('safe')
+ _filtered_alpha('exact')
+
+def _safe_alpha_persistence_comparison(complexity):
#generate periodic signal
time = np.arange(0, 10, 1)
signal = [math.sin(x) for x in time]
@@ -131,10 +144,10 @@ def test_safe_alpha_persistence_comparison():
embedding2 = [[signal[i], delayed[i]] for i in range(len(time))]
#build alpha complex and simplex tree
- alpha_complex1 = AlphaComplex(points=embedding1)
+ alpha_complex1 = AlphaComplex(points=embedding1, complexity = complexity)
simplex_tree1 = alpha_complex1.create_simplex_tree()
- alpha_complex2 = AlphaComplex(points=embedding2)
+ alpha_complex2 = AlphaComplex(points=embedding2, complexity = complexity)
simplex_tree2 = alpha_complex2.create_simplex_tree()
diag1 = simplex_tree1.persistence()
@@ -143,3 +156,47 @@ def test_safe_alpha_persistence_comparison():
for (first_p, second_p) in zip_longest(diag1, diag2):
assert first_p[0] == pytest.approx(second_p[0])
assert first_p[1] == pytest.approx(second_p[1])
+
+
+def test_safe_alpha_persistence_comparison():
+ # Won't work for 'fast' version
+ _safe_alpha_persistence_comparison('safe')
+ _safe_alpha_persistence_comparison('exact')
+
+def _delaunay_complex(complexity):
+ point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
+ filtered_alpha = AlphaComplex(points=point_list, complexity = complexity)
+
+ simplex_tree = filtered_alpha.create_simplex_tree(default_filtration_value = True)
+
+ assert simplex_tree.num_simplices() == 11
+ assert simplex_tree.num_vertices() == 4
+
+ assert point_list[0] == filtered_alpha.get_point(0)
+ assert point_list[1] == filtered_alpha.get_point(1)
+ assert point_list[2] == filtered_alpha.get_point(2)
+ assert point_list[3] == filtered_alpha.get_point(3)
+ try:
+ filtered_alpha.get_point(4) == []
+ except IndexError:
+ pass
+ else:
+ assert False
+ try:
+ filtered_alpha.get_point(125) == []
+ except IndexError:
+ pass
+ else:
+ assert False
+
+ for filtered_value in simplex_tree.get_filtration():
+ assert math.isnan(filtered_value[1])
+ for filtered_value in simplex_tree.get_star([0]):
+ assert math.isnan(filtered_value[1])
+ for filtered_value in simplex_tree.get_cofaces([0], 1):
+ assert math.isnan(filtered_value[1])
+
+def test_delaunay_complex():
+ _delaunay_complex('fast')
+ _delaunay_complex('safe')
+ _delaunay_complex('exact')