Skip to content

Commit

Permalink
Updated docstring comments and made methods protected
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikitas100 committed Jan 14, 2025
1 parent 87dfffd commit 7e4af72
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions aeon/classification/dictionary_based/_cboss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -51,18 +51,18 @@ 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
Minimum window size.
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",
Expand All @@ -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
----------
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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"
)
Expand Down

0 comments on commit 7e4af72

Please sign in to comment.