|
| 1 | +"""COPOD for anomaly detection.""" |
| 2 | + |
| 3 | +__maintainer__ = [] |
| 4 | +__all__ = ["COPOD"] |
| 5 | + |
| 6 | +from typing import Union |
| 7 | + |
| 8 | +import numpy as np |
| 9 | + |
| 10 | +from aeon.anomaly_detection._pyodadapter import PyODAdapter |
| 11 | +from aeon.utils.validation._dependencies import _check_soft_dependencies |
| 12 | + |
| 13 | + |
| 14 | +class COPOD(PyODAdapter): |
| 15 | + """COPOD for anomaly detection. |
| 16 | +
|
| 17 | + This class implements the COPOD using PyODAdadpter to be used in the aeon framework. |
| 18 | + The parameter `n_jobs` is passed to COPOD model from PyOD, `window_size` and |
| 19 | + `stride` are used to construct the sliding windows. |
| 20 | +
|
| 21 | + .. list-table:: Capabilities |
| 22 | + :stub-columns: 1 |
| 23 | + * - Input data format |
| 24 | + - univariate and multivariate |
| 25 | + * - Output data format |
| 26 | + - anomaly scores |
| 27 | + * - Learning Type |
| 28 | + - unsupervised or semi-supervised |
| 29 | +
|
| 30 | + Parameters |
| 31 | + ---------- |
| 32 | + n_jobs : int, default=1 |
| 33 | + The number of jobs to run in parallel for the COPOD model. |
| 34 | +
|
| 35 | + window_size : int, default=10 |
| 36 | + Size of the sliding window. |
| 37 | +
|
| 38 | + stride : int, default=1 |
| 39 | + Stride of the sliding window. |
| 40 | + """ |
| 41 | + |
| 42 | + _tags = { |
| 43 | + "capability:multivariate": True, |
| 44 | + "capability:univariate": True, |
| 45 | + "capability:missing_values": False, |
| 46 | + "fit_is_empty": False, |
| 47 | + "python_dependencies": ["pyod"], |
| 48 | + } |
| 49 | + |
| 50 | + def __init__(self, n_jobs: int = 1, window_size: int = 10, stride: int = 1): |
| 51 | + _check_soft_dependencies(*self._tags["python_dependencies"]) |
| 52 | + from pyod.models.copod import COPOD |
| 53 | + |
| 54 | + model = COPOD(n_jobs=n_jobs) |
| 55 | + self.n_jobs = n_jobs |
| 56 | + super().__init__(model, window_size=window_size, stride=stride) |
| 57 | + |
| 58 | + def _fit(self, X: np.ndarray, y: Union[np.ndarray, None] = None) -> None: |
| 59 | + super()._fit(X, y) |
| 60 | + |
| 61 | + def _predict(self, X: np.ndarray) -> np.ndarray: |
| 62 | + return super()._predict(X) |
| 63 | + |
| 64 | + def _fit_predict( |
| 65 | + self, X: np.ndarray, y: Union[np.ndarray, None] = None |
| 66 | + ) -> np.ndarray: |
| 67 | + return super()._fit_predict(X, y) |
| 68 | + |
| 69 | + @classmethod |
| 70 | + def get_test_params(cls, parameter_set="default") -> dict: |
| 71 | + """Return testing parameter settings for the estimator. |
| 72 | +
|
| 73 | + Parameters |
| 74 | + ---------- |
| 75 | + parameter_set : str, default="default" |
| 76 | + Name of the set of test parameters to return, for use in tests. If no |
| 77 | + special parameters are defined for a value, will return `"default"` set. |
| 78 | +
|
| 79 | + Returns |
| 80 | + ------- |
| 81 | + params : dict or list of dict, default={} |
| 82 | + Parameters to create testing instances of the class. |
| 83 | + Each dict are parameters to construct an "interesting" test instance, i.e., |
| 84 | + `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. |
| 85 | + `create_test_instance` uses the first (or only) dictionary in `params`. |
| 86 | + """ |
| 87 | + return {} |
0 commit comments