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
258 stars 66 forks source link

Re-expand simplextrees after edge collapse #768

Open DavidLapous opened 1 year ago

DavidLapous commented 1 year ago

As far as I'm aware, edge collapses are only useful for graphs and clique complexes. Wouldn't that make sense to re-expand by default the simplextree to its original dimension after collapsing ? That will ensure that clique complexes simplextrees preserves their homology. I'm thinking about something like this in the simplextree.pyx file

def collapse_edges(self, max_dimension:int=None, num:int=1, ...)->SimplexTree:
    max_dimension = self.dimension() if max_dimension is None else max_dimension
    <old code for collapse>
    self.expansion(max_dimension) # Expands back the simplextree to the original dimension.
    return self
mglisse commented 1 year ago

Thank you for this suggestion. The main goal of edge collapses is to avoid computing the complex you would use as input in your code. That is, we only want to build triangles, tetrahedra, etc after doing the edge collapse. I am afraid that if we did what you suggest, some users would get confused into doing expansion before edge collapse, defeating the purpose. There could be valid reasons to expand, then collapse and expand again, if only to see how many simplices you save with the collapses, but that looks like a rather niche use case, with an easy workaround (call expansion yourself afterwards), so for now I think I'd rather not do it. But I'll leave this issue open for a while, to see if other opinions are coming.

Note that we will probably add an extra interface to edge collapses in Python, working on coo_matrix or similar.

DavidLapous commented 1 year ago

I am afraid that if we did what you suggest, some users would get confused into doing expansion before edge collapse, defeating the purpose.

That's a very good point. Do you think that adding a (python) warning in that case would be enough to prevent users to do that ?

mglisse commented 1 year ago

That's a very good point. Do you think that adding a (python) warning in that case would be enough to prevent users to do that ?

In collapse_edges, adding something like if self.dimension() > 1: print("Warning: collapse_edges() ignores all the simplices of dimension 2 or more in this complex", file=sys.stderr)? Yes, I think that would be ok.