diff --git a/Troubled_Cell_Detector.py b/Troubled_Cell_Detector.py index 10cbcc3a7c6de1b3eb49e153e1b30232341179d2..19f0a4e04d2cd0394f83d519641825b567696bb8 100644 --- a/Troubled_Cell_Detector.py +++ b/Troubled_Cell_Detector.py @@ -3,6 +3,7 @@ @author: Laura C. Kühle, Soraya Terrab (sorayaterrab) TODO: Introduce Adjusted Outer Fence method in Boxplot using global_mean + -> Done TODO: Introduce overlapping cell for adjacent folds in Boxplot TODO: Introduce lower/upper extreme outliers in Boxplot (each cell is also checked for neighboring domains if existing) @@ -339,6 +340,8 @@ class Boxplot(WaveletDetector): Length of folds considered in one Boxplot. whisker_len : int Length of Boxplot whiskers. + adjust_outer_fences : bool + Flag whether outer fences should be adjusted using global mean. """ def _reset(self, config): @@ -355,6 +358,7 @@ class Boxplot(WaveletDetector): # Unpack necessary configurations self._fold_len = config.pop('fold_len', 16) self._whisker_len = config.pop('whisker_len', 3) + self._adjust_outer_fences = config.pop('adjust_outer_fences', True) def _get_cells(self, multiwavelet_coeffs, projection): """Calculates troubled cells using multiwavelet coefficients. @@ -374,6 +378,12 @@ class Boxplot(WaveletDetector): """ indexed_coeffs = [[multiwavelet_coeffs[0, i], i] for i in range(self._mesh.num_grid_cells)] + # max_multiwavelets = [multiwavelet_coeffs[0, i] + # for i in range(self._mesh.num_grid_cells)] + # global_mean_old = np.mean(abs(np.array(max_multiwavelets))) + if self._adjust_outer_fences: + global_mean = np.mean(abs(np.array(indexed_coeffs)[:, 0])) + # print(global_mean == global_mean_old) if self._mesh.num_grid_cells < self._fold_len: self._fold_len = self._mesh.num_grid_cells @@ -400,6 +410,11 @@ class Boxplot(WaveletDetector): upper_bound = third_quartile \ + self._whisker_len * (third_quartile-first_quartile) + # Adjust outer fences if flag is set + if self._adjust_outer_fences: + lower_bound = min(-global_mean, lower_bound) + upper_bound = max(global_mean, upper_bound) + # Check for lower extreme outliers and add respective cells for cell in sorted_fold: if cell[0] < lower_bound: