-
Notifications
You must be signed in to change notification settings - Fork 172
/
witness_complex_interface.py
53 lines (45 loc) · 1.85 KB
/
witness_complex_interface.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
from ..modules.gtda_witness_complex \
import Witness_complex_interface
from . import SimplexTree
# WitnessComplex python interface
class WitnessComplex:
"""Constructs (weak) witness complex for a given table of nearest landmarks
with respect to witnesses.
"""
def __init__(self, nearest_landmark_table=None):
"""WitnessComplex constructor.
:param nearest_landmark_table: A list of lists of nearest landmarks and
their distances. `nearest_landmark_table[w][k]==(l,d)` means that l is
the k-th nearest landmark to witness w, and d is the (squared) distance
between l and w.
:type nearest_landmark_table: list of list of pair of int and float
"""
self.thisptr = None
if nearest_landmark_table is not None:
self.thisptr = Witness_complex_interface(nearest_landmark_table)
def __del__(self):
if self.thisptr is not None:
del self.thisptr
def __is_defined(self):
"""Returns true if WitnessComplex pointer is not NULL.
"""
if self.thisptr is not None:
return True
return False
def create_simplex_tree(self, max_alpha_square=float('inf'),
limit_dimension=-1):
"""
:param max_alpha_square: The maximum relaxation parameter.
Default is set to infinity.
:type max_alpha_square: float
:returns: A simplex tree created from the Delaunay Triangulation.
:rtype: SimplexTree
"""
stree = SimplexTree()
stree_int_ptr = stree.thisptr
if limit_dimension != -1:
self.thisptr.create_simplex_tree(stree_int_ptr, max_alpha_square,
limit_dimension)
else:
self.thisptr.create_simplex_tree(stree_int_ptr, max_alpha_square)
return stree