multipers 2.0.0__cp310-cp310-macosx_13_0_x86_64.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 (78) hide show
  1. multipers/.dylibs/libc++.1.0.dylib +0 -0
  2. multipers/.dylibs/libtbb.12.12.dylib +0 -0
  3. multipers/.dylibs/libtbbmalloc.2.12.dylib +0 -0
  4. multipers/__init__.py +11 -0
  5. multipers/_signed_measure_meta.py +268 -0
  6. multipers/_slicer_meta.py +171 -0
  7. multipers/data/MOL2.py +350 -0
  8. multipers/data/UCR.py +18 -0
  9. multipers/data/__init__.py +1 -0
  10. multipers/data/graphs.py +466 -0
  11. multipers/data/immuno_regions.py +27 -0
  12. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  13. multipers/data/pytorch2simplextree.py +91 -0
  14. multipers/data/shape3d.py +101 -0
  15. multipers/data/synthetic.py +68 -0
  16. multipers/distances.py +198 -0
  17. multipers/euler_characteristic.pyx +132 -0
  18. multipers/filtration_conversions.pxd +229 -0
  19. multipers/filtrations.pxd +225 -0
  20. multipers/function_rips.cpython-310-darwin.so +0 -0
  21. multipers/function_rips.pyx +105 -0
  22. multipers/grids.cpython-310-darwin.so +0 -0
  23. multipers/grids.pyx +281 -0
  24. multipers/hilbert_function.pyi +46 -0
  25. multipers/hilbert_function.pyx +153 -0
  26. multipers/io.cpython-310-darwin.so +0 -0
  27. multipers/io.pyx +571 -0
  28. multipers/ml/__init__.py +0 -0
  29. multipers/ml/accuracies.py +90 -0
  30. multipers/ml/convolutions.py +532 -0
  31. multipers/ml/invariants_with_persistable.py +79 -0
  32. multipers/ml/kernels.py +176 -0
  33. multipers/ml/mma.py +659 -0
  34. multipers/ml/one.py +472 -0
  35. multipers/ml/point_clouds.py +238 -0
  36. multipers/ml/signed_betti.py +50 -0
  37. multipers/ml/signed_measures.py +1542 -0
  38. multipers/ml/sliced_wasserstein.py +461 -0
  39. multipers/ml/tools.py +113 -0
  40. multipers/mma_structures.cpython-310-darwin.so +0 -0
  41. multipers/mma_structures.pxd +127 -0
  42. multipers/mma_structures.pyx +2433 -0
  43. multipers/multiparameter_edge_collapse.py +41 -0
  44. multipers/multiparameter_module_approximation.cpython-310-darwin.so +0 -0
  45. multipers/multiparameter_module_approximation.pyx +211 -0
  46. multipers/pickle.py +53 -0
  47. multipers/plots.py +326 -0
  48. multipers/point_measure_integration.cpython-310-darwin.so +0 -0
  49. multipers/point_measure_integration.pyx +139 -0
  50. multipers/rank_invariant.cpython-310-darwin.so +0 -0
  51. multipers/rank_invariant.pyx +229 -0
  52. multipers/simplex_tree_multi.cpython-310-darwin.so +0 -0
  53. multipers/simplex_tree_multi.pxd +129 -0
  54. multipers/simplex_tree_multi.pyi +715 -0
  55. multipers/simplex_tree_multi.pyx +4655 -0
  56. multipers/slicer.cpython-310-darwin.so +0 -0
  57. multipers/slicer.pxd +781 -0
  58. multipers/slicer.pyx +3393 -0
  59. multipers/tensor.pxd +13 -0
  60. multipers/test.pyx +44 -0
  61. multipers/tests/__init__.py +40 -0
  62. multipers/tests/old_test_rank_invariant.py +91 -0
  63. multipers/tests/test_diff_helper.py +74 -0
  64. multipers/tests/test_hilbert_function.py +82 -0
  65. multipers/tests/test_mma.py +51 -0
  66. multipers/tests/test_point_clouds.py +59 -0
  67. multipers/tests/test_python-cpp_conversion.py +82 -0
  68. multipers/tests/test_signed_betti.py +181 -0
  69. multipers/tests/test_simplextreemulti.py +98 -0
  70. multipers/tests/test_slicer.py +63 -0
  71. multipers/torch/__init__.py +1 -0
  72. multipers/torch/diff_grids.py +217 -0
  73. multipers/torch/rips_density.py +257 -0
  74. multipers-2.0.0.dist-info/LICENSE +21 -0
  75. multipers-2.0.0.dist-info/METADATA +29 -0
  76. multipers-2.0.0.dist-info/RECORD +78 -0
  77. multipers-2.0.0.dist-info/WHEEL +5 -0
  78. 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