The following code is for “Homology Groups”. I used library for implementation purpose.
import gudhi
# Create a simplicial complex
simplex_tree = gudhi.SimplexTree()
simplex_tree.insert([1, 2, 3])
simplex_tree.insert([2, 3, 4])
simplex_tree.insert([3, 4, 5])
# Compute homology
homology = simplex_tree.persistence()
print("Homology groups:")
for interval in homology:
dim, (birth, death) = interval
print(f"Dimension {dim}: birth = {birth}, death = {death}")
The output I get
Homology groups:
Dimension 0: birth = 0.0, death = inf
Why I did not get the output for Dimension 1?
The reason is:
As defined in the code, there are no non-trivial 1-dimensional loops.
if there is no 1-d features that presist by homology
e.g.
a loop like 1>2>3>1 exists but it is filled by triangle so it does not contribute to the first homology group H1
I hope you will get the point, otherwise you can ask for further clarification and I will further explain
try these lines in your code as well to loop and print the H1 I hope it will work for you 🙂
print("Homology groups:")
for interval in
simplex_tree.persistence_intervals_in_dimension(0):
print(f"Dimension 0: birth = {interval[0]}, death =
{interval[1]}")
for interval in
simplex_tree.persistence_intervals_in_dimension(1):
print(f"Dimension 1: birth = {interval[0]}, death =
{interval[1]}")
2
Can you try this with 1 D cycle
import gudhi
# Create a simplicial complex with a 1D cycle
simplex_tree = gudhi.SimplexTree()
simplex_tree.insert([1, 2])
simplex_tree.insert([2, 3])
simplex_tree.insert([3, 4])
simplex_tree.insert([4, 1])
# Forms a 1D loop
# Compute homology
homology = simplex_tree.persistence()
print("Homology groups:")
for interval in homology:
dim, (birth, death) = interval
print(f"Dimension {dim}: birth = {birth}, death = {death}")
Homology groups:
Dimension 0: birth = 0.0, death = inf
Dimension 1: birth = 0.0, death = inf
Now its working for myself as I just change in your code and limited the dim to 1d Create a simplicial complex with a 1D cycle