From fabd57bc9ad7b52b88ddbe3cf541b2113bf6f3db Mon Sep 17 00:00:00 2001 From: Aryan Date: Sat, 10 Aug 2024 19:42:57 +0530 Subject: [PATCH 1/6] Added Type Hints for dilated shapelets --- .../_dilated_shapelet_transform.py | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py index 23e4b19e4a..905f8e8576 100644 --- a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py +++ b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py @@ -14,6 +14,9 @@ from numba.typed import List from sklearn.preprocessing import LabelEncoder +from typing import Optional, Union, List, Dict +from numba.core.registry import CPUDispatcher + from aeon.distances import get_distance_function from aeon.transformations.collection import BaseCollectionTransformer from aeon.utils.numba.general import ( @@ -149,15 +152,15 @@ class RandomDilatedShapeletTransform(BaseCollectionTransformer): def __init__( self, - max_shapelets=10_000, - shapelet_lengths=None, - proba_normalization=0.8, - threshold_percentiles=None, - alpha_similarity=0.5, - use_prime_dilations=False, - random_state=None, - distance="manhattan", - n_jobs=1, + max_shapelets: int=10_000, + shapelet_lengths: Optional[Union[List[int], np.ndarray]]=None, + proba_normalization: float=0.8, + threshold_percentiles: Optional[Union[List[float], np.ndarray]]=None, + alpha_similarity: float=0.5, + use_prime_dilations: bool=False, + random_state: Optional[int]=None, + distance: CPUDispatcher="manhattan", + n_jobs: int=1, ): self.max_shapelets = max_shapelets self.shapelet_lengths = shapelet_lengths @@ -171,7 +174,7 @@ def __init__( super().__init__() - def _fit(self, X, y=None): + def _fit(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]]=None) -> 'RandomDilatedShapeletTransform': """Fit the random dilated shapelet transform to a specified X and y. Parameters @@ -245,7 +248,7 @@ def _fit(self, X, y=None): return self - def _transform(self, X, y=None): + def _transform(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]]=None): """Transform X according to the extracted shapelets. Parameters @@ -345,7 +348,7 @@ def _check_input_params(self): self.threshold_percentiles_ = np.asarray(self.threshold_percentiles_) @classmethod - def get_test_params(cls, parameter_set="default"): + def get_test_params(cls, parameter_set: str="default") -> 'Union[Dict, List[Dict]]': """Return testing parameter settings for the estimator. Parameters @@ -364,7 +367,7 @@ def get_test_params(cls, parameter_set="default"): `create_test_instance` uses the first (or only) dictionary in `params` """ if parameter_set == "default": - params = {"max_shapelets": 10} + params : Union[Dict, List[Dict]]= {"max_shapelets": 10} else: raise NotImplementedError( f"The parameter set {parameter_set} is not yet implemented" @@ -374,12 +377,12 @@ def get_test_params(cls, parameter_set="default"): @njit(fastmath=True, cache=True) def _init_random_shapelet_params( - max_shapelets, - shapelet_lengths, - proba_normalization, - use_prime_dilations, - n_channels, - n_timepoints, + max_shapelets: int, + shapelet_lengths: Union[np.ndarray,List[int]], + proba_normalization: float, + use_prime_dilations: bool, + n_channels: int, + n_timepoints: int, ): """Randomly initialize the parameters of the shapelets. @@ -426,9 +429,9 @@ def _init_random_shapelet_params( """ # Lengths of the shapelets # test dtypes correctness - lengths = np.random.choice(shapelet_lengths, size=max_shapelets).astype(np.int32) + lengths: np.ndarray= np.random.choice(shapelet_lengths, size=max_shapelets).astype(np.int32) # Upper bound values for dilations - dilations = np.zeros(max_shapelets, dtype=np.int32) + dilations: np.ndarray = np.zeros(max_shapelets, dtype=np.int32) upper_bounds = np.log2(np.floor_divide(n_timepoints - 1, lengths - 1)) if use_prime_dilations: @@ -484,16 +487,16 @@ def _get_admissible_sampling_point(current_mask): @njit(fastmath=True, cache=True, parallel=True) def random_dilated_shapelet_extraction( - X, - y, - max_shapelets, - shapelet_lengths, - proba_normalization, - threshold_percentiles, - alpha_similarity, - use_prime_dilations, - seed, - distance, + X: np.ndarray, + y: np.ndarray, + max_shapelets: int, + shapelet_lengths: Union[np.ndarray, List[int]], + proba_normalization: float, + threshold_percentiles: Union[np.ndarray, List[float]], + alpha_similarity: float, + use_prime_dilations: bool, + seed: int, + distance: CPUDispatcher, ): """Randomly generate a set of shapelets given the input parameters. @@ -554,9 +557,9 @@ def random_dilated_shapelet_extraction( - stds : array, shape (max_shapelets, n_channels) Standard deviation of the shapelets """ - n_cases = len(X) - n_channels = X[0].shape[0] - n_timepointss = np.zeros(n_cases, dtype=np.int64) + n_cases: int = len(X) + n_channels: int = X[0].shape[0] + n_timepointss: np.ndarray = np.zeros(n_cases, dtype=np.int64) for i in range(n_cases): n_timepointss[i] = X[i].shape[1] min_n_timepoints = n_timepointss.min() @@ -685,7 +688,7 @@ def random_dilated_shapelet_extraction( @njit(fastmath=True, cache=True, parallel=True) -def dilated_shapelet_transform(X, shapelets, distance): +def dilated_shapelet_transform(X: np.ndarray, shapelets: tuple[np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,], distance:CPUDispatcher): """Perform the shapelet transform with a set of shapelets and a set of time series. Parameters @@ -797,7 +800,7 @@ def normalize_subsequences(X_subs, X_means, X_stds): @njit(fastmath=True, cache=True) -def get_all_subsequences(X, length, dilation): +def get_all_subsequences(X: np.ndarray, length: int, dilation: int) -> np.ndarray: """ Generate subsequences from a time series given the length and dilation parameters. @@ -828,7 +831,7 @@ def get_all_subsequences(X, length, dilation): @njit(fastmath=True, cache=True) -def compute_shapelet_features(X_subs, values, length, threshold, distance): +def compute_shapelet_features(X_subs: np.ndarray, values: np.ndarray, length: int, threshold: float, distance:CPUDispatcher): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting @@ -875,7 +878,7 @@ def compute_shapelet_features(X_subs, values, length, threshold, distance): @njit(fastmath=True, cache=True) -def compute_shapelet_dist_vector(X_subs, values, length, distance): +def compute_shapelet_dist_vector(X_subs: np.ndarray, values:np.ndarray, length: int, distanceCPUDispatcher): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting From 903a7c4d98c90f87f8065898aa5600ca35b04eac Mon Sep 17 00:00:00 2001 From: aryanpola Date: Sat, 10 Aug 2024 14:33:36 +0000 Subject: [PATCH 2/6] Automatic `pre-commit` fixes --- .../_dilated_shapelet_transform.py | 67 +++++++++++++------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py index 905f8e8576..b6b47edd93 100644 --- a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py +++ b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py @@ -8,15 +8,14 @@ __all__ = ["RandomDilatedShapeletTransform"] import warnings +from typing import Dict, List, Optional, Union import numpy as np from numba import njit, prange, set_num_threads +from numba.core.registry import CPUDispatcher from numba.typed import List from sklearn.preprocessing import LabelEncoder -from typing import Optional, Union, List, Dict -from numba.core.registry import CPUDispatcher - from aeon.distances import get_distance_function from aeon.transformations.collection import BaseCollectionTransformer from aeon.utils.numba.general import ( @@ -152,15 +151,15 @@ class RandomDilatedShapeletTransform(BaseCollectionTransformer): def __init__( self, - max_shapelets: int=10_000, - shapelet_lengths: Optional[Union[List[int], np.ndarray]]=None, - proba_normalization: float=0.8, - threshold_percentiles: Optional[Union[List[float], np.ndarray]]=None, - alpha_similarity: float=0.5, - use_prime_dilations: bool=False, - random_state: Optional[int]=None, - distance: CPUDispatcher="manhattan", - n_jobs: int=1, + max_shapelets: int = 10_000, + shapelet_lengths: Optional[Union[List[int], np.ndarray]] = None, + proba_normalization: float = 0.8, + threshold_percentiles: Optional[Union[List[float], np.ndarray]] = None, + alpha_similarity: float = 0.5, + use_prime_dilations: bool = False, + random_state: Optional[int] = None, + distance: CPUDispatcher = "manhattan", + n_jobs: int = 1, ): self.max_shapelets = max_shapelets self.shapelet_lengths = shapelet_lengths @@ -174,7 +173,9 @@ def __init__( super().__init__() - def _fit(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]]=None) -> 'RandomDilatedShapeletTransform': + def _fit( + self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None + ) -> "RandomDilatedShapeletTransform": """Fit the random dilated shapelet transform to a specified X and y. Parameters @@ -248,7 +249,7 @@ def _fit(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]]=None) -> 'Ran return self - def _transform(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]]=None): + def _transform(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None): """Transform X according to the extracted shapelets. Parameters @@ -348,7 +349,9 @@ def _check_input_params(self): self.threshold_percentiles_ = np.asarray(self.threshold_percentiles_) @classmethod - def get_test_params(cls, parameter_set: str="default") -> 'Union[Dict, List[Dict]]': + def get_test_params( + cls, parameter_set: str = "default" + ) -> "Union[Dict, List[Dict]]": """Return testing parameter settings for the estimator. Parameters @@ -367,7 +370,7 @@ def get_test_params(cls, parameter_set: str="default") -> 'Union[Dict, List[Dict `create_test_instance` uses the first (or only) dictionary in `params` """ if parameter_set == "default": - params : Union[Dict, List[Dict]]= {"max_shapelets": 10} + params: Union[Dict, List[Dict]] = {"max_shapelets": 10} else: raise NotImplementedError( f"The parameter set {parameter_set} is not yet implemented" @@ -378,7 +381,7 @@ def get_test_params(cls, parameter_set: str="default") -> 'Union[Dict, List[Dict @njit(fastmath=True, cache=True) def _init_random_shapelet_params( max_shapelets: int, - shapelet_lengths: Union[np.ndarray,List[int]], + shapelet_lengths: Union[np.ndarray, List[int]], proba_normalization: float, use_prime_dilations: bool, n_channels: int, @@ -429,7 +432,9 @@ def _init_random_shapelet_params( """ # Lengths of the shapelets # test dtypes correctness - lengths: np.ndarray= np.random.choice(shapelet_lengths, size=max_shapelets).astype(np.int32) + lengths: np.ndarray = np.random.choice(shapelet_lengths, size=max_shapelets).astype( + np.int32 + ) # Upper bound values for dilations dilations: np.ndarray = np.zeros(max_shapelets, dtype=np.int32) upper_bounds = np.log2(np.floor_divide(n_timepoints - 1, lengths - 1)) @@ -688,7 +693,19 @@ def random_dilated_shapelet_extraction( @njit(fastmath=True, cache=True, parallel=True) -def dilated_shapelet_transform(X: np.ndarray, shapelets: tuple[np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,], distance:CPUDispatcher): +def dilated_shapelet_transform( + X: np.ndarray, + shapelets: tuple[ + np.ndarray, + np.ndarray, + np.ndarray, + np.ndarray, + np.ndarray, + np.ndarray, + np.ndarray, + ], + distance: CPUDispatcher, +): """Perform the shapelet transform with a set of shapelets and a set of time series. Parameters @@ -831,7 +848,13 @@ def get_all_subsequences(X: np.ndarray, length: int, dilation: int) -> np.ndarra @njit(fastmath=True, cache=True) -def compute_shapelet_features(X_subs: np.ndarray, values: np.ndarray, length: int, threshold: float, distance:CPUDispatcher): +def compute_shapelet_features( + X_subs: np.ndarray, + values: np.ndarray, + length: int, + threshold: float, + distance: CPUDispatcher, +): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting @@ -878,7 +901,9 @@ def compute_shapelet_features(X_subs: np.ndarray, values: np.ndarray, length: in @njit(fastmath=True, cache=True) -def compute_shapelet_dist_vector(X_subs: np.ndarray, values:np.ndarray, length: int, distanceCPUDispatcher): +def compute_shapelet_dist_vector( + X_subs: np.ndarray, values: np.ndarray, length: int, distanceCPUDispatcher +): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting From e4cbfaf57e26af627874791ac7d3a45e12070ec9 Mon Sep 17 00:00:00 2001 From: Aryan Date: Sat, 10 Aug 2024 19:42:57 +0530 Subject: [PATCH 3/6] Added changes --- .../_dilated_shapelet_transform.py | 75 +++++++------------ 1 file changed, 26 insertions(+), 49 deletions(-) diff --git a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py index b6b47edd93..8b73768cbc 100644 --- a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py +++ b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py @@ -16,6 +16,9 @@ from numba.typed import List from sklearn.preprocessing import LabelEncoder +from typing import Optional, Union, List, Dict +from numba.core.registry import CPUDispatcher + from aeon.distances import get_distance_function from aeon.transformations.collection import BaseCollectionTransformer from aeon.utils.numba.general import ( @@ -151,15 +154,15 @@ class RandomDilatedShapeletTransform(BaseCollectionTransformer): def __init__( self, - max_shapelets: int = 10_000, - shapelet_lengths: Optional[Union[List[int], np.ndarray]] = None, - proba_normalization: float = 0.8, - threshold_percentiles: Optional[Union[List[float], np.ndarray]] = None, - alpha_similarity: float = 0.5, - use_prime_dilations: bool = False, - random_state: Optional[int] = None, - distance: CPUDispatcher = "manhattan", - n_jobs: int = 1, + max_shapelets=10_000, + shapelet_lengths=None, + proba_normalization=0.8, + threshold_percentiles=None, + alpha_similarity=0.5, + use_prime_dilations=False, + random_state=None, + distance="manhattan", + n_jobs=1, ): self.max_shapelets = max_shapelets self.shapelet_lengths = shapelet_lengths @@ -173,9 +176,7 @@ def __init__( super().__init__() - def _fit( - self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None - ) -> "RandomDilatedShapeletTransform": + def _fit(self, X, y=None): """Fit the random dilated shapelet transform to a specified X and y. Parameters @@ -249,7 +250,7 @@ def _fit( return self - def _transform(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None): + def _transform(self, X, y=None): """Transform X according to the extracted shapelets. Parameters @@ -349,9 +350,7 @@ def _check_input_params(self): self.threshold_percentiles_ = np.asarray(self.threshold_percentiles_) @classmethod - def get_test_params( - cls, parameter_set: str = "default" - ) -> "Union[Dict, List[Dict]]": + def get_test_params(cls, parameter_set="default"): """Return testing parameter settings for the estimator. Parameters @@ -370,7 +369,7 @@ def get_test_params( `create_test_instance` uses the first (or only) dictionary in `params` """ if parameter_set == "default": - params: Union[Dict, List[Dict]] = {"max_shapelets": 10} + params = {"max_shapelets": 10} else: raise NotImplementedError( f"The parameter set {parameter_set} is not yet implemented" @@ -380,12 +379,12 @@ def get_test_params( @njit(fastmath=True, cache=True) def _init_random_shapelet_params( - max_shapelets: int, - shapelet_lengths: Union[np.ndarray, List[int]], - proba_normalization: float, - use_prime_dilations: bool, - n_channels: int, - n_timepoints: int, + max_shapelets, + shapelet_lengths, + proba_normalization, + use_prime_dilations, + n_channels, + n_timepoints, ): """Randomly initialize the parameters of the shapelets. @@ -432,9 +431,7 @@ def _init_random_shapelet_params( """ # Lengths of the shapelets # test dtypes correctness - lengths: np.ndarray = np.random.choice(shapelet_lengths, size=max_shapelets).astype( - np.int32 - ) + lengths = np.random.choice(shapelet_lengths, size=max_shapelets).astype(np.int32) # Upper bound values for dilations dilations: np.ndarray = np.zeros(max_shapelets, dtype=np.int32) upper_bounds = np.log2(np.floor_divide(n_timepoints - 1, lengths - 1)) @@ -693,19 +690,7 @@ def random_dilated_shapelet_extraction( @njit(fastmath=True, cache=True, parallel=True) -def dilated_shapelet_transform( - X: np.ndarray, - shapelets: tuple[ - np.ndarray, - np.ndarray, - np.ndarray, - np.ndarray, - np.ndarray, - np.ndarray, - np.ndarray, - ], - distance: CPUDispatcher, -): +def dilated_shapelet_transform(X, shapelets, distance): """Perform the shapelet transform with a set of shapelets and a set of time series. Parameters @@ -848,13 +833,7 @@ def get_all_subsequences(X: np.ndarray, length: int, dilation: int) -> np.ndarra @njit(fastmath=True, cache=True) -def compute_shapelet_features( - X_subs: np.ndarray, - values: np.ndarray, - length: int, - threshold: float, - distance: CPUDispatcher, -): +def compute_shapelet_features(X_subs, values, length, threshold, distance): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting @@ -901,9 +880,7 @@ def compute_shapelet_features( @njit(fastmath=True, cache=True) -def compute_shapelet_dist_vector( - X_subs: np.ndarray, values: np.ndarray, length: int, distanceCPUDispatcher -): +def compute_shapelet_dist_vector(X_subs, values, length, distance): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting From f57d244bec6521b9c0d52916e72a7dbee62fbf1e Mon Sep 17 00:00:00 2001 From: aryanpola Date: Mon, 12 Aug 2024 06:04:53 +0000 Subject: [PATCH 4/6] Automatic `pre-commit` fixes --- .../collection/shapelet_based/_dilated_shapelet_transform.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py index 8b73768cbc..df94d10436 100644 --- a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py +++ b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py @@ -16,9 +16,6 @@ from numba.typed import List from sklearn.preprocessing import LabelEncoder -from typing import Optional, Union, List, Dict -from numba.core.registry import CPUDispatcher - from aeon.distances import get_distance_function from aeon.transformations.collection import BaseCollectionTransformer from aeon.utils.numba.general import ( From 2eb864e7f9c57f0af4a950f9dfdcc15c7518dde4 Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 12 Aug 2024 11:50:16 +0530 Subject: [PATCH 5/6] Changed File --- .../_dilated_shapelet_transform.py | 46 ++++--------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py index b6b47edd93..fd4397f4a9 100644 --- a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py +++ b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py @@ -16,6 +16,7 @@ from numba.typed import List from sklearn.preprocessing import LabelEncoder + from aeon.distances import get_distance_function from aeon.transformations.collection import BaseCollectionTransformer from aeon.utils.numba.general import ( @@ -150,7 +151,6 @@ class RandomDilatedShapeletTransform(BaseCollectionTransformer): } def __init__( - self, max_shapelets: int = 10_000, shapelet_lengths: Optional[Union[List[int], np.ndarray]] = None, proba_normalization: float = 0.8, @@ -173,9 +173,7 @@ def __init__( super().__init__() - def _fit( - self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None - ) -> "RandomDilatedShapeletTransform": + def _fit(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] =None): """Fit the random dilated shapelet transform to a specified X and y. Parameters @@ -249,7 +247,7 @@ def _fit( return self - def _transform(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None): + def _transform(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]]=None): """Transform X according to the extracted shapelets. Parameters @@ -349,9 +347,7 @@ def _check_input_params(self): self.threshold_percentiles_ = np.asarray(self.threshold_percentiles_) @classmethod - def get_test_params( - cls, parameter_set: str = "default" - ) -> "Union[Dict, List[Dict]]": + def get_test_params(cls, parameter_set: str="default") -> "Union[Dict, List[Dict]]": """Return testing parameter settings for the estimator. Parameters @@ -370,7 +366,7 @@ def get_test_params( `create_test_instance` uses the first (or only) dictionary in `params` """ if parameter_set == "default": - params: Union[Dict, List[Dict]] = {"max_shapelets": 10} + params = {"max_shapelets": 10} else: raise NotImplementedError( f"The parameter set {parameter_set} is not yet implemented" @@ -432,9 +428,7 @@ def _init_random_shapelet_params( """ # Lengths of the shapelets # test dtypes correctness - lengths: np.ndarray = np.random.choice(shapelet_lengths, size=max_shapelets).astype( - np.int32 - ) + lengths = np.random.choice(shapelet_lengths, size=max_shapelets).astype(np.int32) # Upper bound values for dilations dilations: np.ndarray = np.zeros(max_shapelets, dtype=np.int32) upper_bounds = np.log2(np.floor_divide(n_timepoints - 1, lengths - 1)) @@ -544,7 +538,7 @@ def random_dilated_shapelet_extraction( shapelets and candidate subsequences Returns - ------- + -------- Shapelets : tuple The returned tuple contains 7 arrays describing the shapelets parameters: - values : array, shape (max_shapelets, n_channels, max(shapelet_lengths)) @@ -693,19 +687,7 @@ def random_dilated_shapelet_extraction( @njit(fastmath=True, cache=True, parallel=True) -def dilated_shapelet_transform( - X: np.ndarray, - shapelets: tuple[ - np.ndarray, - np.ndarray, - np.ndarray, - np.ndarray, - np.ndarray, - np.ndarray, - np.ndarray, - ], - distance: CPUDispatcher, -): +def dilated_shapelet_transform(X: np.ndarray, shapelets: tuple[np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray], distance: CPUDispatcher): """Perform the shapelet transform with a set of shapelets and a set of time series. Parameters @@ -848,13 +830,7 @@ def get_all_subsequences(X: np.ndarray, length: int, dilation: int) -> np.ndarra @njit(fastmath=True, cache=True) -def compute_shapelet_features( - X_subs: np.ndarray, - values: np.ndarray, - length: int, - threshold: float, - distance: CPUDispatcher, -): +def compute_shapelet_features(X_subs: np.ndarray, values: np.ndarray, length: int, threshold: float, distance: CPUDispatcher): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting @@ -901,9 +877,7 @@ def compute_shapelet_features( @njit(fastmath=True, cache=True) -def compute_shapelet_dist_vector( - X_subs: np.ndarray, values: np.ndarray, length: int, distanceCPUDispatcher -): +def compute_shapelet_dist_vector(X_subs: np.ndarray, values: np.ndarray, length: int, distance: CPUDispatcher): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting From 1e2756658bd4cdace9408b727761886c6462ba45 Mon Sep 17 00:00:00 2001 From: aryanpola Date: Mon, 12 Aug 2024 06:24:23 +0000 Subject: [PATCH 6/6] Automatic `pre-commit` fixes --- .../_dilated_shapelet_transform.py | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py index b2087537c2..d883055750 100644 --- a/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py +++ b/aeon/transformations/collection/shapelet_based/_dilated_shapelet_transform.py @@ -16,7 +16,6 @@ from numba.typed import List from sklearn.preprocessing import LabelEncoder - from aeon.distances import get_distance_function from aeon.transformations.collection import BaseCollectionTransformer from aeon.utils.numba.general import ( @@ -173,7 +172,7 @@ def __init__( super().__init__() - def _fit(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] =None): + def _fit(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None): """Fit the random dilated shapelet transform to a specified X and y. Parameters @@ -247,7 +246,7 @@ def _fit(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] =None): return self - def _transform(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]]=None): + def _transform(self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None): """Transform X according to the extracted shapelets. Parameters @@ -347,7 +346,9 @@ def _check_input_params(self): self.threshold_percentiles_ = np.asarray(self.threshold_percentiles_) @classmethod - def get_test_params(cls, parameter_set: str="default") -> "Union[Dict, List[Dict]]": + def get_test_params( + cls, parameter_set: str = "default" + ) -> "Union[Dict, List[Dict]]": """Return testing parameter settings for the estimator. Parameters @@ -540,7 +541,7 @@ def random_dilated_shapelet_extraction( shapelets and candidate subsequences Returns - -------- + ------- Shapelets : tuple The returned tuple contains 7 arrays describing the shapelets parameters: - values : array, shape (max_shapelets, n_channels, max(shapelet_lengths)) @@ -689,7 +690,19 @@ def random_dilated_shapelet_extraction( @njit(fastmath=True, cache=True, parallel=True) -def dilated_shapelet_transform(X: np.ndarray, shapelets: tuple[np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray,np.ndarray], distance: CPUDispatcher): +def dilated_shapelet_transform( + X: np.ndarray, + shapelets: tuple[ + np.ndarray, + np.ndarray, + np.ndarray, + np.ndarray, + np.ndarray, + np.ndarray, + np.ndarray, + ], + distance: CPUDispatcher, +): """Perform the shapelet transform with a set of shapelets and a set of time series. Parameters @@ -832,7 +845,13 @@ def get_all_subsequences(X: np.ndarray, length: int, dilation: int) -> np.ndarra @njit(fastmath=True, cache=True) -def compute_shapelet_features(X_subs: np.ndarray, values: np.ndarray, length: int, threshold: float, distance: CPUDispatcher): +def compute_shapelet_features( + X_subs: np.ndarray, + values: np.ndarray, + length: int, + threshold: float, + distance: CPUDispatcher, +): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting @@ -879,7 +898,9 @@ def compute_shapelet_features(X_subs: np.ndarray, values: np.ndarray, length: in @njit(fastmath=True, cache=True) -def compute_shapelet_dist_vector(X_subs: np.ndarray, values: np.ndarray, length: int, distance: CPUDispatcher): +def compute_shapelet_dist_vector( + X_subs: np.ndarray, values: np.ndarray, length: int, distance: CPUDispatcher +): """Extract the features from a shapelet distance vector. Given a shapelet and a time series, extract three features from the resulting