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

output squared filtration values true/false mechanism for Delaunay complexes #1172

Merged

Conversation

VincentRouvreau
Copy link
Contributor

@VincentRouvreau VincentRouvreau commented Feb 10, 2025

Replace #1138 (remove function instead of classes)
While keeping backward compatibilities of former Delaunay complexes (cpp, utils and python)

Fix #80 and #771

Comment on lines 379 to 380
* \note Weighted Alpha complex can have negative filtration values. If `output_squared_values` is set to `false`,
* filtration values will be `NaN` in this case.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understood correctly, contrary to the regular Alpha filtration, the filtration values in a weighted Alpha filtration are not distances and the option of having $\alpha$ squared or not has not much meaning for it. It would make more sense in that case to ignore output_squared_values. If the user did not want the filtration values (what the NaN represent, I guess?), he would just use a simplex tree with store_filtration at false, no?

Or are the NaN needed for some cases? Or did I simply misunderstood something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the weighted case, filtration values are the power distance of the smallest power sphere, and it can be a negative value. If it is asked to square root the filtration values, these will be NaN. I am ok with the idea to deactivate the square root mechanism in the weighted case. I will print a user warning in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The power distance is not euclidean, from which the "square trick" is coming from. The option of squared or not squared feels off topic in this context. So, I would be more in the favor that we ignore this argument in the case of weighted alpha complexes (i.e., we do the same thing whatever its value). We could just state it like that in the documentation of the method, I am not sure a warning is needed then.
Except is there is some technical detail for which the NaN are helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did so on 44a6747, but I had to print a warning to the user in case he sets weights but don't want square filtration values.

Comment on lines +399 to +400
// For users to be able to define their own sqrt function on their desired Filtration_value type
using std::sqrt;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could perhaps add in the concept of SimplicialComplexForAlpha that for "custom" filtration value types, having its own sqrt is possible and if not existing std::sqrt is used instead?

Copy link
Contributor Author

@VincentRouvreau VincentRouvreau Feb 14, 2025

Choose a reason for hiding this comment

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

I specified it on 021561a

@@ -29,8 +30,9 @@ using Simplex_tree = Gudhi::Simplex_tree<>;
using Filtration_value = Simplex_tree::Filtration_value;

void program_options(int argc, char *argv[], std::string &off_file_points, bool &exact, bool &fast,
std::string &weight_file, std::string &output_file_diag, Filtration_value &alpha_square_max_value,
int &coeff_field_characteristic, Filtration_value &min_persistence);
bool& output_squared_root_values, std::string &weight_file, std::string &output_file_diag,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it be output_squared_values instead of output_squared_root_values? To be more consistent with the create_complex interface.

And is the correct term not square_root (without de d)? Or is it used as some sort of verb?

Edit: it seems that for the utilities in general (also for cech etc.), the option is inverted to the notion for the option. Was there a particular reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, for the utilities the option is inverted because I wanted to keep backward compatibility.
Before this feature, it was returning squared values, so I wanted the utils to keep the behaviour.
And then the user can ask for square root filtration values with -s.

Does it seem ok for you ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I just realized that this code will only be used precompiled with command lines, it is not a method to include. The only way to keep the old behaviour without inverting the argument would be to use -squared-filtrations=ON by default and explicity put -squared-filtrations=OFF instead of --square-root-filtrations in the command line arguments.

If this is too annoying to do, just keep it like that then. But I would still correct output_squared_root_values to output_square_root_values. Or be more explicit about the meaning of the option with do_not_square_filtration_values.

On this note, we could also change output_squared_values to use_squared_filtration_values / output_squared_filtration_values. As just value sounds a bit vague. But that is perhaps a bit subjective.

Copy link
Contributor Author

@VincentRouvreau VincentRouvreau Feb 14, 2025

Choose a reason for hiding this comment

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

I did so on 44a6747, 4227322 and 404cb39

}
}
std::clog << "Weighted alpha complex with output_squared_values\n";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it the other way around? "without output_squared_values", as create_complex<false> is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed the log on a8d8634

src/Alpha_complex/utilities/alpha_complex_persistence.cpp Outdated Show resolved Hide resolved
src/Alpha_complex/utilities/alpha_complex_persistence.cpp Outdated Show resolved Hide resolved
src/Alpha_complex/utilities/alpha_complex_persistence.cpp Outdated Show resolved Hide resolved
src/Alpha_complex/utilities/alpha_complex_persistence.cpp Outdated Show resolved Hide resolved
@VincentRouvreau
Copy link
Contributor Author

@mglisse In the Weighted case, do you think we should always set output_squared_values to true ? As the distances can be negative, we would never have NaN values like this. This would be another way of coding the feature that may be (or not) less confusing for the end-user, no ?

@VincentRouvreau VincentRouvreau added the enhancement New feature or request label Feb 14, 2025
@VincentRouvreau
Copy link
Contributor Author

@hschreiber I took your proposal on 4ee4878 to always set output_squared_values to true in the weighted case, I just throw an exception otherwise. Does it fit what you were proposing ? I tried to static_assert, but it doesn't fit our need with the python interface. I could also ignore the user's choice in this case, but exceptions are quite convenient in Python.

Comment on lines 379 to 380
* \exception std::invalid_argument In case of a Weighted Alpha complex with `Output_squared_values` set to `false`,
* as Weighted Alpha complex can have negative filtration values.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Radical, but I am fine with the new proposition (even though, the value should be the other way around, as the filtration value is not squared (couldn't be negative otherwise), but technically it would not fit with the default value of the non weighted case). But here I would write "..., as the filtration values of a Weighted Alpha complex results from a power product and not from an euclidean distance. Therefore this template argument should be kept to the default value." instead of "..., as Weighted Alpha complex can have negative filtration values."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am fine with your proposal. On bc7fbb6

@VincentRouvreau VincentRouvreau added the 3.11.0 GUDHI version 3.11.0 label Feb 18, 2025
@VincentRouvreau VincentRouvreau merged commit 1f274c8 into GUDHI:master Feb 18, 2025
7 checks passed
@VincentRouvreau VincentRouvreau deleted the delaunay_square_root_filtrations branch February 18, 2025 14:32
@mglisse
Copy link
Member

mglisse commented Feb 19, 2025

@mglisse In the Weighted case, do you think we should always set output_squared_values to true ? As the distances can be negative, we would never have NaN values like this. This would be another way of coding the feature that may be (or not) less confusing for the end-user, no ?

If a user knows they always have positive weights and wants the square root, it seems a bit disappointing to say NO when it would actually work just fine.

filtration: Set this value to `None` (default value) if filtration values are not needed to be computed
(will be set to `NaN`). Set it to `alpha` to compute the filtration values with the Alpha complex, or
to `cech` to compute the Delaunay Cech complex.
output_squared_values: Square filtration values when `True`. Default is `True`.
Copy link
Member

Choose a reason for hiding this comment

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

Does the Python doc mention somewhere that passing False can be dangerous with negative weights?

@hschreiber
Copy link
Collaborator

hschreiber commented Feb 19, 2025

@mglisse In the Weighted case, do you think we should always set output_squared_values to true ? As the distances can be negative, we would never have NaN values like this. This would be another way of coding the feature that may be (or not) less confusing for the end-user, no ?

If a user knows they always have positive weights and wants the square root, it seems a bit disappointing to say NO when it would actually work just fine.

But what is the meaning of a "square rooted filtration value" of a weighted alpha complex? Would we return something like ||x-y||² - w when output_squared_values is true and ||x-y|| - w when false? Or sqrt(||x-y||² - w) when positive? I don't even know if CGAL makes it possible. In both cases, I don't feel like it is Gudhi's responsability to handle how users want to post-process the power product when there is no clear convention for it. Or is there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11.0 GUDHI version 3.11.0 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Alpha_complex] new do_sqrt argument
3 participants