2.3.4. Persistence
- teaspoon.TDA.Persistence.BettiCurve(Dgm, maxEps=3, numStops=10)[source]
Computes the Betti Curve for a persistence diagram for thresholds 0 to maxEps
- Parameters:
(array) (Dgm) – 2D numpy array of persistence diagram of a specific homology class
(Optional[float]) (maxEps) – Maximum value of threshold; default: 3
(Optional[int]) (numStops) – Number of points between 0 and maxEps; default: 10
- Returns:
array of threshold values, Betti curve
- teaspoon.TDA.Persistence.CROCKER(DGMS, maxEps=3, numStops=10, plotting=True)[source]
Computes the CROCKER plot for a list of persistence diagrams for thresholds 0 to maxEps
- Parameters:
(list) (DGMS) – A python list of 2D numpy arrays of persistence diagrams of a specific homology class
(Optional[float]) (maxEps) – Maximum value of threshold; default: 3
(Optional[int]) (numStops) – Number of points between 0 and maxEps; default: 10
(Optional[bool]) (plotting) – Plots the CROCKER for the given diagrams; default: True
- Returns:
2D CROCKER plot
- teaspoon.TDA.Persistence.maxBirth(Dgm)[source]
Finds maximum birth for a given diagram
- Parameters:
Dgm – A 2D numpy array
- Returns:
(float) Maximum birth time for the given diagram
- teaspoon.TDA.Persistence.maxBirthSeries(DgmsSeries)[source]
Takes data frame DgmsDF. Finds maximum persistence over all diagrams in column with label dgm_col. It gets maximum persistence for a pandas.Series with diagrams as entries.
- Parameters:
DgmSeries – A pandas.Series with entries Kx2 numpy arrays representing persistence diagrams.
- Returns:
(float) Maximum persistence over all diagrams
- teaspoon.TDA.Persistence.maxPers(Dgm)[source]
Finds maximum persistence for a given diagram
- Parameters:
Dgm – A 2D numpy array
- Returns:
(float) Maximum persistence for the given diagram
- teaspoon.TDA.Persistence.maxPersistenceSeries(DgmsSeries)[source]
Takes data frame DgmsDF. Finds maximum persistence over all diagrams in column with label dgm_col. Gets maximum persistence for a pandas.Series with diagrams as entries
- Parameters:
DgmsSeries – A pandas.Series with entries Kx2 numpy arrays representing persistence diagrams.
- Returns:
(float) Maximum persistence over all diagrams
- teaspoon.TDA.Persistence.minBirth(Dgm)[source]
Finds minimum birth for a given diagram
- Parameters:
Dgm – A 2D numpy array
- Returns:
(float) Minimum birth time for the given diagram
- teaspoon.TDA.Persistence.minBirthSeries(DgmsSeries)[source]
Takes data frame DgmsDF. Finds minimum persistence over all diagrams in column with label dgm_col. Gets minimum persistence for a pandas.Series with diagrams as entries
- Parameters:
DgmSeries – A pandas.Series with entries Kx2 numpy arrays representing persistence diagrams.
- Returns:
(float) Minimum birth time over all diagrams
- teaspoon.TDA.Persistence.minPers(Dgm)[source]
Finds minimum persistence for a given diagram
- Parameters:
Dgm – A 2D numpy array
- Returns:
(float) Minimum persistence for the given diagram
- teaspoon.TDA.Persistence.minPersistenceSeries(DgmsSeries)[source]
Takes data frame DgmsDF. Finds minimum persistence over all diagrams in column with label dgm_col. Gets minimum persistence for a pandas.Series with diagrams as entries
- Parameters:
DgmSeries – A pandas.Series with entries Kx2 numpy arrays representing persistence diagrams.
- Returns:
(float) Minimum persistence over all diagrams
- teaspoon.TDA.Persistence.removeInfiniteClasses(Dgm)[source]
Simply deletes classes that have infinite lifetimes.
The following example computes the minimum and maximum birth times, as well as the maximum persistence:
from ripser import ripser
from teaspoon.TDA.Draw import drawDgm
from teaspoon.MakeData.PointCloud import Torus
from teaspoon.TDA.Persistence import maxBirth, minBirth, maxPers
numPts = 500
seed = 0
# Generate Torus
t = Torus(N=numPts,seed = seed)
# Compute persistence diagrams
PD1 = ripser(t,2)['dgms'][1]
print('Maximum Birth: ', maxBirth(PD1))
print('Minimum Birth: ', minBirth(PD1))
print('Max Persistence: ', maxPers(PD1))
The output of this code is:
Maximum Birth: 1.0100464820861816
Minimum Birth: 0.17203105986118317
Max Persistence: 1.3953008949756622
The following example computes the minimum and maximum birth times and the maximum persistence across all persistence diagrams in the specified column of the DataFrame:
from teaspoon.MakeData.PointCloud import testSetManifolds
from teaspoon.TDA.Persistence import maxBirthSeries, minBirthSeries, maxPersistenceSeries
df = testSetManifolds(numDgms = 1, numPts = 500, seed=0)
print('Maximum Birth of all diagrams: ', maxBirthSeries(df['Dgm1']))
print('Minimum Birth of all diagrams: ', minBirthSeries(df['Dgm1']))
print('Max Persistence of all diagrams: ', maxPersistenceSeries(df['Dgm1']))
The output of this code is:
Maximum Birth of all diagrams: 1.2070081233978271
Minimum Birth of all diagrams: 0.028233738616108894
Max Persistence of all diagrams: 1.6290252953767776
The following example computes the Betti Curve for a persistence diagram:
from teaspoon.MakeData.PointCloud import Torus
from teaspoon.TDA.Persistence import BettiCurve
from ripser import ripser
T = Torus(N=300, r=1, R=2, seed=48823)
Dgm = ripser(T,2)['dgms'][1]
t, x = BettiCurve(Dgm,3,5)
print('Betti Curve:', x)
The output of this code is:
Betti Curve: [ 0. 36. 2. 0. 0.]
The following example computes the CROCKER plot for a set of persistence diagrams:
from teaspoon.MakeData.PointCloud import Torus
from teaspoon.TDA.Persistence import CROCKER
from ripser import ripser
DGMS = []
for i in range(0, 5):
T = Torus(N=300, r=i+1, R=i+2, seed=48823)
Dgm = ripser(T,2)['dgms'][0]
DGMS.append(Dgm)
Crocker = CROCKER(DGMS, 3, 5, plotting=False)