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

[ENH] Replace SFA with SFAFast in REDCOMETS #2418

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 14 additions & 15 deletions aeon/classification/dictionary_based/_redcomets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from aeon.classification.base import BaseClassifier
from aeon.transformations.collection import Normalizer
from aeon.transformations.collection.dictionary_based import SAX, SFA
from aeon.transformations.collection.dictionary_based import SAX, SFAFast
from aeon.utils.validation._dependencies import _check_soft_dependencies


Expand Down Expand Up @@ -62,7 +62,7 @@ class REDCOMETS(BaseClassifier):

See Also
--------
SAX, SFA
SAX, SFA, SFAFast

Notes
-----
Expand Down Expand Up @@ -182,9 +182,9 @@ def _build_univariate_ensemble(self, X, y):
Returns
-------
sfa_transforms :
List of ``SFA()`` instances with random word length and alpabet size
List of ``SFAFast()`` instances with random word length and alpabet size
sfa_clfs :
List of ``(RandomForestClassifier(), weight)`` tuples fitted on `SFA`
List of ``(RandomForestClassifier(), weight)`` tuples fitted on `SFAFast`
transformed training data
sax_transforms :
List of ``SAX()`` instances with random word length and alpabet size
Expand Down Expand Up @@ -241,7 +241,7 @@ def _build_univariate_ensemble(self, X, y):
cv = np.min([5, len(y_smote) // len(list(set(y_smote)))])

sfa_transforms = [
SFA(
SFAFast(
word_length=w,
alphabet_size=a,
window_size=X_smote.shape[1],
Expand All @@ -254,8 +254,9 @@ def _build_univariate_ensemble(self, X, y):

sfa_clfs = []
for sfa in sfa_transforms:
sfa_dics = sfa.fit_transform(X_smote, y_smote)
X_sfa = np.array([sfa.word_list(list(d.keys())[0]) for d in sfa_dics[0]])
sfa.fit(X_smote, y_smote)
sfa_dics = sfa.transform_words(X_smote)
X_sfa = sfa_dics[:, 0, :]

rf = RandomForestClassifier(
n_estimators=self.n_trees,
Expand Down Expand Up @@ -318,11 +319,11 @@ def _build_dimension_ensemble(self, X, y):
Returns
-------
sfa_transforms : list
List of lists of ``SFA()`` instances with random word length and alpabet
List of lists of ``SFAFast()`` instances with random word length and alpabet
size
sfa_clfs : list
List of lists of ``(RandomForestClassifier(), weight)`` tuples fitted on
`SFA` transformed training data
`SFAFast` transformed training data
sax_transforms : list
List of lists of ``SAX()`` instances with random word length and alpabet
size
Expand Down Expand Up @@ -416,8 +417,8 @@ def _predict_proba_unvivariate(self, X) -> np.ndarray:
pred_mat = np.zeros((X.shape[0], self.n_classes_))

for sfa, (rf, weight) in zip(self.sfa_transforms, self.sfa_clfs):
sfa_dics = sfa.transform(X)
X_sfa = np.array([sfa.word_list(list(d.keys())[0]) for d in sfa_dics[0]])
sfa_dics = sfa.transform_words(X)
X_sfa = sfa_dics[:, 0, :]

rf_pred_mat = rf.predict_proba(X_sfa)

Expand Down Expand Up @@ -471,10 +472,8 @@ def _predict_proba_dimension_ensemble(self, X) -> np.ndarray:
if self.variant in [6, 7, 8, 9]:
dimension_pred_mats = None
for sfa, (rf, _) in zip(sfa_transforms, sfa_clfs):
sfa_dics = sfa.transform(X_d)
X_sfa = np.array(
[sfa.word_list(list(d.keys())[0]) for d in sfa_dics[0]]
)
sfa_dics = sfa.transform_words(X_d)
X_sfa = sfa_dics[:, 0, :]

rf_pred_mat = rf.predict_proba(X_sfa)

Expand Down