summaryrefslogtreecommitdiff
path: root/src/python/test
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/python/test
parent28a6889dc9865c75acc3d3be4edce01b3942e56f (diff)
Delaunay complex and tests all possibilities
Diffstat (limited to 'src/python/test')
-rwxr-xr-xsrc/python/test/test_alpha_complex.py75
1 files changed, 66 insertions, 9 deletions
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')