diff --git a/aeon/classification/distance_based/_proximity_tree.py b/aeon/classification/distance_based/_proximity_tree.py index 9af2edfe84..86a5be86fe 100644 --- a/aeon/classification/distance_based/_proximity_tree.py +++ b/aeon/classification/distance_based/_proximity_tree.py @@ -234,7 +234,7 @@ def _get_best_splitter(self, X, y): dist = distance( X[j], splitter[0][labels[k]], - measure=measure, + method=measure, **splitter[1][measure], ) if dist < min_dist: @@ -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]], - measure=measure, + method=measure, **splitter[1][measure], ) if dist < min_dist: @@ -404,7 +404,7 @@ def _classify(self, treenode, x): dist = distance( x, treenode.splitter[0][branches[i]], - measure=measure, + method=measure, **treenode.splitter[1][measure], ) if dist < min_dist: diff --git a/aeon/classification/distance_based/_time_series_neighbors.py b/aeon/classification/distance_based/_time_series_neighbors.py index efb7473e65..f89b1be636 100644 --- a/aeon/classification/distance_based/_time_series_neighbors.py +++ b/aeon/classification/distance_based/_time_series_neighbors.py @@ -111,7 +111,7 @@ def _fit(self, X, y): y : array-like, shape = (n_cases) The class labels. """ - self.metric_ = get_distance_function(measure=self.distance) + self.metric_ = get_distance_function(method=self.distance) self.X_ = X self.classes_, self.y_ = np.unique(y, return_inverse=True) return self diff --git a/aeon/clustering/_clara.py b/aeon/clustering/_clara.py index edc334f6c9..27075ef133 100644 --- a/aeon/clustering/_clara.py +++ b/aeon/clustering/_clara.py @@ -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 measure to compute similarity between time series. A list of valid + Distance method 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. @@ -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 measure being used. + Dictionary containing kwargs for the distance method being used. Attributes ---------- @@ -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, measure=self.distance, **pam._distance_params + X, curr_centers, method=self.distance, **pam._distance_params ) else: pairwise_matrix = pairwise_distance( diff --git a/aeon/clustering/_clarans.py b/aeon/clustering/_clarans.py index c13d177dfa..1b4a2506bf 100644 --- a/aeon/clustering/_clarans.py +++ b/aeon/clustering/_clarans.py @@ -43,7 +43,7 @@ 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 measure to compute similarity between time series. A list of valid + Distance method 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. @@ -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 measure being used. + Dictionary containing kwargs for the distance method being used. Attributes ---------- diff --git a/aeon/clustering/_elastic_som.py b/aeon/clustering/_elastic_som.py index e4edec42ab..da88bb541c 100644 --- a/aeon/clustering/_elastic_som.py +++ b/aeon/clustering/_elastic_som.py @@ -44,7 +44,7 @@ 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 measure to compute similarity between time series. A list of valid + Distance method 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. @@ -105,7 +105,7 @@ class ElasticSOM(BaseClusterer): by `np.random`. custom_alignment_path : Callable, default=None Custom alignment path function to use for the distance. If None, the default - alignment path function for the distance will be used. If the distance measure + alignment path function for the distance will be used. If the distance method does not have an elastic alignment path then the default SOM einsum update will be used. See aeon.clustering.elastic_som.VALID_ELASTIC_SOM_METRICS for a list of distances that have an elastic alignment path. @@ -224,7 +224,7 @@ def _find_bmu(self, x, weights): pairwise_matrix = pairwise_distance( x, weights, - measure=self.distance, + method=self.distance, **self._distance_params, ) return pairwise_matrix.argmin(axis=1) @@ -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], measure=self.distance, **self._distance_params + X, X[indexes], method=self.distance, **self._distance_params ) min_distances = pw_dist.min(axis=1) probabilities = min_distances / min_distances.sum() diff --git a/aeon/clustering/_k_means.py b/aeon/clustering/_k_means.py index 7c1e9a07d2..e4e459a5cf 100644 --- a/aeon/clustering/_k_means.py +++ b/aeon/clustering/_k_means.py @@ -54,7 +54,7 @@ class TimeSeriesKMeans(BaseClusterer): n_timepoints) and contains the time series to use as centroids. distance : str or Callable, default='msm' - Distance measure to compute similarity between time series. A list of valid + Distance method 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. @@ -82,9 +82,9 @@ class TimeSeriesKMeans(BaseClusterer): Averaging method to compute the average of a cluster. Any of the following strings are valid: ['mean', 'ba']. If a Callable is provided must take the form Callable[[np.ndarray], np.ndarray]. - If you specify 'ba' then by default the distance measure used will be the same - as the distance measure used for clustering. If you wish to use a different - distance measure you can specify it by passing {"distance": "dtw"} as + If you specify 'ba' then by default the distance method used will be the same + as the distance method used for clustering. If you wish to use a different + distance method you can specify it by passing {"distance": "dtw"} as averaging_params. BA yields 'better' clustering results but is very computationally expensive so you may want to consider setting a bounding window or using a different averaging method if time complexity is a concern. @@ -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, measure=self.distance, **self._distance_params + X, cluster_centres, method=self.distance, **self._distance_params ) curr_labels = curr_pw.argmin(axis=1) curr_inertia = curr_pw.min(axis=1).sum() @@ -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_, measure=self.distance, **self._distance_params + X, self.cluster_centers_, method=self.distance, **self._distance_params ) else: pairwise_matrix = pairwise_distance( X, self.cluster_centers_, - measure=self.distance, + method=self.distance, **self._distance_params, ) return pairwise_matrix.argmin(axis=1) @@ -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], measure=self.distance, **self._distance_params + X, X[indexes], method=self.distance, **self._distance_params ) min_distances = pw_dist.min(axis=1) probabilities = min_distances / min_distances.sum() @@ -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, measure=self.distance, **self._distance_params + X, cluster_centres, method=self.distance, **self._distance_params ) curr_labels = curr_pw.argmin(axis=1) curr_inertia = curr_pw.min(axis=1).sum() diff --git a/aeon/clustering/_k_medoids.py b/aeon/clustering/_k_medoids.py index 6a00f2a46e..12d0f2819d 100644 --- a/aeon/clustering/_k_medoids.py +++ b/aeon/clustering/_k_medoids.py @@ -36,7 +36,7 @@ class TimeSeriesKMedoids(BaseClusterer): accurate than PAM. For a full review of varations of k-medoids for time series see [5]_. - K-medoids for time series uses a dissimilarity measure to compute the distance + K-medoids for time series uses a dissimilarity method to compute the distance between time series. The default is 'msm' (move split merge) as it was found to significantly outperform the other measures in [2]_. @@ -56,7 +56,7 @@ 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 measure to compute similarity between time series. A list of valid + Distance method 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. @@ -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 measure being used. + Dictionary containing kwargs for the distance method being used. Attributes ---------- @@ -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_, measure=self.distance, **self._distance_params + X, self.cluster_centers_, method=self.distance, **self._distance_params ) else: pairwise_matrix = pairwise_distance( @@ -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(measure=self.distance) + self._distance_callable = get_distance_function(method=self.distance) self._distance_cache = np.full((X.shape[0], X.shape[0]), np.inf) if self.method == "alternate": @@ -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], measure=self.distance, **self._distance_params + X, X[indexes], method=self.distance, **self._distance_params ) min_distances = pw_dist.min(axis=1) probabilities = min_distances / min_distances.sum() diff --git a/aeon/clustering/averaging/_ba_petitjean.py b/aeon/clustering/averaging/_ba_petitjean.py index 6b3765f77e..b2b03bca91 100644 --- a/aeon/clustering/averaging/_ba_petitjean.py +++ b/aeon/clustering/averaging/_ba_petitjean.py @@ -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 measure. + Keyword arguments to pass to the distance method. Returns ------- diff --git a/aeon/clustering/averaging/_ba_subgradient.py b/aeon/clustering/averaging/_ba_subgradient.py index 369ad6bded..5405852cc8 100644 --- a/aeon/clustering/averaging/_ba_subgradient.py +++ b/aeon/clustering/averaging/_ba_subgradient.py @@ -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 measure. + Keyword arguments to pass to the distance method. Returns ------- diff --git a/aeon/clustering/averaging/_ba_utils.py b/aeon/clustering/averaging/_ba_utils.py index 496f1f6e74..6172d6b8e3 100644 --- a/aeon/clustering/averaging/_ba_utils.py +++ b/aeon/clustering/averaging/_ba_utils.py @@ -31,7 +31,7 @@ def _medoids( return X if precomputed_pairwise_distance is None: - precomputed_pairwise_distance = pairwise_distance(X, measure=distance, **kwargs) + precomputed_pairwise_distance = pairwise_distance(X, method=distance, **kwargs) x_size = X.shape[0] distance_matrix = np.zeros((x_size, x_size)) @@ -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 measure + # When numba version > 0.57 add more informative error with what method # was passed. raise ValueError("Distance parameter invalid") diff --git a/aeon/clustering/averaging/_barycenter_averaging.py b/aeon/clustering/averaging/_barycenter_averaging.py index 48397f8f84..db35a01e81 100644 --- a/aeon/clustering/averaging/_barycenter_averaging.py +++ b/aeon/clustering/averaging/_barycenter_averaging.py @@ -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 measure. + Keyword arguments to pass to the distance method. Returns ------- diff --git a/aeon/distances/_distance.py b/aeon/distances/_distance.py index 0004884184..b63d4589ae 100644 --- a/aeon/distances/_distance.py +++ b/aeon/distances/_distance.py @@ -118,7 +118,7 @@ class DistanceKwargs(TypedDict, total=False): def distance( x: np.ndarray, y: np.ndarray, - measure: Union[str, DistanceFunction], + method: Union[str, DistanceFunction], **kwargs: Unpack[DistanceKwargs], ) -> float: """Compute the distance between two time series. @@ -131,13 +131,13 @@ def distance( y : np.ndarray Second time series, either univariate, shape ``(n_timepoints,)``, or multivariate, shape ``(n_channels, n_timepoints)``. - measure : str or Callable - The distance measure to use. - A list of valid distance measures can be found in the documentation for + method : str or Callable + The distance to use. + A list of valid distance can be found in the documentation for :func:`aeon.distances.get_distance_function` or by calling the function :func:`aeon.distances.get_distance_function_names`. kwargs : Any - Arguments for measure. Refer to each measure documentation for a list of + Arguments for distance. Refer to each distance documentation for a list of possible arguments. Returns @@ -149,7 +149,7 @@ def distance( ------ ValueError If x and y are not 1D, or 2D arrays. - If measure is not a valid string or callable. + If distance is not a valid string or callable. Examples -------- @@ -157,21 +157,21 @@ def distance( >>> from aeon.distances import distance >>> x = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) >>> y = np.array([[11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) - >>> distance(x, y, measure="dtw") + >>> distance(x, y, method="dtw") 768.0 """ - if measure in DISTANCES_DICT: - return DISTANCES_DICT[measure]["distance"](x, y, **kwargs) - elif isinstance(measure, Callable): - return measure(x, y, **kwargs) + if method in DISTANCES_DICT: + return DISTANCES_DICT[method]["distance"](x, y, **kwargs) + elif isinstance(method, Callable): + return method(x, y, **kwargs) else: - raise ValueError("Measure must be one of the supported strings or a callable") + raise ValueError("Method must be one of the supported strings or a callable") def pairwise_distance( x: np.ndarray, y: Optional[np.ndarray] = None, - measure: Union[str, DistanceFunction, None] = None, + method: Union[str, DistanceFunction, None] = None, symmetric: bool = True, **kwargs: Unpack[DistanceKwargs], ) -> np.ndarray: @@ -185,20 +185,20 @@ def pairwise_distance( y : np.ndarray or None, default=None A single series or a collection of time series of shape ``(m_timepoints,)`` or ``(m_cases, m_timepoints)`` or ``(m_cases, m_channels, m_timepoints)`` - measure : str or Callable - The distance measure to use. - A list of valid distance measure can be found in the documentation for + method : str or Callable + The distance to use. + A list of valid distance can be found in the documentation for :func:`aeon.distances.get_distance_function` or by calling the function :func:`aeon.distances.get_distance_function_names`. symmetric : bool, default=True - If True and a function is provided as the "measure" paramter, then it will + If True and a function is provided as the "method" paramter, then it will compute a symmetric distance matrix where d(x, y) = d(y, x). Only the lower triangle is calculated, and the upper triangle is ignored. If False and a - function is provided as the "measure" parameter, then it will compute an + function is provided as the "method" parameter, then it will compute an asymmetric distance matrix, and the entire matrix (including both upper and lower triangles) is returned. kwargs : Any - Extra arguments for measure. Refer to each measure documentation for a list of + Extra arguments for distance. Refer to each distance documentation for a list of possible arguments. Returns @@ -211,7 +211,7 @@ def pairwise_distance( ValueError If X is not 2D or 3D array when only passing X. If X and y are not 1D, 2D or 3D arrays when passing both X and y. - If measure is not a valid string or callable. + If distance is not a valid string or callable. Examples -------- @@ -219,7 +219,7 @@ def pairwise_distance( >>> from aeon.distances import pairwise_distance >>> # Distance between each time series in a collection of time series >>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]]) - >>> pairwise_distance(X, measure='dtw') + >>> pairwise_distance(X, method='dtw') array([[ 0., 26., 108.], [ 26., 0., 26.], [108., 26., 0.]]) @@ -227,26 +227,26 @@ def pairwise_distance( >>> # Distance between two collections of time series >>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]]) >>> y = np.array([[[11, 12, 13]],[[14, 15, 16]], [[17, 18, 19]]]) - >>> pairwise_distance(X, y, measure='dtw') + >>> pairwise_distance(X, y, method='dtw') array([[300., 507., 768.], [147., 300., 507.], [ 48., 147., 300.]]) >>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]]) >>> y_univariate = np.array([11, 12, 13]) - >>> pairwise_distance(X, y_univariate, measure='dtw') + >>> pairwise_distance(X, y_univariate, method='dtw') array([[300.], [147.], [ 48.]]) """ - if measure in PAIRWISE_DISTANCE: - return DISTANCES_DICT[measure]["pairwise_distance"](x, y, **kwargs) - elif isinstance(measure, Callable): + if method in PAIRWISE_DISTANCE: + return DISTANCES_DICT[method]["pairwise_distance"](x, y, **kwargs) + elif isinstance(method, Callable): if y is None and not symmetric: - return _custom_func_pairwise(x, x, measure, **kwargs) - return _custom_func_pairwise(x, y, measure, **kwargs) + return _custom_func_pairwise(x, x, method, **kwargs) + return _custom_func_pairwise(x, y, method, **kwargs) else: - raise ValueError("Measure must be one of the supported strings or a callable") + raise ValueError("Method must be one of the supported strings or a callable") def _custom_func_pairwise( @@ -302,7 +302,7 @@ def _custom_from_multiple_to_multiple_distance( def alignment_path( x: np.ndarray, y: np.ndarray, - measure: Union[str, DistanceFunction, None] = None, + method: Union[str, DistanceFunction, None] = None, **kwargs: Unpack[DistanceKwargs], ) -> tuple[list[tuple[int, int]], float]: """Compute the alignment path and distance between two time series. @@ -313,13 +313,13 @@ def alignment_path( First time series. y : np.ndarray, of shape (m_channels, m_timepoints) or (m_timepoints,) Second time series. - measure : str or Callable - The distance measure to use. - A list of valid distance measure can be found in the documentation for + method : str or Callable + The distance method to use. + A list of valid distances can be found in the documentation for :func:`aeon.distances.get_distance_function` or by calling the function :func:`aeon.distances.get_distance_function_names`. kwargs : any - Arguments for measure. Refer to each measure documentation for a list of + Arguments for distance. Refer to each distance documentation for a list of possible arguments. Returns @@ -335,7 +335,7 @@ def alignment_path( ------ ValueError If x and y are not 1D, or 2D arrays. - If measure is not one of the supported strings or a callable. + If distance is not one of the supported strings or a callable. Examples -------- @@ -343,21 +343,21 @@ def alignment_path( >>> from aeon.distances import alignment_path >>> x = np.array([[1, 2, 3, 6]]) >>> y = np.array([[1, 2, 3, 4]]) - >>> alignment_path(x, y, measure='dtw') + >>> alignment_path(x, y, method='dtw') ([(0, 0), (1, 1), (2, 2), (3, 3)], 4.0) """ - if measure in ALIGNMENT_PATH: - return DISTANCES_DICT[measure]["alignment_path"](x, y, **kwargs) - elif isinstance(measure, Callable): - return measure(x, y, **kwargs) + if method in ALIGNMENT_PATH: + return DISTANCES_DICT[method]["alignment_path"](x, y, **kwargs) + elif isinstance(method, Callable): + return method(x, y, **kwargs) else: - raise ValueError("Measure must be one of the supported strings") + raise ValueError("Method must be one of the supported strings") def cost_matrix( x: np.ndarray, y: np.ndarray, - measure: Union[str, DistanceFunction, None] = None, + method: Union[str, DistanceFunction, None] = None, **kwargs: Unpack[DistanceKwargs], ) -> np.ndarray: """Compute the alignment path and distance between two time series. @@ -368,13 +368,13 @@ def cost_matrix( First time series. y : np.ndarray, of shape (m_channels, m_timepoints) or (m_timepoints,) Second time series. - measure : str or Callable - The distance measure to use. - A list of valid distance measures can be found in the documentation for + method : str or Callable + The distance to use. + A list of valid distances can be found in the documentation for :func:`aeon.distances.get_distance_function` or by calling the function :func:`aeon.distances.get_distance_function_names`. kwargs : Any - Arguments for measure. Refer to each measures documentation for a list of + Arguments for distance. Refer to each distance documentation for a list of possible arguments. Returns @@ -386,7 +386,7 @@ def cost_matrix( ------ ValueError If x and y are not 1D, or 2D arrays. - If measure is not one of the supported strings or a callable. + If distance is not one of the supported strings or a callable. Examples -------- @@ -394,7 +394,7 @@ def cost_matrix( >>> from aeon.distances import cost_matrix >>> x = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) >>> y = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) - >>> cost_matrix(x, y, measure="dtw") + >>> cost_matrix(x, y, method="dtw") array([[ 0., 1., 5., 14., 30., 55., 91., 140., 204., 285.], [ 1., 0., 1., 5., 14., 30., 55., 91., 140., 204.], [ 5., 1., 0., 1., 5., 14., 30., 55., 91., 140.], @@ -406,12 +406,12 @@ def cost_matrix( [204., 140., 91., 55., 30., 14., 5., 1., 0., 1.], [285., 204., 140., 91., 55., 30., 14., 5., 1., 0.]]) """ - if measure in COST_MATRIX: - return DISTANCES_DICT[measure]["cost_matrix"](x, y, **kwargs) - elif isinstance(measure, Callable): - return measure(x, y, **kwargs) + if method in COST_MATRIX: + return DISTANCES_DICT[method]["cost_matrix"](x, y, **kwargs) + elif isinstance(method, Callable): + return method(x, y, **kwargs) else: - raise ValueError("Measure must be one of the supported strings") + raise ValueError("Method must be one of the supported strings") def get_distance_function_names() -> list[str]: @@ -440,11 +440,11 @@ def get_distance_function_names() -> list[str]: return sorted(DISTANCES_DICT.keys()) -def get_distance_function(measure: Union[str, DistanceFunction]) -> DistanceFunction: - """Get the distance function for a given measure string or callable. +def get_distance_function(method: Union[str, DistanceFunction]) -> DistanceFunction: + """Get the distance function for a given distance string or callable. =============== ======================================== - measure Distance Function + method Distance Function =============== ======================================== 'dtw' distances.dtw_distance 'shape_dtw' distances.shape_dtw_distance @@ -468,8 +468,8 @@ def get_distance_function(measure: Union[str, DistanceFunction]) -> DistanceFunc Parameters ---------- - measure : str or Callable - The distance measure to use. + method : str or Callable + The distance to use. If string given then it will be resolved to a alignment path function. If a callable is given, the value must be a function that accepts two numpy arrays and **kwargs returns a float. @@ -477,12 +477,12 @@ def get_distance_function(measure: Union[str, DistanceFunction]) -> DistanceFunc Returns ------- Callable[[np.ndarray, np.ndarray, Any], float] - The distance function for the given measure. + The distance function for the given method. Raises ------ ValueError - If measure is not one of the supported strings or a callable. + If distance is not one of the supported strings or a callable. Examples -------- @@ -494,16 +494,16 @@ def get_distance_function(measure: Union[str, DistanceFunction]) -> DistanceFunc >>> dtw_dist_func(x, y, window=0.2) 874.0 """ - return _resolve_key_from_distance(measure, "distance") + return _resolve_key_from_distance(method, "distance") def get_pairwise_distance_function( - measure: Union[str, PairwiseFunction] + method: Union[str, PairwiseFunction] ) -> PairwiseFunction: - """Get the pairwise distance function for a given measure string or callable. + """Get the pairwise distance function for a given method string or callable. =============== ======================================== - measure Distance Function + method Distance Function =============== ======================================== 'dtw' distances.dtw_pairwise_distance 'shape_dtw' distances.shape_dtw_pairwise_distance @@ -527,8 +527,8 @@ def get_pairwise_distance_function( Parameters ---------- - measure : str or Callable - The measure string to resolve to a alignment path function. + method : str or Callable + The distance string to resolve to a alignment path function. If string given then it will be resolved to a alignment path function. If a callable is given, the value must be a function that accepts two numpy arrays and **kwargs returns a np.ndarray that is the pairwise distance @@ -537,12 +537,12 @@ def get_pairwise_distance_function( Returns ------- Callable[[np.ndarray, np.ndarray, Any], np.ndarray] - The pairwise distance function for the given measure. + The pairwise distance function for the given method. Raises ------ ValueError - If measure is not one of the supported strings or a callable. + If mehtod is not one of the supported strings or a callable. Examples -------- @@ -556,14 +556,14 @@ def get_pairwise_distance_function( [147., 300., 507.], [ 48., 147., 300.]]) """ - return _resolve_key_from_distance(measure, "pairwise_distance") + return _resolve_key_from_distance(method, "pairwise_distance") -def get_alignment_path_function(measure: str) -> AlignmentPathFunction: - """Get the alignment path function for a given measure string or callable. +def get_alignment_path_function(method: str) -> AlignmentPathFunction: + """Get the alignment path function for a given method string or callable. =============== ======================================== - measure Distance Function + method Distance Function =============== ======================================== 'dtw' distances.dtw_alignment_path 'shape_dtw' distances.shape_dtw_alignment_path @@ -581,19 +581,19 @@ def get_alignment_path_function(measure: str) -> AlignmentPathFunction: Parameters ---------- - measure : str or Callable - The measure string to resolve to an alignment path function. + method : str or Callable + The distance string to resolve to an alignment path function. Returns ------- Callable[[np.ndarray, np.ndarray, Any], Tuple[List[Tuple[int, int]], float]] - The alignment path function for the given measure. + The alignment path function for the given distance. Raises ------ ValueError - If measure is not one of the supported strings or a callable. - If the measure doesn't have an alignment path function. + If distance is not one of the supported strings or a callable. + If the distance doesn't have an alignment path function. Examples -------- @@ -605,14 +605,14 @@ def get_alignment_path_function(measure: str) -> AlignmentPathFunction: >>> dtw_alignment_path_func(x, y, window=0.2) ([(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)], 500.0) """ - return _resolve_key_from_distance(measure, "alignment_path") + return _resolve_key_from_distance(method, "alignment_path") -def get_cost_matrix_function(measure: str) -> CostMatrixFunction: - """Get the cost matrix function for a given measure string or callable. +def get_cost_matrix_function(method: str) -> CostMatrixFunction: + """Get the cost matrix function for a given distance string or callable. =============== ======================================== - measure Distance Function + method Distance Function =============== ======================================== 'dtw' distances.dtw_cost_matrix 'shape_dtw' distances.shape_dtw_cost_matrix @@ -630,19 +630,19 @@ def get_cost_matrix_function(measure: str) -> CostMatrixFunction: Parameters ---------- - measure : str or Callable - The measure string to resolve to a cost matrix function. + method : str or Callable + The distance string to resolve to a cost matrix function. Returns ------- Callable[[np.ndarray, np.ndarray, Any], np.ndarray] - The cost matrix function for the given measure. + The cost matrix function for the given distance. Raises ------ ValueError - If measure is not one of the supported strings or a callable. - If the measure doesn't have a cost matrix function. + If distance is not one of the supported strings or a callable. + If the distance doesn't have a cost matrix function. Examples -------- @@ -658,20 +658,20 @@ def get_cost_matrix_function(measure: str) -> CostMatrixFunction: [ inf, inf, 343., 400., 521.], [ inf, inf, inf, 424., 500.]]) """ - return _resolve_key_from_distance(measure, "cost_matrix") + return _resolve_key_from_distance(method, "cost_matrix") -def _resolve_key_from_distance(measure: Union[str, Callable], key: str) -> Any: - if isinstance(measure, Callable): - return measure - if measure == "mpdist": +def _resolve_key_from_distance(method: Union[str, Callable], key: str) -> Any: + if isinstance(method, Callable): + return method + if method == "mpdist": return mp_distance - dist = DISTANCES_DICT.get(measure) + dist = DISTANCES_DICT.get(method) if dist is None: - raise ValueError(f"Unknown measure {measure}") + raise ValueError(f"Unknown method {method}") dist_callable = dist.get(key) if dist_callable is None: - raise ValueError(f"Measure {measure} does not have a {key} function") + raise ValueError(f"Method {method} does not have a {key} function") return dist_callable diff --git a/aeon/distances/_mpdist.py b/aeon/distances/_mpdist.py index b3ca9e2b8f..c679daef5c 100644 --- a/aeon/distances/_mpdist.py +++ b/aeon/distances/_mpdist.py @@ -13,7 +13,7 @@ def mp_distance(x: np.ndarray, y: np.ndarray, m: int = 0) -> float: r"""Matrix Profile Distance. - MPdist [2]_ is a distance measure based on the matrix profile [1]_. Given a + MPdist [2]_ is a distance method based on the matrix profile [1]_. Given a window length $m$, the matrix profile between two series $x$ and $y$, denoted $P_{xy}$, is a new time series where each point $i$ stores the Euclidean distance between `x[i:i+m]` and the nearest neighbour window to x[i:i+m]` in $y$ . MPdist @@ -47,11 +47,11 @@ def mp_distance(x: np.ndarray, y: np.ndarray, m: int = 0) -> float: References ---------- .. [1] S. Gharghabi, S. Imani, A. Bagnall, A. Darvishzadeh and E. Keogh, - "Matrix Profile XII: MPdist: A Novel Time Series Distance Measure to Allow + "Matrix Profile XII: MPdist: A Novel Time Series Distance Method to Allow Data Mining in More Challenging Scenarios", 2018 IEEE International Conference on Data Mining (ICDM), 2018. .. [2] S. Gharghabi, S. Imani, A. Bagnall, A. Darvishzadeh and E. Keogh - "An ultra-fast time series distancemeasure to allow data mining inmore complex + "An ultra-fast time series distancemethod to allow data mining inmore complex real-world deployments", Data Mining and Knowledge Discovery, 34(5), 2020. Examples diff --git a/aeon/distances/_sbd.py b/aeon/distances/_sbd.py index 8c3651db63..1097f27b5a 100644 --- a/aeon/distances/_sbd.py +++ b/aeon/distances/_sbd.py @@ -38,7 +38,7 @@ def sbd_distance(x: np.ndarray, y: np.ndarray, standardize: bool = True) -> floa \sqrt{ (\mathbf{x} \cdot \mathbf{x}) * (\mathbf{y} \cdot \mathbf{y}) } }\right) - This distance measure has values between 0 and 2; 0 is perfect similarity. + This distance method has values between 0 and 2; 0 is perfect similarity. The computation of the cross-correlation :math:`CC(\mathbf{x}, \mathbf{y})` for all values of w requires :math:`O(m^2)` time, where m is the maximum time-series diff --git a/aeon/distances/elastic/_dtw.py b/aeon/distances/elastic/_dtw.py index 85a5c3a6aa..73cce697ab 100644 --- a/aeon/distances/elastic/_dtw.py +++ b/aeon/distances/elastic/_dtw.py @@ -24,7 +24,7 @@ def dtw_distance( ) -> float: r"""Compute the DTW distance between two time series. - DTW is the most widely researched and used elastic distance measure. It mitigates + DTW is the most widely researched and used elastic distance method. It mitigates distortions in the time axis by realligning (warping) the series to best match each other. A good background into DTW can be found in [1]_. For two series, possibly of unequal length, diff --git a/aeon/distances/elastic/_msm.py b/aeon/distances/elastic/_msm.py index 2f5d5241bf..c51eca3ab6 100644 --- a/aeon/distances/elastic/_msm.py +++ b/aeon/distances/elastic/_msm.py @@ -26,7 +26,7 @@ def msm_distance( ) -> float: r"""Compute the MSM distance between two time series. - Move-Split-Merge (MSM) [1]_ is a distance measure that is conceptually similar to + Move-Split-Merge (MSM) [1]_ is a distance method that is conceptually similar to other edit distance-based approaches, where similarity is calculated by using a set of operations to transform one series into another. Each operation has an associated cost, and three operations are defined for MSM: move, split, and merge. @@ -102,7 +102,7 @@ def msm_distance( series. IEEE Transactions on Knowledge and Data Engineering 25(6), 2013. .. [2] A. Shifaz, C. Pelletier, F. Petitjean, G. Webb: Elastic similarity and - distance measures for multivariate time series. Knowl. Inf. Syst. 65(6), 2023. + distance methods for multivariate time series. Knowl. Inf. Syst. 65(6), 2023. Examples -------- diff --git a/aeon/distances/elastic/_shape_dtw.py b/aeon/distances/elastic/_shape_dtw.py index c68eeeb6fd..25a72cef10 100644 --- a/aeon/distances/elastic/_shape_dtw.py +++ b/aeon/distances/elastic/_shape_dtw.py @@ -131,7 +131,7 @@ def shape_dtw_distance( ) -> float: """Compute the ShapeDTW distance function between two series x and y. - The ShapeDTW distance measure was proposed in [1] and used for time series + The ShapeDTW distance method was proposed in [1] and used for time series averaging in [2] as well. Parameters diff --git a/aeon/distances/elastic/_twe.py b/aeon/distances/elastic/_twe.py index f8a5f10896..fa4a3f4dea 100644 --- a/aeon/distances/elastic/_twe.py +++ b/aeon/distances/elastic/_twe.py @@ -26,7 +26,7 @@ def twe_distance( ) -> float: r"""Compute the TWE distance between two time series. - Proposed in [1]_, the Time Warp Edit (TWE) distance is a distance measure for time + Proposed in [1]_, the Time Warp Edit (TWE) distance is a distance method for time series matching with time 'elasticity'. For two series, possibly of unequal length, :math:`\mathbf{x}=\{x_1,x_2,\ldots,x_n\}` and :math:`\mathbf{y}=\{y_1,y_2, \ldots,y_m\}` TWE works by iterating over series @@ -133,7 +133,7 @@ def twe_cost_matrix( shortest time series. nu : float, default=0.001 A non-negative constant which characterizes the stiffness of the elastic - twe measure. Must be > 0. + twe method. Must be > 0. lmbda : float, default=1.0 A constant penalty that punishes the editing efforts. Must be >= 1.0. itakura_max_slope : float, default=None @@ -268,7 +268,7 @@ def twe_pairwise_distance( is used. nu : float, default=0.001 A non-negative constant which characterizes the stiffness of the elastic - twe measure. Must be > 0. + twe method. Must be > 0. lmbda : float, default=1.0 A constant penalty that punishes the editing efforts. Must be >= 1.0. itakura_max_slope : float, default=None @@ -432,7 +432,7 @@ def twe_alignment_path( is used. nu : float, default=0.001 A non-negative constant which characterizes the stiffness of the elastic - twe measure. Must be > 0. + twe method. Must be > 0. lmbda : float, default=1.0 A constant penalty that punishes the editing efforts. Must be >= 1.0. itakura_max_slope : float, default=None diff --git a/aeon/distances/elastic/tests/test_alignment_path.py b/aeon/distances/elastic/tests/test_alignment_path.py index 5fd1132783..b5f6c5cc49 100644 --- a/aeon/distances/elastic/tests/test_alignment_path.py +++ b/aeon/distances/elastic/tests/test_alignment_path.py @@ -32,7 +32,7 @@ def _validate_alignment_path_result( assert isinstance(alignment_path_result, tuple) assert isinstance(alignment_path_result[0], list) assert isinstance(alignment_path_result[1], float) - assert compute_alignment_path(x, y, measure=name) == alignment_path_result + assert compute_alignment_path(x, y, method=name) == alignment_path_result # Test a callable being passed assert callable_alignment_path == alignment_path_result diff --git a/aeon/distances/elastic/tests/test_cost_matrix.py b/aeon/distances/elastic/tests/test_cost_matrix.py index 46f4c0d47a..36c75d0c02 100644 --- a/aeon/distances/elastic/tests/test_cost_matrix.py +++ b/aeon/distances/elastic/tests/test_cost_matrix.py @@ -30,8 +30,8 @@ def _validate_cost_matrix_result( ---------- x (np.ndarray): The first input array. y (np.ndarray): The second input array. - name: The name of the distance measure. - distance: The distance measure function. + name: The name of the distance method. + distance: The distance method function. cost_matrix: The cost matrix function. """ original_x = x.copy() @@ -40,7 +40,7 @@ def _validate_cost_matrix_result( cost_matrix_callable_result = DISTANCES_DICT[name]["cost_matrix"](x, y) assert isinstance(cost_matrix_result, np.ndarray) - assert_almost_equal(cost_matrix_result, compute_cost_matrix(x, y, measure=name)) + assert_almost_equal(cost_matrix_result, compute_cost_matrix(x, y, method=name)) assert_almost_equal(cost_matrix_callable_result, cost_matrix_result) if name == "ddtw" or name == "wddtw": assert cost_matrix_result.shape == (x.shape[-1] - 2, y.shape[-1] - 2) diff --git a/aeon/distances/tests/test_distances.py b/aeon/distances/tests/test_distances.py index efcbd1ee2e..c2dcefe436 100644 --- a/aeon/distances/tests/test_distances.py +++ b/aeon/distances/tests/test_distances.py @@ -37,7 +37,7 @@ def _validate_distance_result( ---------- x (np.ndarray): First array. y (np.ndarray): Second array. - name (str): Name of the distance measure. + name (str): Name of the distance method. distance (callable): Distance function. expected_result (float): Expected distance result. check_xy_permuted: (bool): recursively call with swapped series @@ -50,8 +50,8 @@ def _validate_distance_result( dist_result = distance(x, y) assert isinstance(dist_result, float) assert_almost_equal(dist_result, expected_result) - assert_almost_equal(dist_result, compute_distance(x, y, measure=name)) - assert_almost_equal(dist_result, compute_distance(x, y, measure=distance)) + assert_almost_equal(dist_result, compute_distance(x, y, method=name)) + assert_almost_equal(dist_result, compute_distance(x, y, method=distance)) dist_result_to_self = distance(x, x) assert isinstance(dist_result_to_self, float) @@ -160,10 +160,10 @@ def test_get_distance_function_names(): def test_resolve_key_from_distance(): """Test _resolve_key_from_distance.""" - with pytest.raises(ValueError, match="Unknown measure"): - _resolve_key_from_distance(measure="FOO", key="cost_matrix") + with pytest.raises(ValueError, match="Unknown method"): + _resolve_key_from_distance(method="FOO", key="cost_matrix") with pytest.raises(ValueError): - _resolve_key_from_distance(measure="dtw", key="FOO") + _resolve_key_from_distance(method="dtw", key="FOO") def foo(x, y): return 0 @@ -177,22 +177,18 @@ def test_incorrect_inputs(): y = np.array([[11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) with pytest.raises( ValueError, - match="Measure must be one of the supported strings or a " "callable", + match="Method must be one of the supported strings or a " "callable", ): - compute_distance(x, y, measure="FOO") + compute_distance(x, y, method="FOO") with pytest.raises( ValueError, - match="Measure must be one of the supported strings or a " "callable", + match="Method must be one of the supported strings or a " "callable", ): - pairwise_distance(x, y, measure="FOO") - with pytest.raises( - ValueError, match="Measure must be one of the supported strings" - ): - alignment_path(x, y, measure="FOO") - with pytest.raises( - ValueError, match="Measure must be one of the supported strings" - ): - cost_matrix(x, y, measure="FOO") + pairwise_distance(x, y, method="FOO") + with pytest.raises(ValueError, match="Method must be one of the supported strings"): + alignment_path(x, y, method="FOO") + with pytest.raises(ValueError, match="Method must be one of the supported strings"): + cost_matrix(x, y, method="FOO") x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) with pytest.raises(ValueError, match="dist_func must be a callable"): diff --git a/aeon/distances/tests/test_numba_distance_parameters.py b/aeon/distances/tests/test_numba_distance_parameters.py index 5b0bc385d0..2293a239bd 100644 --- a/aeon/distances/tests/test_numba_distance_parameters.py +++ b/aeon/distances/tests/test_numba_distance_parameters.py @@ -93,7 +93,7 @@ def _test_distance_params( del param_dict["g"] results = [ distance_func(x, y, **param_dict.copy()), - distance(x, y, measure=distance_str, **param_dict.copy()), + distance(x, y, method=distance_str, **param_dict.copy()), ] if distance_str in _expected_distance_results_params: diff --git a/aeon/distances/tests/test_pairwise.py b/aeon/distances/tests/test_pairwise.py index 152913aee0..14c604f8c2 100644 --- a/aeon/distances/tests/test_pairwise.py +++ b/aeon/distances/tests/test_pairwise.py @@ -52,7 +52,7 @@ def _validate_pairwise_result( Parameters ---------- x: Input np.ndarray. - name: Name of the distance measure. + name: Name of the distance method. distance: Distance function. pairwise_distance: Pairwise distance function. """ @@ -64,11 +64,11 @@ def _validate_pairwise_result( assert isinstance(pairwise_result, np.ndarray) assert pairwise_result.shape == expected_size assert_almost_equal( - pairwise_result, compute_pairwise_distance(x, measure=name, symmetric=symmetric) + pairwise_result, compute_pairwise_distance(x, method=name, symmetric=symmetric) ) assert_almost_equal( pairwise_result, - compute_pairwise_distance(x, measure=distance, symmetric=symmetric), + compute_pairwise_distance(x, method=distance, symmetric=symmetric), ) if isinstance(x, np.ndarray): @@ -100,7 +100,7 @@ def _validate_multiple_to_multiple_result( ---------- x: Input array. y: Input array. - name: Name of the distance measure. + name: Name of the distance method. distance: Distance function. multiple_to_multiple_distance: Mul-to-Mul distance function. check_xy_permuted: recursively call with swapped series @@ -123,11 +123,11 @@ def _validate_multiple_to_multiple_result( assert multiple_to_multiple_result.shape == expected_size assert_almost_equal( - multiple_to_multiple_result, compute_pairwise_distance(x, y, measure=name) + multiple_to_multiple_result, compute_pairwise_distance(x, y, method=name) ) assert_almost_equal( multiple_to_multiple_result, - compute_pairwise_distance(x, y, measure=distance), + compute_pairwise_distance(x, y, method=distance), ) if isinstance(x, np.ndarray) and isinstance(y, np.ndarray): @@ -168,7 +168,7 @@ def _validate_single_to_multiple_result( ---------- x: Input array. y: Input array. - name: Name of the distance measure. + name: Name of the distance method. distance: Distance function. single_to_multiple_distance: Single to multiple distance function. run_inverse: Boolean that reruns the test with x and y swapped in position @@ -198,11 +198,11 @@ def _validate_single_to_multiple_result( assert single_to_multiple_result.shape[1] == expected_size assert_almost_equal( single_to_multiple_result, - compute_pairwise_distance(x, y, measure=name, symmetric=symmetric), + compute_pairwise_distance(x, y, method=name, symmetric=symmetric), ) assert_almost_equal( single_to_multiple_result, - compute_pairwise_distance(x, y, measure=distance, symmetric=symmetric), + compute_pairwise_distance(x, y, method=distance, symmetric=symmetric), ) if len(x_shape) < len(y_shape): diff --git a/aeon/regression/distance_based/_time_series_neighbors.py b/aeon/regression/distance_based/_time_series_neighbors.py index d56120ea92..9981e2dc12 100644 --- a/aeon/regression/distance_based/_time_series_neighbors.py +++ b/aeon/regression/distance_based/_time_series_neighbors.py @@ -111,7 +111,7 @@ def _fit(self, X, y): y : array-like, shape = (n_cases) The output value. """ - self.metric_ = get_distance_function(measure=self.distance) + self.metric_ = get_distance_function(method=self.distance) self.X_ = X self.y_ = y return self diff --git a/aeon/transformations/collection/channel_selection/_elbow_class.py b/aeon/transformations/collection/channel_selection/_elbow_class.py index be0f8102de..a9d5e744b0 100644 --- a/aeon/transformations/collection/channel_selection/_elbow_class.py +++ b/aeon/transformations/collection/channel_selection/_elbow_class.py @@ -90,7 +90,7 @@ class values {len(class_vals)} must be of same length." lambda row: aeon_distance( row[: row.shape[0] // 2], row[row.shape[0] // 2 :], - measure="dtw", + method="dtw", ), axis=1, arr=np.concatenate((cls1_ch, cls2_ch), axis=1), diff --git a/aeon/transformations/series/tests/test_warping.py b/aeon/transformations/series/tests/test_warping.py index f707d0e198..15aa99d70f 100644 --- a/aeon/transformations/series/tests/test_warping.py +++ b/aeon/transformations/series/tests/test_warping.py @@ -16,7 +16,7 @@ def test_warping_path_transformer(distance): x = make_example_2d_numpy_series(n_timepoints=20, n_channels=2) y = make_example_2d_numpy_series(n_timepoints=20, n_channels=2) - alignment_path_function = get_alignment_path_function(measure=distance) + alignment_path_function = get_alignment_path_function(method=distance) warping_path = alignment_path_function(x, y)[0] diff --git a/examples/distances/distances.ipynb b/examples/distances/distances.ipynb index 6e441e5533..19afa35f03 100644 --- a/examples/distances/distances.ipynb +++ b/examples/distances/distances.ipynb @@ -192,7 +192,7 @@ "\n", "d1 = euclidean_distance(first, second)\n", "d2 = euclidean_distance(first, third)\n", - "d3 = distance(second, third, measure=\"euclidean\")\n", + "d3 = distance(second, third, method=\"euclidean\")\n", "print(d1, \",\", d2, \",\", d3)" ] }, @@ -568,7 +568,7 @@ "y = np.array([[2, 3, 4, 5, 6, 7]])\n", "p, d = dtw_alignment_path(x, y)\n", "print(\"path =\", p, \" distance = \", d)\n", - "p, d = alignment_path(x, y, measure=\"dtw\")\n", + "p, d = alignment_path(x, y, method=\"dtw\")\n", "print(\"path =\", p, \" distance = \", d)" ] },