multipers 1.1.3__cp310-cp310-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.
- multipers/.dylibs/libtbb.12.12.dylib +0 -0
- multipers/.dylibs/libtbbmalloc.2.12.dylib +0 -0
- multipers/__init__.py +5 -0
- multipers/_old_rank_invariant.pyx +328 -0
- multipers/_signed_measure_meta.py +193 -0
- multipers/data/MOL2.py +350 -0
- multipers/data/UCR.py +18 -0
- multipers/data/__init__.py +1 -0
- multipers/data/graphs.py +466 -0
- multipers/data/immuno_regions.py +27 -0
- multipers/data/minimal_presentation_to_st_bf.py +0 -0
- multipers/data/pytorch2simplextree.py +91 -0
- multipers/data/shape3d.py +101 -0
- multipers/data/synthetic.py +68 -0
- multipers/distances.py +172 -0
- multipers/euler_characteristic.cpython-310-darwin.so +0 -0
- multipers/euler_characteristic.pyx +137 -0
- multipers/function_rips.cpython-310-darwin.so +0 -0
- multipers/function_rips.pyx +102 -0
- multipers/hilbert_function.cpython-310-darwin.so +0 -0
- multipers/hilbert_function.pyi +46 -0
- multipers/hilbert_function.pyx +151 -0
- multipers/io.cpython-310-darwin.so +0 -0
- multipers/io.pyx +176 -0
- multipers/ml/__init__.py +0 -0
- multipers/ml/accuracies.py +61 -0
- multipers/ml/convolutions.py +510 -0
- multipers/ml/invariants_with_persistable.py +79 -0
- multipers/ml/kernels.py +128 -0
- multipers/ml/mma.py +657 -0
- multipers/ml/one.py +472 -0
- multipers/ml/point_clouds.py +191 -0
- multipers/ml/signed_betti.py +50 -0
- multipers/ml/signed_measures.py +1479 -0
- multipers/ml/sliced_wasserstein.py +313 -0
- multipers/ml/tools.py +116 -0
- multipers/mma_structures.cpython-310-darwin.so +0 -0
- multipers/mma_structures.pxd +155 -0
- multipers/mma_structures.pyx +651 -0
- multipers/multiparameter_edge_collapse.py +29 -0
- multipers/multiparameter_module_approximation.cpython-310-darwin.so +0 -0
- multipers/multiparameter_module_approximation.pyi +439 -0
- multipers/multiparameter_module_approximation.pyx +311 -0
- multipers/pickle.py +53 -0
- multipers/plots.py +292 -0
- multipers/point_measure_integration.cpython-310-darwin.so +0 -0
- multipers/point_measure_integration.pyx +59 -0
- multipers/rank_invariant.cpython-310-darwin.so +0 -0
- multipers/rank_invariant.pyx +154 -0
- multipers/simplex_tree_multi.cpython-310-darwin.so +0 -0
- multipers/simplex_tree_multi.pxd +121 -0
- multipers/simplex_tree_multi.pyi +715 -0
- multipers/simplex_tree_multi.pyx +1417 -0
- multipers/slicer.cpython-310-darwin.so +0 -0
- multipers/slicer.pxd +94 -0
- multipers/slicer.pyx +276 -0
- multipers/tensor.pxd +13 -0
- multipers/test.pyx +44 -0
- multipers-1.1.3.dist-info/LICENSE +21 -0
- multipers-1.1.3.dist-info/METADATA +22 -0
- multipers-1.1.3.dist-info/RECORD +63 -0
- multipers-1.1.3.dist-info/WHEEL +5 -0
- multipers-1.1.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
|
|
2
|
+
#########################################################################
|
|
3
|
+
## Small hack for typing
|
|
4
|
+
from multipers.simplex_tree_multi import SimplexTreeMulti
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PySummand:
|
|
9
|
+
"""
|
|
10
|
+
Stores a Summand of a PyModule
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_birth_list(self): # TODO: FIXME
|
|
15
|
+
...
|
|
16
|
+
def get_death_list(self):
|
|
17
|
+
...
|
|
18
|
+
@property
|
|
19
|
+
def num_parameters(self)->int:
|
|
20
|
+
...
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class PyBox:
|
|
24
|
+
@property
|
|
25
|
+
def num_parameters(self)->int:
|
|
26
|
+
...
|
|
27
|
+
def contains(self, x)->bool:
|
|
28
|
+
...
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get(self):
|
|
32
|
+
...
|
|
33
|
+
def to_multipers(self):
|
|
34
|
+
...
|
|
35
|
+
|
|
36
|
+
class PyMultiDiagramPoint:
|
|
37
|
+
def get_degree(self):
|
|
38
|
+
...
|
|
39
|
+
def get_birth(self):
|
|
40
|
+
...
|
|
41
|
+
def get_death(self):
|
|
42
|
+
...
|
|
43
|
+
|
|
44
|
+
class PyMultiDiagram:
|
|
45
|
+
"""
|
|
46
|
+
Stores the diagram of a PyModule on a line
|
|
47
|
+
"""
|
|
48
|
+
def get_points(self, degree:int=-1) -> np.ndarray:
|
|
49
|
+
...
|
|
50
|
+
def to_multipers(self, dimension:int):
|
|
51
|
+
...
|
|
52
|
+
def __len__(self) -> int:
|
|
53
|
+
...
|
|
54
|
+
def __getitem__(self,i:int) -> PyMultiDiagramPoint:
|
|
55
|
+
...
|
|
56
|
+
class PyMultiDiagrams:
|
|
57
|
+
"""
|
|
58
|
+
Stores the barcodes of a PyModule on multiple lines
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def to_multipers(self):
|
|
62
|
+
...
|
|
63
|
+
def __getitem__(self,i:int):
|
|
64
|
+
...
|
|
65
|
+
def __len__(self):
|
|
66
|
+
...
|
|
67
|
+
def get_points(self, degree:int=-1):
|
|
68
|
+
...
|
|
69
|
+
|
|
70
|
+
def plot(self, degree:int=-1, min_persistence:float=0):
|
|
71
|
+
"""
|
|
72
|
+
Plots the barcodes.
|
|
73
|
+
|
|
74
|
+
Parameters
|
|
75
|
+
----------
|
|
76
|
+
degree:int=-1
|
|
77
|
+
Only plots the bars of specified homology degree. Useful when the multidiagrams contains multiple dimenions
|
|
78
|
+
min_persistence:float=0
|
|
79
|
+
Only plot bars of length greater than this value. Useful to reduce the time to plot.
|
|
80
|
+
|
|
81
|
+
Warning
|
|
82
|
+
-------
|
|
83
|
+
If the barcodes are not thresholded, essential barcodes will not be displayed !
|
|
84
|
+
|
|
85
|
+
Returns
|
|
86
|
+
-------
|
|
87
|
+
Nothing
|
|
88
|
+
"""
|
|
89
|
+
...
|
|
90
|
+
|
|
91
|
+
class PyModule:
|
|
92
|
+
"""
|
|
93
|
+
Stores a representation of a n-persistence module.
|
|
94
|
+
"""
|
|
95
|
+
def get_module_of_dimension(self, degree:int)->PyModule: # TODO : in c++ ?
|
|
96
|
+
...
|
|
97
|
+
|
|
98
|
+
def __len__(self)->int:
|
|
99
|
+
...
|
|
100
|
+
def get_bottom(self):
|
|
101
|
+
...
|
|
102
|
+
def get_top(self):
|
|
103
|
+
...
|
|
104
|
+
def get_box(self):
|
|
105
|
+
...
|
|
106
|
+
@property
|
|
107
|
+
def num_parameters(self)->int:
|
|
108
|
+
...
|
|
109
|
+
def dump(self, path:str|None=None):
|
|
110
|
+
"""
|
|
111
|
+
Dumps the module into a pickle-able format.
|
|
112
|
+
|
|
113
|
+
Parameters
|
|
114
|
+
----------
|
|
115
|
+
path:str=None (optional) saves the pickled module in specified path
|
|
116
|
+
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
list of list, encoding the module, which can be retrieved with the function `from_dump`.
|
|
120
|
+
"""
|
|
121
|
+
...
|
|
122
|
+
def __getitem__(self, i:int) -> PySummand:
|
|
123
|
+
...
|
|
124
|
+
|
|
125
|
+
def plot(self, degree:int=-1,**kwargs)->None:
|
|
126
|
+
"""Shows the module on a plot. Each color corresponds to an apprimation summand of the module, and its shape corresponds to its support.
|
|
127
|
+
Only works with 2-parameter modules.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
degree = -1 : integer
|
|
132
|
+
If positive returns only the image of dimension `dimension`.
|
|
133
|
+
box=None : of the form [[b_x,b_y], [d_x,d_y]] where b,d are the bottom and top corner of the rectangle.
|
|
134
|
+
If non-None, will plot the module on this specific rectangle.
|
|
135
|
+
min_persistence =0 : float
|
|
136
|
+
Only plots the summand with a persistence above this threshold.
|
|
137
|
+
separated=False : bool
|
|
138
|
+
If true, plot each summand in a different plot.
|
|
139
|
+
alpha=1 : float
|
|
140
|
+
Transparancy parameter
|
|
141
|
+
save = False : string
|
|
142
|
+
if nontrivial, will save the figure at this path
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
Returns
|
|
146
|
+
-------
|
|
147
|
+
The figure of the plot.
|
|
148
|
+
"""
|
|
149
|
+
...
|
|
150
|
+
|
|
151
|
+
def barcode(self, basepoint, degree:int,*, threshold = False): # TODO direction vector interface
|
|
152
|
+
"""Computes the barcode of module along a lines.
|
|
153
|
+
|
|
154
|
+
Parameters
|
|
155
|
+
----------
|
|
156
|
+
basepoint : vector
|
|
157
|
+
basepoint of the lines on which to compute the barcodes, i.e. a point on the line
|
|
158
|
+
degree = -1 : integer
|
|
159
|
+
Homology degree on which to compute the bars. If negative, every dimension is computed
|
|
160
|
+
box (default) :
|
|
161
|
+
box on which to compute the barcodes if basepoints is not specified. Default is a linspace of lines crossing that box.
|
|
162
|
+
threshold = False : threshold t
|
|
163
|
+
Resolution of the image(s).
|
|
164
|
+
|
|
165
|
+
Warning
|
|
166
|
+
-------
|
|
167
|
+
If the barcodes are not thresholded, essential barcodes will not be plot-able.
|
|
168
|
+
|
|
169
|
+
Returns
|
|
170
|
+
-------
|
|
171
|
+
PyMultiDiagrams
|
|
172
|
+
Structure that holds the barcodes. Barcodes can be retrieved with a .get_points() or a .to_multipers() or a .plot().
|
|
173
|
+
"""
|
|
174
|
+
...
|
|
175
|
+
def barcodes(self, degree:int, basepoints = None, num=100, box = None,threshold = False):
|
|
176
|
+
"""Computes barcodes of module along a set of lines.
|
|
177
|
+
|
|
178
|
+
Parameters
|
|
179
|
+
----------
|
|
180
|
+
basepoints = None : list of vectors
|
|
181
|
+
basepoints of the lines on which to compute the barcodes.
|
|
182
|
+
degree = -1 : integer
|
|
183
|
+
Homology degree on which to compute the bars. If negative, every dimension is computed
|
|
184
|
+
box (default) :
|
|
185
|
+
box on which to compute the barcodes if basepoints is not specified. Default is a linspace of lines crossing that box.
|
|
186
|
+
num:int=100
|
|
187
|
+
if basepoints is not specified, defines the number of lines to consider.
|
|
188
|
+
threshold = False : threshold t
|
|
189
|
+
Resolution of the image(s).
|
|
190
|
+
|
|
191
|
+
Warning
|
|
192
|
+
-------
|
|
193
|
+
If the barcodes are not thresholded, essential barcodes will not be plot-able.
|
|
194
|
+
|
|
195
|
+
Returns
|
|
196
|
+
-------
|
|
197
|
+
PyMultiDiagrams
|
|
198
|
+
Structure that holds the barcodes. Barcodes can be retrieved with a .get_points() or a .to_multipers() or a .plot().
|
|
199
|
+
"""
|
|
200
|
+
...
|
|
201
|
+
def landscape(self, degree:int, k:int=0,box:list|np.ndarray|None=None, resolution:List=[100,100], plot=True):
|
|
202
|
+
"""Computes the multiparameter landscape from a PyModule. Python interface only bifiltrations.
|
|
203
|
+
|
|
204
|
+
Parameters
|
|
205
|
+
----------
|
|
206
|
+
degree : integer
|
|
207
|
+
The homology degree of the landscape.
|
|
208
|
+
k = 0 : int
|
|
209
|
+
the k-th landscape
|
|
210
|
+
resolution = [50,50] : pair of integers
|
|
211
|
+
Resolution of the image.
|
|
212
|
+
box = None : in the format [[a,b], [c,d]]
|
|
213
|
+
If nontrivial, compute the landscape of this box. Default is the PyModule box.
|
|
214
|
+
plot = True : Boolean
|
|
215
|
+
If true, plots the images;
|
|
216
|
+
Returns
|
|
217
|
+
-------
|
|
218
|
+
Numpy array
|
|
219
|
+
The landscape of the module.
|
|
220
|
+
"""
|
|
221
|
+
...
|
|
222
|
+
def landscapes(self, degree:int, ks:list|np.ndarray=[0],box=None, resolution:list|np.ndarray=[100,100], plot=True):
|
|
223
|
+
"""Computes the multiparameter landscape from a PyModule. Python interface only bifiltrations.
|
|
224
|
+
|
|
225
|
+
Parameters
|
|
226
|
+
----------
|
|
227
|
+
degree : integer
|
|
228
|
+
The homology degree of the landscape.
|
|
229
|
+
ks = 0 : list of int
|
|
230
|
+
the k-th landscape
|
|
231
|
+
resolution = [50,50] : pair of integers
|
|
232
|
+
Resolution of the image.
|
|
233
|
+
box = None : in the format [[a,b], [c,d]]
|
|
234
|
+
If nontrivial, compute the landscape of this box. Default is the PyModule box.
|
|
235
|
+
plot = True : Boolean
|
|
236
|
+
If true, plots the images;
|
|
237
|
+
Returns
|
|
238
|
+
-------
|
|
239
|
+
Numpy array
|
|
240
|
+
The landscapes of the module with parameters ks.
|
|
241
|
+
"""
|
|
242
|
+
...
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def image(self, degree:int = -1, bandwidth:float=0.1, resolution:list=[100,100], normalize:bool=False, plot:bool=True, save:bool=False, dpi:int=200,p:float=1., **kwargs)->np.ndarray:
|
|
246
|
+
"""Computes a vectorization from a PyModule. Python interface only bifiltrations.
|
|
247
|
+
|
|
248
|
+
Parameters
|
|
249
|
+
----------
|
|
250
|
+
degree = -1 : integer
|
|
251
|
+
If positive returns only the image of homology degree `degree`.
|
|
252
|
+
bandwidth = 0.1 : float
|
|
253
|
+
Image parameter. TODO : different weights
|
|
254
|
+
resolution = [100,100] : pair of integers
|
|
255
|
+
Resolution of the image(s).
|
|
256
|
+
normalize = True : Boolean
|
|
257
|
+
Ensures that the image belongs to [0,1].
|
|
258
|
+
plot = True : Boolean
|
|
259
|
+
If true, plots the images;
|
|
260
|
+
|
|
261
|
+
Returns
|
|
262
|
+
-------
|
|
263
|
+
List of Numpy arrays or numpy array
|
|
264
|
+
The list of images, or the image of fixed dimension.
|
|
265
|
+
"""
|
|
266
|
+
...
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def euler_char(self, points:list|np.ndarray) -> np.ndarray:
|
|
270
|
+
""" Computes the Euler Characteristic of the filtered complex at given (multiparameter) time
|
|
271
|
+
|
|
272
|
+
Parameters
|
|
273
|
+
----------
|
|
274
|
+
points: list[float] | list[list[float]] | np.ndarray
|
|
275
|
+
List of filtration values on which to compute the euler characteristic.
|
|
276
|
+
WARNING FIXME : the points have to have the same dimension as the simplextree.
|
|
277
|
+
|
|
278
|
+
Returns
|
|
279
|
+
-------
|
|
280
|
+
The list of euler characteristic values
|
|
281
|
+
"""
|
|
282
|
+
...
|
|
283
|
+
|
|
284
|
+
def module_approximation(
|
|
285
|
+
st:SimplexTreeMulti,
|
|
286
|
+
max_error:float|None = None,
|
|
287
|
+
box:list|np.ndarray|None = None,
|
|
288
|
+
threshold:bool = False,
|
|
289
|
+
complete:bool = True,
|
|
290
|
+
multithread:bool = False,
|
|
291
|
+
verbose:bool = False,
|
|
292
|
+
ignore_warning:bool = False,
|
|
293
|
+
nlines:int = 500,
|
|
294
|
+
max_dimension=np.inf,
|
|
295
|
+
boundary = None,
|
|
296
|
+
filtration = None,
|
|
297
|
+
**kwargs)->PyModule:
|
|
298
|
+
"""Computes an interval module approximation of a multiparameter filtration.
|
|
299
|
+
|
|
300
|
+
Parameters
|
|
301
|
+
----------
|
|
302
|
+
st : n-filtered Simplextree.
|
|
303
|
+
Defines the n-filtration on which to compute the homology.
|
|
304
|
+
max_error: positive float
|
|
305
|
+
Trade-off between approximation and computational complexity.
|
|
306
|
+
Upper bound of the module approximation, in bottleneck distance,
|
|
307
|
+
for interval-decomposable modules.
|
|
308
|
+
nlines: int
|
|
309
|
+
Alternative to precision.
|
|
310
|
+
box : pair of list of floats
|
|
311
|
+
Defines a rectangle on which to compute the approximation.
|
|
312
|
+
Format : [x,y], where x,y defines the rectangle {z : x ≤ z ≤ y}
|
|
313
|
+
threshold: bool
|
|
314
|
+
When true, intersects the module support with the box.
|
|
315
|
+
verbose: bool
|
|
316
|
+
Prints C++ infos.
|
|
317
|
+
ignore_warning : bool
|
|
318
|
+
Unless set to true, prevents computing on more than 10k lines. Useful to prevent a segmentation fault due to "infinite" recursion.
|
|
319
|
+
Returns
|
|
320
|
+
-------
|
|
321
|
+
PyModule
|
|
322
|
+
An interval decomposable module approximation of the module defined by the
|
|
323
|
+
homology of this multi-filtration.
|
|
324
|
+
"""
|
|
325
|
+
|
|
326
|
+
...
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def from_dump(dump)->PyModule:
|
|
331
|
+
"""Retrieves a PyModule from a previous dump.
|
|
332
|
+
|
|
333
|
+
Parameters
|
|
334
|
+
----------
|
|
335
|
+
dump: either the output of the dump function, or a file containing the output of a dump.
|
|
336
|
+
The dumped module to retrieve
|
|
337
|
+
|
|
338
|
+
Returns
|
|
339
|
+
-------
|
|
340
|
+
PyModule
|
|
341
|
+
The retrieved module.
|
|
342
|
+
"""
|
|
343
|
+
...
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
#################################################### DATASETS for test
|
|
347
|
+
|
|
348
|
+
def noisy_annulus(r1:float=1, r2:float=2, n1:int=1000,n2:int=200, dim:int=2, center:np.ndarray|list|None=None, **kwargs)->np.ndarray:
|
|
349
|
+
"""Generates a noisy annulus dataset.
|
|
350
|
+
|
|
351
|
+
Parameters
|
|
352
|
+
----------
|
|
353
|
+
r1 : float.
|
|
354
|
+
Lower radius of the annulus.
|
|
355
|
+
r2 : float.
|
|
356
|
+
Upper radius of the annulus.
|
|
357
|
+
n1 : int
|
|
358
|
+
Number of points in the annulus.
|
|
359
|
+
n2 : int
|
|
360
|
+
Number of points in the square.
|
|
361
|
+
dim : int
|
|
362
|
+
Dimension of the annulus.
|
|
363
|
+
center: list or array
|
|
364
|
+
center of the annulus.
|
|
365
|
+
|
|
366
|
+
Returns
|
|
367
|
+
-------
|
|
368
|
+
numpy array
|
|
369
|
+
Dataset. size : (n1+n2) x dim
|
|
370
|
+
|
|
371
|
+
"""
|
|
372
|
+
...
|
|
373
|
+
|
|
374
|
+
def test_module(**kwargs):
|
|
375
|
+
"""Generates a module from a noisy annulus.
|
|
376
|
+
|
|
377
|
+
Parameters
|
|
378
|
+
----------
|
|
379
|
+
r1 : float.
|
|
380
|
+
Lower radius of the annulus.
|
|
381
|
+
r2 : float.
|
|
382
|
+
Upper radius of the annulus.
|
|
383
|
+
n1 : int
|
|
384
|
+
Number of points in the annulus.
|
|
385
|
+
n2 : int
|
|
386
|
+
Number of points in the square.
|
|
387
|
+
dim : int
|
|
388
|
+
Dimension of the annulus.
|
|
389
|
+
center: list or array
|
|
390
|
+
center of the annulus.
|
|
391
|
+
|
|
392
|
+
Returns
|
|
393
|
+
-------
|
|
394
|
+
PyModule
|
|
395
|
+
The associated module.
|
|
396
|
+
|
|
397
|
+
"""
|
|
398
|
+
...
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
##################################################### MMA CONVERSIONS
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
############################################# MMA - Matching distances
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def estimate_matching(b1:PyMultiDiagrams, b2:PyMultiDiagrams)->float:
|
|
415
|
+
...
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
#### Functions to estimate precision
|
|
419
|
+
def estimate_error(st:SimplexTreeMulti, module:PyModule, degree:int, nlines = 100, verbose:bool =False)->float:
|
|
420
|
+
"""
|
|
421
|
+
Given an MMA SimplexTree and PyModule, estimates the bottleneck distance using barcodes given by gudhi.
|
|
422
|
+
|
|
423
|
+
Parameters
|
|
424
|
+
----------
|
|
425
|
+
st:SimplexTree
|
|
426
|
+
The simplextree representing the n-filtered complex. Used to define the gudhi simplextrees on different lines.
|
|
427
|
+
module:PyModule
|
|
428
|
+
The module on which to estimate approximation error, w.r.t. the original simplextree st.
|
|
429
|
+
degree: The homology degree to consider
|
|
430
|
+
|
|
431
|
+
Returns
|
|
432
|
+
-------
|
|
433
|
+
The estimation of the matching distance, i.e., the maximum of the sampled bottleneck distances.
|
|
434
|
+
|
|
435
|
+
"""
|
|
436
|
+
...
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|