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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Christine Kühle
Troubled Cell Detection
Commits
19b27131
Commit
19b27131
authored
2 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Vectorized '_get_cells()' in Boxplot method.
parent
b325651d
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
+72
-77
72 additions, 77 deletions
Troubled_Cell_Detector.py
with
72 additions
and
77 deletions
Troubled_Cell_Detector.py
+
72
−
77
View file @
19b27131
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
"""
"""
@author: Laura C. Kühle, Soraya Terrab (sorayaterrab)
@author: Laura C. Kühle, Soraya Terrab (sorayaterrab)
TODO: Vectorize _get_cells() in Boxplot method
TODO: Vectorize _get_cells() in Boxplot method -> Done
TODO: Restructure Boxplot method
TODO: Introduce lower/upper extreme outliers in Boxplot
TODO: Introduce lower/upper extreme outliers in Boxplot
(each cell is also checked for neighboring domains if existing)
(each cell is also checked for neighboring domains if existing)
TODO: Determine max_value for Theoretical only over highest degree
TODO: Determine max_value for Theoretical only over highest degree
...
@@ -388,87 +389,81 @@ class Boxplot(WaveletDetector):
...
@@ -388,87 +389,81 @@ class Boxplot(WaveletDetector):
List of indices for all detected troubled cells.
List of indices for all detected troubled cells.
"""
"""
# indexed_coeffs = [[multiwavelet_coeffs[0, i], i]
# for i in range(self._mesh.num_grid_cells)]
coeffs
=
multiwavelet_coeffs
[
0
]
coeffs
=
multiwavelet_coeffs
[
0
]
# print(coeffs.shape)
if
self
.
_mesh
.
num_grid_cells
<
self
.
_fold_len
:
if
self
.
_mesh
.
num_grid_cells
<
self
.
_fold_len
:
self
.
_fold_len
=
self
.
_mesh
.
num_grid_cells
self
.
_fold_len
=
self
.
_mesh
.
num_grid_cells
num_folds
=
self
.
_mesh
.
num_grid_cells
//
self
.
_fold_len
troubled_cells
=
[]
# troubled_cells_new = []
for
fold
in
range
(
num_folds
):
# indexed_fold = np.array(indexed_coeffs)[self._folds[fold]]
# sorted_fold_old = indexed_fold[indexed_fold[:, 0].argsort()]
sorted_fold
=
sorted
(
coeffs
[
self
.
_folds
[
fold
]])
# print(sorted_fold == sorted_fold_old[:, 0])
boundary_index
=
self
.
_fold_len
//
4
boundary_index
=
self
.
_fold_len
//
4
balance_factor
=
self
.
_fold_len
/
4.0
-
boundary_index
balance_factor
=
self
.
_fold_len
/
4.0
-
boundary_index
first_quartile
=
(
1
-
balance_factor
)
\
folds
=
coeffs
[
self
.
_folds
]
*
sorted_fold
[
boundary_index
-
1
]
\
folds
.
sort
()
+
balance_factor
*
sorted_fold
[
boundary_index
]
first_quartiles
=
(
1
-
balance_factor
)
\
third_quartile
=
(
1
-
balance_factor
)
\
*
folds
[:,
boundary_index
-
1
]
\
*
sorted_fold
[
3
*
boundary_index
-
1
]
\
+
balance_factor
*
folds
[:,
boundary_index
]
+
balance_factor
*
sorted_fold
[
3
*
boundary_index
]
third_quartiles
=
(
1
-
balance_factor
)
\
*
folds
[:,
3
*
boundary_index
-
1
]
\
+
balance_factor
*
folds
[:,
3
*
boundary_index
]
lower_bound
=
first_quartile
\
lower_bound
s
=
first_quartile
s
-
self
.
_whisker_len
*
(
-
self
.
_whisker_len
*
(
third_quartile
-
first_quartile
)
third_quartile
s
-
first_quartile
s
)
upper_bound
=
third_quartile
\
upper_bound
s
=
third_quartile
s
+
self
.
_whisker_len
*
(
+
self
.
_whisker_len
*
(
third_quartile
-
first_quartile
)
third_quartile
s
-
first_quartile
s
)
# Adjust outer fences if flag is set
if
self
.
_adjust_outer_fences
:
if
self
.
_adjust_outer_fences
:
global_mean
=
np
.
mean
(
abs
(
coeffs
))
global_mean
=
np
.
mean
(
abs
(
coeffs
))
lower_bound
=
min
(
-
global_mean
,
lower_bound
)
lower_bounds
[
lower_bounds
>
-
global_mean
]
=
-
global_mean
upper_bound
=
max
(
global_mean
,
upper_bound
)
upper_bounds
[
upper_bounds
<
global_mean
]
=
global_mean
# # Check for lower extreme outliers and add respective cells
# for cell in sorted_fold:
# if cell[0] < lower_bound:
# troubled_cells.append(int(cell[1]))
# else:
# break
#
# # Check for upper extreme outliers and add respective cells
# for cell in sorted_fold[::-1][:]:
# if cell[0] > upper_bound:
# troubled_cells.append(int(cell[1]))
# else:
# break
# Check for extreme outlier and add respective cells
for
cell
in
self
.
_folds
[
fold
]:
if
(
coeffs
[
cell
]
>
upper_bound
)
\
or
(
coeffs
[
cell
]
<
lower_bound
):
troubled_cells
.
append
(
int
(
cell
))
# print(upper_bound, lower_bound)
# print(sorted_fold_new)
# print(type(sorted_fold_new))
# print(sorted_fold_new > upper_bound)
# print(sorted_fold_new < lower_bound)
# test =
# print(type(test), test)
# print(list(test), list(test[0]))
# troubled_cells_new += list(np.flatnonzero(np.logical_or(
# sorted_fold_new > upper_bound,
# sorted_fold_new < lower_bound)).astype(int))
# print(troubled_cells_new)
# troubled_cells_new = sorted(troubled_cells_new)
troubled_cells_new
=
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)
# print(troubled_cells_new)
# print(troubled_cells)
# print(sorted(troubled_cells) == sorted(troubled_cells_new))
# print(type(troubled_cells_new[0]), type(troubled_cells[0]))
return
sorted
(
troubled_cells
)
return
troubled_cells_new
# return sorted(troubled_cells)
class
Theoretical
(
WaveletDetector
):
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