diff --git a/tods/detection_algorithm/core/MultiAutoRegOD.py b/tods/detection_algorithm/core/MultiAutoRegOD.py index d1f6a07..9ef92b3 100644 --- a/tods/detection_algorithm/core/MultiAutoRegOD.py +++ b/tods/detection_algorithm/core/MultiAutoRegOD.py @@ -157,33 +157,6 @@ class MultiAutoRegOD(CollectiveBaseDetector): self._process_decision_scores() return self - def predict(self, X): # pragma: no cover - """Predict if a particular sample is an outlier or not. - - Parameters - ---------- - X : numpy array of shape (n_samples, n_features) - The input samples. - - Returns - ------- - outlier_labels : numpy array of shape (n_samples,) - For each observation, tells whether or not - it should be considered as an outlier according to the - fitted model. 0 stands for inliers and 1 for outliers. - """ - - check_is_fitted(self, ['decision_scores_', 'threshold_', 'labels_']) - - pred_score, X_left_inds, X_right_inds = self.decision_function(X) - - pred_score = np.concatenate((np.zeros((self.window_size,)), pred_score)) - X_left_inds = np.concatenate((np.zeros((self.window_size,)), X_left_inds)) - X_right_inds = np.concatenate((np.zeros((self.window_size,)), X_right_inds)) - - return (pred_score > self.threshold_).astype( - 'int').ravel(), X_left_inds.ravel(), X_right_inds.ravel() - def decision_function(self, X: np.array): """Predict raw anomaly scores of X using the fitted detector. @@ -221,6 +194,12 @@ class MultiAutoRegOD(CollectiveBaseDetector): decison_mat_scaled = self._score_scalar.transform(decison_mat) decision_scores = self._score_combination(decison_mat_scaled) + # print(decision_scores.shape, X_left_inds.shape, X_right_inds.shape) + decision_scores = np.concatenate((np.zeros((self.window_size,)), decision_scores)) + X_left_inds = np.concatenate(((-self.window_size)*np.ones((self.window_size,)).astype(np.int), X_left_inds)) + X_right_inds = np.concatenate((np.zeros((self.window_size,)).astype(np.int), X_right_inds)) + # print(decision_scores.shape, X_left_inds.shape, X_right_inds.shape) + return decision_scores, X_left_inds, X_right_inds diff --git a/tods/tests/detection_algorithm/test_AutoRegODetect.py b/tods/tests/detection_algorithm/test_AutoRegODetect.py index e282b59..759aabc 100644 --- a/tods/tests/detection_algorithm/test_AutoRegODetect.py +++ b/tods/tests/detection_algorithm/test_AutoRegODetect.py @@ -87,21 +87,21 @@ class AutoRegODetectTestCase(unittest.TestCase): 'metadata': { 'name': 'AutoRegODetector0_0', 'semantic_types': ['https://metadata.datadrivendiscovery.org/types/Attribute'], - 'structural_type': 'numpy.float64', + 'structural_type': 'numpy.int64', }, }, { 'selector': ['__ALL_ELEMENTS__', 1], 'metadata': { 'name': 'AutoRegODetector0_1', 'semantic_types': ['https://metadata.datadrivendiscovery.org/types/Attribute'], - 'structural_type': 'numpy.float64', + 'structural_type': 'numpy.int64', }, }, { 'selector': ['__ALL_ELEMENTS__', 2], 'metadata': { 'name': 'AutoRegODetector0_2', 'semantic_types': ['https://metadata.datadrivendiscovery.org/types/Attribute'], - 'structural_type': 'numpy.float64', + 'structural_type': 'numpy.int64', }, }])