summaryrefslogtreecommitdiff
path: root/src/python/test/test_alpha_complex.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/test/test_alpha_complex.py')
-rwxr-xr-xsrc/python/test/test_alpha_complex.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py
index 24f8bf53..0d9e9e45 100755
--- a/src/python/test/test_alpha_complex.py
+++ b/src/python/test/test_alpha_complex.py
@@ -1,5 +1,3 @@
-from gudhi import AlphaComplex, SimplexTree
-
""" 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.
Author(s): Vincent Rouvreau
@@ -10,6 +8,17 @@ from gudhi import AlphaComplex, SimplexTree
- YYYY/MM Author: Description of the modification
"""
+from gudhi import AlphaComplex, SimplexTree
+import math
+import numpy as np
+import pytest
+try:
+ # python3
+ from itertools import zip_longest
+except ImportError:
+ # python2
+ from itertools import izip_longest as zip_longest
+
__author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 Inria"
__license__ = "MIT"
@@ -88,3 +97,28 @@ 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():
+ #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()
+
+ alpha_complex2 = AlphaComplex(points=embedding2)
+ simplex_tree2 = alpha_complex2.create_simplex_tree()
+
+ diag1 = simplex_tree1.persistence()
+ diag2 = simplex_tree2.persistence()
+
+ 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])