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
7b5b70f3
Commit
7b5b70f3
authored
2 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Added option to choose multiwavelet degree used in detection.
parent
990f670c
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
+48
-13
48 additions, 13 deletions
Troubled_Cell_Detector.py
with
48 additions
and
13 deletions
Troubled_Cell_Detector.py
+
48
−
13
View file @
7b5b70f3
...
...
@@ -3,10 +3,11 @@
@author: Laura C. Kühle, Soraya Terrab (sorayaterrab)
TODO: Give option to choose from multiwavelet degrees (first, last or
highest magnitude)
highest magnitude)
-> Done
TODO: Change method of calculating quartiles
TODO: Include overlapping cells in quartile calculation (if needed)
TODO: Determine max_value for Theoretical only over highest degree
-> Done (optional)
TODO: Check if indexing in wavelets is correct
TODO: Combine get_cells() and _get_cells()
TODO: Add TC condition to only flag cell if left-adjacent one is flagged as
...
...
@@ -219,9 +220,19 @@ class WaveletDetector(TroubledCellDetector):
config : dict
Additional parameters for detector.
Raises
------
ValueError
If multiwavelet degree is not in [
'
first
'
,
'
last
'
,
'
max
'
].
"""
super
().
_reset
(
config
)
self
.
_wavelet_degree
=
config
.
pop
(
'
multiwavelet_degree
'
,
'
first
'
)
if
self
.
_wavelet_degree
not
in
[
'
first
'
,
'
last
'
,
'
max
'
]:
raise
ValueError
(
'
Invalid entry for multiwavelet degree. It must
'
'
be either
"
first
"
,
"
last
"
, or
"
max
"
.
'
)
# Set wavelet projections
self
.
_wavelet_projection_left
,
self
.
_wavelet_projection_right
\
=
self
.
_basis
.
multiwavelet_projection
...
...
@@ -241,6 +252,7 @@ class WaveletDetector(TroubledCellDetector):
"""
multiwavelet_coeffs
=
self
.
_calculate_wavelet_coeffs
(
projection
)
multiwavelet_coeffs
=
self
.
_select_degree
(
multiwavelet_coeffs
)
return
self
.
_get_cells
(
multiwavelet_coeffs
,
projection
)
def
_calculate_wavelet_coeffs
(
self
,
projection
):
...
...
@@ -254,7 +266,7 @@ class WaveletDetector(TroubledCellDetector):
Returns
-------
ndarray
Matrix of wavelet coefficients.
Matrix of
multi
wavelet coefficients.
"""
output_matrix
=
[]
...
...
@@ -265,6 +277,32 @@ class WaveletDetector(TroubledCellDetector):
output_matrix
.
append
(
new_entry
)
return
np
.
transpose
(
np
.
array
(
output_matrix
))
def
_select_degree
(
self
,
wavelet_matrix
):
"""
Select degree of wavelet coefficients for troubled cell detection.
Select either the first, last, or highest megnitude degree for each
cell from the multiwavelet coefficients.
Parameters
----------
wavelet_matrix : ndarray
Matrix of multiwavelet coefficients.
Returns
-------
ndarray
Matrix of multiwavelet coefficients of selected degree.
"""
if
self
.
_wavelet_degree
==
'
first
'
:
return
wavelet_matrix
[
0
]
elif
self
.
_wavelet_degree
==
'
last
'
:
return
wavelet_matrix
[
-
1
]
else
:
max_values
=
np
.
max
(
wavelet_matrix
,
axis
=
0
)
min_values
=
np
.
min
(
wavelet_matrix
,
axis
=
0
)
return
np
.
where
(
-
min_values
>
max_values
,
min_values
,
max_values
)
@abstractmethod
def
_get_cells
(
self
,
multiwavelet_coeffs
,
projection
):
"""
Calculates troubled cells using multiwavelet coefficients.
...
...
@@ -378,12 +416,12 @@ class Boxplot(WaveletDetector):
fold
*
self
.
_fold_len
-
num_overlapping_cells
,
(
fold
+
1
)
*
self
.
_fold_len
+
num_overlapping_cells
)])
def
_get_cells
(
self
,
multiwavelet_
coeffs
,
projection
):
def
_get_cells
(
self
,
coeffs
,
projection
):
"""
Calculate troubled cells using multiwavelet coefficients.
Parameters
----------
multiwavelet_
coeffs : ndarray
coeffs : ndarray
Matrix of multiwavelet coefficients.
projection : ndarray
Matrix of projection for each polynomial degree.
...
...
@@ -395,7 +433,6 @@ class Boxplot(WaveletDetector):
"""
# Select and sort fold domains
coeffs
=
multiwavelet_coeffs
[
0
]
folds
=
coeffs
[
self
.
_fold_indices
]
folds
.
sort
()
...
...
@@ -477,12 +514,12 @@ class Theoretical(WaveletDetector):
np
.
sqrt
(
2
)
*
self
.
_mesh
.
cell_len
)
# comment to line above: or 2 or 3
def
_get_cells
(
self
,
multiwavelet_
coeffs
,
projection
):
def
_get_cells
(
self
,
coeffs
,
projection
):
"""
Calculates troubled cells using multiwavelet coefficients.
Parameters
----------
multiwavelet_
coeffs : ndarray
coeffs : ndarray
Matrix of multiwavelet coefficients.
projection : ndarray
Matrix of projection for each polynomial degree.
...
...
@@ -499,17 +536,17 @@ class Theoretical(WaveletDetector):
for
cell
in
range
(
self
.
_mesh
.
num_grid_cells
)))
for
cell
in
range
(
self
.
_mesh
.
num_grid_cells
):
if
self
.
_is_troubled_cell
(
multiwavelet_
coeffs
,
cell
,
max_avg
):
if
self
.
_is_troubled_cell
(
coeffs
,
cell
,
max_avg
):
troubled_cells
.
append
(
cell
)
return
troubled_cells
def
_is_troubled_cell
(
self
,
multiwavelet_
coeffs
,
cell
,
max_avg
):
def
_is_troubled_cell
(
self
,
coeffs
,
cell
,
max_avg
):
"""
Checks whether a cell is troubled.
Parameters
----------
multiwavelet_
coeffs : ndarray
coeffs : ndarray
Matrix of multiwavelet coefficients.
cell : int
Index of cell.
...
...
@@ -522,9 +559,7 @@ class Theoretical(WaveletDetector):
Flag whether cell is troubled.
"""
max_value
=
max
(
abs
(
multiwavelet_coeffs
[
degree
][
cell
])
for
degree
in
range
(
self
.
_basis
.
polynomial_degree
+
1
))
/
max_avg
max_value
=
abs
(
coeffs
[
cell
])
/
max_avg
eps
=
self
.
_cutoff_factor
\
/
(
self
.
_mesh
.
cell_len
*
self
.
_mesh
.
num_grid_cells
)
...
...
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