tdads.distance
Classes
Module Contents
- class tdads.distance.distance(dim: int = 0, metric='W', p: float = 2.0, sigma: float = None, inf_replace_val: float = None, n_cores: int = cpu_count() - 1)[source]
- __str__()[source]
Describe a distance metric by type (Wasserstein, bottleneck or Fisher information metric) and major parameter (p for Wasserstein and sigma for Fisher information metric).
- compute(D1, D2) float[source]
Compute the distance between two persistence diagrams.
- Parameters:
D1 (any) – The first persistence diagram (computed from either the ripser, gph, flagser, gudhi or cechmate packages).
D2 (any) – The second persistence diagram (“”).
- Returns:
The numeric distance calculation value. In dimension 0 persistence diagrams may contain a point whose death is inf, and these points are ignored (if you wish to use these points make sure to replace inf with the maximum filtration value you used to compute the diagram).
- Return type:
float
Examples
>>> from tdads import distance >>> from ripser import ripser >>> import numpy as np >>> # create 2 datasets >>> data1 = np.random((100,2)) >>> data2 = np.random((100,2)) >>> # compute persistence diagrams with ripser >>> diagram1 = ripser(data1) >>> diagram2 = ripser(data2) >>> # create distance object >>> d_wass = distance() # 2-wasserstein distance >>> # compute distance >>> d_wass.compute(diagram1, diagrams2)
Citations
Kerber M, Morozov D and Nigmetov A (2017). “Geometry Helps to Compare Persistence Diagrams.” https://dl.acm.org/doi/10.1145/3064175.
Le T, Yamada M (2018). “Persistence fisher kernel: a riemannian manifold kernel for persistence diagrams.” https://proceedings.neurips.cc/paper/2018/file/959ab9a0695c467e7caf75431a872e5c-Paper.pdf.
Vlad I. Morariu, Balaji Vasan Srinivasan, Vikas C. Raykar, Ramani Duraiswami, and Larry S. Davis. Automatic online tuning for fast Gaussian summation. Advances in Neural Information Processing Systems (NIPS), 2008.
- compute_matrix(diagrams: list, other_diagrams: list = None)[source]
Compute a distance matrix between one or two lists of persistence diagrams. :param diagrams: The first first of persistence diagram (computed from either the ripser, gph, flagser, gudhi or cechmate packages). :type diagrams: list :param other_diagrams: The optional second list of persistence diagram for computing a cross-distance matrix. Default None. :type other_diagrams: any
- Returns:
The (cross) distance matrix.
- Return type:
numpy.ndarray
Examples
>>> from tdads import distance >>> from ripser import ripser >>> import numpy as np >>> # create 2 datasets >>> data1 = np.random((100,2)) >>> data2 = np.random((100,2)) >>> # compute persistence diagrams with ripser >>> diagram1 = ripser(data1) >>> diagram2 = ripser(data2) >>> # create distance object >>> d_wass = distance() # 2-wasserstein distance >>> # compute distance matrix >>> d_wass.compute_matrix([diagram1, diagram2]) >>> # this is the same as: >>> d_wass.compute_matrix([diagram1, diagram2], [diagram1, diagram2])