2.4.4. Persistence

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)

2.4.4.1. Functions

teaspoon.TDA.Persistence.BettiCurve(Dgm, maxEps=3, numStops=10, alpha=0)[source]

Computes the Betti Curve for a persistence diagram for thresholds 0 to maxEps

Parameters:
  • Dgm – (array) 2D numpy array of persistence diagram of a specific homology class

  • maxEps – (Optional[float]) Maximum value of threshold; default: 3

  • numStops – (Optional[int]) Number of points between 0 and maxEps; default: 10

  • alpha – (Optional[float]) alpha smoothing to diagonal, points below this line are ignored, used for Crocker Stacks; default: 0

Returns:

array of threshold values representing the 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:
  • DGMS – (list) A python list of 2D numpy arrays of persistence diagrams of a specific homology class

  • maxEps – (Optional[float]) Maximum value of threshold; default: 3

  • numStops – (Optional[int]) Number of points between 0 and maxEps; default: 10

  • plotting – (Optional[bool]) Plots the CROCKER for the given diagrams; default: True

Returns:

2D CROCKER plot

teaspoon.TDA.Persistence.CROCKER_Stack(DGMS, maxEps=3, numStops=10, alpha=None, plotting=True)[source]

Computes the CROCKER stack for a list of persistence diagrams for thresholds 0 to maxEps with given alpha smoothing. Implemented according to the paper “Capturing Dynamics of Time-Varying Data via Topology” by Xian L. et al.

Parameters:
  • DGMS (list) – A python list of 2D numpy arrays of persistence diagrams of a specific homology class

  • maxEps (float, optional) – Maximum value of threshold, defaults to 3

  • numStops (int, optional) – Number of points between 0 and maxEps, defaults to 10

  • alpha (list, optional) – A list of alpha values for smoothing, in default case it is behaving like CROCKER, defaults to [0]

  • plotting (bool, optional) – Plots the CROCKER for the given diagrams, defaults to True

Returns:

the 3D CROCKER stack with dimensions [alpha][row][time]

Return type:

np.darray

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.