persim 0.4.0__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. {persim-0.4.0/persim.egg-info → persim-0.4.2}/PKG-INFO +1 -1
  2. {persim-0.4.0 → persim-0.4.2}/RELEASE.txt +6 -0
  3. persim-0.4.2/persim/_version.py +1 -0
  4. {persim-0.4.0 → persim-0.4.2}/persim/landscapes/auxiliary.py +6 -9
  5. {persim-0.4.0 → persim-0.4.2}/persim/landscapes/exact.py +4 -8
  6. {persim-0.4.0 → persim-0.4.2/persim.egg-info}/PKG-INFO +1 -1
  7. {persim-0.4.0 → persim-0.4.2}/test/test_landscapes.py +49 -4
  8. persim-0.4.0/persim/_version.py +0 -1
  9. {persim-0.4.0 → persim-0.4.2}/LICENSE.txt +0 -0
  10. {persim-0.4.0 → persim-0.4.2}/MANIFEST.in +0 -0
  11. {persim-0.4.0 → persim-0.4.2}/README.md +0 -0
  12. {persim-0.4.0 → persim-0.4.2}/persim/__init__.py +0 -0
  13. {persim-0.4.0 → persim-0.4.2}/persim/bottleneck.py +0 -0
  14. {persim-0.4.0 → persim-0.4.2}/persim/gromov_hausdorff.py +0 -0
  15. {persim-0.4.0 → persim-0.4.2}/persim/heat.py +0 -0
  16. {persim-0.4.0 → persim-0.4.2}/persim/images.py +0 -0
  17. {persim-0.4.0 → persim-0.4.2}/persim/images_kernels.py +0 -0
  18. {persim-0.4.0 → persim-0.4.2}/persim/images_weights.py +0 -0
  19. {persim-0.4.0 → persim-0.4.2}/persim/landscapes/__init__.py +0 -0
  20. {persim-0.4.0 → persim-0.4.2}/persim/landscapes/approximate.py +0 -0
  21. {persim-0.4.0 → persim-0.4.2}/persim/landscapes/base.py +0 -0
  22. {persim-0.4.0 → persim-0.4.2}/persim/landscapes/tools.py +0 -0
  23. {persim-0.4.0 → persim-0.4.2}/persim/landscapes/transformer.py +0 -0
  24. {persim-0.4.0 → persim-0.4.2}/persim/landscapes/visuals.py +0 -0
  25. {persim-0.4.0 → persim-0.4.2}/persim/persistent_entropy.py +0 -0
  26. {persim-0.4.0 → persim-0.4.2}/persim/sliced_wasserstein.py +0 -0
  27. {persim-0.4.0 → persim-0.4.2}/persim/visuals.py +0 -0
  28. {persim-0.4.0 → persim-0.4.2}/persim/wasserstein.py +0 -0
  29. {persim-0.4.0 → persim-0.4.2}/persim.egg-info/SOURCES.txt +0 -0
  30. {persim-0.4.0 → persim-0.4.2}/persim.egg-info/dependency_links.txt +0 -0
  31. {persim-0.4.0 → persim-0.4.2}/persim.egg-info/requires.txt +0 -0
  32. {persim-0.4.0 → persim-0.4.2}/persim.egg-info/top_level.txt +0 -0
  33. {persim-0.4.0 → persim-0.4.2}/pyproject.toml +0 -0
  34. {persim-0.4.0 → persim-0.4.2}/setup.cfg +0 -0
  35. {persim-0.4.0 → persim-0.4.2}/setup.py +0 -0
  36. {persim-0.4.0 → persim-0.4.2}/test/test_distances.py +0 -0
  37. {persim-0.4.0 → persim-0.4.2}/test/test_persim.py +0 -0
  38. {persim-0.4.0 → persim-0.4.2}/test/test_persistence_imager.py +0 -0
  39. {persim-0.4.0 → persim-0.4.2}/test/test_persistent_entropy.py +0 -0
  40. {persim-0.4.0 → persim-0.4.2}/test/test_visuals.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: persim
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Distances and representations of persistence diagrams
5
5
  Author-email: Nathaniel Saul <nat@riverasaul.com>, Chris Tralie <chris.tralie@gmail.com>, Francis Motta <francis.c.motta@gmail.com>, Michael Catanzaro <catanzaromj@pm.me>, Gabrielle Angeloro <gabrielleangeloro@gmail.com>, Calder Sheagren <caldersheagren@gmail.com>
6
6
  Maintainer-email: Nathaniel Saul <nat@riverasaul.com>, Chris Tralie <chris.tralie@gmail.com>, Michael Catanzaro <catanzaromj@pm.me>, Abraham Smith <abraham.smith@geomdata.com>
@@ -1,3 +1,9 @@
1
+ 0.4.2
2
+ - Keep duplicate diagram bars in the exact landscape sweep so later, nonduplicate features are not copied into deeper layers.
3
+
4
+ 0.4.1
5
+ - Correct Lp norms of signed persistence landscapes, including zero crossings and fractional p. Compute segment integrals from endpoint magnitudes to avoid coordinate-intercept cancellation.
6
+
1
7
  0.4.0
2
8
  - Replace the abandoned GPLv3 `hopcroftkarp` dependency with `scipy.sparse.csgraph.maximum_bipartite_matching` in bottleneck, Issue #106 (https://github.com/scikit-tda/persim/issues/106).
3
9
  - `bottleneck(..., matching=True)` may now return a different optimal matching where several exist! The distance returned is unchanged. A UserWarning is now emitted on `matching=True` noting this; one-time notice for the 0.4.x series, will be removed in 0.5.0.
@@ -0,0 +1 @@
1
+ __version__ = "0.4.2"
@@ -156,17 +156,14 @@ def _p_norm(p: float, critical_pairs: list = []):
156
156
  continue
157
157
  # slope is well-defined
158
158
  slope = (y1 - y0) / (x1 - x0)
159
- b = y0 - slope * x0
159
+ # Endpoint magnitudes avoid cancellation from the line intercept
160
+ # and keep fractional powers real on negative segments.
161
+ value0 = np.abs(y0) ** (p + 1)
162
+ value1 = np.abs(y1) ** (p + 1)
160
163
  # segment crosses the x-axis
161
164
  if (y0 < 0 and y1 > 0) or (y0 > 0 and y1 < 0):
162
- z = -b / slope
163
- ev_x1 = (slope * x1 + b) ** (p + 1) / (slope * (p + 1))
164
- ev_x0 = (slope * x0 + b) ** (p + 1) / (slope * (p + 1))
165
- ev_z = (slope * z + +b) ** (p + 1) / (slope * (p + 1))
166
- result += np.abs(ev_x1 + ev_x0 - 2 * ev_z)
165
+ result += (value0 + value1) / (np.abs(slope) * (p + 1))
167
166
  # segment does not cross the x-axis
168
167
  else:
169
- ev_x1 = (slope * x1 + b) ** (p + 1) / (slope * (p + 1))
170
- ev_x0 = (slope * x0 + b) ** (p + 1) / (slope * (p + 1))
171
- result += np.abs(ev_x1 - ev_x0)
168
+ result += np.abs((value1 - value0) / (slope * (p + 1)))
172
169
  return (result) ** (1.0 / p)
@@ -281,15 +281,12 @@ class PersLandscapeExact(PersLandscape):
281
281
  # outer brackets for start of L_k
282
282
  L.append([[-np.inf, 0], [b, 0], [(b + d) / 2, (d - b) / 2]])
283
283
 
284
- # check for duplicates of (b,d)
284
+ # Copy duplicate tents only if no later bar extends the landscape.
285
285
  duplicate = 0
286
-
287
- for j, itemj in enumerate(A):
288
- if itemj == [b, d]:
286
+ if A and A[0] == [b, d] and all(d >= item[1] for item in A):
287
+ while A and A[0] == [b, d]:
289
288
  duplicate += 1
290
- A.pop(j)
291
- else:
292
- break
289
+ A.pop(0)
293
290
 
294
291
  while L[landscape_idx][-1] != [np.inf, 0]:
295
292
  # if d is > = all remaining pairs, then end lambda
@@ -297,7 +294,6 @@ class PersLandscapeExact(PersLandscape):
297
294
  if all(d >= _[1] for _ in A):
298
295
  # add to end of L_k
299
296
  L[landscape_idx].extend([[d, 0], [np.inf, 0]])
300
- # for duplicates, add another copy of the last computed lambda
301
297
  for _ in range(duplicate):
302
298
  L.append(L[-1])
303
299
  landscape_idx += 1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: persim
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Distances and representations of persistence diagrams
5
5
  Author-email: Nathaniel Saul <nat@riverasaul.com>, Chris Tralie <chris.tralie@gmail.com>, Francis Motta <francis.c.motta@gmail.com>, Michael Catanzaro <catanzaromj@pm.me>, Gabrielle Angeloro <gabrielleangeloro@gmail.com>, Calder Sheagren <caldersheagren@gmail.com>
6
6
  Maintainer-email: Nathaniel Saul <nat@riverasaul.com>, Chris Tralie <chris.tralie@gmail.com>, Michael Catanzaro <catanzaromj@pm.me>, Abraham Smith <abraham.smith@geomdata.com>
@@ -13,6 +13,53 @@ from persim.landscapes import (
13
13
  )
14
14
 
15
15
 
16
+ @pytest.mark.parametrize("p", [1, 1.5, 2, 3, 4])
17
+ @pytest.mark.parametrize("approximate", [False, True])
18
+ def test_signed_landscape_norm(p, approximate):
19
+ if approximate:
20
+ landscape = PersLandscapeApprox(
21
+ start=0, stop=4, num_steps=5, values=np.array([[0.0, 1.0, -1.0, 1.0, 0.0]])
22
+ )
23
+ else:
24
+ landscape = PersLandscapeExact(
25
+ critical_pairs=[[[0, 0.0], [1, 1.0], [2, -1.0], [3, 1.0], [4, 0.0]]]
26
+ )
27
+ # Each unit-length segment integrates to 1 / (p + 1).
28
+ assert landscape.p_norm(p) == pytest.approx((4 / (p + 1)) ** (1 / p))
29
+
30
+
31
+ def test_landscape_norm_translation():
32
+ heights = [0.0, 1e-9, 0.0]
33
+ original = PersLandscapeExact(critical_pairs=[list(zip([0, 1, 2], heights))])
34
+ translated = PersLandscapeExact(
35
+ critical_pairs=[list(zip([2**40, 2**40 + 1, 2**40 + 2], heights))]
36
+ )
37
+ assert translated.p_norm(2) == pytest.approx(original.p_norm(2), rel=1e-14, abs=0)
38
+
39
+
40
+ def test_norm_of_landscape_difference():
41
+ first = PersLandscapeExact(dgms=[np.array([[0.0, 4.0]])])
42
+ second = PersLandscapeExact(dgms=[np.array([[1.0, 5.0]])])
43
+ assert (first - second).p_norm(2) == pytest.approx(np.sqrt(3))
44
+
45
+
46
+ @pytest.mark.parametrize("copies", [2, 3, 4])
47
+ @pytest.mark.parametrize("other", [(3, 5), (2, 4), (1, 4), (0, 3), (0.5, 1.5), (-1, 2)])
48
+ def test_duplicate_bars_against_sorted_tents(copies, other):
49
+ diagram = np.array([[0, 2]] * copies + [other], dtype=float)
50
+ landscape = PersLandscapeExact(dgms=[diagram])
51
+ grid = np.linspace(-1, 5, 49)
52
+ tents = np.maximum(
53
+ np.minimum(grid[:, None] - diagram[:, 0], diagram[:, 1] - grid[:, None]), 0
54
+ )
55
+ expected = np.sort(tents, axis=1)[:, ::-1]
56
+ actual = np.zeros_like(expected)
57
+ for depth, pairs in enumerate(landscape.critical_pairs):
58
+ points = np.array(pairs)
59
+ actual[:, depth] = np.interp(grid, points[:, 0], points[:, 1], left=0, right=0)
60
+ np.testing.assert_allclose(actual, expected, atol=0, rtol=0)
61
+
62
+
16
63
  class TestPersLandscapeExact:
17
64
  def test_exact_empty(self):
18
65
  with pytest.raises(ValueError):
@@ -63,7 +110,7 @@ class TestPersLandscapeExact:
63
110
 
64
111
  expected_Q_pairs = [
65
112
  [[1, 0], [3.0, 2.0], [4.0, 1.0], [4.5, 1.5], [6, 0]],
66
- [[1, 0], [3.0, 2.0], [4.0, 1.0], [4.5, 1.5], [6, 0]],
113
+ [[1, 0], [3.0, 2.0], [5, 0]],
67
114
  [[3, 0], [4.0, 1.0], [5, 0]],
68
115
  ]
69
116
  assert len(Q.critical_pairs) == len(expected_Q_pairs)
@@ -113,9 +160,7 @@ class TestPersLandscapeExact:
113
160
 
114
161
  def test_exact_get_item(self):
115
162
  P = PersLandscapeExact(dgms=[np.array([[1, 5], [1, 5], [3, 6]])])
116
- np.testing.assert_array_equal(
117
- P[1], [[1, 0], [3, 2], [4, 1], [4.5, 1.5], [6, 0]]
118
- )
163
+ np.testing.assert_array_equal(P[1], [[1, 0], [3, 2], [5, 0]])
119
164
  with pytest.raises(IndexError):
120
165
  P[3]
121
166
 
@@ -1 +0,0 @@
1
- __version__ = "0.4.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes