Repository: aeon-toolkit/aeon
Pull request #1935 (2024-08-09 11:51:50)

[DOC] Correct sast tags to shapelet
Quick small PR request by Tony in the intern meeting to fix a class tag.

aeon-actions-bot[bot]: 
## Thank you for contributing to `aeon`

I have added the following labels to this PR based on the title: **[ $\\color{#F3B9F8}{\\textsf{documentation}}$ ]**.
I have added the following labels to this PR based on the changes made: **[ $\\color{#BCAE15}{\\textsf{classification}}$, $\\color{#41A8F6}{\\textsf{transformations}}$ ]**. Feel free to change these if they do not properly represent the PR.

The [Checks](https://github.com/aeon-toolkit/aeon/pull/1935/checks) tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.

If our `pre-commit` code quality check fails, any trivial fixes will automatically be pushed to your PR unless it is a draft.

Don't hesitate to ask questions on the `aeon` [Slack](https://join.slack.com/t/aeon-toolkit/shared_invite/zt-22vwvut29-HDpCu~7VBUozyfL_8j3dLA) channel if you have any.

### PR CI actions

These checkboxes will add labels to enable/disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.

- [ ] Run `pre-commit` checks for all files
- [ ] Run all `pytest` tests and configurations
- [ ] Run all notebook example tests
- [ ] Run numba-disabled `codecov` tests
- [ ] Stop automatic `pre-commit` fixes (always disabled for drafts)
- [ ] Push an empty commit to re-run CI checks
    

Patch:
diff --git a/aeon/classification/shapelet_based/_sast.py b/aeon/classification/shapelet_based/_sast.py
index e12bf811..26b51446 100644
--- a/aeon/classification/shapelet_based/_sast.py
+++ b/aeon/classification/shapelet_based/_sast.py
@@ -61,7 +61,7 @@ class SASTClassifier(BaseClassifier):
     _tags = {
         "capability:multithreading": True,
         "capability:multivariate": False,
-        "algorithm_type": "subsequence",
+        "algorithm_type": "shapelet",
     }
 
     def __init__(
diff --git a/aeon/clustering/_clara.py b/aeon/clustering/_clara.py
index fda6644f..d6cdc895 100644
--- a/aeon/clustering/_clara.py
+++ b/aeon/clustering/_clara.py
@@ -10,6 +10,7 @@ from sklearn.utils import check_random_state
 
 from aeon.clustering._k_medoids import TimeSeriesKMedoids
 from aeon.clustering.base import BaseClusterer
+from aeon.distances import pairwise_distance
 
 
 class TimeSeriesCLARA(BaseClusterer):
@@ -158,8 +159,9 @@ class TimeSeriesCLARA(BaseClusterer):
         else:
             n_samples = self.n_samples
 
-        best_score = np.inf
+        best_inertia = np.inf
         best_pam = None
+        best_labels = None
         for _ in range(self.n_sampling_iters):
             sample_idxs = np.arange(n_samples)
             if n_samples < n_cases:
@@ -181,11 +183,24 @@ class TimeSeriesCLARA(BaseClusterer):
                 method="pam",
             )
             pam.fit(X[sample_idxs])
-            if pam.inertia_ < best_score:
+            curr_centers = pam.cluster_centers_
+            if isinstance(pam.distance, str):
+                pairwise_matrix = pairwise_distance(
+                    X, curr_centers, metric=self.distance, **pam._distance_params
+                )
+            else:
+                pairwise_matrix = pairwise_distance(
+                    X, curr_centers, pam._distance_callable, **pam._distance_params
+                )
+            curr_td = pairwise_matrix.min(axis=1).sum()
+
+            if curr_td < best_inertia:
                 best_pam = pam
+                best_inertia = curr_td
+                best_labels = pairwise_matrix.argmin(axis=1)
 
-        self.labels_ = best_pam.labels_
-        self.inertia_ = best_pam.inertia_
+        self.labels_ = best_labels
+        self.inertia_ = best_inertia
         self.cluster_centers_ = best_pam.cluster_centers_
         self.n_iter_ = best_pam.n_iter_
         self._kmedoids_instance = best_pam
diff --git a/aeon/transformations/collection/shapelet_based/_sast.py b/aeon/transformations/collection/shapelet_based/_sast.py
index 513ef0ac..9b1b2ec9 100644
--- a/aeon/transformations/collection/shapelet_based/_sast.py
+++ b/aeon/transformations/collection/shapelet_based/_sast.py
@@ -83,7 +83,7 @@ class SAST(BaseCollectionTransformer):
     _tags = {
         "output_data_type": "Tabular",
         "capability:multivariate": False,
-        "algorithm_type": "subsequence",
+        "algorithm_type": "shapelet",
     }
 
     def __init__(


Test patch:
diff --git a/aeon/clustering/tests/test_clara.py b/aeon/clustering/tests/test_clara.py
index 72383c99..ebfb3dad 100644
--- a/aeon/clustering/tests/test_clara.py
+++ b/aeon/clustering/tests/test_clara.py
@@ -34,17 +34,19 @@ def test_clara_uni():
     proba = clara.predict_proba(X_test)
     assert np.array_equal(
         test_medoids_result,
-        [0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1],
+        [1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0],
     )
     assert np.array_equal(
         train_medoids_result,
-        [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0],
+        [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1],
     )
-    assert test_score == 0.4789473684210526
-    assert train_score == 0.4789473684210526
-    assert np.isclose(clara.inertia_, 44.156819900725814)
+    assert test_score == 0.5210526315789473
+    assert train_score == 0.5578947368421052
+    assert np.isclose(clara.inertia_, 78.79839208236065)
     assert clara.n_iter_ == 2
-    assert np.array_equal(clara.labels_, [0, 0, 1, 0, 1, 1, 1, 0, 1, 1])
+    assert np.array_equal(
+        clara.labels_, [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1]
+    )
     assert isinstance(clara.cluster_centers_, np.ndarray)
     for val in proba:
         assert np.count_nonzero(val == 1.0) == 1
@@ -77,17 +79,19 @@ def test_clara_multi():
     proba = clara.predict_proba(X_test)
     assert np.array_equal(
         test_medoids_result,
-        [0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1],
+        [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
     )
     assert np.array_equal(
         train_medoids_result,
-        [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0],
+        [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1],
     )
     assert test_score == 0.4789473684210526
     assert train_score == 0.5578947368421052
-    assert np.isclose(clara.inertia_, 95.91411895660636)
+    assert np.isclose(clara.inertia_, 1900.6752544011563)
     assert clara.n_iter_ == 3
-    assert np.array_equal(clara.labels_, [1, 1, 1, 1, 1, 1, 0, 1, 1, 1])
+    assert np.array_equal(
+        clara.labels_, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1]
+    )
     assert isinstance(clara.cluster_centers_, np.ndarray)
     for val in proba:
         assert np.count_nonzero(val == 1.0) == 1