Skip to content
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
2 changes: 2 additions & 0 deletions docs/source/notebooks/circles.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
fig = plot.plot_plotly(
colors=labels,
cmap=["jet", "viridis", "cividis"],
node_size=[0.0, 0.5, 1.0, 1.5, 2.0],
agg=np.nanmean,
width=600,
height=600,
Expand All @@ -118,6 +119,7 @@
fig = plot.plot_plotly(
colors=labels,
cmap=["jet", "viridis", "cividis"],
node_size=[0.0, 0.5, 1.0, 1.5, 2.0],
agg=np.nanstd,
width=600,
height=600,
Expand Down
4 changes: 2 additions & 2 deletions docs/source/notebooks/digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ def mode(arr):
colors=labels,
cmap=["jet", "viridis", "cividis"],
agg=mode,
node_size=[0.0, 0.5, 1.0, 1.5, 2.0],
title="mode of digits",
width=600,
height=600,
node_size=0.5,
)

fig.show(config={"scrollZoom": True}, renderer="notebook_connected")
Expand Down Expand Up @@ -134,10 +134,10 @@ def entropy(arr):
colors=labels,
cmap=["jet", "viridis", "cividis"],
agg=entropy,
node_size=[0.0, 0.5, 1.0, 1.5, 2.0],
title="entropy of digits",
width=600,
height=600,
node_size=0.5,
)

fig.show(config={"scrollZoom": True}, renderer="notebook_connected")
Expand Down
16 changes: 8 additions & 8 deletions src/tdamapper/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def warn_user(msg):

class EstimatorMixin:

def __is_sparse(self, X):
def _is_sparse(self, X):
# simple alternative use scipy.sparse.issparse
return hasattr(X, "toarray")

def _validate_X_y(self, X, y):
if self.__is_sparse(X):
if self._is_sparse(X):
raise ValueError("Sparse data not supported.")

X = np.asarray(X)
Expand Down Expand Up @@ -80,10 +80,10 @@ class ParamsMixin:
scikit-learn `get_params` and `set_params`.
"""

def __is_param_public(self, k):
def _is_param_public(self, k):
return (not k.startswith("_")) and (not k.endswith("_"))

def __split_param(self, k):
def _split_param(self, k):
k_split = k.split("__")
outer = k_split[0]
inner = "__".join(k_split[1:])
Expand All @@ -98,7 +98,7 @@ def get_params(self, deep=True):
"""
params = {}
for k, v in self.__dict__.items():
if self.__is_param_public(k):
if self._is_param_public(k):
params[k] = v
if hasattr(v, "get_params") and deep:
for _k, _v in v.get_params().items():
Expand All @@ -111,8 +111,8 @@ def set_params(self, **params):
"""
nested_params = []
for k, v in params.items():
if self.__is_param_public(k):
k_outer, k_inner = self.__split_param(k)
if self._is_param_public(k):
k_outer, k_inner = self._split_param(k)
if not k_inner:
if hasattr(self, k_outer):
setattr(self, k_outer, v)
Expand All @@ -131,7 +131,7 @@ def __repr__(self):
v_default = getattr(obj_noargs, k)
v_default_repr = repr(v_default)
v_repr = repr(v)
if self.__is_param_public(k) and not v_repr == v_default_repr:
if self._is_param_public(k) and not v_repr == v_default_repr:
args_repr.append(f"{k}={v_repr}")
return f"{self.__class__.__name__}({', '.join(args_repr)})"

Expand Down
42 changes: 21 additions & 21 deletions src/tdamapper/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
:return: The object itself.
:rtype: self
"""
self.__X = X
self._X = X

Check warning on line 300 in src/tdamapper/core.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/core.py#L300

Added line #L300 was not covered by tests
return self

def search(self, x):
Expand All @@ -314,7 +314,7 @@
dataset.
:rtype: list[int]
"""
return list(range(0, len(self.__X)))
return list(range(0, len(self._X)))

Check warning on line 317 in src/tdamapper/core.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/core.py#L317

Added line #L317 was not covered by tests

def apply(self, X):
"""
Expand Down Expand Up @@ -385,27 +385,27 @@

def fit(self, X, y=None):
X, y = self._validate_X_y(X, y)
self.__cover = TrivialCover() if self.cover is None else self.cover
self.__clustering = (
self._cover = TrivialCover() if self.cover is None else self.cover
self._clustering = (
TrivialClustering() if self.clustering is None else self.clustering
)
self.__verbose = self.verbose
self.__failsafe = self.failsafe
if self.__failsafe:
self.__clustering = FailSafeClustering(
clustering=self.__clustering,
verbose=self.__verbose,
self._verbose = self.verbose
self._failsafe = self.failsafe
if self._failsafe:
self._clustering = FailSafeClustering(
clustering=self._clustering,
verbose=self._verbose,
)
self.__cover = clone(self.__cover)
self.__clustering = clone(self.__clustering)
self.__n_jobs = self.n_jobs
self._cover = clone(self._cover)
self._clustering = clone(self._clustering)
self._n_jobs = self.n_jobs
y = X if y is None else y
self.graph_ = mapper_graph(
X,
y,
self.__cover,
self.__clustering,
n_jobs=self.__n_jobs,
self._cover,
self._clustering,
n_jobs=self._n_jobs,
)
self._set_n_features_in(X)
return self
Expand Down Expand Up @@ -451,16 +451,16 @@
self.verbose = verbose

def fit(self, X, y=None):
self.__clustering = (
self._clustering = (
TrivialClustering() if self.clustering is None else self.clustering
)
self.__verbose = self.verbose
self._verbose = self.verbose
self.labels_ = None
try:
self.__clustering.fit(X, y)
self.labels_ = self.__clustering.labels_
self._clustering.fit(X, y)
self.labels_ = self._clustering.labels_
except ValueError as err:
if self.__verbose:
if self._verbose:
_logger.warning("Unable to perform clustering on local chart: %s", err)
self.labels_ = [0 for _ in X]
return self
Expand Down
26 changes: 13 additions & 13 deletions src/tdamapper/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ def fit(self, X):
:rtype: self
"""
metric = get_metric(self.metric, **(self.metric_params or {}))
self.__radius = self.radius
self.__data = list(enumerate(X))
self.__vptree = VPTree(
self.__data,
self._radius = self.radius
self._data = list(enumerate(X))
self._vptree = VPTree(
self._data,
metric=_Pullback(_snd, metric),
metric_params=None,
kind=self.kind,
Expand All @@ -121,11 +121,11 @@ def search(self, x):
:return: The indices of the neighbors contained in the dataset.
:rtype: list[int]
"""
if self.__vptree is None:
if self._vptree is None:
return []
neighs = self.__vptree.ball_search(
neighs = self._vptree.ball_search(
(-1, x),
self.__radius,
self._radius,
inclusive=False,
)
return [x for (x, _) in neighs]
Expand Down Expand Up @@ -198,10 +198,10 @@ def fit(self, X):
:rtype: self
"""
metric = get_metric(self.metric, **(self.metric_params or {}))
self.__neighbors = self.neighbors
self.__data = list(enumerate(X))
self.__vptree = VPTree(
self.__data,
self._neighbors = self.neighbors
self._data = list(enumerate(X))
self._vptree = VPTree(
self._data,
metric=_Pullback(_snd, metric),
metric_params=None,
kind=self.kind,
Expand All @@ -223,9 +223,9 @@ def search(self, x):
:return: The indices of the neighbors contained in the dataset.
:rtype: list[int]
"""
if self.__vptree is None:
if self._vptree is None:
return []
neighs = self.__vptree.knn_search((-1, x), self.__neighbors)
neighs = self._vptree.knn_search((-1, x), self._neighbors)
return [x for (x, _) in neighs]


Expand Down
98 changes: 47 additions & 51 deletions src/tdamapper/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import numpy as np

from tdamapper._common import deprecated
from tdamapper._plot_matplotlib import plot_matplotlib
from tdamapper._plot_plotly import plot_plotly, plot_plotly_update
from tdamapper._plot_pyvis import plot_pyvis
from tdamapper.plot_backends.plot_matplotlib import plot_matplotlib
from tdamapper.plot_backends.plot_plotly import plot_plotly, plot_plotly_update
from tdamapper.plot_backends.plot_pyvis import plot_pyvis


class MapperPlot:
Expand Down Expand Up @@ -206,10 +206,6 @@
cmap=cmap,
)

@deprecated(
"This method is deprecated and will be removed in a future release. "
"Use a new instance of tdamapper.plot.MapperPlot."
)
def plot_plotly_update(
self,
fig,
Expand Down Expand Up @@ -382,29 +378,29 @@
height=512,
cmap="jet",
):
self.__graph = graph
self.__dim = dim
self.__iterations = iterations
self.__seed = seed
self.__mapper_plot = MapperPlot(
graph=self.__graph,
dim=self.__dim,
iterations=self.__iterations,
seed=self.__seed,
self._graph = graph
self._dim = dim
self._iterations = iterations
self._seed = seed
self._mapper_plot = MapperPlot(

Check warning on line 385 in src/tdamapper/plot.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/plot.py#L381-L385

Added lines #L381 - L385 were not covered by tests
graph=self._graph,
dim=self._dim,
iterations=self._iterations,
seed=self._seed,
)
self.__colors = colors
self.__agg = agg
self.__title = title
self.__width = width
self.__height = height
self.__cmap = cmap
self.__fig = self.__mapper_plot.plot_plotly(
colors=self.__colors,
agg=self.__agg,
title=self.__title,
width=self.__width,
height=self.__height,
cmap=self.__cmap,
self._colors = colors
self._agg = agg
self._title = title
self._width = width
self._height = height
self._cmap = cmap
self._fig = self._mapper_plot.plot_plotly(

Check warning on line 397 in src/tdamapper/plot.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/plot.py#L391-L397

Added lines #L391 - L397 were not covered by tests
colors=self._colors,
agg=self._agg,
title=self._title,
width=self._width,
height=self._height,
cmap=self._cmap,
)

def update(
Expand Down Expand Up @@ -451,20 +447,20 @@
"""
_update_pos = False
if seed is not None:
self.__seed = seed
self._seed = seed

Check warning on line 450 in src/tdamapper/plot.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/plot.py#L450

Added line #L450 was not covered by tests
_update_pos = True
if iterations is not None:
self.__iterations = iterations
self._iterations = iterations

Check warning on line 453 in src/tdamapper/plot.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/plot.py#L453

Added line #L453 was not covered by tests
_update_pos = True
if _update_pos:
self.__mapper_plot = MapperPlot(
graph=self.__graph,
dim=self.__dim,
iterations=self.__iterations,
seed=self.__seed,
self._mapper_plot = MapperPlot(

Check warning on line 456 in src/tdamapper/plot.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/plot.py#L456

Added line #L456 was not covered by tests
graph=self._graph,
dim=self._dim,
iterations=self._iterations,
seed=self._seed,
)
self.__mapper_plot.plot_plotly_update(
self.__fig,
self._mapper_plot.plot_plotly_update(

Check warning on line 462 in src/tdamapper/plot.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/plot.py#L462

Added line #L462 was not covered by tests
self._fig,
colors=colors,
agg=agg,
title=title,
Expand All @@ -482,7 +478,7 @@
context to be shown.
:rtype: :class:`plotly.graph_objects.Figure`
"""
return self.__fig
return self._fig

Check warning on line 481 in src/tdamapper/plot.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/plot.py#L481

Added line #L481 was not covered by tests


class MapperLayoutStatic:
Expand Down Expand Up @@ -543,12 +539,12 @@
height=512,
cmap="jet",
):
self.__colors = colors
self.__agg = agg
self.__title = title
self.__width = width
self.__height = height
self.__cmap = cmap
self._colors = colors
self._agg = agg
self._title = title
self._width = width
self._height = height
self._cmap = cmap

Check warning on line 547 in src/tdamapper/plot.py

View check run for this annotation

Codecov / codecov/patch

src/tdamapper/plot.py#L542-L547

Added lines #L542 - L547 were not covered by tests
self.mapper_plot = MapperPlot(
graph=graph,
dim=dim,
Expand All @@ -566,10 +562,10 @@
:class:`matplotlib.axes.Axes`
"""
return self.mapper_plot.plot_matplotlib(
colors=self.__colors,
agg=self.__agg,
title=self.__title,
width=self.__width,
height=self.__height,
cmap=self.__cmap,
colors=self._colors,
agg=self._agg,
title=self._title,
width=self._width,
height=self._height,
cmap=self._cmap,
)
Empty file.
Loading