-
Notifications
You must be signed in to change notification settings - Fork 0
/
vietoris_rips_test.py
62 lines (50 loc) · 1.58 KB
/
vietoris_rips_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Unit tests for the Vietoris-Rips algorithm.
# Test 1
# Points:
# A(-1, 0), B(1, 0), C(0, 1)
# Illustration:
# .
# . .
#
# Test 2
# Points:
# A(0, -2), B(0, -1), C (0, 1), D(0, 2)
# Illustration:
# .
# .
#
# .
# .
from abstract_simplicial_complex import Point, Simplex, ASC, vietoris_rips
from metrics import induced_metric
import numpy as np
def test_1():
print("\nTest 1\n")
points = set([
Point(name='A', coordinates=np.array([-1, 0]), dist_metric=induced_metric),
Point(name='B', coordinates=np.array([+1, 0]), dist_metric=induced_metric),
Point(name='C', coordinates=np.array([ 0, +1]), dist_metric=induced_metric)
])
for max_diam in [0.5, 1.5, 2.5]:
rips_complex = vietoris_rips(points, len(points) - 1, max_diam)
print("Distance threshold of %.1f:\n" % max_diam)
print(rips_complex)
print()
print("\n")
def test_2():
print("\nTest 2\n")
points = set([
Point(name='A', coordinates=np.array([ 0, -2]), dist_metric=induced_metric),
Point(name='B', coordinates=np.array([ 0, -1]), dist_metric=induced_metric),
Point(name='C', coordinates=np.array([ 0, +1]), dist_metric=induced_metric),
Point(name='D', coordinates=np.array([ 0, +2]), dist_metric=induced_metric)
])
for max_diam in range(5):
rips_complex = vietoris_rips(points, len(points) - 1, max_diam)
print("Distance threshold of %.1f:\n" % max_diam)
print(rips_complex)
print()
print("\n")
if __name__ == '__main__':
test_1()
test_2()