persim 0.4.2__tar.gz → 0.4.3__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.2/persim.egg-info → persim-0.4.3}/PKG-INFO +1 -1
  2. {persim-0.4.2 → persim-0.4.3}/RELEASE.txt +3 -0
  3. persim-0.4.3/persim/_version.py +1 -0
  4. {persim-0.4.2 → persim-0.4.3}/persim/images.py +33 -30
  5. {persim-0.4.2 → persim-0.4.3/persim.egg-info}/PKG-INFO +1 -1
  6. {persim-0.4.2 → persim-0.4.3}/test/test_persistence_imager.py +73 -0
  7. persim-0.4.2/persim/_version.py +0 -1
  8. {persim-0.4.2 → persim-0.4.3}/LICENSE.txt +0 -0
  9. {persim-0.4.2 → persim-0.4.3}/MANIFEST.in +0 -0
  10. {persim-0.4.2 → persim-0.4.3}/README.md +0 -0
  11. {persim-0.4.2 → persim-0.4.3}/persim/__init__.py +0 -0
  12. {persim-0.4.2 → persim-0.4.3}/persim/bottleneck.py +0 -0
  13. {persim-0.4.2 → persim-0.4.3}/persim/gromov_hausdorff.py +0 -0
  14. {persim-0.4.2 → persim-0.4.3}/persim/heat.py +0 -0
  15. {persim-0.4.2 → persim-0.4.3}/persim/images_kernels.py +0 -0
  16. {persim-0.4.2 → persim-0.4.3}/persim/images_weights.py +0 -0
  17. {persim-0.4.2 → persim-0.4.3}/persim/landscapes/__init__.py +0 -0
  18. {persim-0.4.2 → persim-0.4.3}/persim/landscapes/approximate.py +0 -0
  19. {persim-0.4.2 → persim-0.4.3}/persim/landscapes/auxiliary.py +0 -0
  20. {persim-0.4.2 → persim-0.4.3}/persim/landscapes/base.py +0 -0
  21. {persim-0.4.2 → persim-0.4.3}/persim/landscapes/exact.py +0 -0
  22. {persim-0.4.2 → persim-0.4.3}/persim/landscapes/tools.py +0 -0
  23. {persim-0.4.2 → persim-0.4.3}/persim/landscapes/transformer.py +0 -0
  24. {persim-0.4.2 → persim-0.4.3}/persim/landscapes/visuals.py +0 -0
  25. {persim-0.4.2 → persim-0.4.3}/persim/persistent_entropy.py +0 -0
  26. {persim-0.4.2 → persim-0.4.3}/persim/sliced_wasserstein.py +0 -0
  27. {persim-0.4.2 → persim-0.4.3}/persim/visuals.py +0 -0
  28. {persim-0.4.2 → persim-0.4.3}/persim/wasserstein.py +0 -0
  29. {persim-0.4.2 → persim-0.4.3}/persim.egg-info/SOURCES.txt +0 -0
  30. {persim-0.4.2 → persim-0.4.3}/persim.egg-info/dependency_links.txt +0 -0
  31. {persim-0.4.2 → persim-0.4.3}/persim.egg-info/requires.txt +0 -0
  32. {persim-0.4.2 → persim-0.4.3}/persim.egg-info/top_level.txt +0 -0
  33. {persim-0.4.2 → persim-0.4.3}/pyproject.toml +0 -0
  34. {persim-0.4.2 → persim-0.4.3}/setup.cfg +0 -0
  35. {persim-0.4.2 → persim-0.4.3}/setup.py +0 -0
  36. {persim-0.4.2 → persim-0.4.3}/test/test_distances.py +0 -0
  37. {persim-0.4.2 → persim-0.4.3}/test/test_landscapes.py +0 -0
  38. {persim-0.4.2 → persim-0.4.3}/test/test_persim.py +0 -0
  39. {persim-0.4.2 → persim-0.4.3}/test/test_persistent_entropy.py +0 -0
  40. {persim-0.4.2 → persim-0.4.3}/test/test_visuals.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: persim
3
- Version: 0.4.2
3
+ Version: 0.4.3
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,6 @@
1
+ 0.4.3
2
+ - Preserve integer persistence-image pixel counts and pad constructor ranges consistently with parameter updates. Correct roundoff in the range subtraction and division against the actual covered width. Reassigning an unchanged grid parameter keeps the grid unchanged.
3
+
1
4
  0.4.2
2
5
  - Keep duplicate diagram bars in the exact landscape sweep so later, nonduplicate features are not copied into deeper layers.
3
6
 
@@ -0,0 +1 @@
1
+ __version__ = "0.4.3"
@@ -17,6 +17,18 @@ from persim import images_kernels, images_weights
17
17
  __all__ = ["PersImage", "PersistenceImager"]
18
18
 
19
19
 
20
+ def _pixel_count(bounds, pixel_size):
21
+ """Count covering pixels without rounding an exact multiple up."""
22
+ span = bounds[1] - bounds[0]
23
+ count = int(np.ceil(span / pixel_size))
24
+ # Roundoff in the subtraction or the division can add a pixel to a span that
25
+ # is a multiple of the pixel size, such as (0.9, 2.1) with pixel size 0.3.
26
+ tol = 1e-9 * max(abs(bounds[0]), abs(bounds[1]), pixel_size)
27
+ if count > 0 and (count - 1) * pixel_size >= span - tol:
28
+ return count - 1
29
+ return count
30
+
31
+
20
32
  @deprecated(
21
33
  reason="""Replaced with the class :class:`persim.PersistenceImager`.""",
22
34
  version="0.1.5",
@@ -345,12 +357,13 @@ class PersistenceImager(TransformerMixin):
345
357
  self._pixel_size = pixel_size
346
358
  self._birth_range = birth_range
347
359
  self._pers_range = pers_range
348
- self._width = birth_range[1] - birth_range[0]
349
- self._height = pers_range[1] - pers_range[0]
360
+ # Retain integer counts: dividing rounded widths can lose a pixel.
350
361
  self._resolution = (
351
- int(self._width / self._pixel_size),
352
- int(self._height / self._pixel_size),
362
+ _pixel_count(birth_range, pixel_size),
363
+ _pixel_count(pers_range, pixel_size),
353
364
  )
365
+ self._width = self._resolution[0] * pixel_size
366
+ self._height = self._resolution[1] * pixel_size
354
367
  self._create_mesh()
355
368
 
356
369
  @property
@@ -403,19 +416,15 @@ class PersistenceImager(TransformerMixin):
403
416
 
404
417
  @pixel_size.setter
405
418
  def pixel_size(self, val):
419
+ if val == self._pixel_size:
420
+ return
406
421
  self._pixel_size = val
407
- self._width = (
408
- int(np.ceil((self.birth_range[1] - self.birth_range[0]) / self.pixel_size))
409
- * self.pixel_size
410
- )
411
- self._height = (
412
- int(np.ceil((self.pers_range[1] - self.pers_range[0]) / self.pixel_size))
413
- * self.pixel_size
414
- )
415
422
  self._resolution = (
416
- int(self.width / self.pixel_size),
417
- int(self.height / self.pixel_size),
423
+ _pixel_count(self.birth_range, self.pixel_size),
424
+ _pixel_count(self.pers_range, self.pixel_size),
418
425
  )
426
+ self._width = self._resolution[0] * self.pixel_size
427
+ self._height = self._resolution[1] * self.pixel_size
419
428
  self._create_mesh()
420
429
 
421
430
  @property
@@ -432,15 +441,12 @@ class PersistenceImager(TransformerMixin):
432
441
 
433
442
  @birth_range.setter
434
443
  def birth_range(self, val):
444
+ if np.array_equal(val, self._birth_range):
445
+ return
435
446
  self._birth_range = val
436
- self._width = (
437
- int(np.ceil((self.birth_range[1] - self.birth_range[0]) / self.pixel_size))
438
- * self._pixel_size
439
- )
440
- self._resolution = (
441
- int(self.width / self.pixel_size),
442
- int(self.height / self.pixel_size),
443
- )
447
+ count = _pixel_count(self.birth_range, self.pixel_size)
448
+ self._width = count * self.pixel_size
449
+ self._resolution = (count, self.resolution[1])
444
450
  self._create_mesh()
445
451
 
446
452
  @property
@@ -457,15 +463,12 @@ class PersistenceImager(TransformerMixin):
457
463
 
458
464
  @pers_range.setter
459
465
  def pers_range(self, val):
466
+ if np.array_equal(val, self._pers_range):
467
+ return
460
468
  self._pers_range = val
461
- self._height = (
462
- int(np.ceil((self.pers_range[1] - self.pers_range[0]) / self.pixel_size))
463
- * self._pixel_size
464
- )
465
- self._resolution = (
466
- int(self.width / self.pixel_size),
467
- int(self.height / self.pixel_size),
468
- )
469
+ count = _pixel_count(self.pers_range, self.pixel_size)
470
+ self._height = count * self.pixel_size
471
+ self._resolution = (self.resolution[0], count)
469
472
  self._create_mesh()
470
473
 
471
474
  def __repr__(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: persim
3
- Version: 0.4.2
3
+ Version: 0.4.3
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,4 +1,5 @@
1
1
  import numpy as np
2
+ import pytest
2
3
 
3
4
  from persim import PersistenceImager, images_kernels, images_weights
4
5
 
@@ -7,6 +8,78 @@ from persim import PersistenceImager, images_kernels, images_weights
7
8
  # ----------------------------------------
8
9
 
9
10
 
11
+ @pytest.mark.parametrize(
12
+ "bounds,pixel_size,count",
13
+ [
14
+ ((0, 0.3), 0.1, 3),
15
+ ((0, 4.3), 0.1, 43),
16
+ ((0, 0.95), 0.2, 5),
17
+ ((0, 1.3), 0.3, 5),
18
+ ((0, 0.9), 0.3, 3),
19
+ ((0.9, 2.1), 0.3, 4),
20
+ ((-1.6, -1.5), 0.1, 1),
21
+ ((0.25, 1.15), 0.3, 3),
22
+ ((1.0, 5.3), 0.1, 43),
23
+ ((-0.95, 0.0), 0.2, 5),
24
+ ((-2.1, -0.9), 0.3, 4),
25
+ ],
26
+ )
27
+ @pytest.mark.parametrize("operation", ["constructor", "pixel_size", "birth_range", "pers_range"])
28
+ def test_pixel_grid_dimensions(bounds, pixel_size, count, operation):
29
+ if operation == "constructor":
30
+ imager = PersistenceImager(
31
+ birth_range=bounds, pers_range=bounds, pixel_size=pixel_size
32
+ )
33
+ expected = (count, count)
34
+ elif operation == "pixel_size":
35
+ imager = PersistenceImager(
36
+ birth_range=bounds, pers_range=bounds, pixel_size=bounds[1] - bounds[0]
37
+ )
38
+ imager.pixel_size = pixel_size
39
+ expected = (count, count)
40
+ else:
41
+ imager = PersistenceImager(
42
+ birth_range=(0, pixel_size),
43
+ pers_range=(0, pixel_size),
44
+ pixel_size=pixel_size,
45
+ )
46
+ setattr(imager, operation, bounds)
47
+ expected = (count, 1) if operation == "birth_range" else (1, count)
48
+
49
+ assert imager.resolution == expected
50
+ assert imager.transform(np.array([[0.1, 0.2]])).shape == expected
51
+ np.testing.assert_allclose(np.diff(imager._bpnts), pixel_size, rtol=1e-13)
52
+ np.testing.assert_allclose(np.diff(imager._ppnts), pixel_size, rtol=1e-13)
53
+ assert imager._bpnts[-1] == pytest.approx(imager.birth_range[1])
54
+ assert imager._ppnts[-1] == pytest.approx(imager.pers_range[1])
55
+
56
+
57
+ @pytest.mark.parametrize("attribute", ["pixel_size", "birth_range", "pers_range"])
58
+ def test_unchanged_grid_parameter(attribute):
59
+ imager = PersistenceImager(birth_range=(0, 0.3), pers_range=(0, 0.3), pixel_size=0.1)
60
+ before = (imager.resolution, imager.birth_range, imager.pers_range)
61
+ birth_points, persistence_points = imager._bpnts.copy(), imager._ppnts.copy()
62
+ setattr(imager, attribute, getattr(imager, attribute))
63
+ assert (imager.resolution, imager.birth_range, imager.pers_range) == before
64
+ np.testing.assert_array_equal(imager._bpnts, birth_points)
65
+ np.testing.assert_array_equal(imager._ppnts, persistence_points)
66
+
67
+
68
+ @pytest.mark.parametrize("pixel_size", [0.1, 0.2, 0.3, 0.05])
69
+ @pytest.mark.parametrize("operation", ["constructor", "pixel_size"])
70
+ def test_integer_pixel_multiple(pixel_size, operation):
71
+ width = 3 * pixel_size
72
+ imager = PersistenceImager(
73
+ birth_range=(0, width),
74
+ pers_range=(0, width),
75
+ pixel_size=pixel_size if operation == "constructor" else width,
76
+ )
77
+ if operation == "pixel_size":
78
+ imager.pixel_size = pixel_size
79
+ assert imager.resolution == (3, 3)
80
+ np.testing.assert_allclose(np.diff(imager._bpnts), pixel_size, rtol=1e-13)
81
+
82
+
10
83
  def test_empty_diagram():
11
84
  dgm = np.zeros((0, 2))
12
85
  persimgr = PersistenceImager(pixel_size=0.1)
@@ -1 +0,0 @@
1
- __version__ = "0.4.2"
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