Skip to content

Commit

Permalink
Change meaning of default None for weight_function in PersistenceImage
Browse files Browse the repository at this point in the history
- ``None`` corresponding the identity means that there really is a non-trivial weighting in that case. Semantically, this does not seem correct ("None" should mean no weighting at all)
  • Loading branch information
ulupo committed Aug 11, 2020
1 parent 0852b02 commit 011bac7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gtda/diagrams/_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sklearn.utils import gen_even_slices
from sklearn.utils.validation import _num_samples

from ._utils import identity, _subdiagrams, _sample_image
from ._utils import _subdiagrams, _sample_image
from ..externals.modules.gtda_bottleneck import bottleneck_distance
from ..externals.modules.gtda_wasserstein import wasserstein_distance
from ..utils.intervals import Interval
Expand Down
11 changes: 6 additions & 5 deletions gtda/diagrams/representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ._metrics import betti_curves, landscapes, heats, \
persistence_images, silhouettes
from ._utils import identity, _subdiagrams, _bin
from ._utils import _subdiagrams, _bin
from ..base import PlotterMixin
from ..plotting import plot_heatmap
from ..utils._docs import adapt_fit_transform_docs
Expand Down Expand Up @@ -752,9 +752,10 @@ class PersistenceImage(BaseEstimator, TransformerMixin, PlotterMixin):
dimension, to sample during :meth:`fit`.
weight_function : callable or None, default: ``None``
Function mapping the 1D array of persistence values of the points of an
input diagram to a 1D array of weights. ``None`` is equivalent to
passing the identity function.
Function mapping the 1D array of sampled persistence values (see
:attr:`samplings_`) to a 1D array of weights. ``None`` is equivalent to
passing ``numpy.ones_like``. More weight can be given to regions of
high persistence by passing a monotonic function, e.g. the identity.
n_jobs : int or None, optional, default: ``None``
The number of jobs to use for the computation. ``None`` means 1 unless
Expand Down Expand Up @@ -851,7 +852,7 @@ def fit(self, X, y=None):
self.get_params(), self._hyperparameters, exclude=["n_jobs"])

if self.weight_function is None:
self.effective_weight_function_ = identity
self.effective_weight_function_ = np.ones_like
else:
self.effective_weight_function_ = self.weight_function

Expand Down

0 comments on commit 011bac7

Please sign in to comment.