summaryrefslogtreecommitdiff
path: root/src/python/test/test_alpha_complex.py
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2019-12-05 17:05:19 +0100
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2019-12-05 17:05:19 +0100
commit3757fedbf7ad387cdc06870a1db9532bbee4bab9 (patch)
treebd816f6ea18d414d91739030e3d90081fb85196e /src/python/test/test_alpha_complex.py
parent9fc45aafa4588b86ccd903b9173a8cdf48db68a1 (diff)
Add a test that fixes #107
Diffstat (limited to 'src/python/test/test_alpha_complex.py')
-rwxr-xr-xsrc/python/test/test_alpha_complex.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py
index 24f8bf53..ab84daaa 100755
--- a/src/python/test/test_alpha_complex.py
+++ b/src/python/test/test_alpha_complex.py
@@ -1,4 +1,8 @@
from gudhi import AlphaComplex, SimplexTree
+import math
+import numpy as np
+import itertools
+import pytest
""" This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
@@ -88,3 +92,34 @@ 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 alpha_persistence_comparison(exact_version):
+ #generate periodic signal
+ time = np.arange(0, 10, 1)
+ signal = [math.sin(x) for x in time]
+ delta = math.pi
+ delayed = [math.sin(x + delta) for x in time]
+
+ #construct embedding
+ embedding1 = [[signal[i], -signal[i]] for i in range(len(time))]
+ embedding2 = [[signal[i], delayed[i]] for i in range(len(time))]
+
+ #build alpha complex and simplex tree
+ alpha_complex1 = AlphaComplex(points=embedding1)
+ simplex_tree1 = alpha_complex1.create_simplex_tree(exact_version = exact_version)
+
+ alpha_complex2 = AlphaComplex(points=embedding2)
+ simplex_tree2 = alpha_complex2.create_simplex_tree(exact_version = exact_version)
+
+ diag1 = simplex_tree1.persistence()
+ diag2 = simplex_tree2.persistence()
+
+ for (first_p, second_p) in itertools.zip_longest(diag1, diag2):
+ assert first_p[0] == pytest.approx(second_p[0])
+ assert first_p[1] == pytest.approx(second_p[1])
+
+def test_exact_alpha_version():
+ alpha_persistence_comparison(exact_version = True)
+
+def test_safe_alpha_version():
+ alpha_persistence_comparison(exact_version = False)