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

Change default value of nan_fill_value in PersistenceEntropy to -1 #474

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions gtda/diagrams/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ class PersistenceEntropy(BaseEstimator, TransformerMixin):
Can aid comparison between diagrams in an input collection when these
have different numbers of (non-trivial) points. [1]_

nan_fill_value : float or None, optional, default: ``None``
nan_fill_value : float or None, optional, default: ``-1.``
If a float, (normalized) persistence entropies initially computed as
``numpy.nan`` are replaced with this value.
``numpy.nan`` are replaced with this value. If ``None``, these values
are left as ``numpy.nan``.

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 @@ -78,9 +79,10 @@ class PersistenceEntropy(BaseEstimator, TransformerMixin):

_hyperparameters = {
'normalize': {'type': bool},
'nan_fill_value': {'type': (Real, type(None))}}
'nan_fill_value': {'type': (Real, type(None))}
}

def __init__(self, normalize=False, nan_fill_value=None, n_jobs=None):
def __init__(self, normalize=False, nan_fill_value=-1., n_jobs=None):
self.normalize = normalize
self.nan_fill_value = nan_fill_value
self.n_jobs = n_jobs
Expand Down Expand Up @@ -170,7 +172,7 @@ def transform(self, X, y=None):
_subdiagrams(X[s], [dim]),
normalize=self.normalize,
nan_fill_value=self.nan_fill_value
)
)
for dim in self.homology_dimensions_
for s in gen_even_slices(len(X), effective_n_jobs(self.n_jobs))
)
Expand Down
4 changes: 2 additions & 2 deletions gtda/diagrams/tests/test_features_representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_fit_transform_plot_one_hom_dim(transformer, hom_dim_idx):
transformer.fit_transform_plot(
X, sample=0, homology_dimension_idx=hom_dim_idx,
plotly_params=plotly_params
)
)


@pytest.mark.parametrize('transformer',
Expand All @@ -51,7 +51,7 @@ def test_fit_transform_plot_many_hom_dims(transformer, hom_dims):
{"traces": line_plots_traces_params, "layout": layout_params}
transformer.fit_transform_plot(
X, sample=0, homology_dimensions=hom_dims, plotly_params=plotly_params
)
)


@pytest.mark.parametrize('transformer',
Expand Down