scikit-tda/ripser.py

Retrieving Max Lifespan from Rips

aflytle opened this issue · 1 comments

I'm relatively new to TDA, so forgive some uninformed sounding wording.

In the Ripser.py implementation, I see that we are using the C++ structs for the arrays of points.
Is there any way to (still in Python) retrieve the maximum lifespan of some points in the persistence diagram/barcodes? I.E., is there a way to find the maximum lifespan of a point in a point cloud, when running the rips complex persistence homology on it?

I need to find the two longest lifespans in the dataset.

Respectfully,
Aidan Lytle

Hello,
Thank you for your patience on our response. Here's an example of how one might do this:

import numpy as np
from ripser import ripser
X = np.random.randn(100, 20) # Make a random point cloud with 100 points in 20 dimensions
dgms = ripser(X)['dgms'] # Pull out the diagrams (by default up to H1)
H1 = dgms[1] # Look at H1
H1 = H1[np.argsort(H1[:, 0] - H1[:, 1]), :] # Sort the points in descending order of persistence
lifespans = H1[:, 1] - H1[:, 0] # Now we have the lifespans in decreasing order