Skip to content

Commit cae337c

Browse files
committed
Refactor auxiliary and tools
Move `death_vector` into auxiliary, remove `linear_combination` since it is no longer needed, rename `snap_PL` to `snap_pl`
1 parent d762468 commit cae337c

File tree

3 files changed

+28
-54
lines changed

3 files changed

+28
-54
lines changed

persim/landscapes/auxiliary.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,6 @@
66
import numpy as np
77

88

9-
__all__ = [
10-
"death_vector",
11-
"linear_combination",
12-
]
13-
14-
15-
def death_vector(dgms: list, hom_deg: int = 0):
16-
"""Returns the death vector in degree 0 for the persistence diagram
17-
18-
For Vietoris-Rips or Cech complexes, or any similar filtration, all bars in
19-
homological degree 0 start at filtration value 0. Therefore, the discerning
20-
information is the death values. The death vector is the vector of death times,
21-
sorted from largest to smallest.
22-
23-
Parameters
24-
----------
25-
dgms : list of persistence diagrams
26-
27-
hom_deg : int specifying the homological degree
28-
29-
"""
30-
if hom_deg != 0:
31-
raise NotImplementedError(
32-
"The death vector is not defined for "
33-
"homological degrees greater than zero."
34-
)
35-
return sorted(dgms[hom_deg][:, 1], reverse=True)
36-
37-
38-
def linear_combination(landscapes: list, coeffs: list):
39-
"""Compute a linear combination of landscapes
40-
Parameters
41-
----------
42-
landscapes : list of PersistenceLandscape objects
43-
44-
coeffs : list, optional
45-
46-
Returns
47-
-------
48-
None.
49-
"""
50-
result = coeffs[0] * landscapes[0]
51-
for c, L in enumerate(landscapes):
52-
result += coeffs[c] * L
53-
return result
54-
55-
569
def union_vals(A, B):
5710
"""Helper function for summing grid landscapes.
5811

persim/landscapes/tools.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,45 @@
22
Tools for working with exact and approximate persistence landscapes.
33
"""
44

5-
import itertools
65
import numpy as np
76
from operator import itemgetter, attrgetter
87

98
from .approximate import PersLandscapeApprox
109
from .exact import PersLandscapeExact
1110

1211
__all__ = [
12+
"death_vector",
1313
"vectorize",
14-
"snap_PL",
14+
"snap_pl",
1515
"lc_approx",
1616
"average_approx",
1717
]
1818

1919

20-
def snap_PL(
20+
def death_vector(dgms: list, hom_deg: int = 0):
21+
"""Returns the death vector in degree 0 for the persistence diagram
22+
23+
For Vietoris-Rips or Cech complexes, or any similar filtration, all bars in
24+
homological degree 0 start at filtration value 0. Therefore, the discerning
25+
information is the death values. The death vector is the vector of death times,
26+
sorted from largest to smallest.
27+
28+
Parameters
29+
----------
30+
dgms : list of persistence diagrams
31+
32+
hom_deg : int specifying the homological degree
33+
34+
"""
35+
if hom_deg != 0:
36+
raise NotImplementedError(
37+
"The death vector is not defined for "
38+
"homological degrees greater than zero."
39+
)
40+
return sorted(dgms[hom_deg][:, 1], reverse=True)
41+
42+
43+
def snap_pl(
2144
pls: list, start: float = None, stop: float = None, num_steps: int = None
2245
) -> list:
2346
"""Snap a list of PersLandscapeApprox tpes to a common grid
@@ -71,7 +94,7 @@ def lc_approx(
7194
"""Compute the linear combination of a list of PersLandscapeApprox objects.
7295
7396
This uses vectorized arithmetic from numpy, so it should be faster and
74-
more memory efficient than a naive for-loop.
97+
more memory efficient than a standard for-loop.
7598
7699
Parameters
77100
-------
@@ -100,7 +123,7 @@ def lc_approx(
100123
in `landscapes`
101124
102125
"""
103-
pl = snap_PL(landscapes, start=start, stop=stop, num_steps=num_steps)
126+
pl = snap_pl(landscapes, start=start, stop=stop, num_steps=num_steps)
104127
return np.sum(np.array(coeffs) * np.array(pl))
105128

106129

persim/landscapes/transformer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
landscapes.
44
"""
55
from operator import itemgetter
6-
import numpy as np
76
from sklearn.base import BaseEstimator, TransformerMixin
87

98
from .approximate import PersLandscapeApprox
10-
from .exact import PersLandscapeExact
119

1210

1311
__all__ = ["PersistenceLandscaper"]

0 commit comments

Comments
 (0)