From 942b9218b096e8112991184bc64bbcfbd9251665 Mon Sep 17 00:00:00 2001 From: Hellsice <46599932+Hellsice@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:42:41 +0200 Subject: [PATCH 1/2] Fixed ECOD and COPOD decision functions ECOD and COPOD decision functions were swapped. The papers said COPOD was was the max of the three and ECOD used the aggregated left-tail and right-tail code showed that COPOD used the aggregated left-tail and right-tail, and ECOD used the max of the three --- pyod/models/copod.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyod/models/copod.py b/pyod/models/copod.py index 3d357fd66..1877bd902 100644 --- a/pyod/models/copod.py +++ b/pyod/models/copod.py @@ -136,7 +136,10 @@ def decision_function(self, X): skewness = np.sign(skew(X, axis=0)) self.U_skew = self.U_l * -1 * np.sign( skewness - 1) + self.U_r * np.sign(skewness + 1) - self.O = np.maximum(self.U_skew, np.add(self.U_l, self.U_r) / 2) + + self.O = np.maximum(self.U_l, self.U_r) + self.O = np.maximum(self.U_skew, self.O) + if hasattr(self, 'X_train'): decision_scores_ = self.O.sum(axis=1)[-original_size:] else: @@ -195,7 +198,10 @@ def _decision_function_parallel(self, X): skewness = np.sign(skew(X, axis=0)) self.U_skew = self.U_l * -1 * np.sign( skewness - 1) + self.U_r * np.sign(skewness + 1) - self.O = np.maximum(self.U_skew, np.add(self.U_l, self.U_r) / 2) + + self.O = np.maximum(self.U_l, self.U_r) + self.O = np.maximum(self.U_skew, self.O) + if hasattr(self, 'X_train'): decision_scores_ = self.O.sum(axis=1)[-original_size:] else: From d5222c9a1b51f738964daab87fb2e79784b4e1d6 Mon Sep 17 00:00:00 2001 From: Hellsice <46599932+Hellsice@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:42:44 +0200 Subject: [PATCH 2/2] Fixed ECOD and COPOD decision functions ECOD and COPOD decision functions were swapped. The papers said COPOD was was the max of the three and ECOD used the aggregated left-tail and right-tail code showed that COPOD used the aggregated left-tail and right-tail, and ECOD used the max of the three --- pyod/models/ecod.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pyod/models/ecod.py b/pyod/models/ecod.py index fe278b454..00ade951a 100644 --- a/pyod/models/ecod.py +++ b/pyod/models/ecod.py @@ -138,10 +138,7 @@ def decision_function(self, X): skewness = np.sign(skew(X, axis=0)) self.U_skew = self.U_l * -1 * np.sign( skewness - 1) + self.U_r * np.sign(skewness + 1) - - self.O = np.maximum(self.U_l, self.U_r) - self.O = np.maximum(self.U_skew, self.O) - + self.O = np.maximum(self.U_skew, np.add(self.U_l, self.U_r) / 2) if hasattr(self, 'X_train'): decision_scores_ = self.O.sum(axis=1)[-original_size:] else: @@ -200,10 +197,7 @@ def _decision_function_parallel(self, X): skewness = np.sign(skew(X, axis=0)) self.U_skew = self.U_l * -1 * np.sign( skewness - 1) + self.U_r * np.sign(skewness + 1) - - self.O = np.maximum(self.U_l, self.U_r) - self.O = np.maximum(self.U_skew, self.O) - + self.O = np.maximum(self.U_skew, np.add(self.U_l, self.U_r) / 2) if hasattr(self, 'X_train'): decision_scores_ = self.O.sum(axis=1)[-original_size:] else: