masspcf.persistence#
Persistent homology, barcodes, and stable rank functions.
barcode#
- class masspcf.persistence.barcode.Barcode(bc)#
Bases:
objectA persistence barcode, i.e. a collection of bars (birth-death intervals).
A barcode is represented as an (n, 2) array where each row is a bar given as a
(birth, death)pair from a persistent homology computation.- Parameters:
bc (Barcode or numpy.ndarray) – An existing
Barcodeto copy, or an (n, 2) NumPy array of(birth, death)pairs (float32orfloat64).
- is_isomorphic_to(bc: Barcode, atol: float = 1e-08, rtol: float = 1e-05)#
Check whether two barcodes are isomorphic (same multiset of bars).
Bar endpoints are compared with a numerical tolerance so that barcodes computed via different but mathematically equivalent routes (for example, from a point cloud versus a precomputed distance matrix) still compare equal despite floating-point rounding. Two endpoints
aandbare considered equal whenabs(a - b) <= atol + rtol * abs(b); infinite endpoints must match exactly.- Parameters:
bc (Barcode) – The barcode to compare against.
atol (float, optional) – Absolute tolerance for endpoint comparison, by default
1e-8.rtol (float, optional) – Relative tolerance for endpoint comparison, by default
1e-5. Passatol=0, rtol=0for a bitwise comparison.
- to_numpy()#
Return the bars as an (n, 2) NumPy array of
(birth, death)pairs.
ph_tensor#
- class masspcf.persistence.ph_tensor.BarcodeTensor(data)#
Bases:
Tensor
homology#
- masspcf.persistence.homology.compute_persistent_homology(X: PointCloudTensor | DistanceMatrix | DistanceMatrixTensor | FloatTensor | ndarray, max_dim: int = 1, distance_type: DistanceType = DistanceType.Euclidean, complex_type: ComplexType = ComplexType.VietorisRips, reduced: bool = False, verbose: bool = False) BarcodeTensor#
Compute persistent homology of a point cloud or distance matrix.
Returns barcodes for homology dimensions 0 through
max_dim. Whencomplex_typeisComplexType.VietorisRips(currently the only available option), the computation uses Ripser [1]. When the input contains multiple point clouds or distance matrices, the computations are parallelized across them.For an input tensor of shape \((d_1, \ldots, d_n)\), the output has shape \((d_1, \ldots, d_n, \texttt{max_dim} + 1)\).
- Parameters:
X (PointCloudTensor, DistanceMatrix, DistanceMatrixTensor, FloatTensor, or numpy.ndarray) – Input data. A
FloatTensoror NumPy array is interpreted as a single point cloud (one row per point). ADistanceMatrixorDistanceMatrixTensorprovides precomputed pairwise distances directly;distance_typeis ignored in that case.max_dim (int, optional) – Maximum homology dimension to compute, by default 1.
distance_type (DistanceType, optional) – Distance metric for point cloud input, by default
DistanceType.Euclidean. Ignored when the input is a distance matrix.complex_type (ComplexType, optional) – Simplicial complex type, by default
ComplexType.VietorisRips.reduced (bool, optional) – If
True, compute reduced homology (no essential H0 class). IfFalse(default), an infinite bar[0, inf)is added to H0 representing the single connected component.verbose (bool, optional) – Show progress information, by default False.
- Returns:
A tensor of barcodes.
- Return type:
barcode_summary#
- masspcf.persistence.barcode_summary.barcode_to_accumulated_persistence(bc: Barcode | BarcodeTensor, max_death: float = inf, verbose: bool = True)#
Convert barcodes to accumulated persistence functions.
The accumulated persistence function (APF) is defined as
\[\mathrm{APF}(t) = \sum_{i=1}^{N} \ell_i \, \mathbf{1}_{m_i \leq t}\]where \(N\) is the number of bars, \(\ell_i = d_i - b_i\) is the lifetime of bar \(i\), and \(m_i = (b_i + d_i) / 2\) is its midpoint [2].
When
max_deathis finite, only bars with \(d_i \leq\)max_deathare included (Equation 2 in the paper).- Parameters:
bc (Barcode or BarcodeTensor) – A single barcode or a tensor of barcodes.
max_death (float, optional) – If finite, exclude bars whose death time exceeds this value. By default
inf(all finite bars included).verbose (bool, optional) – Show progress information, by default False.
- Returns:
A single
Pcfif the input is a singleBarcode, otherwise aPcfTensorwith the same shape as the input.- Return type:
- masspcf.persistence.barcode_summary.barcode_to_betti_curve(bc: Barcode | BarcodeTensor, verbose=False)#
Convert barcodes to Betti curves.
The Betti curve is the PCF that counts, for each filtration value \(t \geq 0\), the number of bars alive at \(t\) (i.e., bars with birth \(\leq t <\) death) [3][4].
- Parameters:
bc (Barcode or BarcodeTensor) – A single barcode or a tensor of barcodes.
verbose (bool, optional) – Show progress information, by default False.
- Returns:
A single
Pcfif the input is a singleBarcode, otherwise aPcfTensorwith the same shape as the input.- Return type:
- masspcf.persistence.barcode_summary.barcode_to_stable_rank(bc: Barcode | BarcodeTensor, verbose=False)#
Convert barcodes to stable rank functions.
The stable rank of a barcode is the PCF that counts, for each \(t \geq 0\), the number of bars with length (death minus birth) strictly greater than \(t\) [5].
- Parameters:
bc (Barcode or BarcodeTensor) – A single barcode or a tensor of barcodes.
verbose (bool, optional) – Show progress information, by default False.
- Returns:
A single
Pcfif the input is a singleBarcode, otherwise aPcfTensorwith the same shape as the input.- Return type: