IBM / matilda

maTilDA - Multipurpose toolkit for TDA
Apache License 2.0
3 stars 2 forks source link

Suspicious number of persistent 1-cycles when creating a FilteredComplex from scratch #2

Open janfsenge opened 4 months ago

janfsenge commented 4 months ago

When creating a FilteredComplex from scratch by giving the simplices, indices and filtration values for a triangulation (with one hole for some time), there can appear superfluous persistent 1-cycles.

Attached example below

issue_persistence.ipynb.zip

Screenshot 2024-02-27 at 21 33 01
aldo-at-ibm commented 4 months ago

Hi @janfsenge, thank you for bringing this to our attention. Would it be possible for you to also share how Ks was constructed, to help us diagnose the issue?

janfsenge commented 4 months ago

Hi @aldo-at-ibm ,

sorry, seems that the attachment of the jupyter file did not work. Here is a MWE for when thickening the empty rectangle before closing it in the end results in 4 infinite 1-dim homology classes.

# Construct the filtered simplicial complex
simplices = [[0],[1],[2],[3],
 [0, 1],[0, 2],[1, 3],[2, 3],
 [4],[5],[6],[7],[8],[9],[10],[11],
 [0, 4],[4, 8],[2, 4],[5, 6],[0, 5],[1, 5],[5, 6],[1, 6],[1, 7],[7, 10],[4, 8],
 [2, 8],[2, 9],[9, 11],[3, 10],[7, 10],[1, 10],[9, 11],[3, 11],[2, 11],
 [2, 4, 8],[0, 2, 4],[0, 1, 5],[1, 5, 6],[1, 3, 10],[1, 7, 10],[2, 9, 11],[2, 3, 11],
 [0, 3],[0, 1, 3],[0, 2, 3]]

indices = range(55)

appears_at = \
  [0,0,0,0,
   0,0,0,0,
   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
   10,10,10]

# just for the plotting
pos = {0: [0, 1],1: [1, 1], 2: [0, 0], 3: [1, 0], 4: [-1, 1], 5: [0, 2], 6: [1, 2], 7: [2, 1], 8: [-1, 0], 9: [0, -1], 10: [2, 0], 11: [1, -1]}

# check if we adhere to the ordering of simplices
for simp in simplices:
    assert sorted(simp) == simp

Ks = matilda.FilteredSimplicialComplex(
    dimension=2,
    simplices=simplices,
    simplices_indices=indices,
    appears_at=appears_at
)

# check the indices of the simplices
Ks.make_consistent_indices()
Ks.has_valid_filtration()

# now get the homologies
homology_computer = matilda.PersistentHomologyComputer()
homology_computer.compute_persistent_homology(Ks)

for k,v in homology_computer.bars.items():
    if k>1:
        break
    print("Bars of dimension {}".format(k))
    for kk,vv in v.items():
        print("{}:{}".format(kk,vv))