gudhi-devel icon indicating copy to clipboard operation
gudhi-devel copied to clipboard

Possible bug in cofaces_of_persistence_pairs

Open afperezm opened this issue 2 years ago • 1 comments

I am trying to obtain the persistence birth and death cells for the following image:

Figure_1

To this end I am using the cofaces_of_persistence_pairs function from CubicalComplex as follows:

cc = gd.CubicalComplex(
    dimensions=X.shape,
    top_dimensional_cells=X.flatten()
)

cc.compute_persistence(homology_coeff_field=2, min_persistence=0.0)
pairs_lh = cc.cofaces_of_persistence_pairs()

The function returns two lists, the first list contains the regular persistence pairs and the second list contains the essential features. However the first array of the first list containing the regular persistence pairs is empty while the second array is not:

The length of pairs_lh[0][0] differs from that of pairs_lh[0][1], why is this happening?

afperezm avatar Jun 11 '22 22:06 afperezm

If you refer to CubicalComplex.cofaces_of_persistence_pairs documentation, it says:

The top-dimensional cells/cofaces of the positive and negative cells, together with the corresponding homological dimension, in two lists of numpy arrays of integers. The first list contains the regular persistence pairs, grouped by dimension. It contains numpy arrays of shape [number_of_persistence_points, 2].

So if you take the following example (sorry, your image was not available):

from sklearn.datasets import fetch_openml
import matplotlib.pyplot as plt
import gudhi as gd

X, y = fetch_openml("mnist_784", version=1, return_X_y=True, as_frame=False)

# X[17] is an '8'
cc = gd.CubicalComplex(top_dimensional_cells=X[17], dimensions=[28, 28])
diag = cc.persistence()
# diag = [(1, (0.0, 255.0)), (1, (223.0, 254.0)), (1, (228.0, 253.0)), (1, (236.0, 254.0)), (1, (236.0, 253.0)), (1, (239.0, 254.0)), (1, (215.0, 229.0)), (1, (244.0, 254.0)), (1, (245.0, 253.0)), (1, (253.0, 254.0)), (1, (253.0, 254.0)), (1, (253.0, 254.0)), (1, (253.0, 254.0)), (0, (0.0, inf)), (0, (0.0, 234.0)), (0, (0.0, 223.0))]
pp = cc.cofaces_of_persistence_pairs()

pp[0][0] contains cofaces of persistence pairs for dimension 0 (the ones that creates [(0, (0.0, 234.0)), (0, (0.0, 223.0))]):

pp[0][0]
# array([[783, 211],
#        [570, 573]])
# 2 cofaces of persistence pairs for dimension 0, that's ok as there are 2 persistence pairs in dimension 0

pp[0][1] contains cofaces of persistence pairs for dimension 1 (the ones that creates [(1, (0.0, 255.0)), (1, (223.0, 254.0)), (1, (228.0, 253.0)), (1, (236.0, 254.0)), (1, (236.0, 253.0)), (1, (239.0, 254.0)), (1, (215.0, 229.0)), (1, (244.0, 254.0)), (1, (245.0, 253.0)), (1, (253.0, 254.0)), (1, (253.0, 254.0)), (1, (253.0, 254.0)), (1, (253.0, 254.0))]):

# array([[189, 161],
#        [241, 213],
#        [263, 264],
#        [655, 628],
#        [292, 291],
#        [299, 298],
#        [406, 407],
#        [462, 434],
#        [459, 514],
#        [596, 568],
#        [540, 574],
#        [326, 654],
#        [711, 216]])
# 13 cofaces of persistence pairs for dimension 1 that's ok as there are 13 persistence pairs in dimension 1

Is it clearer for you @afperezm , or did I miss something ?

VincentRouvreau avatar Jun 14 '22 13:06 VincentRouvreau