Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Troubled Cell Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Christine Kühle
Troubled Cell Detection
Commits
89aa2bb8
Commit
89aa2bb8
authored
2 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Restructured Boxplot method.
parent
19b27131
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Troubled_Cell_Detector.py
+23
-62
23 additions, 62 deletions
Troubled_Cell_Detector.py
with
23 additions
and
62 deletions
Troubled_Cell_Detector.py
+
23
−
62
View file @
89aa2bb8
...
...
@@ -3,7 +3,7 @@
@author: Laura C. Kühle, Soraya Terrab (sorayaterrab)
TODO: Vectorize _get_cells() in Boxplot method -> Done
TODO: Restructure Boxplot method
TODO: Restructure Boxplot method
-> Done
TODO: Introduce lower/upper extreme outliers in Boxplot
(each cell is also checked for neighboring domains if existing)
TODO: Determine max_value for Theoretical only over highest degree
...
...
@@ -340,8 +340,6 @@ class Boxplot(WaveletDetector):
Length of Boxplot whiskers.
adjust_outer_fences : bool
Flag whether outer fences should be adjusted using global mean.
num_overlapping_cells : int
Number of cells overlapping with adjacent folds.
folds : ndarray
Array with indices for elements of each fold (including
overlaps).
...
...
@@ -362,19 +360,23 @@ class Boxplot(WaveletDetector):
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
)
self
.
_num_overlapping_cells
=
config
.
pop
(
'
num_overlapping_cells
'
,
1
)
if
self
.
_mesh
.
num_grid_cells
<
self
.
_fold_len
:
self
.
_fold_len
=
self
.
_mesh
.
num_grid_cells
num_overlapping_cells
=
config
.
pop
(
'
num_overlapping_cells
'
,
1
)
num_folds
=
self
.
_mesh
.
num_grid_cells
//
self
.
_fold_len
self
.
_folds
=
np
.
zeros
([
num_folds
,
self
.
_fold_len
+
2
*
self
.
_num_overlapping_cells
]).
astype
(
int
)
self
.
_fold_indices
=
np
.
zeros
([
num_folds
,
self
.
_fold_len
+
2
*
num_overlapping_cells
]).
astype
(
np
.
int32
)
for
fold
in
range
(
num_folds
):
self
.
_folds
[
fold
]
=
np
.
array
(
self
.
_fold
_indice
s
[
fold
]
=
np
.
array
(
[
i
%
self
.
_mesh
.
num_grid_cells
for
i
in
range
(
fold
*
self
.
_fold_len
-
self
.
_num_overlapping_cells
,
(
fold
+
1
)
*
self
.
_fold_len
+
self
.
_num_overlapping_cells
)])
# print(self._folds)
fold
*
self
.
_fold_len
-
num_overlapping_cells
,
(
fold
+
1
)
*
self
.
_fold_len
+
num_overlapping_cells
)])
def
_get_cells
(
self
,
multiwavelet_coeffs
,
projection
):
"""
Calculate
s
troubled cells using multiwavelet coefficients.
"""
Calculate troubled cells using multiwavelet coefficients.
Parameters
----------
...
...
@@ -386,19 +388,19 @@ class Boxplot(WaveletDetector):
Returns
-------
list
List of indices f
or
all detected troubled cells.
List of indices
o
f all detected troubled cells.
"""
# Select and sort fold domains
coeffs
=
multiwavelet_coeffs
[
0
]
folds
=
coeffs
[
self
.
_fold_indices
]
folds
.
sort
()
if
self
.
_mesh
.
num_grid_cells
<
self
.
_fold_len
:
self
.
_fold_len
=
self
.
_mesh
.
num_grid_cells
# Determine quartile parameters
boundary_index
=
self
.
_fold_len
//
4
balance_factor
=
self
.
_fold_len
/
4.0
-
boundary_index
folds
=
coeffs
[
self
.
_folds
]
folds
.
sort
()
# Determine bounds based on first and third quartiles of a boxplot
first_quartiles
=
(
1
-
balance_factor
)
\
*
folds
[:,
boundary_index
-
1
]
\
+
balance_factor
*
folds
[:,
boundary_index
]
...
...
@@ -411,59 +413,18 @@ class Boxplot(WaveletDetector):
upper_bounds
=
third_quartiles
+
self
.
_whisker_len
*
(
third_quartiles
-
first_quartiles
)
# Adjust outer fences if flag is set
if
self
.
_adjust_outer_fences
:
global_mean
=
np
.
mean
(
abs
(
coeffs
))
lower_bounds
[
lower_bounds
>
-
global_mean
]
=
-
global_mean
upper_bounds
[
upper_bounds
<
global_mean
]
=
global_mean
troubled_cells_new
=
np
.
flatnonzero
(
np
.
logical_or
(
# Select outliers as troubled cells
troubled_cells
=
np
.
flatnonzero
(
np
.
logical_or
(
coeffs
<
np
.
repeat
(
lower_bounds
,
self
.
_fold_len
),
coeffs
>
np
.
repeat
(
upper_bounds
,
self
.
_fold_len
))).
tolist
()
# num_folds = self._mesh.num_grid_cells//self._fold_len
# troubled_cells = []
#
# lower_bound = np.zeros(num_folds)
# upper_bound = np.zeros(num_folds)
#
# for fold in range(num_folds):
# sorted_fold = sorted(coeffs[self._folds[fold]])
#
# first_quartile = (1-balance_factor) \
# * sorted_fold[boundary_index-1] \
# + balance_factor * sorted_fold[boundary_index]
# third_quartile = (1-balance_factor) \
# * sorted_fold[3*boundary_index-1]\
# + balance_factor * sorted_fold[3*boundary_index]
#
# lower_bound[fold] = first_quartile \
# - self._whisker_len * (third_quartile-first_quartile)
# upper_bound[fold] = third_quartile \
# + self._whisker_len * (third_quartile-first_quartile)
#
# # Adjust outer fences if flag is set
# if self._adjust_outer_fences:
# global_mean = np.mean(abs(coeffs))
# lower_bound[fold] = min(-global_mean, lower_bound[fold])
# upper_bound[fold] = max(global_mean, upper_bound[fold])
#
# # Check for extreme outlier and add respective cells
# for cell in self._folds[
# fold, self._num_overlapping_cells:
# -self._num_overlapping_cells]:
# if (coeffs[cell] > upper_bound[fold]) \
# or (coeffs[cell] < lower_bound[fold]):
# troubled_cells.append(int(cell))
#
# same = np.all(sorted(troubled_cells) == troubled_cells_new)
# if not same:
# print(np.all(lower_bounds == lower_bound),
# np.all(upper_bounds == upper_bound))
# print(sorted(troubled_cells))
# print(troubled_cells_new)
return
troubled_cells_new
# return sorted(troubled_cells)
return
troubled_cells
class
Theoretical
(
WaveletDetector
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment