From 7e4af72f58dba3988f3be3b364974b545fac1674 Mon Sep 17 00:00:00 2001 From: Nikita Singh Date: Tue, 14 Jan 2025 23:11:34 +0530 Subject: [PATCH] Updated docstring comments and made methods protected --- .../classification/dictionary_based/_cboss.py | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/aeon/classification/dictionary_based/_cboss.py b/aeon/classification/dictionary_based/_cboss.py index f8d0b1aa80..ec4884e507 100644 --- a/aeon/classification/dictionary_based/_cboss.py +++ b/aeon/classification/dictionary_based/_cboss.py @@ -26,22 +26,22 @@ class ContractableBOSS(BaseClassifier): Implementation of BOSS Ensemble from [1]_ with refinements described in [2]_. - Overview: Input "n" series of length "m" and cBOSS randomly samples - `n_parameter_samples` parameter sets, evaluting each with LOOCV. It then - retains `max_ensemble_size` classifiers with the highest accuracy + Overview: Input ``n`` series of length ``m`` and cBOSS randomly samples + ``n_parameter_samples`` parameter sets, evaluting each with LOOCV. It then + retains ``max_ensemble_size`` classifiers with the highest accuracy There are three primary parameters: - - alpha: alphabet size - - w: window length - - l: word length. - - For any combination, a single BOSS slides a window length "w" along the - series. The "w" length window is shortened to an "l" length word by - taking a Fourier transform and keeping the first l/2 complex coefficients. - These "l" coefficients are then discretised into "alpha" possible values, - to form a word length "l". A histogram of words for each + - ``alpha``: alphabet size + - ``w``: window length + - ``l``: word length. + + For any combination, a single BOSS slides a window length ``w`` along the + series. The ``w`` length window is shortened to an ``l`` length word by + taking a Fourier transform and keeping the first ``l/2`` complex coefficients. + These ``l`` coefficients are then discretised into ``alpha`` possible values, + to form a word length ``l``. A histogram of words for each series is formed and stored. - Fit involves finding "n" histograms. + Fit involves finding ``n`` histograms. Predict uses 1 nearest neighbor with a bespoke BOSS distance function. @@ -51,7 +51,7 @@ class ContractableBOSS(BaseClassifier): If search is randomised, number of parameter combos to try. max_ensemble_size : int or None, default = 50 Maximum number of classifiers to retain. Will limit number of retained - classifiers even if more than `max_ensemble_size` are within threshold. + classifiers even if more than ``max_ensemble_size`` are within threshold. max_win_len_prop : int or float, default = 1 Maximum window length as a proportion of the series length. min_window : int, default = 10 @@ -59,10 +59,10 @@ class ContractableBOSS(BaseClassifier): time_limit_in_minutes : int, default = 0 Time contract to limit build time in minutes. Default of 0 means no limit. contract_max_n_parameter_samples : int, default=np.inf - Max number of parameter combinations to consider when time_limit_in_minutes is - set. + Max number of parameter combinations to consider when ``time_limit_in_minutes`` + is set. n_jobs : int, default = 1 - The number of jobs to run in parallel for both `fit` and `predict`. + The number of jobs to run in parallel for both ``fit`` and ``predict``. ``-1`` means using all processors. feature_selection : str, default = "none" Sets the feature selections strategy to be used. One of {"chi2", "none", @@ -71,10 +71,10 @@ class ContractableBOSS(BaseClassifier): applies not feature selectiona and yields large bag of words, e.g. much memory may be needed. random_state : int, RandomState instance or None, default=None - If `int`, random_state is the seed used by the random number generator; - If `RandomState` instance, random_state is the random number generator; - If `None`, the random number generator is the `RandomState` instance used - by `np.random`. + If ``int``, ``random_state`` is the seed used by the random number generator; + If ``RandomState`` instance, ``random_state`` is the random number generator; + If ``None``, the random number generator is the ``RandomState`` instance used + by ``np.random``. Attributes ---------- @@ -97,8 +97,8 @@ class ContractableBOSS(BaseClassifier): Raises ------ ValueError - Raised when `min_window` is greater than `max_window + 1`. - This ensures that `min_window` does not exceed `max_window`, + Raised when ``min_window`` is greater than ``max_window + 1``. + This ensures that ``min_window`` does not exceed ``max_window``, preventing invalid window size configurations. @@ -162,7 +162,7 @@ def __init__( self.min_window = min_window # Calculate and initialize max_window - self.max_window = self.calculate_max_window() + self.max_window = self._calculate_max_window() self.time_limit_in_minutes = time_limit_in_minutes self.contract_max_n_parameter_samples = contract_max_n_parameter_samples @@ -183,14 +183,14 @@ def __init__( super().__init__() - def calculate_max_window(self): + def _calculate_max_window(self): """Calculate max_window based on max_win_len_prop or other parameters.""" return int(self.max_win_len_prop * 100) - def validate_window_sizes(self): - """Validate if the min_window size is valid against max_window. + def _validate_window_sizes(self): + """Validate if the ``min_window`` size is valid against ``max_window``. - Raises a ValueError if min_window is greater than max_window + 1. + Raises a ValueError if ``min_window`` is greater than ``max_window + 1``. """ if self.min_window > self.max_window + 1: raise ValueError( @@ -225,7 +225,7 @@ def _fit(self, X, y, keep_train_preds=True): """ # validate window sizes - self.validate_window_sizes() + self._validate_window_sizes() time_limit = self.time_limit_in_minutes * 60 self.n_cases_, _, self.n_timepoints_ = X.shape @@ -240,10 +240,10 @@ def _fit(self, X, y, keep_train_preds=True): win_inc = max(win_inc, 1) if self.min_window > max_window + 1: raise ValueError( - f"Error in ContractableBOSS, min_window =" + f"Error in ContractableBOSS, ``min_window`` =" f"{self.min_window} is bigger" f" than max_window ={max_window}." - f" Try set min_window to be smaller than series length in " + f" Try set ``min_window`` to be smaller than series length in " f"the constructor, but the classifier may not work at " f"all with very short series" )