GUDHI / gudhi-devel

The GUDHI library is a generic open source C++ library, with a Python interface, for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.
https://gudhi.inria.fr/
MIT License
249 stars 65 forks source link

[bug] a strange result of extended_persistentce #601

Closed TJPaik closed 2 years ago

TJPaik commented 2 years ago

Hello, I'm a student who is interested in TDA. While using the gudhi, I found something strange. Please look at the code below.

import gudhi

st = gudhi.SimplexTree()

st.insert([0, 1], filtration=2)
st.insert([2, 3], filtration=1)
st.insert([1, 2], filtration=3)

st.make_filtration_non_decreasing()

dgm = st.persistence(homology_coeff_field=2,)
for el in dgm:
    print(el)
print('-----------------')
st.extend_filtration()
dgms = st.extended_persistence(homology_coeff_field=2, )
print(dgms)

The result is :

(0, (1.0, inf))
(0, (2.0, 3.0))
-----------------
[[], [], [(0, (1.0, 2.0))], []]

I think the ordinary part of extended persistent homology and the barcode of just persistent homology (excluding infinite barcode) should be the same, but the result is different. I think it's a bug if I didn't misunderstand the documentation.

mglisse commented 2 years ago

The documentation for extend_filtration() says

This function only uses the filtration values at the 0-dimensional simplices, and computes the extended persistence diagram induced by the lower-star filtration computed with these values.

The st on which you compute persistence is not a lower-star filtration, so it isn't surprising you get different results. Currently, your call to st.make_filtration_non_decreasing() has no effect. Did you mean to do st.reset_filtration(-np.inf,min_dim=1) before that?

TJPaik commented 2 years ago

@mglisse Thanks! I must have read it wrong. Thank you for fixing it. Let me close this issue. 👍 I just added the make_filtration_non_decreasing part to make sure.