Last active
December 24, 2019 22:00
-
-
Save lewtun/0ca68dbc05635a3975b51108caa63e6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# define topological features to track | |
homology_dimensions = [0, 1, 2] | |
# calculate persistence diagram | |
persistence_diagram = ... | |
# convert NumPy array of triples to DataFrame | |
persistence_table = pd.DataFrame( | |
persistence_diagram, columns=["birth", "death", "homology_dim"] | |
) | |
# calculate the lifetime per point | |
persistence_table["lifetime"] = persistence_table["death"] - persistence_table["birth"] | |
# calculate average lifetimes per homology dimension | |
average_lifetimes = [ | |
persistence_table.query(f"homology == {homology_dim}")["lifetime"].mean() | |
for homology_dim in homology_dimensions | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment