Skip to content

[Doc] A fix to inconsistent ticks in Base module #2734

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
85 changes: 45 additions & 40 deletions aeon/base/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ class BaseAeonEstimator(BaseEstimator, ABC):

Contains the following methods:

- reset estimator to post-init - reset(keep)
- clone stimator (copy) - clone(random_state)
- inspect tags (class method) - get_class_tags()
- inspect tags (one tag, class) - get_class_tag(tag_name, tag_value_default,
raise_error)
- inspect tags (all) - get_tags()
- inspect tags (one tag) - get_tag(tag_name, tag_value_default, raise_error)
- setting dynamic tags - set_tags(**tag_dict)
- get fitted parameters - get_fitted_params(deep)
- reset estimator to post-init - ``reset(keep)``
- clone stimator (copy) - ``clone(random_state)``
- inspect tags (class method) - ``get_class_tags()``
- inspect tags (one tag, class) - ``get_class_tag(tag_name, tag_value_default
, raise_error)``
- inspect tags (all) - ``get_tags()``
- inspect tags (one tag) - ``get_tag(tag_name, tag_value_default
, raise_error)``
- setting dynamic tags - ``set_tags(**tag_dict)``
- get fitted parameters - ``get_fitted_params(deep)``

All estimators have the attribute:

- fitted state flag - is_fitted
- fitted state flag - ``is_fitted``
"""

_tags = {
Expand All @@ -59,14 +60,14 @@ def reset(self, keep=None):
"""
Reset the object to a clean post-init state.

After a ``self.reset()`` call, self is equal or similar in value to
After a ``self.reset()`` call, ``self`` is equal or similar in value to
``type(self)(**self.get_params(deep=False))``, assuming no other attributes
were kept using ``keep``.

Detailed behaviour:
removes any object attributes, except:
hyper-parameters (arguments of ``__init__``)
object attributes containing double-underscores, i.e., the string "__"
object attributes containing double-underscores, i.e., the string ``__``
runs ``__init__`` with current values of hyperparameters (result of
``get_params``)

Expand All @@ -78,9 +79,9 @@ class and object methods, class attributes
Parameters
----------
keep : None, str, or list of str, default=None
If None, all attributes are removed except hyperparameters.
If str, only the attribute with this name is kept.
If list of str, only the attributes with these names are kept.
If ``None``, all attributes are removed except hyperparameters.
If ``str``, only the attribute with this name is kept.
If ``list`` of ``str``, only the attributes with these names are kept.

Returns
-------
Expand Down Expand Up @@ -125,15 +126,18 @@ def clone(self, random_state=None):
Obtain a clone of the object with the same hyperparameters.

A clone is a different object without shared references, in post-init state.
This function is equivalent to returning ``sklearn.clone`` of self.
This function is equivalent to returning ``sklearn.clone`` of ``self``.
Equal in value to ``type(self)(**self.get_params(deep=False))``.

Parameters
----------
random_state : int, RandomState instance, or None, default=None
Sets the random state of the clone. If None, the random state is not set.
If int, random_state is the seed used by the random number generator.
If RandomState instance, random_state is the random number generator.
Sets the random state of the clone. If ``None``, the random state is not
set.
If ``int``, ``random_state`` is the seed used by the random number
generator.
If ``RandomState`` instance, ``random_state`` is the random number
generator.

Returns
-------
Expand Down Expand Up @@ -187,21 +191,21 @@ def get_class_tag(
tag_name : str
Name of tag value.
raise_error : bool, default=True
Whether a ValueError is raised when the tag is not found.
Whether a ``ValueError`` is raised when the tag is not found.
tag_value_default : any type, default=None
Default/fallback value if tag is not found and error is not raised.

Returns
-------
tag_value
Value of the ``tag_name`` tag in cls.
If not found, returns an error if ``raise_error`` is True, otherwise it
If not found, returns an error if ``raise_error`` is ``True``, otherwise it
returns ``tag_value_default``.

Raises
------
ValueError
if ``raise_error`` is True and ``tag_name`` is not in
if ``raise_error`` is ``True`` and ``tag_name`` is not in
``self.get_tags().keys()``

Examples
Expand Down Expand Up @@ -247,15 +251,15 @@ def get_tag(self, tag_name, raise_error=True, tag_value_default=None):
tag_name : str
Name of tag to be retrieved.
raise_error : bool, default=True
Whether a ValueError is raised when the tag is not found.
Whether a ``ValueError`` is raised when the tag is not found.
tag_value_default : any type, default=None
Default/fallback value if tag is not found and error is not raised.

Returns
-------
tag_value
Value of the ``tag_name`` tag in self.
If not found, returns an error if ``raise_error`` is True, otherwise it
If not found, returns an error if ``raise_error`` is ``True``, otherwise it
returns ``tag_value_default``.

Raises
Expand Down Expand Up @@ -292,7 +296,7 @@ def set_tags(self, **tag_dict):
Returns
-------
self : object
Reference to self.
Reference to ``self``.
"""
tag_update = deepcopy(tag_dict)
self._tags_dynamic.update(tag_update)
Expand All @@ -307,7 +311,7 @@ def get_fitted_params(self, deep=True):
Parameters
----------
deep : bool, default=True
If True, will return the fitted parameters for this estimator and
If ``True``, will return the fitted parameters for this estimator and
contained subobjects that are estimators.

Returns
Expand Down Expand Up @@ -354,7 +358,7 @@ def _check_is_fitted(self):
if not self.is_fitted:
raise NotFittedError(
f"This instance of {self.__class__.__name__} has not "
f"been fitted yet; please call `fit` first."
f"been fitted yet; please call ``fit`` first."
)

@classmethod
Expand All @@ -366,14 +370,15 @@ def _get_test_params(cls, parameter_set="default"):
----------
parameter_set : str, default="default"
Name of the set of test parameters to return, for use in tests. If no
special parameters are defined for a value, will return `"default"` set.
special parameters are defined for a value, will return ``default`` set.

Returns
-------
params : dict or list of dict, default = {}
Parameters to create testing instances of the class. Each dict are
parameters to construct an "interesting" test instance, i.e.,
`MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
Parameters to create testing instances of the class. Each ``dict`` are
parameters to construct an ``interesting`` test instance, i.e.,
``MyClass(**params)`` or ``MyClass(**params[i])`` creates a valid test
instance.
"""
# default parameters = empty dict
return {}
Expand All @@ -383,23 +388,23 @@ def _create_test_instance(cls, parameter_set="default", return_first=True):
"""
Construct Estimator instance if possible.

Calls the `_get_test_params` method and returns an instance or list of instances
using the returned dict or list of dict.
Calls the ``_get_test_params`` method and returns an instance or ``list``
of instances using the returned ``dict`` or list of ``dict``.

Parameters
----------
parameter_set : str, default="default"
Name of the set of test parameters to return, for use in tests. If no
special parameters are defined for a value, will return `"default"` set.
special parameters are defined for a value, will return ``default`` set.
return_first : bool, default=True
If True, return the first instance of the list of instances.
If False, return the list of instances.
If ``True``, return the first instance of the list of instances.
If ``False``, return the list of instances.

Returns
-------
instance : BaseAeonEstimator or list of BaseAeonEstimator
Instance of the class with default parameters. If return_first
is False, returns list of instances.
Instance of the class with default parameters. If ``return_first``
is ``False``, returns list of instances.
"""
params = cls._get_test_params(parameter_set=parameter_set)

Expand Down Expand Up @@ -441,15 +446,15 @@ def _validate_data(self, **kwargs):
def get_metadata_routing(self):
"""Sklearn metadata routing.

Not supported by ``aeon`` estimators.
Not supported by aeon estimators.
"""
raise NotImplementedError(
"aeon estimators do not have a get_metadata_routing method."
)

@classmethod
def _get_default_requests(cls):
"""Sklearn metadata request defaults."""
"""``Sklearn`` metadata request defaults."""
from sklearn.utils._metadata_requests import MetadataRequest

return MetadataRequest(None)
Expand Down
79 changes: 41 additions & 38 deletions aeon/base/_base_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
class name: BaseCollectionEstimator

Defining methods:
preprocessing - _preprocess_collection(self, X, store_metadata=True)
input checking - _check_X(self, X)
input conversion - _convert_X(self, X)
shape checking - _check_shape(self, X)
preprocessing - ``_preprocess_collection(self, X, store_metadata=True)``
input checking - ``_check_X(self, X)``
input conversion - ``_convert_X(self, X)``
shape checking - ``_check_shape(self, X)``

Inherited inspection methods:
hyper-parameter inspection - get_params()
fitted parameter inspection - get_fitted_params()
hyper-parameter inspection - ``get_params()``
fitted parameter inspection - ``get_fitted_params()``

State:
fitted model/strategy - by convention, any attributes ending in "_"
fitted state flag - is_fitted (property)
fitted state inspection - check_is_fitted()
fitted model/strategy - by convention, any attributes ending in ``_``
fitted state flag - ``is_fitted (property)``
fitted state inspection - ``check_is_fitted()``

"""

Expand Down Expand Up @@ -80,26 +80,26 @@ def _preprocess_collection(self, X, store_metadata=True):
Parameters
----------
X : collection
See aeon.utils.COLLECTIONS_DATA_TYPES for details on aeon supported
See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported
data structures.
store_metadata : bool, default=True
Whether to store metadata about X in self.metadata_.
Whether to store metadata about ``X`` in ``self.metadata_``.

Returns
-------
X : collection
Processed X. A data structure of type self.get_tag("X_inner_type").
Processed ``X``. A data structure of type ``self.get_tag("X_inner_type")``.

Raises
------
ValueError
If X is an invalid type or has characteristics that the estimator cannot
If ``X`` is an invalid type or has characteristics that the estimator cannot
handle.

See Also
--------
_check_X :
Function that checks X is valid before conversion.
Function that checks ``X`` is valid before conversion.
_convert_X :
Function that converts to inner type.

Expand Down Expand Up @@ -138,37 +138,39 @@ def _check_X(self, X):
Check if the input data is a compatible type, and that this estimator is
able to handle the data characteristics.
This is done by matching the capabilities of the estimator against the metadata
for X i.e., univariate/multivariate, equal length/unequal length and no missing
values/missing values.
for ``X`` i.e., univariate/multivariate, equal length/unequal length
and no missing values/missing values.

Parameters
----------
X : collection
See aeon.utils.COLLECTIONS_DATA_TYPES for details on aeon supported
See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported
data structures.

Returns
-------
metadata : dict
Metadata about X, with flags:
metadata["multivariate"] : whether X has more than one channel or not
metadata["missing_values"] : whether X has missing values or not
metadata["unequal_length"] : whether X contains unequal length series.
metadata["n_cases"] : number of cases in X
metadata["n_channels"] : number of channels in X
metadata["n_timepoints"] : number of timepoints in X if equal length, else
None
Metadata about ```X```, with flags:
``metadata["multivariate"]`` : whether ``X`` has more than one channel or
not
``metadata["missing_values"]`` : whether ``X`` has missing values or not
``metadata["unequal_length"]`` : whether ``X`` contains unequal length
series.
``metadata["n_cases"]`` : number of cases in ``X``
``metadata["n_channels"]`` : number of channels in ``X``
``metadata["n_timepoints"]`` : number of timepoints in ``X`` if equal
length, else ``None``

Raises
------
ValueError
If X is an invalid type or has characteristics that the estimator cannot
If ``X`` is an invalid type or has characteristics that the estimator cannot
handle.

See Also
--------
_convert_X :
Function that converts X after it has been checked.
Function that converts ``X`` after it has been checked.

Examples
--------
Expand Down Expand Up @@ -209,30 +211,31 @@ def _check_X(self, X):

def _convert_X(self, X):
"""
Convert X to type defined by tag X_inner_type.
Convert ``X`` to type defined by tag ``X_inner_type``.

If the input data is already an allowed type, it is returned unchanged.

If multiple types are allowed by self, then the best one for the type of input
data is selected. So, for example, if X_inner_tag is ["np-list", "numpy3D"]
and an df-list is passed, it will be converted to numpy3D if the series
are equal length, and np-list if the series are unequal length.
If multiple types are allowed by ``self``, then the best
one for the type of input data is selected. So, for example, if
``X_inner_tag`` is ["np-list", "numpy3D"] and an df-list is passed, it will
be converted to ``numpy3D`` if the series are equal length, and np-list
if the series are unequal length.

Parameters
----------
X : collection
See aeon.utils.COLLECTIONS_DATA_TYPES for details on aeon supported
See ``aeon.utils.COLLECTIONS_DATA_TYPES`` for details on aeon supported
data structures.

Returns
-------
X : collection
Converted X. A data structure of type self.get_tag("X_inner_type").
Converted ``X``. A data structure of type ``self.get_tag("X_inner_type")``.

See Also
--------
_check_X :
Function that checks X is valid and finds metadata.
Function that checks ``X`` is valid and finds metadata.

Examples
--------
Expand Down Expand Up @@ -275,17 +278,17 @@ def _convert_X(self, X):

def _check_shape(self, X):
"""
Check that the shape of X is consistent with the data seen in fit.
Check that the shape of ``X`` is consistent with the data seen in fit.

Parameters
----------
X : data structure
Must be of type aeon.registry.COLLECTIONS_DATA_TYPES.
Must be of type ``aeon.registry.COLLECTIONS_DATA_TYPES``.

Raises
------
ValueError
If the shape of X is not consistent with the data seen in fit.
If the shape of ``X`` is not consistent with the data seen in fit.
"""
# if metadata is empty, then we have not seen any data in fit. If the estimator
# has not been fitted, then _is_fitted should catch this.
Expand Down
Loading