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

[MNT] Change the "metric" parameter to "measure in the distance module #2403

Merged
merged 2 commits into from
Nov 26, 2024
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
6 changes: 3 additions & 3 deletions aeon/classification/distance_based/_proximity_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _get_best_splitter(self, X, y):
dist = distance(
X[j],
splitter[0][labels[k]],
metric=measure,
measure=measure,
**splitter[1][measure],
)
if dist < min_dist:
Expand Down Expand Up @@ -320,7 +320,7 @@ def _build_tree(self, X, y, depth, node_id, parent_target_value=None):
dist = distance(
X[i],
splitter[0][labels[j]],
metric=measure,
measure=measure,
**splitter[1][measure],
)
if dist < min_dist:
Expand Down Expand Up @@ -404,7 +404,7 @@ def _classify(self, treenode, x):
dist = distance(
x,
treenode.splitter[0][branches[i]],
metric=measure,
measure=measure,
**treenode.splitter[1][measure],
)
if dist < min_dist:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _fit(self, X, y):
y : array-like, shape = (n_cases)
The class labels.
"""
self.metric_ = get_distance_function(metric=self.distance)
self.metric_ = get_distance_function(measure=self.distance)
self.X_ = X
self.classes_, self.y_ = np.unique(y, return_inverse=True)
return self
Expand Down
6 changes: 3 additions & 3 deletions aeon/clustering/_clara.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TimeSeriesCLARA(BaseClusterer):
If a np.ndarray provided it must be of shape (n_clusters,) and contain
the indexes of the time series to use as centroids.
distance : str or Callable, default='msm'
Distance metric to compute similarity between time series. A list of valid
Distance measure to compute similarity between time series. A list of valid
strings for metrics can be found in the documentation for
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
a function that takes two 2d numpy arrays as input and returns a float.
Expand Down Expand Up @@ -73,7 +73,7 @@ class TimeSeriesCLARA(BaseClusterer):
If `None`, the random number generator is the `RandomState` instance used
by `np.random`.
distance_params : dict, default=None
Dictionary containing kwargs for the distance metric being used.
Dictionary containing kwargs for the distance measure being used.

Attributes
----------
Expand Down Expand Up @@ -189,7 +189,7 @@ def _fit(self, X: np.ndarray, y=None):
curr_centers = pam.cluster_centers_
if isinstance(pam.distance, str):
pairwise_matrix = pairwise_distance(
X, curr_centers, metric=self.distance, **pam._distance_params
X, curr_centers, measure=self.distance, **pam._distance_params
)
else:
pairwise_matrix = pairwise_distance(
Expand Down
6 changes: 3 additions & 3 deletions aeon/clustering/_clarans.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class TimeSeriesCLARANS(TimeSeriesKMedoids):
If a np.ndarray provided it must be of shape (n_clusters,) and contain
the indexes of the time series to use as centroids.
distance : str or Callable, default='msm'
Distance metric to compute similarity between time series. A list of valid
strings for metrics can be found in the documentation for
Distance measure to compute similarity between time series. A list of valid
strings for measures can be found in the documentation for
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
a function that takes two 2d numpy arrays as input and returns a float.
max_neighbours : int, default=None,
Expand All @@ -62,7 +62,7 @@ class TimeSeriesCLARANS(TimeSeriesKMedoids):
random_state : int or np.random.RandomState instance or None, default=None
Determines random number generation for centroid initialization.
distance_params : dict, default=None
Dictionary containing kwargs for the distance metric being used.
Dictionary containing kwargs for the distance measure being used.

Attributes
----------
Expand Down
8 changes: 4 additions & 4 deletions aeon/clustering/_elastic_som.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class ElasticSOM(BaseClusterer):
n_clusters : int, default=8
The number of clusters to form as well as the number of centroids to generate.
distance : str or Callable, default='dtw'
Distance metric to compute similarity between time series. A list of valid
strings for metrics can be found in the documentation for
Distance measure to compute similarity between time series. A list of valid
strings for measures can be found in the documentation for
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
a function that takes two 2d numpy arrays as input and returns a float.
init : str or np.ndarray, default='random'
Expand Down Expand Up @@ -224,7 +224,7 @@ def _find_bmu(self, x, weights):
pairwise_matrix = pairwise_distance(
x,
weights,
metric=self.distance,
measure=self.distance,
**self._distance_params,
)
return pairwise_matrix.argmin(axis=1)
Expand Down Expand Up @@ -366,7 +366,7 @@ def _kmeans_plus_plus_center_initializer(self, X: np.ndarray):

for _ in range(1, self.n_clusters):
pw_dist = pairwise_distance(
X, X[indexes], metric=self.distance, **self._distance_params
X, X[indexes], measure=self.distance, **self._distance_params
)
min_distances = pw_dist.min(axis=1)
probabilities = min_distances / min_distances.sum()
Expand Down
14 changes: 7 additions & 7 deletions aeon/clustering/_k_means.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class TimeSeriesKMeans(BaseClusterer):
n_timepoints)
and contains the time series to use as centroids.
distance : str or Callable, default='msm'
Distance metric to compute similarity between time series. A list of valid
strings for metrics can be found in the documentation for
Distance measure to compute similarity between time series. A list of valid
strings for measures can be found in the documentation for
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
a function that takes two 2d numpy arrays as input and returns a float.
n_init : int, default=10
Expand Down Expand Up @@ -236,7 +236,7 @@ def _fit_one_init(self, X: np.ndarray) -> tuple:
prev_labels = None
for i in range(self.max_iter):
curr_pw = pairwise_distance(
X, cluster_centres, metric=self.distance, **self._distance_params
X, cluster_centres, measure=self.distance, **self._distance_params
)
curr_labels = curr_pw.argmin(axis=1)
curr_inertia = curr_pw.min(axis=1).sum()
Expand Down Expand Up @@ -273,13 +273,13 @@ def _fit_one_init(self, X: np.ndarray) -> tuple:
def _predict(self, X: np.ndarray, y=None) -> np.ndarray:
if isinstance(self.distance, str):
pairwise_matrix = pairwise_distance(
X, self.cluster_centers_, metric=self.distance, **self._distance_params
X, self.cluster_centers_, measure=self.distance, **self._distance_params
)
else:
pairwise_matrix = pairwise_distance(
X,
self.cluster_centers_,
metric=self.distance,
measure=self.distance,
**self._distance_params,
)
return pairwise_matrix.argmin(axis=1)
Expand Down Expand Up @@ -346,7 +346,7 @@ def _kmeans_plus_plus_center_initializer(self, X: np.ndarray):

for _ in range(1, self.n_clusters):
pw_dist = pairwise_distance(
X, X[indexes], metric=self.distance, **self._distance_params
X, X[indexes], measure=self.distance, **self._distance_params
)
min_distances = pw_dist.min(axis=1)
probabilities = min_distances / min_distances.sum()
Expand Down Expand Up @@ -381,7 +381,7 @@ def _handle_empty_cluster(
index_furthest_from_centre = curr_pw.min(axis=1).argmax()
cluster_centres[current_empty_cluster_index] = X[index_furthest_from_centre]
curr_pw = pairwise_distance(
X, cluster_centres, metric=self.distance, **self._distance_params
X, cluster_centres, measure=self.distance, **self._distance_params
)
curr_labels = curr_pw.argmin(axis=1)
curr_inertia = curr_pw.min(axis=1).sum()
Expand Down
12 changes: 6 additions & 6 deletions aeon/clustering/_k_medoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class TimeSeriesKMedoids(BaseClusterer):
If a np.ndarray provided it must be of shape (n_clusters,) and contain
the indexes of the time series to use as centroids.
distance : str or Callable, default='msm'
Distance metric to compute similarity between time series. A list of valid
strings for metrics can be found in the documentation for
Distance measure to compute similarity between time series. A list of valid
strings for measures can be found in the documentation for
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
a function that takes two 2d numpy arrays as input and returns a float.
method : str, default='pam'
Expand Down Expand Up @@ -88,7 +88,7 @@ class TimeSeriesKMedoids(BaseClusterer):
If `None`, the random number generator is the `RandomState` instance used
by `np.random`.
distance_params: dict, default=None
Dictionary containing kwargs for the distance metric being used.
Dictionary containing kwargs for the distance measure being used.

Attributes
----------
Expand Down Expand Up @@ -211,7 +211,7 @@ def _fit(self, X: np.ndarray, y=None):
def _predict(self, X: np.ndarray, y=None) -> np.ndarray:
if isinstance(self.distance, str):
pairwise_matrix = pairwise_distance(
X, self.cluster_centers_, metric=self.distance, **self._distance_params
X, self.cluster_centers_, measure=self.distance, **self._distance_params
)
else:
pairwise_matrix = pairwise_distance(
Expand Down Expand Up @@ -456,7 +456,7 @@ def _check_params(self, X: np.ndarray) -> None:
f"n_clusters ({self.n_clusters}) cannot be larger than "
f"n_cases ({X.shape[0]})"
)
self._distance_callable = get_distance_function(metric=self.distance)
self._distance_callable = get_distance_function(measure=self.distance)
self._distance_cache = np.full((X.shape[0], X.shape[0]), np.inf)

if self.method == "alternate":
Expand Down Expand Up @@ -486,7 +486,7 @@ def _kmedoids_plus_plus_center_initializer(self, X: np.ndarray):

for _ in range(1, self.n_clusters):
pw_dist = pairwise_distance(
X, X[indexes], metric=self.distance, **self._distance_params
X, X[indexes], measure=self.distance, **self._distance_params
)
min_distances = pw_dist.min(axis=1)
probabilities = min_distances / min_distances.sum()
Expand Down
2 changes: 1 addition & 1 deletion aeon/clustering/averaging/_ba_petitjean.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def petitjean_barycenter_average(
random_state: int or None, default=None
Random state to use for the barycenter averaging.
**kwargs
Keyword arguments to pass to the distance metric.
Keyword arguments to pass to the distance measure.

Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion aeon/clustering/averaging/_ba_subgradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def subgradient_barycenter_average(
random_state: int or None, default=None
Random state to use for the barycenter averaging.
**kwargs
Keyword arguments to pass to the distance metric.
Keyword arguments to pass to the distance measure.

Returns
-------
Expand Down
4 changes: 2 additions & 2 deletions aeon/clustering/averaging/_ba_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _medoids(
return X

if precomputed_pairwise_distance is None:
precomputed_pairwise_distance = pairwise_distance(X, metric=distance, **kwargs)
precomputed_pairwise_distance = pairwise_distance(X, measure=distance, **kwargs)

x_size = X.shape[0]
distance_matrix = np.zeros((x_size, x_size))
Expand Down Expand Up @@ -155,6 +155,6 @@ def _get_alignment_path(
elif distance == "adtw":
return adtw_alignment_path(ts, center, window=window, warp_penalty=warp_penalty)
else:
# When numba version > 0.57 add more informative error with what metric
# When numba version > 0.57 add more informative error with what measure
# was passed.
raise ValueError("Distance parameter invalid")
2 changes: 1 addition & 1 deletion aeon/clustering/averaging/_barycenter_averaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def elastic_barycenter_average(
random_state: int or None, default=None
Random state to use for the barycenter averaging.
**kwargs
Keyword arguments to pass to the distance metric.
Keyword arguments to pass to the distance measure.

Returns
-------
Expand Down
Loading