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

More consistent choice of a grid for diagram representations #719

Merged
merged 6 commits into from
Dec 15, 2022

Conversation

mglisse
Copy link
Member

@mglisse mglisse commented Nov 4, 2022

Fix #715.

@mglisse mglisse requested a review from wreise November 4, 2022 13:30
Copy link
Collaborator

@wreise wreise left a comment

Choose a reason for hiding this comment

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

The changes fully address the issue.

The definition of self.grid_ could be extracted to a common function for BettiCurve, Silhouette and Landscape. If you agree that it improves readability and reduces redundancy, then such changes could be included in this pr.

Comment on lines 346 to 353
self.nan_in_range = np.isnan(np.array(self.sample_range))
self.new_resolution = self.resolution
if not self.keep_endpoints:
self.new_resolution += self.nan_in_range.sum()
self.sample_range = _automatic_sample_range(np.array(self.sample_range), X, y)
self.grid_ = np.linspace(self.sample_range[0], self.sample_range[1], self.resolution)
self.grid_ = np.linspace(self.sample_range[0], self.sample_range[1], self.new_resolution)
if not self.keep_endpoints:
self.grid_ = _trim_endpoints(self.grid_, self.nan_in_range)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole block is common to the three classes t,argeted by this PR and they could be extracted. I think it might improve readability.

This would require moving the first 3 lines from __init__ tofit for Landscape and Silhouette.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I temporarily had a small problem where calling fit twice (possibly forbidden, but happens naturally with __call__) would be different from just once, but I fixed that.

"""
Constructor for the Landscape class.

Parameters:
num_landscapes (int): number of piecewise-linear functions to output (default 5).
resolution (int): number of sample for all piecewise-linear functions (default 100).
sample_range ([double, double]): minimum and maximum of all piecewise-linear function domains, of the form [x_min, x_max] (default [numpy.nan, numpy.nan]). It is the interval on which samples will be drawn evenly. If one of the values is numpy.nan, it can be computed from the persistence diagrams with the fit() method.
keep_endpoints (bool): when guessing `sample_range`, use the exact extremities (where the value is always 0). This is mostly useful for plotting, the default is to use a slightly smaller range.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is guessing the right word? What about something like when `sample_range` is not specified (contains np.nan)? Or provided?

Copy link
Member Author

@mglisse mglisse Nov 14, 2022

Choose a reason for hiding this comment

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

Ok. I guess "guessing" doesn't sound professional 😉
I used "compute" because that's the word used in the description of sample_range on the previous line.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect, thanks!

@mglisse
Copy link
Member Author

mglisse commented Nov 11, 2022

The changes fully address the issue.

Actually, I missed Entropy's vector mode 😞

Copy link
Collaborator

@wreise wreise left a comment

Choose a reason for hiding this comment

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

Actually, I missed Entropy's vector mode disappointed

I missed that it was available!

All good for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7.0 GUDHI version 3.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent sampling for landscape vs silhouette vs betticurve
3 participants