Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added type hints for rsast and sast files #1994

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions aeon/transformations/collection/shapelet_based/_rsast.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List, Optional, Union

import numpy as np
import pandas as pd
from numba import get_num_threads, njit, prange, set_num_threads
Expand All @@ -8,7 +10,7 @@


@njit(fastmath=False)
def _apply_kernel(ts, arr):
def _apply_kernel(ts: np.ndarray, arr: np.ndarray) -> float:
d_best = np.inf # sdist
m = ts.shape[0]
kernel = arr[~np.isnan(arr)] # ignore nan
Expand All @@ -22,7 +24,7 @@ def _apply_kernel(ts, arr):


@njit(parallel=True, fastmath=True)
def _apply_kernels(X, kernels):
def _apply_kernels(X: np.ndarray, kernels: np.ndarray) -> np.ndarray:
nbk = len(kernels)
out = np.zeros((X.shape[0], nbk), dtype=np.float32)
for i in prange(nbk):
Expand Down Expand Up @@ -96,11 +98,11 @@ class RSAST(BaseCollectionTransformer):

def __init__(
self,
n_random_points=10,
len_method="both",
nb_inst_per_class=10,
seed=None,
n_jobs=-1,
n_random_points: int = 10,
len_method: str = "both",
nb_inst_per_class: int = 10,
seed: int = None,
n_jobs: int = 1, # Parllel Processing
):
self.n_random_points = n_random_points
self.len_method = len_method
Expand All @@ -113,7 +115,7 @@ def __init__(
self._kernels_generators = {} # Reference time series
super().__init__()

def _fit(self, X, y):
def _fit(self, X: np.ndarray, y: Union[np.ndarray, List]) -> "RSAST":
from scipy.stats import ConstantInputWarning, DegenerateDataWarning, f_oneway
from statsmodels.tsa.stattools import acf, pacf

Expand Down Expand Up @@ -300,7 +302,9 @@ def _fit(self, X, y):

return self

def _transform(self, X, y=None):
def _transform(
self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None
) -> np.ndarray:
"""Transform the input X using the generated subsequences.

Parameters
Expand Down
22 changes: 13 additions & 9 deletions aeon/transformations/collection/shapelet_based/_sast.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List, Optional, Union

import numpy as np
from numba import get_num_threads, njit, prange, set_num_threads

Expand All @@ -7,7 +9,7 @@


@njit(fastmath=False)
def _apply_kernel(ts, arr):
def _apply_kernel(ts: np.ndarray, arr: np.ndarray) -> float:
d_best = np.inf # sdist
m = ts.shape[0]
kernel = arr[~np.isnan(arr)] # ignore nan
Expand All @@ -22,7 +24,7 @@ def _apply_kernel(ts, arr):


@njit(parallel=True, fastmath=True)
def _apply_kernels(X, kernels):
def _apply_kernels(X: np.ndarray, kernels: np.ndarray) -> np.ndarray:
nbk = len(kernels)
out = np.zeros((X.shape[0], nbk), dtype=np.float32)
for i in prange(nbk):
Expand Down Expand Up @@ -88,11 +90,11 @@ class SAST(BaseCollectionTransformer):

def __init__(
self,
lengths=None,
stride=1,
nb_inst_per_class=1,
seed=None,
n_jobs=-1,
lengths: Optional[np.ndarray] = None,
stride: int = 1,
nb_inst_per_class: int = 1,
seed: Optional[int] = None,
n_jobs: int = 1, # Parallel processing
):
super().__init__()
self.lengths = lengths
Expand All @@ -104,7 +106,7 @@ def __init__(
self.n_jobs = n_jobs
self.seed = seed

def _fit(self, X, y):
def _fit(self, X: np.ndarray, y: Union[np.ndarray, List]) -> "SAST":
"""Select reference time series and generate subsequences from them.

Parameters
Expand Down Expand Up @@ -171,7 +173,9 @@ def _fit(self, X, y):
k += 1
return self

def _transform(self, X, y=None):
def _transform(
self, X: np.ndarray, y: Optional[Union[np.ndarray, List]] = None
) -> np.ndarray:
"""Transform the input X using the generated subsequences.

Parameters
Expand Down