Search code examples
pythontopology

Gudhi python library did not show the output for dimension 1


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?


Solution

  • 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