|
2 | 2 | Tools for working with exact and approximate persistence landscapes.
|
3 | 3 | """
|
4 | 4 |
|
5 |
| -import itertools |
6 | 5 | import numpy as np
|
7 | 6 | from operator import itemgetter, attrgetter
|
8 | 7 |
|
9 | 8 | from .approximate import PersLandscapeApprox
|
10 | 9 | from .exact import PersLandscapeExact
|
11 | 10 |
|
12 | 11 | __all__ = [
|
| 12 | + "death_vector", |
13 | 13 | "vectorize",
|
14 |
| - "snap_PL", |
| 14 | + "snap_pl", |
15 | 15 | "lc_approx",
|
16 | 16 | "average_approx",
|
17 | 17 | ]
|
18 | 18 |
|
19 | 19 |
|
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( |
21 | 44 | pls: list, start: float = None, stop: float = None, num_steps: int = None
|
22 | 45 | ) -> list:
|
23 | 46 | """Snap a list of PersLandscapeApprox tpes to a common grid
|
@@ -71,7 +94,7 @@ def lc_approx(
|
71 | 94 | """Compute the linear combination of a list of PersLandscapeApprox objects.
|
72 | 95 |
|
73 | 96 | 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. |
75 | 98 |
|
76 | 99 | Parameters
|
77 | 100 | -------
|
@@ -100,7 +123,7 @@ def lc_approx(
|
100 | 123 | in `landscapes`
|
101 | 124 |
|
102 | 125 | """
|
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) |
104 | 127 | return np.sum(np.array(coeffs) * np.array(pl))
|
105 | 128 |
|
106 | 129 |
|
|
0 commit comments