multipers 2.0.0__cp311-cp311-macosx_13_0_arm64.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/libc++.1.0.dylib +0 -0
- multipers/.dylibs/libtbb.12.12.dylib +0 -0
- multipers/.dylibs/libtbbmalloc.2.12.dylib +0 -0
- multipers/__init__.py +11 -0
- multipers/_signed_measure_meta.py +268 -0
- multipers/_slicer_meta.py +171 -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 +198 -0
- multipers/euler_characteristic.pyx +132 -0
- multipers/filtration_conversions.pxd +229 -0
- multipers/filtrations.pxd +225 -0
- multipers/function_rips.cpython-311-darwin.so +0 -0
- multipers/function_rips.pyx +105 -0
- multipers/grids.cpython-311-darwin.so +0 -0
- multipers/grids.pyx +281 -0
- multipers/hilbert_function.pyi +46 -0
- multipers/hilbert_function.pyx +153 -0
- multipers/io.cpython-311-darwin.so +0 -0
- multipers/io.pyx +571 -0
- multipers/ml/__init__.py +0 -0
- multipers/ml/accuracies.py +90 -0
- multipers/ml/convolutions.py +532 -0
- multipers/ml/invariants_with_persistable.py +79 -0
- multipers/ml/kernels.py +176 -0
- multipers/ml/mma.py +659 -0
- multipers/ml/one.py +472 -0
- multipers/ml/point_clouds.py +238 -0
- multipers/ml/signed_betti.py +50 -0
- multipers/ml/signed_measures.py +1542 -0
- multipers/ml/sliced_wasserstein.py +461 -0
- multipers/ml/tools.py +113 -0
- multipers/mma_structures.cpython-311-darwin.so +0 -0
- multipers/mma_structures.pxd +127 -0
- multipers/mma_structures.pyx +2433 -0
- multipers/multiparameter_edge_collapse.py +41 -0
- multipers/multiparameter_module_approximation.cpython-311-darwin.so +0 -0
- multipers/multiparameter_module_approximation.pyx +211 -0
- multipers/pickle.py +53 -0
- multipers/plots.py +326 -0
- multipers/point_measure_integration.cpython-311-darwin.so +0 -0
- multipers/point_measure_integration.pyx +139 -0
- multipers/rank_invariant.cpython-311-darwin.so +0 -0
- multipers/rank_invariant.pyx +229 -0
- multipers/simplex_tree_multi.cpython-311-darwin.so +0 -0
- multipers/simplex_tree_multi.pxd +129 -0
- multipers/simplex_tree_multi.pyi +715 -0
- multipers/simplex_tree_multi.pyx +4655 -0
- multipers/slicer.cpython-311-darwin.so +0 -0
- multipers/slicer.pxd +781 -0
- multipers/slicer.pyx +3393 -0
- multipers/tensor.pxd +13 -0
- multipers/test.pyx +44 -0
- multipers/tests/__init__.py +40 -0
- multipers/tests/old_test_rank_invariant.py +91 -0
- multipers/tests/test_diff_helper.py +74 -0
- multipers/tests/test_hilbert_function.py +82 -0
- multipers/tests/test_mma.py +51 -0
- multipers/tests/test_point_clouds.py +59 -0
- multipers/tests/test_python-cpp_conversion.py +82 -0
- multipers/tests/test_signed_betti.py +181 -0
- multipers/tests/test_simplextreemulti.py +98 -0
- multipers/tests/test_slicer.py +63 -0
- multipers/torch/__init__.py +1 -0
- multipers/torch/diff_grids.py +217 -0
- multipers/torch/rips_density.py +257 -0
- multipers-2.0.0.dist-info/LICENSE +21 -0
- multipers-2.0.0.dist-info/METADATA +29 -0
- multipers-2.0.0.dist-info/RECORD +78 -0
- multipers-2.0.0.dist-info/WHEEL +5 -0
- multipers-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# cimport multipers.tensor as mt
|
|
2
|
+
from libc.stdint cimport intptr_t, uint16_t, uint32_t, int32_t
|
|
3
|
+
from libcpp.vector cimport vector
|
|
4
|
+
from libcpp cimport bool, int, float
|
|
5
|
+
from libcpp.utility cimport pair
|
|
6
|
+
from typing import Optional,Iterable,Callable
|
|
7
|
+
from multipers.grids import sms_in_grid
|
|
8
|
+
import numpy as np
|
|
9
|
+
cimport numpy as cnp
|
|
10
|
+
cnp.import_array()
|
|
11
|
+
|
|
12
|
+
ctypedef float value_type
|
|
13
|
+
python_value_type=np.float32
|
|
14
|
+
|
|
15
|
+
ctypedef int32_t indices_type # uint fails for some reason
|
|
16
|
+
python_indices_type=np.int32
|
|
17
|
+
|
|
18
|
+
ctypedef int32_t tensor_dtype
|
|
19
|
+
python_tensor_dtype = np.int32
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
ctypedef pair[vector[vector[indices_type]], vector[tensor_dtype]] signed_measure_type
|
|
23
|
+
|
|
24
|
+
cdef extern from "multi_parameter_rank_invariant/hilbert_function.h" namespace "Gudhi::multiparameter::hilbert_function":
|
|
25
|
+
void get_hilbert_surface_python(const intptr_t, tensor_dtype* , const vector[indices_type], const vector[indices_type], bool, bool, indices_type, bool) except + nogil
|
|
26
|
+
signed_measure_type get_hilbert_signed_measure(const intptr_t, tensor_dtype* , const vector[indices_type], const vector[indices_type], bool, indices_type, bool, bool) except + nogil
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def hilbert_signed_measure(
|
|
31
|
+
simplextree,
|
|
32
|
+
vector[indices_type] degrees,
|
|
33
|
+
mass_default=None,
|
|
34
|
+
plot=False,
|
|
35
|
+
indices_type n_jobs=0,
|
|
36
|
+
bool verbose=False,
|
|
37
|
+
bool expand_collapse=False,
|
|
38
|
+
grid_conversion = None
|
|
39
|
+
):
|
|
40
|
+
"""
|
|
41
|
+
Computes the signed measures given by the decomposition of the hilbert function.
|
|
42
|
+
|
|
43
|
+
Input
|
|
44
|
+
-----
|
|
45
|
+
- simplextree:SimplexTreeMulti, the multifiltered simplicial complex
|
|
46
|
+
- degrees:array-like of ints, the degrees to compute
|
|
47
|
+
- mass_default: Either None, or 'auto' or 'inf', or array-like of floats. Where to put the default mass to get a zero-mass measure.
|
|
48
|
+
- plot:bool, plots the computed measures if true.
|
|
49
|
+
- n_jobs:int, number of jobs. Defaults to #cpu, but when doing parallel computations of signed measures, we recommend setting this to 1.
|
|
50
|
+
- verbose:bool, prints c++ logs.
|
|
51
|
+
|
|
52
|
+
Output
|
|
53
|
+
------
|
|
54
|
+
`[signed_measure_of_degree for degree in degrees]`
|
|
55
|
+
with `signed_measure_of_degree` of the form `(dirac location, dirac weights)`.
|
|
56
|
+
"""
|
|
57
|
+
assert simplextree._is_squeezed, "Squeeze grid first."
|
|
58
|
+
cdef bool zero_pad = mass_default is not None
|
|
59
|
+
# assert simplextree.num_parameters == 2
|
|
60
|
+
grid_shape = np.array([len(f) for f in simplextree.filtration_grid])
|
|
61
|
+
if mass_default is None:
|
|
62
|
+
mass_default = mass_default
|
|
63
|
+
else:
|
|
64
|
+
mass_default = np.asarray(mass_default)
|
|
65
|
+
assert mass_default.ndim == 1 and mass_default.shape[0] == simplextree.num_parameters
|
|
66
|
+
if zero_pad:
|
|
67
|
+
for i, _ in enumerate(grid_shape):
|
|
68
|
+
grid_shape[i] += 1 # adds a 0
|
|
69
|
+
if grid_conversion is not None:
|
|
70
|
+
for i,f in enumerate(grid_conversion):
|
|
71
|
+
grid_conversion[i] = np.concatenate([f, [mass_default[i]]])
|
|
72
|
+
assert len(grid_shape) == simplextree.num_parameters, "Grid shape size has to be the number of parameters."
|
|
73
|
+
grid_shape_with_degree = np.asarray(np.concatenate([[len(degrees)], grid_shape]), dtype=python_indices_type)
|
|
74
|
+
container_array = np.ascontiguousarray(np.zeros(grid_shape_with_degree, dtype=python_tensor_dtype).flatten())
|
|
75
|
+
assert len(container_array) < np.iinfo(np.uint32).max, "Too large container. Raise an issue on github if you encounter this issue. (Due to tensor's operator[])"
|
|
76
|
+
cdef intptr_t simplextree_ptr = simplextree.thisptr
|
|
77
|
+
cdef vector[indices_type] c_grid_shape = grid_shape_with_degree
|
|
78
|
+
cdef tensor_dtype[::1] container = container_array
|
|
79
|
+
cdef tensor_dtype* container_ptr = &container[0]
|
|
80
|
+
cdef signed_measure_type out
|
|
81
|
+
with nogil:
|
|
82
|
+
out = get_hilbert_signed_measure(simplextree_ptr, container_ptr, c_grid_shape, degrees, zero_pad, n_jobs, verbose, expand_collapse)
|
|
83
|
+
pts, weights = np.asarray(out.first, dtype=int).reshape(-1, simplextree.num_parameters+1), np.asarray(out.second, dtype=int)
|
|
84
|
+
# return pts, weights
|
|
85
|
+
|
|
86
|
+
# degree_indices = [np.argwhere(pts[:,0] == degree_index).flatten() for degree_index, degree in enumerate(degrees)] ## TODO : maybe optimize
|
|
87
|
+
# sms = [(pts[idx,1:], weights[idx]) for idx in degree_indices]
|
|
88
|
+
|
|
89
|
+
# is_sorted = lambda a: np.all(a[:-1] <= a[1:])
|
|
90
|
+
# assert is_sorted(pts[:,0]), "TODO : REMOVE THIS."
|
|
91
|
+
slices = np.concatenate([np.searchsorted(pts[:,0], np.arange(degrees.size())), [pts.shape[0]] ])
|
|
92
|
+
sms = [
|
|
93
|
+
(pts[slices[i]:slices[i+1],1:],weights[slices[i]:slices[i+1]])
|
|
94
|
+
for i in range(slices.shape[0]-1)
|
|
95
|
+
]
|
|
96
|
+
if grid_conversion is not None:
|
|
97
|
+
sms = sms_in_grid(sms,grid_conversion)
|
|
98
|
+
|
|
99
|
+
if plot:
|
|
100
|
+
from multipers.plots import plot_signed_measures
|
|
101
|
+
plot_signed_measures(sms)
|
|
102
|
+
return sms
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def hilbert_surface(simplextree, vector[indices_type] degrees, mass_default=None, bool mobius_inversion=False, bool plot=False, indices_type n_jobs=0, bool expand_collapse=False):
|
|
107
|
+
"""
|
|
108
|
+
Computes the hilbert function.
|
|
109
|
+
|
|
110
|
+
Input
|
|
111
|
+
-----
|
|
112
|
+
- simplextree:SimplexTreeMulti, the multifiltered simplicial complex
|
|
113
|
+
- degrees:array-like of ints, the degrees to compute
|
|
114
|
+
- mass_default: Either None, or 'auto' or 'inf', or array-like of floats. Where to put the default mass to get a zero-mass measure.
|
|
115
|
+
- plot:bool, plots the computed measures if true.
|
|
116
|
+
- n_jobs:int, number of jobs. Defaults to #cpu, but when doing parallel computations of signed measures, we recommend setting this to 1.
|
|
117
|
+
- verbose:bool, prints c++ logs.
|
|
118
|
+
|
|
119
|
+
Output
|
|
120
|
+
------
|
|
121
|
+
Integer array of the form `(num_degrees, num_filtration_values_of_parameter 1, ..., num_filtration_values_of_parameter n)`
|
|
122
|
+
"""
|
|
123
|
+
assert simplextree._is_squeezed > 0, "Squeeze grid first."
|
|
124
|
+
cdef bool zero_pad = mass_default is not None
|
|
125
|
+
grid_conversion = [np.asarray(f) for f in simplextree.filtration_grid]
|
|
126
|
+
grid_shape = np.array([len(f) for f in grid_conversion])
|
|
127
|
+
if mass_default is None:
|
|
128
|
+
mass_default = mass_default
|
|
129
|
+
else:
|
|
130
|
+
mass_default = np.asarray(mass_default)
|
|
131
|
+
assert mass_default.ndim == 1 and mass_default.shape[0] == simplextree.num_parameters
|
|
132
|
+
if zero_pad:
|
|
133
|
+
for i, _ in enumerate(grid_shape):
|
|
134
|
+
grid_shape[i] += 1 # adds a 0
|
|
135
|
+
for i,f in enumerate(grid_conversion):
|
|
136
|
+
grid_conversion[i] = np.concatenate([f, [mass_default[i]]])
|
|
137
|
+
assert len(grid_shape) == simplextree.num_parameters, "Grid shape size has to be the number of parameters."
|
|
138
|
+
grid_shape_with_degree = np.asarray(np.concatenate([[len(degrees)], grid_shape]), dtype=python_indices_type)
|
|
139
|
+
container_array = np.ascontiguousarray(np.zeros(grid_shape_with_degree, dtype=python_tensor_dtype).flatten())
|
|
140
|
+
assert len(container_array) < np.iinfo(np.uint32).max, "Too large container. Raise an issue on github if you encounter this issue. (Due to tensor's operator[])"
|
|
141
|
+
cdef intptr_t simplextree_ptr = simplextree.thisptr
|
|
142
|
+
cdef vector[indices_type] c_grid_shape = grid_shape_with_degree
|
|
143
|
+
cdef tensor_dtype[::1] container = container_array
|
|
144
|
+
cdef tensor_dtype* container_ptr = &container[0]
|
|
145
|
+
with nogil:
|
|
146
|
+
get_hilbert_surface_python(simplextree_ptr, container_ptr, c_grid_shape, degrees, mobius_inversion, zero_pad, n_jobs, expand_collapse)
|
|
147
|
+
out = (grid_conversion, container_array.reshape(grid_shape_with_degree))
|
|
148
|
+
if plot:
|
|
149
|
+
from multipers.plots import plot_surfaces
|
|
150
|
+
plot_surfaces(out)
|
|
151
|
+
return out
|
|
152
|
+
|
|
153
|
+
|
|
Binary file
|