multipers 1.1.3__cp311-cp311-macosx_11_0_universal2.whl

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.

Potentially problematic release.


This version of multipers might be problematic. Click here for more details.

Files changed (63) hide show
  1. multipers/.dylibs/libtbb.12.12.dylib +0 -0
  2. multipers/.dylibs/libtbbmalloc.2.12.dylib +0 -0
  3. multipers/__init__.py +5 -0
  4. multipers/_old_rank_invariant.pyx +328 -0
  5. multipers/_signed_measure_meta.py +193 -0
  6. multipers/data/MOL2.py +350 -0
  7. multipers/data/UCR.py +18 -0
  8. multipers/data/__init__.py +1 -0
  9. multipers/data/graphs.py +466 -0
  10. multipers/data/immuno_regions.py +27 -0
  11. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  12. multipers/data/pytorch2simplextree.py +91 -0
  13. multipers/data/shape3d.py +101 -0
  14. multipers/data/synthetic.py +68 -0
  15. multipers/distances.py +172 -0
  16. multipers/euler_characteristic.cpython-311-darwin.so +0 -0
  17. multipers/euler_characteristic.pyx +137 -0
  18. multipers/function_rips.cpython-311-darwin.so +0 -0
  19. multipers/function_rips.pyx +102 -0
  20. multipers/hilbert_function.cpython-311-darwin.so +0 -0
  21. multipers/hilbert_function.pyi +46 -0
  22. multipers/hilbert_function.pyx +151 -0
  23. multipers/io.cpython-311-darwin.so +0 -0
  24. multipers/io.pyx +176 -0
  25. multipers/ml/__init__.py +0 -0
  26. multipers/ml/accuracies.py +61 -0
  27. multipers/ml/convolutions.py +510 -0
  28. multipers/ml/invariants_with_persistable.py +79 -0
  29. multipers/ml/kernels.py +128 -0
  30. multipers/ml/mma.py +657 -0
  31. multipers/ml/one.py +472 -0
  32. multipers/ml/point_clouds.py +191 -0
  33. multipers/ml/signed_betti.py +50 -0
  34. multipers/ml/signed_measures.py +1479 -0
  35. multipers/ml/sliced_wasserstein.py +313 -0
  36. multipers/ml/tools.py +116 -0
  37. multipers/mma_structures.cpython-311-darwin.so +0 -0
  38. multipers/mma_structures.pxd +155 -0
  39. multipers/mma_structures.pyx +651 -0
  40. multipers/multiparameter_edge_collapse.py +29 -0
  41. multipers/multiparameter_module_approximation.cpython-311-darwin.so +0 -0
  42. multipers/multiparameter_module_approximation.pyi +439 -0
  43. multipers/multiparameter_module_approximation.pyx +311 -0
  44. multipers/pickle.py +53 -0
  45. multipers/plots.py +292 -0
  46. multipers/point_measure_integration.cpython-311-darwin.so +0 -0
  47. multipers/point_measure_integration.pyx +59 -0
  48. multipers/rank_invariant.cpython-311-darwin.so +0 -0
  49. multipers/rank_invariant.pyx +154 -0
  50. multipers/simplex_tree_multi.cpython-311-darwin.so +0 -0
  51. multipers/simplex_tree_multi.pxd +121 -0
  52. multipers/simplex_tree_multi.pyi +715 -0
  53. multipers/simplex_tree_multi.pyx +1417 -0
  54. multipers/slicer.cpython-311-darwin.so +0 -0
  55. multipers/slicer.pxd +94 -0
  56. multipers/slicer.pyx +276 -0
  57. multipers/tensor.pxd +13 -0
  58. multipers/test.pyx +44 -0
  59. multipers-1.1.3.dist-info/LICENSE +21 -0
  60. multipers-1.1.3.dist-info/METADATA +22 -0
  61. multipers-1.1.3.dist-info/RECORD +63 -0
  62. multipers-1.1.3.dist-info/WHEEL +5 -0
  63. multipers-1.1.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,128 @@
1
+ from sklearn.base import BaseEstimator, TransformerMixin, clone
2
+ import numpy as np
3
+ from typing import Iterable
4
+
5
+ ## To do k folds with a distance matrix, we need to slice it into list of distances.
6
+ # k-fold usually shuffles the lists, so we need to add an identifier to each entry,
7
+ #
8
+ class DistanceMatrix2DistanceList(BaseEstimator, TransformerMixin):
9
+ def __init__(self) -> None:
10
+ super().__init__()
11
+ def fit(self, X, y=None):
12
+ return self
13
+ def transform(self,X):
14
+ X = np.asarray(X)
15
+ assert X.ndim == 2 ## Its a matrix
16
+ return np.asarray([[i, *distance_to_pt] for i,distance_to_pt in enumerate(X)])
17
+
18
+
19
+ class DistanceList2DistanceMatrix(BaseEstimator, TransformerMixin):
20
+ def __init__(self) -> None:
21
+ super().__init__()
22
+ def fit(self, X, y=None):
23
+ return self
24
+ def transform(self,X):
25
+ index_list = np.asarray(X[:,0], dtype=int) + 1 # shift of 1, because the first index is for indexing the pts
26
+ return X[:, index_list] ## The distance matrix of the index_list
27
+
28
+
29
+ class DistanceMatrices2DistancesList(BaseEstimator, TransformerMixin):
30
+ """
31
+ Input (degree) x (distance matrix) or (axis) x (degree) x (distance matrix D)
32
+ Output _ (D1) x opt (axis) x (degree) x (D2, , with indices first)
33
+ """
34
+ def __init__(self) -> None:
35
+ super().__init__()
36
+ self._axes=None
37
+ def fit(self, X, y=None):
38
+ X = np.asarray(X)
39
+ self._axes = X.ndim ==4
40
+ assert self._axes or X.ndim == 3, " Bad input shape. Input is either (degree) x (distance matrix) or (axis) x (degree) x (distance matrix) "
41
+
42
+ return self
43
+ def transform(self, X):
44
+ X = np.asarray(X)
45
+ assert (X.ndim == 3 and not self._axes) or (X.ndim == 4 and self._axes), f"X shape ({X.shape}) is not valid"
46
+ if self._axes:
47
+ out = np.asarray([[DistanceMatrix2DistanceList().fit_transform(M) for M in matrices_in_axes] for matrices_in_axes in X])
48
+ return np.moveaxis(out, [2,0,1,3], [0,1,2,3])
49
+ else:
50
+ out = np.array([DistanceMatrix2DistanceList().fit_transform(M) for M in X]) ## indices are at [:,0,Any_coord]
51
+ # return np.moveaxis(out, 0, -1) ## indices are at [:,0,any_coord], degree axis is the last
52
+ return np.moveaxis(out, [1,0,2], [0,1,2])
53
+
54
+
55
+ def predict(self,X):
56
+ return self.transform(X)
57
+
58
+ class DistancesLists2DistanceMatrices(BaseEstimator, TransformerMixin):
59
+ """
60
+ Input (D1) x opt (axis) x (degree) x (D2 with indices first)
61
+ Output opt (axis) x (degree) x (distance matrix (D1,D2))
62
+ """
63
+ def __init__(self) -> None:
64
+ super().__init__()
65
+ self.train_indices = None
66
+ self._axes = None
67
+ def fit(self, X:np.ndarray, y=None):
68
+ X = np.asarray(X)
69
+ assert X.ndim in [3,4]
70
+ self._axes = X.ndim == 4
71
+ if self._axes:
72
+ self.train_indices = np.asarray(X[:,0,0,0], dtype=int)
73
+ else:
74
+ self.train_indices = np.asarray(X[:,0,0], dtype=int)
75
+ return self
76
+ def transform(self,X):
77
+ X = np.asarray(X)
78
+ assert X.ndim in [3,4]
79
+ # test_indices = np.asarray(X[:,0,0], dtype=int)
80
+ # print(X.shape, self.train_indices, test_indices, flush=1)
81
+ # First coord of X is test indices by design, train indices have to be selected in the second coord, last one is the degree
82
+ if self._axes:
83
+ Y=X[:,:,:,self.train_indices+1]
84
+ return np.moveaxis(Y, [0,1,2,3], [2,0,1,3])
85
+ else:
86
+ Y = X[:,:,self.train_indices+1] ## we only keep the good indices # shift of 1, because the first index is for indexing the pts
87
+ return np.moveaxis(Y, [0,1,2], [1,0,2]) ## we put back the degree axis first
88
+
89
+ # # out = np.moveaxis(Y,-1,0) ## we put back the degree axis first
90
+ # return out
91
+
92
+
93
+
94
+ class DistanceMatrix2Kernel(BaseEstimator, TransformerMixin):
95
+ """
96
+ Input : (degree) x (distance matrix) or (axis) x (degree) x (distance matrix) in the second case, axis HAS to be specified (meant for cross validation)
97
+ Output : kernel of the same shape of distance matrix
98
+ """
99
+ def __init__(self, sigma:float|Iterable[float]=1, axis:int|None=None, weights:Iterable[float]|float=1) -> None:
100
+ super().__init__()
101
+ self.sigma = sigma
102
+ self.axis=axis
103
+ self.weights = weights
104
+ # self._num_axes=None
105
+ self._num_degrees = None
106
+ def fit(self, X, y=None):
107
+ if len(X) == 0: return self
108
+ assert X.ndim in [3,4], "Bad input."
109
+ if self.axis is None:
110
+ assert X.ndim ==3 or X.shape[0] == 1, "Set an axis for data with axis !"
111
+ if X.shape[0] == 1 and X.ndim == 4:
112
+ self.axis=0
113
+ self._num_degrees = len(X[0])
114
+ else:
115
+ self._num_degrees = len(X)
116
+ else:
117
+ assert X.ndim ==4, "Cannot choose axis from data with no axis !"
118
+ self._num_degrees = len(X[self.axis])
119
+ if isinstance(self.weights,float) or isinstance(self.weights,int): self.weights = [self.weights]*self._num_degrees
120
+ assert len(self.weights) == self._num_degrees, f"Number of weights ({len(self.weights)}) has to be the same as the number of degrees ({self._num_degrees})"
121
+ return self
122
+ def transform(self,X)->np.ndarray:
123
+ if self.axis is not None:
124
+ X=X[self.axis]
125
+ kernels = np.asarray([np.exp(-distance_matrix / (2*self.sigma**2))*weight for distance_matrix, weight in zip(X, self.weights)])
126
+ out = np.mean(kernels, axis=0)
127
+
128
+ return out