Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test insertion of simplex with NaN filtration value #424

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mglisse
Copy link
Member

@mglisse mglisse commented Nov 5, 2020

This patch documents (and tests) that inserting simplices with filtration value NaN does not modify the value for existing simplices.
Now to discuss whether that's actually the behavior we want 😉

@mglisse mglisse requested a review from tlacombe November 5, 2020 12:55
Copy link
Contributor

@tlacombe tlacombe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my (biased) perspective, it seems to be a nice addition. Perhaps it is almost useless (I don't really know how people use gudhi in general), but when you typically want to build a lower start filtration, starting from a complex + values on its vertices, this might simplify things a bit.

st.insert([4], 5.)
st.insert([2], -1.)
st.insert([1, 2, 4], math.nan)
assert math.isnan(st.filtration([2, 4]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert math.isnan(st.filtration([2, 4]))
assert math.isnan(st.filtration([2, 4]))
assert st.filtration([4]) == 5.
assert st.filtration([2]) == -1.
assert st.filtration([1]) == 2.
assert st.filtration([1,2]) == 2.

Perhaps we may want to make sure that we did not modify any of the previous values even before calling st.make_persistence_non_decreasing().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that checking after make_persistence_non_decreasing would be sufficient (if we overwrite a value with insert, make_persistence_non_decreasing won't be able to reinvent that value), but why not, done.

st = SimplexTree()
st.insert([1], 2.)
st.insert([4], 5.)
st.insert([2], -1.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
st.insert([2], -1.)
st.insert([2], -1.)
st.insert([1,2], 2.)

Perhaps already add a single edge (with an admissible value) to make sure that both inserting nan and make_filtration_non_decreasing() do not play any role there

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inserted an extra edge.

.. note::

Inserting a simplex with filtration value `math.nan` does not
modify the filtration value of any simplex already present.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps complete this note by adding a warning in the vein of what is done for assign_filtration() saying (e.g.) "In this particular case, the result will not be a valid filtration anymore. Callers are responsible for fixing this (using assign_filtration() or make_filtration_non_decreasing() for instance) before calling any function that relies on the filtration property, like persistence().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't realized it, but having some NaN in the complex can have some weird effects. In particular, if I have vertex 0 with value NaN, inserting edge [0, 1] with value 42 does not change the value of vertex 0. I added some confusing text to the doc. We could change that behavior, but would need to check that it doesn't slow things down for normal operations.

@VincentRouvreau
Copy link
Contributor

It would be nice to test it at C++ level. Here is a gist that translates the python test in C++.

@mglisse mglisse marked this pull request as draft November 26, 2020 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants