forked from aeon-toolkit/aeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_copod.py
79 lines (60 loc) · 2.55 KB
/
_copod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""COPOD for anomaly detection."""
__maintainer__ = []
__all__ = ["COPOD"]
from typing import Union
import numpy as np
from aeon.anomaly_detection.outlier_detection._pyodadapter import PyODAdapter
from aeon.utils.validation._dependencies import _check_soft_dependencies
class COPOD(PyODAdapter):
"""COPOD for anomaly detection.
This class implements the COPOD using PyODAdadpter to be used in the aeon framework.
The parameter `n_jobs` is passed to COPOD model from PyOD, `window_size` and
`stride` are used to construct the sliding windows.
Parameters
----------
n_jobs : int, default=1
The number of jobs to run in parallel for the COPOD model.
window_size : int, default=10
Size of the sliding window.
stride : int, default=1
Stride of the sliding window.
"""
_tags = {
"capability:multivariate": True,
"capability:univariate": True,
"capability:missing_values": False,
"capability:multithreading": True,
"fit_is_empty": False,
"python_dependencies": ["pyod"],
}
def __init__(self, n_jobs: int = 1, window_size: int = 10, stride: int = 1):
_check_soft_dependencies(*self._tags["python_dependencies"])
from pyod.models.copod import COPOD
model = COPOD(n_jobs=n_jobs)
self.n_jobs = n_jobs
super().__init__(model, window_size=window_size, stride=stride)
def _fit(self, X: np.ndarray, y: Union[np.ndarray, None] = None) -> None:
super()._fit(X, y)
def _predict(self, X: np.ndarray) -> np.ndarray:
return super()._predict(X)
def _fit_predict(
self, X: np.ndarray, y: Union[np.ndarray, None] = None
) -> np.ndarray:
return super()._fit_predict(X, y)
@classmethod
def _get_test_params(cls, parameter_set="default") -> dict:
"""Return testing parameter settings for the estimator.
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.
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.
`create_test_instance` uses the first (or only) dictionary in `params`.
"""
return {}