Skip to content

Commit 80d1523

Browse files
authored
[MNT] Change the "metric" parameter to "measure in the distance module (#2403)
* refactor metric to measure * refactor metric to measure in clustering module
1 parent 87e5602 commit 80d1523

22 files changed

+175
-169
lines changed

aeon/classification/distance_based/_proximity_tree.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def _get_best_splitter(self, X, y):
234234
dist = distance(
235235
X[j],
236236
splitter[0][labels[k]],
237-
metric=measure,
237+
measure=measure,
238238
**splitter[1][measure],
239239
)
240240
if dist < min_dist:
@@ -320,7 +320,7 @@ def _build_tree(self, X, y, depth, node_id, parent_target_value=None):
320320
dist = distance(
321321
X[i],
322322
splitter[0][labels[j]],
323-
metric=measure,
323+
measure=measure,
324324
**splitter[1][measure],
325325
)
326326
if dist < min_dist:
@@ -404,7 +404,7 @@ def _classify(self, treenode, x):
404404
dist = distance(
405405
x,
406406
treenode.splitter[0][branches[i]],
407-
metric=measure,
407+
measure=measure,
408408
**treenode.splitter[1][measure],
409409
)
410410
if dist < min_dist:

aeon/classification/distance_based/_time_series_neighbors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _fit(self, X, y):
111111
y : array-like, shape = (n_cases)
112112
The class labels.
113113
"""
114-
self.metric_ = get_distance_function(metric=self.distance)
114+
self.metric_ = get_distance_function(measure=self.distance)
115115
self.X_ = X
116116
self.classes_, self.y_ = np.unique(y, return_inverse=True)
117117
return self

aeon/clustering/_clara.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TimeSeriesCLARA(BaseClusterer):
4242
If a np.ndarray provided it must be of shape (n_clusters,) and contain
4343
the indexes of the time series to use as centroids.
4444
distance : str or Callable, default='msm'
45-
Distance metric to compute similarity between time series. A list of valid
45+
Distance measure to compute similarity between time series. A list of valid
4646
strings for metrics can be found in the documentation for
4747
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
4848
a function that takes two 2d numpy arrays as input and returns a float.
@@ -73,7 +73,7 @@ class TimeSeriesCLARA(BaseClusterer):
7373
If `None`, the random number generator is the `RandomState` instance used
7474
by `np.random`.
7575
distance_params : dict, default=None
76-
Dictionary containing kwargs for the distance metric being used.
76+
Dictionary containing kwargs for the distance measure being used.
7777
7878
Attributes
7979
----------
@@ -189,7 +189,7 @@ def _fit(self, X: np.ndarray, y=None):
189189
curr_centers = pam.cluster_centers_
190190
if isinstance(pam.distance, str):
191191
pairwise_matrix = pairwise_distance(
192-
X, curr_centers, metric=self.distance, **pam._distance_params
192+
X, curr_centers, measure=self.distance, **pam._distance_params
193193
)
194194
else:
195195
pairwise_matrix = pairwise_distance(

aeon/clustering/_clarans.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class TimeSeriesCLARANS(TimeSeriesKMedoids):
4343
If a np.ndarray provided it must be of shape (n_clusters,) and contain
4444
the indexes of the time series to use as centroids.
4545
distance : str or Callable, default='msm'
46-
Distance metric to compute similarity between time series. A list of valid
47-
strings for metrics can be found in the documentation for
46+
Distance measure to compute similarity between time series. A list of valid
47+
strings for measures can be found in the documentation for
4848
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
4949
a function that takes two 2d numpy arrays as input and returns a float.
5050
max_neighbours : int, default=None,
@@ -62,7 +62,7 @@ class TimeSeriesCLARANS(TimeSeriesKMedoids):
6262
random_state : int or np.random.RandomState instance or None, default=None
6363
Determines random number generation for centroid initialization.
6464
distance_params : dict, default=None
65-
Dictionary containing kwargs for the distance metric being used.
65+
Dictionary containing kwargs for the distance measure being used.
6666
6767
Attributes
6868
----------

aeon/clustering/_elastic_som.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class ElasticSOM(BaseClusterer):
4444
n_clusters : int, default=8
4545
The number of clusters to form as well as the number of centroids to generate.
4646
distance : str or Callable, default='dtw'
47-
Distance metric to compute similarity between time series. A list of valid
48-
strings for metrics can be found in the documentation for
47+
Distance measure to compute similarity between time series. A list of valid
48+
strings for measures can be found in the documentation for
4949
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
5050
a function that takes two 2d numpy arrays as input and returns a float.
5151
init : str or np.ndarray, default='random'
@@ -224,7 +224,7 @@ def _find_bmu(self, x, weights):
224224
pairwise_matrix = pairwise_distance(
225225
x,
226226
weights,
227-
metric=self.distance,
227+
measure=self.distance,
228228
**self._distance_params,
229229
)
230230
return pairwise_matrix.argmin(axis=1)
@@ -366,7 +366,7 @@ def _kmeans_plus_plus_center_initializer(self, X: np.ndarray):
366366

367367
for _ in range(1, self.n_clusters):
368368
pw_dist = pairwise_distance(
369-
X, X[indexes], metric=self.distance, **self._distance_params
369+
X, X[indexes], measure=self.distance, **self._distance_params
370370
)
371371
min_distances = pw_dist.min(axis=1)
372372
probabilities = min_distances / min_distances.sum()

aeon/clustering/_k_means.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class TimeSeriesKMeans(BaseClusterer):
5454
n_timepoints)
5555
and contains the time series to use as centroids.
5656
distance : str or Callable, default='msm'
57-
Distance metric to compute similarity between time series. A list of valid
58-
strings for metrics can be found in the documentation for
57+
Distance measure to compute similarity between time series. A list of valid
58+
strings for measures can be found in the documentation for
5959
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
6060
a function that takes two 2d numpy arrays as input and returns a float.
6161
n_init : int, default=10
@@ -236,7 +236,7 @@ def _fit_one_init(self, X: np.ndarray) -> tuple:
236236
prev_labels = None
237237
for i in range(self.max_iter):
238238
curr_pw = pairwise_distance(
239-
X, cluster_centres, metric=self.distance, **self._distance_params
239+
X, cluster_centres, measure=self.distance, **self._distance_params
240240
)
241241
curr_labels = curr_pw.argmin(axis=1)
242242
curr_inertia = curr_pw.min(axis=1).sum()
@@ -273,13 +273,13 @@ def _fit_one_init(self, X: np.ndarray) -> tuple:
273273
def _predict(self, X: np.ndarray, y=None) -> np.ndarray:
274274
if isinstance(self.distance, str):
275275
pairwise_matrix = pairwise_distance(
276-
X, self.cluster_centers_, metric=self.distance, **self._distance_params
276+
X, self.cluster_centers_, measure=self.distance, **self._distance_params
277277
)
278278
else:
279279
pairwise_matrix = pairwise_distance(
280280
X,
281281
self.cluster_centers_,
282-
metric=self.distance,
282+
measure=self.distance,
283283
**self._distance_params,
284284
)
285285
return pairwise_matrix.argmin(axis=1)
@@ -346,7 +346,7 @@ def _kmeans_plus_plus_center_initializer(self, X: np.ndarray):
346346

347347
for _ in range(1, self.n_clusters):
348348
pw_dist = pairwise_distance(
349-
X, X[indexes], metric=self.distance, **self._distance_params
349+
X, X[indexes], measure=self.distance, **self._distance_params
350350
)
351351
min_distances = pw_dist.min(axis=1)
352352
probabilities = min_distances / min_distances.sum()
@@ -381,7 +381,7 @@ def _handle_empty_cluster(
381381
index_furthest_from_centre = curr_pw.min(axis=1).argmax()
382382
cluster_centres[current_empty_cluster_index] = X[index_furthest_from_centre]
383383
curr_pw = pairwise_distance(
384-
X, cluster_centres, metric=self.distance, **self._distance_params
384+
X, cluster_centres, measure=self.distance, **self._distance_params
385385
)
386386
curr_labels = curr_pw.argmin(axis=1)
387387
curr_inertia = curr_pw.min(axis=1).sum()

aeon/clustering/_k_medoids.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class TimeSeriesKMedoids(BaseClusterer):
5656
If a np.ndarray provided it must be of shape (n_clusters,) and contain
5757
the indexes of the time series to use as centroids.
5858
distance : str or Callable, default='msm'
59-
Distance metric to compute similarity between time series. A list of valid
60-
strings for metrics can be found in the documentation for
59+
Distance measure to compute similarity between time series. A list of valid
60+
strings for measures can be found in the documentation for
6161
:func:`aeon.distances.get_distance_function`. If a callable is passed it must be
6262
a function that takes two 2d numpy arrays as input and returns a float.
6363
method : str, default='pam'
@@ -88,7 +88,7 @@ class TimeSeriesKMedoids(BaseClusterer):
8888
If `None`, the random number generator is the `RandomState` instance used
8989
by `np.random`.
9090
distance_params: dict, default=None
91-
Dictionary containing kwargs for the distance metric being used.
91+
Dictionary containing kwargs for the distance measure being used.
9292
9393
Attributes
9494
----------
@@ -211,7 +211,7 @@ def _fit(self, X: np.ndarray, y=None):
211211
def _predict(self, X: np.ndarray, y=None) -> np.ndarray:
212212
if isinstance(self.distance, str):
213213
pairwise_matrix = pairwise_distance(
214-
X, self.cluster_centers_, metric=self.distance, **self._distance_params
214+
X, self.cluster_centers_, measure=self.distance, **self._distance_params
215215
)
216216
else:
217217
pairwise_matrix = pairwise_distance(
@@ -456,7 +456,7 @@ def _check_params(self, X: np.ndarray) -> None:
456456
f"n_clusters ({self.n_clusters}) cannot be larger than "
457457
f"n_cases ({X.shape[0]})"
458458
)
459-
self._distance_callable = get_distance_function(metric=self.distance)
459+
self._distance_callable = get_distance_function(measure=self.distance)
460460
self._distance_cache = np.full((X.shape[0], X.shape[0]), np.inf)
461461

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

487487
for _ in range(1, self.n_clusters):
488488
pw_dist = pairwise_distance(
489-
X, X[indexes], metric=self.distance, **self._distance_params
489+
X, X[indexes], measure=self.distance, **self._distance_params
490490
)
491491
min_distances = pw_dist.min(axis=1)
492492
probabilities = min_distances / min_distances.sum()

aeon/clustering/averaging/_ba_petitjean.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def petitjean_barycenter_average(
5555
random_state: int or None, default=None
5656
Random state to use for the barycenter averaging.
5757
**kwargs
58-
Keyword arguments to pass to the distance metric.
58+
Keyword arguments to pass to the distance measure.
5959
6060
Returns
6161
-------

aeon/clustering/averaging/_ba_subgradient.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def subgradient_barycenter_average(
7070
random_state: int or None, default=None
7171
Random state to use for the barycenter averaging.
7272
**kwargs
73-
Keyword arguments to pass to the distance metric.
73+
Keyword arguments to pass to the distance measure.
7474
7575
Returns
7676
-------

aeon/clustering/averaging/_ba_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _medoids(
3131
return X
3232

3333
if precomputed_pairwise_distance is None:
34-
precomputed_pairwise_distance = pairwise_distance(X, metric=distance, **kwargs)
34+
precomputed_pairwise_distance = pairwise_distance(X, measure=distance, **kwargs)
3535

3636
x_size = X.shape[0]
3737
distance_matrix = np.zeros((x_size, x_size))
@@ -155,6 +155,6 @@ def _get_alignment_path(
155155
elif distance == "adtw":
156156
return adtw_alignment_path(ts, center, window=window, warp_penalty=warp_penalty)
157157
else:
158-
# When numba version > 0.57 add more informative error with what metric
158+
# When numba version > 0.57 add more informative error with what measure
159159
# was passed.
160160
raise ValueError("Distance parameter invalid")

aeon/clustering/averaging/_barycenter_averaging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def elastic_barycenter_average(
8484
random_state: int or None, default=None
8585
Random state to use for the barycenter averaging.
8686
**kwargs
87-
Keyword arguments to pass to the distance metric.
87+
Keyword arguments to pass to the distance measure.
8888
8989
Returns
9090
-------

0 commit comments

Comments
 (0)