Skip to content

Commit 7508ffd

Browse files
final bits and docs for refactor
1 parent d777a12 commit 7508ffd

File tree

6 files changed

+67
-89
lines changed

6 files changed

+67
-89
lines changed

aeon/anomaly_detection/base.py

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,35 @@
1111

1212

1313
class BaseAnomalyDetector(BaseAeonEstimator):
14-
"""todo base class docs."""
14+
"""Anomaly detection base class."""
1515

1616
_tags = {
17-
# todo
17+
"fit_is_empty": True,
18+
"requires_y": False,
1819
}
1920

2021
def __init__(self):
2122
super().__init__()
2223

2324
@abstractmethod
2425
def fit(self, X, y=None):
25-
"""Fit time series anomaly detector to X.
26+
"""Fit anomaly detector to X, optionally to y.
2627
27-
If the tag ``fit_is_empty`` is true, this just sets the ``is_fitted`` tag to
28-
true. Otherwise, it checks ``self`` can handle ``X``, formats ``X`` into
29-
the structure required by ``self`` then passes ``X`` (and possibly ``y``) to
30-
``_fit``.
28+
State change:
29+
Changes state to "fitted".
30+
31+
Writes to self:
32+
_is_fitted : flag is set to True.
3133
3234
Parameters
3335
----------
34-
X : one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES
35-
The time series to fit the model to.
36-
A valid aeon time series data structure. See
37-
aeon.base._base_series.VALID_SERIES_INPUT_TYPES for aeon supported types.
38-
y : one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES, default=None
39-
The target values for the time series.
40-
A valid aeon time series data structure. See
41-
aeon.base._base_series.VALID_SERIES_INPUT_TYPES for aeon supported types.
42-
axis : int
43-
The time point axis of the input series if it is 2D. If ``axis==0``, it is
44-
assumed each column is a time series and each row is a time point. i.e. the
45-
shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates
46-
the time series are in rows, i.e. the shape of the data is
47-
``(n_channels, n_timepoints)``.
36+
X : Series or Collection, any supported type
37+
Data to fit anomaly detector to, of python type as follows:
38+
Series: 2D np.ndarray shape (n_channels, n_timepoints)
39+
Collection: 3D np.ndarray shape (n_cases, n_channels, n_timepoints)
40+
or list of 2D np.ndarray, case i has shape (n_channels, n_timepoints_i)
41+
y : Series, default=None
42+
Additional data, e.g., labels for anomaly detector.
4843
4944
Returns
5045
-------
@@ -59,16 +54,11 @@ def predict(self, X) -> np.ndarray:
5954
6055
Parameters
6156
----------
62-
X : one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES
63-
The time series to fit the model to.
64-
A valid aeon time series data structure. See
65-
aeon.base._base_series.VALID_SERIES_INPUT_TYPES for aeon supported types.
66-
axis : int, default=1
67-
The time point axis of the input series if it is 2D. If ``axis==0``, it is
68-
assumed each column is a time series and each row is a time point. i.e. the
69-
shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates
70-
the time series are in rows, i.e. the shape of the data is
71-
``(n_channels, n_timepoints)``.
57+
X : Series or Collection, any supported type
58+
Data to fit anomaly detector to, of python type as follows:
59+
Series: 2D np.ndarray shape (n_channels, n_timepoints)
60+
Collection: 3D np.ndarray shape (n_cases, n_channels, n_timepoints)
61+
or list of 2D np.ndarray, case i has shape (n_channels, n_timepoints_i)
7262
7363
Returns
7464
-------
@@ -84,20 +74,11 @@ def fit_predict(self, X, y=None) -> np.ndarray:
8474
8575
Parameters
8676
----------
87-
X : one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES
88-
The time series to fit the model to.
89-
A valid aeon time series data structure. See
90-
aeon.base._base_series.VALID_INPUT_TYPES for aeon supported types.
91-
y : one of aeon.base._base_series.VALID_SERIES_INPUT_TYPES, default=None
92-
The target values for the time series.
93-
A valid aeon time series data structure. See
94-
aeon.base._base_series.VALID_SERIES_INPUT_TYPES for aeon supported types.
95-
axis : int, default=1
96-
The time point axis of the input series if it is 2D. If ``axis==0``, it is
97-
assumed each column is a time series and each row is a time point. i.e. the
98-
shape of the data is ``(n_timepoints, n_channels)``. ``axis==1`` indicates
99-
the time series are in rows, i.e. the shape of the data is
100-
``(n_channels, n_timepoints)``.
77+
X : Series or Collection, any supported type
78+
Data to fit anomaly detector to, of python type as follows:
79+
Series: 2D np.ndarray shape (n_channels, n_timepoints)
80+
Collection: 3D np.ndarray shape (n_cases, n_channels, n_timepoints)
81+
or list of 2D np.ndarray, case i has shape (n_channels, n_timepoints_i)
10182
10283
Returns
10384
-------

aeon/anomaly_detection/collection/_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Adapter to use classification algorithms for collection anomaly detection."""
22

33
__maintainer__ = []
4-
4+
__all__ = ["ClassificationAdapter"]
55

66
from sklearn.base import ClassifierMixin
77
from sklearn.ensemble import RandomForestClassifier
@@ -30,7 +30,7 @@ class ClassificationAdapter(BaseCollectionAnomalyDetector):
3030
"""
3131

3232
_tags = {
33-
"X_inner_type": "numpy2D",
33+
"fit_is_empty": False,
3434
"requires_y": True,
3535
}
3636

aeon/anomaly_detection/collection/_outlier_detection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Adapter to use outlier detection algorithms for collection anomaly detection."""
22

33
__maintainer__ = []
4+
__all__ = ["OutlierDetectionAdapter"]
45

56
from sklearn.base import OutlierMixin
67
from sklearn.ensemble import IsolationForest
@@ -29,6 +30,7 @@ class OutlierDetectionAdapter(BaseCollectionAnomalyDetector):
2930

3031
_tags = {
3132
"X_inner_type": "numpy2D",
33+
"fit_is_empty": False,
3234
}
3335

3436
def __init__(self, detector, random_state=None):

aeon/anomaly_detection/collection/base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ class BaseCollectionAnomalyDetector(BaseCollectionEstimator, BaseAnomalyDetector
5555
Dictionary containing dynamic tag values which have been set at runtime.
5656
"""
5757

58-
_tags = {
59-
"fit_is_empty": False,
60-
"requires_y": False,
61-
}
62-
6358
def __init__(self):
6459
super().__init__()
6560

aeon/anomaly_detection/series/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ class BaseSeriesAnomalyDetector(BaseSeriesEstimator, BaseAnomalyDetector):
7676
Setting this class variable will convert the input data to the chosen axis.
7777
"""
7878

79-
_tags = {
80-
"X_inner_type": "np.ndarray", # One of VALID_SERIES_INNER_TYPES
81-
"fit_is_empty": True,
82-
"requires_y": False,
83-
}
84-
8579
def __init__(self, axis):
8680
super().__init__(axis=axis)
8781

docs/api_reference/anomaly_detection.rst

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,38 @@
33
Anomaly Detection
44
=================
55

6-
The :mod:`aeon.anomaly_detection` module contains algorithms and composition tools for time series classification.
6+
The :mod:`aeon.anomaly_detection` module contains algorithms and composition tools for
7+
time series anomaly detection.
78

89
All detectors in `aeon` can be listed using the `aeon.utils.discovery.all_estimators` utility,
910
using ``estimator_types="anomaly-detector"``, optionally filtered by tags.
10-
Valid tags can be listed by calling the function `aeon.utils.discovery.all_tags_for_estimator`.
11+
Valid tags can be listed by calling the function `aeon.utils.tags.all_tags_for_estimator`.
1112

1213
Each detector in this module specifies its supported input data format, output data
1314
format, and learning type as an overview table in its documentation. Some detectors
1415
support multiple learning types.
1516

16-
.. note::
1717

18-
Not all algorithm families are currently implemented. The documentation includes
19-
placeholders for planned categories which will be supported in future.
18+
Collection anomaly detectors
19+
----------------------------
20+
21+
.. currentmodule:: aeon.anomaly_detection.collection
22+
23+
.. autosummary::
24+
:toctree: auto_generated/
25+
:template: class.rst
26+
27+
BaseCollectionAnomalyDetector
28+
ClassificationAdapter
29+
OutlierDetectionAdapter
30+
31+
Series anomaly detectors
32+
------------------------
2033

2134
Distance-based
22-
--------------
35+
~~~~~~~~~~~~~~
2336

24-
.. currentmodule:: aeon.anomaly_detection.distance_based
37+
.. currentmodule:: aeon.anomaly_detection.series.distance_based
2538

2639
.. autosummary::
2740
:toctree: auto_generated/
@@ -37,9 +50,9 @@ Distance-based
3750
ROCKAD
3851

3952
Distribution-based
40-
-----------------
53+
~~~~~~~~~~~~~~~~~~
4154

42-
.. currentmodule:: aeon.anomaly_detection.distribution_based
55+
.. currentmodule:: aeon.anomaly_detection.series.distribution_based
4356

4457
.. autosummary::
4558
:toctree: auto_generated/
@@ -48,47 +61,40 @@ Distribution-based
4861
COPOD
4962
DWT_MLEAD
5063

51-
Encoding-based
52-
--------------
53-
54-
The algorithms for this family are not implemented yet.
55-
56-
Forecasting-based
57-
-----------------
58-
59-
The algorithms for this family are not implemented yet.
60-
6164
Outlier-Detection
62-
-----------------
65+
~~~~~~~~~~~~~~~~~
6366

64-
.. currentmodule:: aeon.anomaly_detection.outlier_detection
67+
.. currentmodule:: aeon.anomaly_detection.series.outlier_detection
6568

6669
.. autosummary::
6770
:toctree: auto_generated/
6871
:template: class.rst
6972

7073
IsolationForest
71-
PyODAdapter
7274
STRAY
7375

74-
Reconstruction-based
75-
--------------------
76+
Adapters
77+
~~~~~~~~
7678

77-
The algorithms for this family are not implemented yet.
79+
.. currentmodule:: aeon.anomaly_detection.series
7880

81+
.. autosummary::
82+
:toctree: auto_generated/
83+
:template: class.rst
7984

80-
Whole-series
81-
------------
85+
PyODAdapter
8286

83-
.. currentmodule:: aeon.anomaly_detection.collection
87+
Base
88+
~~~~
89+
90+
.. currentmodule:: aeon.anomaly_detection.series
8491

8592
.. autosummary::
8693
:toctree: auto_generated/
8794
:template: class.rst
8895

89-
BaseCollectionAnomalyDetector
90-
ClassificationAdapter
91-
OutlierDetectionAdapter
96+
BaseSeriesAnomalyDetector
97+
9298

9399
Base
94100
----

0 commit comments

Comments
 (0)